Skip to content

Commit 0b67e28

Browse files
test: move test of EliminateAfterExit into origlang-ir-optimizer
1 parent a9345dd commit 0b67e28

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

package/origlang-ir-optimizer/src/ir1/tests.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use origlang_ast::after_parse::BinaryOperatorKind;
22
use origlang_ir::IR1;
33
use origlang_typesystem_model::{Type, TypedExpression, TypedIntLiteral};
4-
use crate::ir1::{FoldBinaryOperatorInvocationWithConstant, FoldIfWithConstantCondition, InlineSimpleBlock};
4+
use crate::ir1::{EliminateAfterExit, FoldBinaryOperatorInvocationWithConstant, FoldIfWithConstantCondition, InlineSimpleBlock};
55

66
#[test]
77
fn fold_binary_operator_is_recursive() {
@@ -84,3 +84,12 @@ fn inline_simple_block() {
8484
])
8585
}
8686

87+
#[test]
88+
fn cut_down_after_exit() {
89+
let opt_output = EliminateAfterExit(vec![
90+
IR1::Exit,
91+
IR1::Output(TypedExpression::BooleanLiteral(false))
92+
]).optimize();
93+
94+
assert_eq!(opt_output, [ IR1::Exit ]);
95+
}

package/origlang-ir-optimizer/src/preset.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl OptimizationPreset<IR1> for SimpleOptimization {
4242
.pipe(FoldBinaryOperatorInvocationWithConstant).pipe(|x| x.optimize())
4343
.pipe(FoldIfWithConstantCondition).pipe(|x| x.optimize())
4444
.pipe(InlineSimpleBlock).pipe(|x| x.optimize())
45+
.pipe(EliminateAfterExit).pipe(|x| x.optimize())
4546
}
4647
}
4748

package/origlang-testsuite/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ print 1
453453
fn test_exit() -> Result<(), Err> {
454454
assert_eq!(Self::ast("exit\n")?.statement, [ Statement::Exit ]);
455455
assert_eq!(Self::evaluated_expressions("exit\n")?, []);
456-
assert_eq!(Self::evaluated_expressions_with_optimization_preset("exit\nprint 1\n", &SimpleOptimization)?, []);
457456

458457
Ok(())
459458
}

0 commit comments

Comments
 (0)