Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test closures_mut_ref fails with inliner <= 0 and brillig #6440

Closed
aakoshh opened this issue Nov 4, 2024 · 2 comments
Closed

Test closures_mut_ref fails with inliner <= 0 and brillig #6440

aakoshh opened this issue Nov 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aakoshh
Copy link
Contributor

aakoshh commented Nov 4, 2024

Aim

Trying to run test_programs with different --inliner-aggressiveness in #6429

Expected Behavior

Tests under execution_success should work.

Bug

nargo execute --force --inliner-aggressiveness 0 --force-brillig
error: Failed to solve program: 'Failed to solve brillig function'
   ┌─ /Users/aakoshh/Work/aztec/noir/test_programs/execution_success/closures_mut_ref/src/main.nr:23:12

23 │     assert(*x1 == 44);
   │            ---------

   = Call stack:
     1. /Users/aakoshh/Work/aztec/noir/test_programs/execution_success/closures_mut_ref/src/main.nr:14:5
     2. /Users/aakoshh/Work/aztec/noir/test_programs/execution_success/closures_mut_ref/src/main.nr:23:12

Failed to solve program: 'Failed to solve brillig function'

To Reproduce

  1. cd test_programs/execution_success/closures_mut_ref
  2. nargo execute --force --force-brillig --inliner-aggressiveness 0 or
  3. nargo execute --force --force-brillig --inliner-aggressiveness -9223372036854775808

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.36.0 noirc version = 0.36.0+2f0cb3e80f3d93a1dee77fffacc397811e300257 (git version hash: 2f0cb3e, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@aakoshh aakoshh added the bug Something isn't working label Nov 4, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 4, 2024
@aakoshh aakoshh changed the title closures_mut_ref fails with inliner <= 0 and brillig Test closures_mut_ref fails with inliner <= 0 and brillig Nov 4, 2024
@aakoshh aakoshh changed the title Test closures_mut_ref fails with inliner <= 0 and brillig Test closures_mut_ref fails with inliner <= 0 and brillig Nov 4, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 5, 2024
@aakoshh aakoshh reopened this Nov 5, 2024
@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 6, 2024

The problem indeed seems to be the same as #6443

Reduced the test program to be just the following:

fn main(mut x: Field) {
    issue_2120();
}
fn issue_2120() {
    let x1 = &mut 42;
    let set_x1 = |y| { *x1 = y; };
    set_x1(44);
    assert(*x1 == 44);
}

The test fails at the assertion. Looking at the SSA, we can see that the f2 function representing the set_x1 lambda gets its body eliminated:

cargo run -q -p nargo_cli --  --program-dir . execute --force --force-brillig --inliner-aggressiveness -9223372036854775808 --show-ssa
Initial SSA:
brillig(inline) fn main f0 {
  b0(v0: Field):
    v1 = allocate
    store v0 at v1
    call f1()
    return 
}
acir(inline) fn issue_2120 f1 {
  b0():
    v0 = allocate
    store Field 42 at v0
    call f2(v0, Field 44)
    v4 = load v0
    v5 = eq v4, Field 44
    constrain v4 == Field 44
    return 
}
acir(inline) fn lambda f2 {
  b0(v0: &mut Field, v1: Field):
    v2 = allocate
    store v0 at v2
    v3 = load v2
    store v1 at v3
    return 
}

...

After Array Set Optimizations:
brillig(inline) fn main f0 {
  b0(v0: Field):
    call f1()
    return 
}
brillig(inline) fn issue_2120 f1 {
  b0():
    v0 = allocate
    store Field 42 at v0
    call f2(v0, Field 44)
    v4 = load v0
    constrain v4 == Field 44
    return 
}
brillig(inline) fn lambda f2 {
  b0(v0: &mut Field, v1: Field):
    return 
}

@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 6, 2024

Fixed by #6452

@aakoshh aakoshh closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: ✅ Done
Development

No branches or pull requests

1 participant