mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-23 10:12:21 +03:00
Add targeted DCE test; cleanup
This commit is contained in:
parent
0e6aa4729b
commit
6c61296f78
@ -47,7 +47,6 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
|
||||
fn visit_identifier(&mut self, input: &'a Identifier) -> (String, String) {
|
||||
println!("{input}");
|
||||
(self.variable_mapping.get(&input.name).unwrap().clone(), String::new())
|
||||
}
|
||||
|
||||
|
@ -14,12 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{DeadCodeEliminator};
|
||||
use crate::DeadCodeEliminator;
|
||||
|
||||
use leo_ast::{
|
||||
Expression, ExpressionReconstructor, Identifier,
|
||||
StructExpression, StructVariableInitializer,
|
||||
};
|
||||
use leo_ast::{Expression, ExpressionReconstructor, Identifier, StructExpression, StructVariableInitializer};
|
||||
|
||||
impl ExpressionReconstructor for DeadCodeEliminator {
|
||||
type AdditionalOutput = ();
|
||||
|
@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{DeadCodeEliminator};
|
||||
use crate::DeadCodeEliminator;
|
||||
|
||||
use leo_ast::{
|
||||
AssertStatement, AssertVariant, AssignStatement, Block, ConditionalStatement, ConsoleStatement, DecrementStatement,
|
||||
@ -69,9 +69,6 @@ impl StatementReconstructor for DeadCodeEliminator {
|
||||
),
|
||||
};
|
||||
|
||||
println!("self.used_variables: {:?}", self.used_variables);
|
||||
println!("Statement: {}, lhs_is_used: {:?}", input, lhs_is_used);
|
||||
|
||||
match lhs_is_used {
|
||||
// If the lhs is used, then we return the original statement.
|
||||
true => {
|
||||
@ -102,10 +99,7 @@ impl StatementReconstructor for DeadCodeEliminator {
|
||||
.statements
|
||||
.into_iter()
|
||||
.rev()
|
||||
.map(|statement| {
|
||||
println!("Reconstructing statement: {}", statement);
|
||||
self.reconstruct_statement(statement).0
|
||||
})
|
||||
.map(|statement| self.reconstruct_statement(statement).0)
|
||||
.collect();
|
||||
|
||||
// Reverse the direction of `statements`.
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
outputs:
|
||||
- initial_ast: d7414ef76b5d83ba8daed6e65487425048596937d5a6f783a313d3264d5db267
|
||||
unrolled_ast: d7414ef76b5d83ba8daed6e65487425048596937d5a6f783a313d3264d5db267
|
||||
ssa_ast: 6722ef50ccdf19eaaa57f68a249a6eb01ba78ec8ec60da0d8d664613324287aa
|
||||
flattened_ast: 58ed29011b87aad89fe50f62402f441c9aa53fc2e18c3a188d94d0a88734236d
|
||||
inlined_ast: 1c57a7047a0523c5f576e5df33fa9b70cf2baedfb8149266686837ba2827c44e
|
||||
dce_ast: 48e52aa4ba7d5f4c5126ec93a14ec29772f80c73cc2d6ab5c77001f920b4c65b
|
||||
bytecode: 0bc43312bbddd72a443eddc893fb31630e9a29db8a6c6cadf79c4ed79f054ae4
|
59
tests/tests/compiler/function/dead_code_elimination.leo
Normal file
59
tests/tests/compiler/function/dead_code_elimination.leo
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Pass
|
||||
*/
|
||||
|
||||
/*
|
||||
The program should produce the following bytecode:
|
||||
|
||||
program test.aleo;
|
||||
|
||||
record dummy:
|
||||
owner as address.private;
|
||||
gates as u64.private;
|
||||
data as u8.private;
|
||||
|
||||
closure eliminate_unused_function_call:
|
||||
input r0 as u8;
|
||||
input r1 as u8;
|
||||
add r0 r1 into r2;
|
||||
output r2 as u8;
|
||||
|
||||
function foo:
|
||||
input r0 as u8.private;
|
||||
input r1 as u8.private;
|
||||
add r0 r1 into r2;
|
||||
output r2 as u8.private;
|
||||
*/
|
||||
|
||||
program test.aleo {
|
||||
|
||||
record dummy {
|
||||
owner: address,
|
||||
gates: u64,
|
||||
data: u8,
|
||||
}
|
||||
|
||||
function eliminate_unused_function_call(a: u8, b: u8) -> u8 {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
inline inline_and_eliminate(a: u8, b: u8) -> u8 {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
transition foo(a: u8, b: u8) -> u8 {
|
||||
let c: u8 = a + b;
|
||||
let d: u8 = eliminate_unused_function_call(a, b);
|
||||
let e: u8 = 0u8;
|
||||
if (a == b) {
|
||||
e = inline_and_eliminate(a, b);
|
||||
}
|
||||
let f: dummy = dummy {
|
||||
owner: self.caller,
|
||||
gates: 0u64,
|
||||
data: e,
|
||||
};
|
||||
return a + b;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user