Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions compiler/noirc_frontend/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod type_check;
#[cfg(feature = "aztec")]
pub(crate) mod aztec_library;

use crate::graph::{CrateGraph, CrateId, Dependency};
use crate::graph::{CrateGraph, CrateId, CrateName};
use crate::hir_def::function::FuncMeta;
use crate::node_interner::{FuncId, NodeInterner, StructId};
use def_map::{Contract, CrateDefMap};
Expand Down Expand Up @@ -119,18 +119,34 @@ impl Context {
if &module_id.krate == crate_id {
module_path
} else {
let crate_name = &self.crate_graph[crate_id]
.dependencies
.iter()
.find_map(|dep| match dep {
Dependency { name, crate_id } if crate_id == &module_id.krate => Some(name),
_ => None,
})
.expect("The Struct was supposed to be defined in a dependency");
format!("{crate_name}::{module_path}")
let crates = self.find_dependencies(crate_id, &module_id.krate);
assert!(!crates.is_empty(), "The Struct was supposed to be defined in a dependency");
let mut fqn = String::new();
for name in crates {
fqn += &name.to_string();
fqn += "::";
}
fqn += &module_path;
fqn
Comment thread
guipublic marked this conversation as resolved.
Outdated
}
}

/// Recursively walks down the crate dependency graph from crate_id until we reach requested crate
/// returns the path from crate_id to target_crate_id
Comment thread
kevaundray marked this conversation as resolved.
Outdated
fn find_dependencies(&self, crate_id: &CrateId, target_crate_id: &CrateId) -> Vec<CrateName> {
for dep in &self.crate_graph[crate_id].dependencies {
if &dep.crate_id == target_crate_id {
return vec![dep.name.clone()];
}
let mut fqn = self.find_dependencies(&dep.crate_id, target_crate_id);
if !fqn.is_empty() {
fqn.insert(0, dep.name.clone());
return fqn;
}
}
Vec::new()
}
Comment thread
guipublic marked this conversation as resolved.
Outdated

pub fn function_meta(&self, func_id: &FuncId) -> FuncMeta {
self.def_interner.function_meta(func_id)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = [
"library",
"library2",
"binary"
]
default-member = "binary"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "binary"
type = "bin"
authors = [""]
[dependencies]
library = { path = "../library" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use dep::library::ReExportMeFromAnotherLib;
fn main(_x : ReExportMeFromAnotherLib) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "library"
type = "lib"
authors = [""]

[dependencies]
library2 = { path = "../library2"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Re-export
use dep::library2::ReExportMeFromAnotherLib;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "library"
type = "lib"
authors = [""]
[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// When we re-export this type from another library and then use it in
// main, we get a panic
struct ReExportMeFromAnotherLib {
x : Field,
}