From 586c0b019d0c2c462188f03c9c31d25a46e35eb6 Mon Sep 17 00:00:00 2001 From: Gregorio Juliana Date: Fri, 5 Jul 2024 10:31:15 +0200 Subject: [PATCH] fix: Allow importing notes from other contracts and inject them in the macros (#7349) Removes an overzealous check that prevented pulling note structs from imported contract dependencies. Since we make sure we only import the same struct once from the "closest" source to the root crate, it should be ok to pull notes from them (at least to generate `compute_note_hash_and_optionally_a_nullifier`. God I hate that name) --- noir-projects/noir-contracts/Nargo.toml | 2 +- .../aztec_macros/src/utils/hir_utils.rs | 37 ++++++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index 534ec69b457..13e3d4d0613 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -44,5 +44,5 @@ members = [ "contracts/uniswap_contract", "contracts/multi_call_entrypoint_contract", "contracts/static_child_contract", - "contracts/static_parent_contract" + "contracts/static_parent_contract", ] diff --git a/noir/noir-repo/aztec_macros/src/utils/hir_utils.rs b/noir/noir-repo/aztec_macros/src/utils/hir_utils.rs index 3f47fe5ca25..7198ed5bd3d 100644 --- a/noir/noir-repo/aztec_macros/src/utils/hir_utils.rs +++ b/noir/noir-repo/aztec_macros/src/utils/hir_utils.rs @@ -269,20 +269,12 @@ pub fn fully_qualified_note_path(context: &HirContext, note_id: StructId) -> Opt if &module_id.krate == context.root_crate_id() { Some(module_path) } else { - find_non_contract_dependencies_bfs(context, context.root_crate_id(), &module_id.krate) + find_dependencies_bfs(context, context.root_crate_id(), &module_id.krate) .map(|crates| crates.join("::") + "::" + &module_path) } } -fn filter_contract_modules(context: &HirContext, crate_id: &CrateId) -> bool { - if let Some(def_map) = context.def_map(crate_id) { - !def_map.modules().iter().any(|(_, module)| module.is_contract) - } else { - true - } -} - -fn find_non_contract_dependencies_bfs( +fn find_dependencies_bfs( context: &HirContext, crate_id: &CrateId, target_crate_id: &CrateId, @@ -290,7 +282,6 @@ fn find_non_contract_dependencies_bfs( context.crate_graph[crate_id] .dependencies .iter() - .filter(|dep| filter_contract_modules(context, &dep.crate_id)) .find_map(|dep| { if &dep.crate_id == target_crate_id { Some(vec![dep.name.to_string()]) @@ -299,20 +290,16 @@ fn find_non_contract_dependencies_bfs( } }) .or_else(|| { - context.crate_graph[crate_id] - .dependencies - .iter() - .filter(|dep| filter_contract_modules(context, &dep.crate_id)) - .find_map(|dep| { - if let Some(mut path) = - find_non_contract_dependencies_bfs(context, &dep.crate_id, target_crate_id) - { - path.insert(0, dep.name.to_string()); - Some(path) - } else { - None - } - }) + context.crate_graph[crate_id].dependencies.iter().find_map(|dep| { + if let Some(mut path) = + find_dependencies_bfs(context, &dep.crate_id, target_crate_id) + { + path.insert(0, dep.name.to_string()); + Some(path) + } else { + None + } + }) }) }