diff --git a/crates/analyzer/src/namespace/items.rs b/crates/analyzer/src/namespace/items.rs index b669042952..a582ef0941 100644 --- a/crates/analyzer/src/namespace/items.rs +++ b/crates/analyzer/src/namespace/items.rs @@ -690,9 +690,13 @@ impl ModuleId { db.module_parent_module(*self) } - /// All contracts, including duplicates - pub fn all_contracts(&self, db: &dyn AnalyzerDb) -> Rc<[ContractId]> { - db.module_contracts(*self) + /// All contracts, including from submodules and including duplicates + pub fn all_contracts(&self, db: &dyn AnalyzerDb) -> Vec { + self.submodules(db) + .iter() + .flat_map(|module| module.all_contracts(db)) + .chain((*db.module_contracts(*self)).to_vec()) + .collect::>() } /// Returns the map of ingot deps, built-ins, and the ingot itself as diff --git a/crates/driver/src/lib.rs b/crates/driver/src/lib.rs index 80972fc053..fa4b085fa2 100644 --- a/crates/driver/src/lib.rs +++ b/crates/driver/src/lib.rs @@ -107,7 +107,7 @@ fn compile_module_id( optimize: bool, ) -> Result { let mut contracts = IndexMap::default(); - for &contract in module_id.all_contracts(db.upcast()).as_ref() { + for contract in module_id.all_contracts(db.upcast()) { let name = &contract.data(db.upcast()).name; let abi = db.codegen_abi_contract(contract); let yul_contract = compile_to_yul(db, contract); @@ -144,7 +144,7 @@ fn compile_module_id( _optimize: bool, ) -> Result { let mut contracts = IndexMap::default(); - for &contract in module_id.all_contracts(db.upcast()).as_ref() { + for contract in module_id.all_contracts(db.upcast()) { let name = &contract.data(db.upcast()).name; let abi = db.codegen_abi_contract(contract); let yul_contract = compile_to_yul(db, contract); diff --git a/newsfragments/726.feature.md b/newsfragments/726.feature.md new file mode 100644 index 0000000000..b07070738e --- /dev/null +++ b/newsfragments/726.feature.md @@ -0,0 +1 @@ +Generate artifacts for all contracts of an ingot, not just for contracts that are defined in `main.fe`