Skip to content

Commit

Permalink
Add a couple of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jan 23, 2025
1 parent edde1a2 commit 36ff6ad
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ mod test {
map::Id,
types::{NumericType, Type},
},
opt::assert_normalized_ssa_equals,
Ssa,
};

Expand Down Expand Up @@ -1618,4 +1619,76 @@ mod test {
);
assert!(tws[3] > max(tws[1], tws[2]), "ideally 'main' has the most weight");
}

#[test]
fn inline_simple_functions_with_zero_instructions() {
let src = "
acir(inline) fn main f0 {
b0(v0: Field):
v2 = call f1(v0) -> Field
v3 = call f1(v0) -> Field
v4 = add v2, v3
return v4
}
acir(inline) fn foo f1 {
b0(v0: Field):
return v0
}
";
let ssa = Ssa::from_str(src).unwrap();

let expected = "
acir(inline) fn main f0 {
b0(v0: Field):
v1 = add v0, v0
return v1
}
acir(inline) fn foo f1 {
b0(v0: Field):
return v0
}
";

let ssa = ssa.inline_simple_functions();
assert_normalized_ssa_equals(ssa, expected);
}

#[test]
fn inline_simple_functions_with_one_instruction() {
let src = "
acir(inline) fn main f0 {
b0(v0: Field):
v2 = call f1(v0) -> Field
v3 = call f1(v0) -> Field
v4 = add v2, v3
return v4
}
acir(inline) fn foo f1 {
b0(v0: Field):
v2 = add v0, Field 1
return v2
}
";
let ssa = Ssa::from_str(src).unwrap();

let expected = "
acir(inline) fn main f0 {
b0(v0: Field):
v2 = add v0, Field 1
v3 = add v0, Field 1
v4 = add v2, v3
return v4
}
acir(inline) fn foo f1 {
b0(v0: Field):
v2 = add v0, Field 1
return v2
}
";

let ssa = ssa.inline_simple_functions();
assert_normalized_ssa_equals(ssa, expected);
}
}

0 comments on commit 36ff6ad

Please sign in to comment.