Skip to content

Commit 4241d2b

Browse files
committed
Contract id cleanup
1 parent e691a96 commit 4241d2b

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

crates/compilers/src/preprocessor/data.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ pub fn collect_preprocessor_data(
3838
continue;
3939
}
4040

41-
let contract_data = ContractData::new(hir, contract, path, source, sess.source_map());
42-
data.insert(contract_data.hir_id, contract_data);
41+
let contract_data =
42+
ContractData::new(hir, contract_id, contract, path, source, sess.source_map());
43+
data.insert(contract_id, contract_data);
4344
}
4445
data
4546
}
@@ -49,9 +50,9 @@ pub fn collect_preprocessor_data(
4950
/// See [`ContractData::build_helper`] for more details.
5051
pub fn create_deploy_helpers(data: &BTreeMap<u32, ContractData>) -> Sources {
5152
let mut deploy_helpers = Sources::new();
52-
for (hir_id, contract) in data {
53+
for (contract_id, contract) in data {
5354
if let Some(code) = contract.build_helper() {
54-
let path = format!("foundry-pp/DeployHelper{hir_id}.sol");
55+
let path = format!("foundry-pp/DeployHelper{contract_id}.sol");
5556
deploy_helpers.insert(path.into(), Source::new(code));
5657
}
5758
}
@@ -71,7 +72,7 @@ pub struct ContractConstructorData {
7172
#[derive(Debug)]
7273
pub struct ContractData {
7374
/// HIR Id of the contract.
74-
hir_id: u32,
75+
contract_id: u32,
7576
/// Path of the source file.
7677
path: PathBuf,
7778
/// Name of the contract
@@ -85,6 +86,7 @@ pub struct ContractData {
8586
impl ContractData {
8687
fn new(
8788
hir: &Hir<'_>,
89+
contract_id: u32,
8890
contract: &Contract<'_>,
8991
path: &Path,
9092
source: &solar_sema::hir::Source<'_>,
@@ -121,7 +123,7 @@ impl ContractData {
121123
});
122124

123125
Self {
124-
hir_id: contract.linearized_bases[0].get(),
126+
contract_id,
125127
path: path.to_path_buf(),
126128
name: contract.name.to_string(),
127129
constructor_data,
@@ -173,12 +175,12 @@ impl ContractData {
173175
/// vm.deployCode("artifact path", encodeArgs335(DeployHelper335.ConstructorArgs({name: name, symbol: symbol})))
174176
/// ```
175177
pub fn build_helper(&self) -> Option<String> {
176-
let Self { hir_id, path, name, constructor_data, artifact } = self;
178+
let Self { contract_id, path, name, constructor_data, artifact } = self;
177179

178180
let Some(constructor_details) = constructor_data else { return None };
179181
let struct_fields = &constructor_details.struct_fields;
180182
let abi_encode_args = &constructor_details.abi_encode_args;
181-
let vm_interface_name = format!("VmContractHelper{hir_id}");
183+
let vm_interface_name = format!("VmContractHelper{contract_id}");
182184
let vm = format!("{vm_interface_name}(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D)");
183185

184186
let helper = format!(
@@ -187,18 +189,18 @@ pragma solidity >=0.4.0;
187189
188190
import "{path}";
189191
190-
abstract contract DeployHelper{hir_id} is {name} {{
192+
abstract contract DeployHelper{contract_id} is {name} {{
191193
struct ConstructorArgs {{
192194
{struct_fields};
193195
}}
194196
}}
195197
196-
function encodeArgs{hir_id}(DeployHelper{hir_id}.ConstructorArgs memory args) pure returns (bytes memory) {{
198+
function encodeArgs{contract_id}(DeployHelper{contract_id}.ConstructorArgs memory args) pure returns (bytes memory) {{
197199
return abi.encode({abi_encode_args});
198200
}}
199201
200-
function deployCode{hir_id}(DeployHelper{hir_id}.ConstructorArgs memory args) returns({name}) {{
201-
return {name}(payable({vm}.deployCode("{artifact}", encodeArgs{hir_id}(args))));
202+
function deployCode{contract_id}(DeployHelper{contract_id}.ConstructorArgs memory args) returns({name}) {{
203+
return {name}(payable({vm}.deployCode("{artifact}", encodeArgs{contract_id}(args))));
202204
}}
203205
204206
interface {vm_interface_name} {{

crates/compilers/src/preprocessor/deps.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ impl PreprocessorDependencies {
3030
pub fn new(sess: &Session, hir: &Hir<'_>, paths: &[PathBuf]) -> Self {
3131
let mut inner = BTreeMap::new();
3232
let mut references = HashSet::default();
33-
for contract in Hir::contracts(hir) {
33+
for contract_id in Hir::contract_ids(hir) {
34+
let contract = Hir::contract(hir, contract_id);
3435
let source = Hir::source(hir, contract.source);
3536

3637
let FileName::Real(path) = &source.file.name else {
@@ -48,7 +49,7 @@ impl PreprocessorDependencies {
4849
deps_collector.walk_contract(contract);
4950
// Ignore empty test contracts declared in source files with other contracts.
5051
if !deps_collector.dependencies.is_empty() {
51-
inner.insert(contract.linearized_bases[0].get(), deps_collector.dependencies);
52+
inner.insert(contract_id.get(), deps_collector.dependencies);
5253
}
5354
// Record collected referenced contract ids.
5455
references.extend(deps_collector.referenced_contracts);

0 commit comments

Comments
 (0)