Skip to content

Commit

Permalink
Fix inlining recursion test
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jan 16, 2025
1 parent deaa311 commit 5817baf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
36 changes: 18 additions & 18 deletions compiler/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ impl InlineContext {

if self.recursion_level > RECURSION_LIMIT {
panic!(
"Attempted to recur more than {RECURSION_LIMIT} times during inlining function '{}': {}", source_function.name(), source_function
"Attempted to recur more than {RECURSION_LIMIT} times during inlining function '{}':\n{}", source_function.name(), source_function
);
}

Expand Down Expand Up @@ -1021,6 +1021,7 @@ mod test {
map::Id,
types::{NumericType, Type},
},
Ssa,
};

#[test]
Expand Down Expand Up @@ -1293,26 +1294,25 @@ mod test {

#[test]
#[should_panic(
expected = "Attempted to recur more than 1000 times during inlining function 'main': acir(inline) fn main f0 {"
expected = "Attempted to recur more than 1000 times during inlining function 'foo':\nacir(inline) fn foo f1 {"
)]
fn unconditional_recursion() {
// fn main f1 {
// b0():
// call f1()
// return
// }
let main_id = Id::test_new(0);
let mut builder = FunctionBuilder::new("main".into(), main_id);

let main = builder.import_function(main_id);
let results = builder.insert_call(main, Vec::new(), vec![]).to_vec();
builder.terminate_with_return(results);

let ssa = builder.finish();
assert_eq!(ssa.functions.len(), 1);
let src = "
acir(inline) fn main f0 {
b0():
call f1()
return
}
acir(inline) fn foo f1 {
b0():
call f1()
return
}
";
let ssa = Ssa::from_str(&src).unwrap();
assert_eq!(ssa.functions.len(), 2);

let inlined = ssa.inline_functions(i64::MAX);
assert_eq!(inlined.functions.len(), 0);
let _ = ssa.inline_functions(i64::MAX);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3456,6 +3456,9 @@ fn arithmetic_generics_rounding_fail_on_struct() {

#[test]
fn unconditional_recursion_fail() {
// These examples are self recursive top level functions, which actually
// would not be inlined now, but this error comes from the compilation checks,
// which is different from what the SSA would try to inline.
let srcs = vec![
r#"
fn main() {
Expand Down

0 comments on commit 5817baf

Please sign in to comment.