Skip to content

Commit

Permalink
Fix inlining issue (#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd authored Sep 18, 2023
1 parent 466ab4d commit edcf905
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 34 deletions.
22 changes: 21 additions & 1 deletion compiler/ast/src/passes/reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,27 @@ pub trait ExpressionReconstructor {
}

fn reconstruct_struct_init(&mut self, input: StructExpression) -> (Expression, Self::AdditionalOutput) {
(Expression::Struct(input), Default::default())
(
Expression::Struct(StructExpression {
name: input.name,
members: input
.members
.into_iter()
.map(|member| StructVariableInitializer {
identifier: member.identifier,
expression: match member.expression {
Some(expression) => Some(self.reconstruct_expression(expression).0),
None => Some(self.reconstruct_expression(Expression::Identifier(member.identifier)).0),
},
span: member.span,
id: member.id,
})
.collect(),
span: input.span,
id: input.id,
}),
Default::default(),
)
}

fn reconstruct_err(&mut self, _input: ErrExpression) -> (Expression, Self::AdditionalOutput) {
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/compiler/examples/board.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: 747ce7178d5222a287460a44a6af1dda0d4d2646d3dafca6a24f3a1c71de86ce
unrolled_symbol_table: 747ce7178d5222a287460a44a6af1dda0d4d2646d3dafca6a24f3a1c71de86ce
initial_ast: d5be8fee6d81e342960c0422830cad66747617795c5fa7adaedb2088dce3be97
unrolled_ast: d5be8fee6d81e342960c0422830cad66747617795c5fa7adaedb2088dce3be97
unrolled_ast: f85ac52da5c38ffb02718a9d5e69c840362012106291fee2348c3d937568f996
ssa_ast: 304bd2dd3450cd385a9f760eea0519cd86025712e4a11da1403b8bffb23816fe
flattened_ast: 2826ed0f1c04c254a9caef5459eeeb756f0868b9680d6dda27689c86ec856602
inlined_ast: 2826ed0f1c04c254a9caef5459eeeb756f0868b9680d6dda27689c86ec856602
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/compiler/examples/move.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: 1d7d583684c95811cd86e4ed36c9d20ac015eef8804fa6f5a9a53b5648c5d0c2
unrolled_symbol_table: 1d7d583684c95811cd86e4ed36c9d20ac015eef8804fa6f5a9a53b5648c5d0c2
initial_ast: bd5d74d72808b4c41ce341a9de74a1c97c825cdf6f682e37c24500468f10be7f
unrolled_ast: bd5d74d72808b4c41ce341a9de74a1c97c825cdf6f682e37c24500468f10be7f
unrolled_ast: e9fe622558335f8a9e478050ceb11174df84db5c7dac987500d81b69daf25375
ssa_ast: bdf2b040f0aa692dabb75d575d09d874194812e717ea89ae36c0bbbd8477a686
flattened_ast: ebabd9d811704b1e60109ca18e2091c63c740005712e3b8e475f8bd0ed48f110
inlined_ast: ebabd9d811704b1e60109ca18e2091c63c740005712e3b8e475f8bd0ed48f110
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/compiler/examples/vote.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: 1ffc999a1854e9e7698468455416d3e4a8633b1295681d4598ec850b49e41cc8
unrolled_symbol_table: 1ffc999a1854e9e7698468455416d3e4a8633b1295681d4598ec850b49e41cc8
initial_ast: cfa18935bddbcde425dfcd4420cdc332bc22cb8f20347c19e974e5745175c448
unrolled_ast: cfa18935bddbcde425dfcd4420cdc332bc22cb8f20347c19e974e5745175c448
unrolled_ast: f14edaac6648de812672a9b72416d49ba67aa74aee127572fe791adf26c21261
ssa_ast: 9db70fe3ef5b857ba47ade60a4dce039ff7afed2fcccd82ed484f5f0d10a839b
flattened_ast: f766a37610cbe458b5a2cc6a22652be6041b07a128899d66b1f449c4bc6ebb65
inlined_ast: f766a37610cbe458b5a2cc6a22652be6041b07a128899d66b1f449c4bc6ebb65
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ outputs:
unrolled_ast: bd57ac53308a67d19485d7f29a006bdd8d780ca05f2427ba0393e63ac000afd9
ssa_ast: 028180997e2f609c93e912c59bb2b84dc43c33ea8aec28ef1e651659f05e961c
flattened_ast: 48008bc440590f8d6f7eec80daffb815a5c340efe5d389fe73a8bf28e236f025
inlined_ast: 8b336b9b7625dcdcb9f70568d2aacf41386860af6f2d8b34789dff18c0b18e9c
dce_ast: 8b336b9b7625dcdcb9f70568d2aacf41386860af6f2d8b34789dff18c0b18e9c
bytecode: 7602c293bf2fee12ca5d58f3651e9a5699a3c1350fc34b8000dfc598ecd77226
inlined_ast: 67800ff1866545d51b8cb58cf19307ad33e11e1d1c9a329d58ca965657d2809e
dce_ast: 67800ff1866545d51b8cb58cf19307ad33e11e1d1c9a329d58ca965657d2809e
bytecode: fffe093215f68fcc292f2c7b67e847897cd0334cdbf4a410f288d7957541a1d3
warnings: ""
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: ba25da0ee16aeea7f700fb370ea16e4fc2ba379bcf5fee6639826dcd2541bb14
unrolled_symbol_table: ba25da0ee16aeea7f700fb370ea16e4fc2ba379bcf5fee6639826dcd2541bb14
initial_ast: 42727bc4ab4e9294867ee74a08e2fe78ff3112b999b4432135e52856576c8e99
unrolled_ast: 42727bc4ab4e9294867ee74a08e2fe78ff3112b999b4432135e52856576c8e99
unrolled_ast: 7f3d5e14802552b7d376dc7f809a962a99e49bf7b7b874cb9efea211873c59d6
ssa_ast: 45a7e89d56652adafaa251a2141711f47e772e2b55a4397e257892bebf01965b
flattened_ast: 5b0af0aebd2d18b4af1d877c888ccc6b3fa29b2e591452720740f4eb678b08d4
inlined_ast: 5b0af0aebd2d18b4af1d877c888ccc6b3fa29b2e591452720740f4eb678b08d4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: 6c6790dd39288815379930977d3d72470a1449cd1b1993c0808cd53534d1f826
unrolled_symbol_table: 6c6790dd39288815379930977d3d72470a1449cd1b1993c0808cd53534d1f826
initial_ast: d62a5becf30494a5c07d515c158267012b6d1c3fdeb88fb07e2f054381cf8acd
unrolled_ast: d62a5becf30494a5c07d515c158267012b6d1c3fdeb88fb07e2f054381cf8acd
unrolled_ast: abcbeedd216970478f0f15f4183a6cbb672601ae80e98ee74cde45e87bc83d40
ssa_ast: ffe50cb7be9258000936ebe65897df029f1d552661be9e398cf932536a04a5c6
flattened_ast: 4efc05812dd074b640d27237c1efbeb006d2948ba97e377be1acaa92ca246a64
inlined_ast: 4efc05812dd074b640d27237c1efbeb006d2948ba97e377be1acaa92ca246a64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
namespace: Execute
expectation: Pass
outputs:
- - initial_symbol_table: 054d3814a6ee68b36846e8bb0a850749c9f80828a06106a3408c3a3445bf9e5c
type_checked_symbol_table: 13284925b72baff0d5ecb7bb256a8bfb9fd6e3f936997707c6c832b3f2d34b43
unrolled_symbol_table: 13284925b72baff0d5ecb7bb256a8bfb9fd6e3f936997707c6c832b3f2d34b43
initial_ast: 312ddd4f956e0c21463e992634f659afb147d2916b2dd3ea3b4cdf77da83ea2d
unrolled_ast: 312ddd4f956e0c21463e992634f659afb147d2916b2dd3ea3b4cdf77da83ea2d
ssa_ast: 916c11c30f5603bd550dd9f02a59cff5ad3dac9519817506e44ab4e041ae53dd
flattened_ast: fa0c633312b9e571902cc78901d6daf2f05121c9081ff23d76d5521af8b9dc35
inlined_ast: f2fb9af6d7aa19ee8bad573bb9cdb2d96cb80022e2bbee84d0f2679e98a49259
dce_ast: f2fb9af6d7aa19ee8bad573bb9cdb2d96cb80022e2bbee84d0f2679e98a49259
bytecode: 05437006a7a0a278a18c8ff76e9fec336ec4f86f6ff8abfb06b816256babef45
- - initial_symbol_table: 9ee9bfe1921cee5f4de19fea4d372a2a54deb758471e5745e12164eb44c447cb
type_checked_symbol_table: 8c2546e10d7482d30a2650f0119041c8a6a20201eb47a4facfe20336976e5654
unrolled_symbol_table: 8c2546e10d7482d30a2650f0119041c8a6a20201eb47a4facfe20336976e5654
initial_ast: 68d7ba720407b7ac2fc26611b2f22c2d2f43766df3a30c05745f152aa9d3caa0
unrolled_ast: 68d7ba720407b7ac2fc26611b2f22c2d2f43766df3a30c05745f152aa9d3caa0
ssa_ast: a66901fb9ee02bc0cd23f2ca49f2b47d7dea7ee398098bc3b72edbf01977b8cc
flattened_ast: 4e3c46685c28a9d7a4169000de7d3c888e3a0ad28500b17b31eb784d189ce86d
inlined_ast: 3fbe6e8a6cd5e19c47e8f8b0a9bceca1534a2219fb6a4443529056cdbb1799c7
dce_ast: 3fbe6e8a6cd5e19c47e8f8b0a9bceca1534a2219fb6a4443529056cdbb1799c7
bytecode: a52c852c5ea5e31d35c812e4ab15e4c098022431bb58b592d797137abf015e29
warnings: ""
results:
bar:
- input: "[true, true, 1u8, 0u8]"
output: "[1u8, 1u8, {\n a: 1u8,\n b: 0u8,\n c: {\n c: 1u8\n }\n}]"
output: "[4u8, 1u8, {\n a: 2u8,\n b: 1u8,\n c: {\n c: 2u8\n }\n}]"
- input: "[true, false, 1u8, 1u8]"
output: "[1u8, 1u8, {\n a: 1u8,\n b: 1u8,\n c: {\n c: 1u8\n }\n}]"
- input: "[false, true, 2u8, 1u8]"
output: "[1u8, 1u8, {\n a: 2u8,\n b: 1u8,\n c: {\n c: 2u8\n }\n}]"
output: "[5u8, 2u8, {\n a: 2u8,\n b: 1u8,\n c: {\n c: 2u8\n }\n}]"
- input: "[false, false, 2u8, 2u8]"
output: "[2u8, 2u8, {\n a: 2u8,\n b: 2u8,\n c: {\n c: 2u8\n }\n}]"
blar:
- input: "[true, true, 1u8, 0u8]"
output: "[1u8, 1u8, {\n a: 1u8,\n b: 1u8,\n c: {\n c: 1u8\n }\n}]"
output: "[4u8, 1u8, {\n a: 2u8,\n b: 1u8,\n c: {\n c: 2u8\n }\n}]"
- input: "[true, false, 1u8, 1u8]"
output: "[1u8, 1u8, {\n a: 1u8,\n b: 1u8,\n c: {\n c: 1u8\n }\n}]"
- input: "[false, true, 2u8, 1u8]"
output: "[1u8, 1u8, {\n a: 1u8,\n b: 1u8,\n c: {\n c: 1u8\n }\n}]"
output: "[5u8, 2u8, {\n a: 2u8,\n b: 1u8,\n c: {\n c: 2u8\n }\n}]"
- input: "[false, false, 2u8, 2u8]"
output: "[2u8, 2u8, {\n a: 2u8,\n b: 2u8,\n c: {\n c: 2u8\n }\n}]"
2 changes: 1 addition & 1 deletion tests/expectations/execution/mint.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ outputs:
type_checked_symbol_table: 538833491862c70880a4292ef436391c2be4483e6bd4c144c53d1dbbe3d58740
unrolled_symbol_table: 538833491862c70880a4292ef436391c2be4483e6bd4c144c53d1dbbe3d58740
initial_ast: 52c7b2b75064c6546d44fc697f86b746d9cd07e316cfb4dc93cccabf63d0708c
unrolled_ast: 52c7b2b75064c6546d44fc697f86b746d9cd07e316cfb4dc93cccabf63d0708c
unrolled_ast: a0c8e83b0bbb7a6759b2bf5a4635aa9b19ff33d6edc3013ecdaa3ed76fcacf80
ssa_ast: afc1d818c985c0fd4aee5264405f7758c96810c5362c7764b71d60bc8da32ff5
flattened_ast: e24f4c783778f4b9508e45bef5d7e2c69eb220d8d16f3cb5c86cb5bb145ce19e
inlined_ast: e24f4c783778f4b9508e45bef5d7e2c69eb220d8d16f3cb5c86cb5bb145ce19e
Expand Down
32 changes: 22 additions & 10 deletions tests/tests/execution/flattened_function_and_inline_matches.leo
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,65 @@ program test.aleo {
c: Extra,
}

inline foo(a: u8, b: u8) -> (u8, u8, Data) {
inline foo(a: u8, b: u8, input: Data) -> (u8, u8, Data) {
let extra: Extra = Extra { c: a };
let data: Data = Data { a: a, b: b, c: extra };
if (a == b) {
return (a, b, data);
}
let c: u8 = a + b;
let d: u8 = a - b;
c = c + input.a;
d = d + input.b;

return (c, d, data);
}

function floo(a: u8, b: u8) -> (u8, u8, Data) {
function floo(a: u8, b: u8, input: Data) -> (u8, u8, Data) {
let extra: Extra = Extra { c: a };
let data: Data = Data { a: a, b: b, c: extra };
if (a == b) {
return (a, b, data);
}
let c: u8 = a + b;
let d: u8 = a - b;
c = c + input.a;
d = d + input.b;

return (c, d, data);
}

transition bar(flag1: bool, flag2: bool, a: u8, b: u8) -> (u8, u8, Data) {
let start: (u8, u8, Data) = foo(a, b);
let data: Data = Data { a: a, b: b, c: Extra { c: a } };
let start: (u8, u8, Data) = foo(a, b, data);
// (2, 1, Data { a: 1, b: 0, c: Extra { c: 1 } })
if flag1 {
start = foo(start.0, start.2.c.c);
// foo (2, 1, Data { a: 1, b: 0, c: Extra { c: 1 } })
start = foo(start.0, start.2.c.c, start.2);
//
} else {
if flag2 {
start = foo(start.1, start.2.b);
// foo (1, 0, Data { a: 1, b: 0, c: Extra { c: 1 } })
start = foo(start.1, start.2.b, start.2);
} else {
start = foo(start.2.a, start.1);
// foo (1, 1, Data { a: 1, b: 0, c: Extra { c: 1 } })
start = foo(start.2.a, start.1, start.2);
}
}
return start;
}

transition blar(flag1: bool, flag2: bool, a: u8, b: u8) -> (u8, u8, Data) {
let start: (u8, u8, Data) = floo(a, b);
let data: Data = Data { a: a, b: b, c: Extra { c: a } };

let start: (u8, u8, Data) = floo(a, b, data);
if flag1 {
start = floo(start.0, start.2.c.c);
start = floo(start.0, start.2.c.c, start.2);
} else {
if flag2 {
start = floo(start.1, start.2.b);
start = floo(start.1, start.2.b, start.2);
} else {
start = floo(start.2.a, start.1);
start = floo(start.2.a, start.1, start.2);
}
}
return start;
Expand Down

0 comments on commit edcf905

Please sign in to comment.