Skip to content

Commit 5800a88

Browse files
authored
Canonicalize function dependency resolusion (argotorg#818)
1 parent 92273c3 commit 5800a88

10 files changed

Lines changed: 25 additions & 33 deletions

crates/codegen/src/yul/isel/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::BTreeSet;
1+
use indexmap::IndexSet;
22

33
use fe_analyzer::namespace::items::ContractId;
44
use fe_mir::ir::FunctionId;
@@ -14,19 +14,19 @@ use super::{lower_contract_deployable, lower_function};
1414

1515
pub struct Context {
1616
pub runtime: Box<dyn RuntimeProvider>,
17-
pub(super) contract_dependency: BTreeSet<ContractId>,
18-
pub(super) function_dependency: BTreeSet<FunctionId>,
19-
pub(super) string_constants: BTreeSet<String>,
17+
pub(super) contract_dependency: IndexSet<ContractId>,
18+
pub(super) function_dependency: IndexSet<FunctionId>,
19+
pub(super) string_constants: IndexSet<String>,
2020
pub(super) lowered_functions: FxHashSet<FunctionId>,
2121
}
2222

2323
impl Default for Context {
2424
fn default() -> Self {
2525
Self {
2626
runtime: Box::new(DefaultRuntimeProvider::default()),
27-
contract_dependency: BTreeSet::default(),
28-
function_dependency: BTreeSet::default(),
29-
string_constants: BTreeSet::default(),
27+
contract_dependency: IndexSet::default(),
28+
function_dependency: IndexSet::default(),
29+
string_constants: IndexSet::default(),
3030
lowered_functions: FxHashSet::default(),
3131
}
3232
}

crates/codegen/src/yul/runtime/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::fmt::Write;
1010
use fe_abi::types::AbiType;
1111
use fe_analyzer::namespace::items::ContractId;
1212
use fe_mir::ir::{types::ArrayDef, FunctionId, TypeId, TypeKind};
13-
use fxhash::FxHashMap;
13+
use indexmap::IndexMap;
1414
use yultsur::*;
1515

1616
use num_bigint::BigInt;
@@ -225,7 +225,7 @@ pub enum AbiSrcLocation {
225225

226226
#[derive(Debug, Default)]
227227
pub struct DefaultRuntimeProvider {
228-
functions: FxHashMap<String, RuntimeFunction>,
228+
functions: IndexMap<String, RuntimeFunction>,
229229
}
230230

231231
impl DefaultRuntimeProvider {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
22
source: crates/tests/src/demo_simple_open_auction.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
bid([]) used 46237 gas
76
bid([]) used 25163 gas
87
withdraw([]) used 15382 gas
98
withdraw([]) used 2429 gas
10-
action_end([]) used 31535 gas
9+
action_end([]) used 31546 gas
1110

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
22
source: crates/tests/src/demo_uniswap.rs
33
expression: "format!(\"{}\", pair_harness.gas_reporter)"
4-
54
---
65
factory([]) used 271 gas
76
token0([]) used 293 gas
87
token1([]) used 315 gas
9-
mint([Address(0x1000000000000000000000000000000000000001)]) used 148541 gas
8+
mint([Address(0x1000000000000000000000000000000000000001)]) used 148540 gas
109
balanceOf([Address(0x1000000000000000000000000000000000000001)]) used 621 gas
1110
balanceOf([Address(0x0000000000000000000000000000000000000000)]) used 621 gas
1211
get_reserves([]) used 797 gas
1312
swap([Uint(1993), Uint(0), Address(0x0000000000000000000000000000000000000042)]) used 36362 gas
1413
get_reserves([]) used 797 gas
15-
transfer([Address(0x1e5a8bf4270c9ed3be04fe19fc875bd758132f4f), Uint(141421356237309503880)]) used 5795 gas
14+
transfer([Address(0x6af4454cb2fc3fdb7e4319d63e1ed9ef7e9c16b8), Uint(141421356237309503880)]) used 5796 gas
1615
burn([Address(0x1000000000000000000000000000000000000001)]) used 3669 gas
1716
get_reserves([]) used 797 gas
1817

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
6-
my_balance([]) used 125 gas
5+
my_balance([]) used 114 gas
76
other_balance([Address(0x5dddfce53ee040d9eb21afbc0ae1bb4dbb0ba643)]) used 311 gas
87
other_balance([Address(0x2000000000000000000000000000000000000002)]) used 2811 gas
9-
my_balance([]) used 125 gas
8+
my_balance([]) used 114 gas
109
other_balance([Address(0x5dddfce53ee040d9eb21afbc0ae1bb4dbb0ba643)]) used 311 gas
1110
other_balance([Address(0x2000000000000000000000000000000000000002)]) used 311 gas
1211

crates/tests/src/snapshots/fe_compiler_tests__features__checked_arithmetic.snap

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
add_u8([Uint(255), Uint(0)]) used 445 gas
76
add_i8([Int(127), Int(0)]) used 713 gas
@@ -39,22 +38,22 @@ mod_i16([Int(1157920892373161954235709850086879078532699846656405640394575840079
3938
mul_u16([Uint(65535), Uint(1)]) used 1231 gas
4039
mul_i16([Int(32767), Int(1)]) used 1616 gas
4140
mul_i16([Int(115792089237316195423570985008687907853269984665640564039457584007913129607168), Int(1)]) used 1616 gas
42-
add_u32([Uint(4294967295), Uint(0)]) used 400 gas
41+
add_u32([Uint(4294967295), Uint(0)]) used 401 gas
4342
add_i32([Int(2147483647), Int(0)]) used 667 gas
4443
add_i32([Int(115792089237316195423570985008687907853269984665640564039457584007910982156288), Int(0)]) used 667 gas
45-
sub_u32([Uint(0), Uint(0)]) used 658 gas
44+
sub_u32([Uint(0), Uint(0)]) used 659 gas
4645
sub_i32([Int(115792089237316195423570985008687907853269984665640564039457584007910982156288), Int(0)]) used 931 gas
4746
sub_i32([Int(2147483647), Int(0)]) used 931 gas
48-
div_u32([Uint(3), Uint(2)]) used 921 gas
47+
div_u32([Uint(3), Uint(2)]) used 922 gas
4948
div_i32([Int(3), Int(115792089237316195423570985008687907853269984665640564039457584007913129639934)]) used 1176 gas
50-
pow_u32([Uint(2), Uint(31)]) used 1839 gas
49+
pow_u32([Uint(2), Uint(31)]) used 1840 gas
5150
pow_i32([Int(2), Uint(30)]) used 2645 gas
5251
pow_i32([Int(115792089237316195423570985008687907853269984665640564039457584007913129639934), Uint(31)]) used 2682 gas
53-
mod_u32([Uint(4294967295), Uint(2)]) used 1449 gas
52+
mod_u32([Uint(4294967295), Uint(2)]) used 1450 gas
5453
mod_i32([Int(2147483647), Int(2)]) used 1663 gas
5554
mod_i32([Int(13), Int(115792089237316195423570985008687907853269984665640564039457584007913129639933)]) used 1663 gas
5655
mod_i32([Int(115792089237316195423570985008687907853269984665640564039457584007913129639923), Int(3)]) used 1663 gas
57-
mul_u32([Uint(4294967295), Uint(1)]) used 1208 gas
56+
mul_u32([Uint(4294967295), Uint(1)]) used 1209 gas
5857
mul_i32([Int(2147483647), Int(1)]) used 1594 gas
5958
mul_i32([Int(115792089237316195423570985008687907853269984665640564039457584007910982156288), Int(1)]) used 1594 gas
6059
add_u64([Uint(18446744073709551615), Uint(0)]) used 421 gas

crates/tests/src/snapshots/fe_compiler_tests__features__enum_match.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
simple_match([Uint(1), Uint(2)]) used 573 gas
76
nested_match([Uint(1), Uint(2)]) used 1502 gas
@@ -21,5 +20,5 @@ rest_pattern_middle([Uint(1), Uint(2)]) used 3256 gas
2120
simple_struct([Int(1), Int(2), Bool(true)]) used 1046 gas
2221
simple_struct([Int(1), Int(2), Bool(false)]) used 1060 gas
2322
nested_struct([]) used 1895 gas
24-
enum_storage([Uint(1), Uint(2), Bool(true)]) used 90860 gas
23+
enum_storage([Uint(1), Uint(2), Bool(true)]) used 90861 gas
2524

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
emit_nums([]) used 1600 gas
76
emit_bases([Address(0x1234000000000000000000000000000000005678)]) used 1673 gas
8-
emit_mix([Address(0x1234000000000000000000000000000000005678), Bytes([116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46])]) used 5316 gas
9-
emit_addresses([Address(0x1234000000000000000000000000000000005678), Address(0x9123000000000000000000000000000000004567)]) used 2672 gas
7+
emit_mix([Address(0x1234000000000000000000000000000000005678), Bytes([116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46, 116, 101, 110, 32, 98, 121, 116, 101, 115, 46])]) used 5255 gas
8+
emit_addresses([Address(0x1234000000000000000000000000000000005678), Address(0x9123000000000000000000000000000000004567)]) used 2625 gas
109

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
static_complex([]) used 614 gas
76
string_complex([]) used 1380 gas
87
bytes_complex([]) used 931 gas
9-
nested_dynamic_complex([]) used 4301 gas
8+
nested_dynamic_complex([]) used 4332 gas
109

crates/tests/src/snapshots/fe_compiler_tests__features__sized_vals_in_sto.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
22
source: crates/tests/src/features.rs
33
expression: "format!(\"{}\", harness.gas_reporter)"
4-
54
---
65
write_num([Uint(68)]) used 22210 gas
76
read_num([]) used 265 gas
8-
write_nums([FixedArray([Uint(0), Uint(1), Uint(2), Uint(3), Uint(4), Uint(5), Uint(6), Uint(7), Uint(8), Uint(9), Uint(10), Uint(11), Uint(12), Uint(13), Uint(14), Uint(15), Uint(16), Uint(17), Uint(18), Uint(19), Uint(20), Uint(21), Uint(22), Uint(23), Uint(24), Uint(25), Uint(26), Uint(27), Uint(28), Uint(29), Uint(30), Uint(31), Uint(32), Uint(33), Uint(34), Uint(35), Uint(36), Uint(37), Uint(38), Uint(39), Uint(40), Uint(41)])]) used 912898 gas
7+
write_nums([FixedArray([Uint(0), Uint(1), Uint(2), Uint(3), Uint(4), Uint(5), Uint(6), Uint(7), Uint(8), Uint(9), Uint(10), Uint(11), Uint(12), Uint(13), Uint(14), Uint(15), Uint(16), Uint(17), Uint(18), Uint(19), Uint(20), Uint(21), Uint(22), Uint(23), Uint(24), Uint(25), Uint(26), Uint(27), Uint(28), Uint(29), Uint(30), Uint(31), Uint(32), Uint(33), Uint(34), Uint(35), Uint(36), Uint(37), Uint(38), Uint(39), Uint(40), Uint(41)])]) used 912897 gas
98
read_nums([]) used 11796 gas
109
write_str([String("there are 26 protons in fe")]) used 44918 gas
1110
read_str([]) used 1228 gas

0 commit comments

Comments
 (0)