Skip to content

Commit

Permalink
Generate artifacts for all contracts of an ingot (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf authored Jun 1, 2022
1 parent 5dc66d5 commit 7f12b32
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,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<ContractId> {
self.submodules(db)
.iter()
.flat_map(|module| module.all_contracts(db))
.chain((*db.module_contracts(*self)).to_vec())
.collect::<Vec<_>>()
}

/// Returns the map of ingot deps, built-ins, and the ingot itself as
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn compile_module_id(
optimize: bool,
) -> Result<CompiledModule, CompileError> {
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);
Expand Down Expand Up @@ -144,7 +144,7 @@ fn compile_module_id(
_optimize: bool,
) -> Result<CompiledModule, CompileError> {
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);
Expand Down
1 change: 1 addition & 0 deletions newsfragments/726.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate artifacts for all contracts of an ingot, not just for contracts that are defined in `main.fe`

0 comments on commit 7f12b32

Please sign in to comment.