Skip to content

Commit

Permalink
test: move test of EliminateAfterExit into origlang-ir-optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective committed Oct 22, 2023
1 parent a9345dd commit 0b67e28
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion package/origlang-ir-optimizer/src/ir1/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use origlang_ast::after_parse::BinaryOperatorKind;
use origlang_ir::IR1;
use origlang_typesystem_model::{Type, TypedExpression, TypedIntLiteral};
use crate::ir1::{FoldBinaryOperatorInvocationWithConstant, FoldIfWithConstantCondition, InlineSimpleBlock};
use crate::ir1::{EliminateAfterExit, FoldBinaryOperatorInvocationWithConstant, FoldIfWithConstantCondition, InlineSimpleBlock};

#[test]
fn fold_binary_operator_is_recursive() {
Expand Down Expand Up @@ -84,3 +84,12 @@ fn inline_simple_block() {
])
}

#[test]
fn cut_down_after_exit() {
let opt_output = EliminateAfterExit(vec![
IR1::Exit,
IR1::Output(TypedExpression::BooleanLiteral(false))
]).optimize();

assert_eq!(opt_output, [ IR1::Exit ]);
}
1 change: 1 addition & 0 deletions package/origlang-ir-optimizer/src/preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl OptimizationPreset<IR1> for SimpleOptimization {
.pipe(FoldBinaryOperatorInvocationWithConstant).pipe(|x| x.optimize())
.pipe(FoldIfWithConstantCondition).pipe(|x| x.optimize())
.pipe(InlineSimpleBlock).pipe(|x| x.optimize())
.pipe(EliminateAfterExit).pipe(|x| x.optimize())
}
}

Expand Down
1 change: 0 additions & 1 deletion package/origlang-testsuite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ print 1
fn test_exit() -> Result<(), Err> {
assert_eq!(Self::ast("exit\n")?.statement, [ Statement::Exit ]);
assert_eq!(Self::evaluated_expressions("exit\n")?, []);
assert_eq!(Self::evaluated_expressions_with_optimization_preset("exit\nprint 1\n", &SimpleOptimization)?, []);

Ok(())
}
Expand Down

0 comments on commit 0b67e28

Please sign in to comment.