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

Truncates on constants aren't folded #1624

Closed
joss-aztec opened this issue Jun 9, 2023 · 2 comments
Closed

Truncates on constants aren't folded #1624

joss-aztec opened this issue Jun 9, 2023 · 2 comments
Labels
bug Something isn't working refactor ssa

Comments

@joss-aztec
Copy link
Contributor

Aim

The test named poseidonsponge_x5_254 should pass

Expected Behavior

^

Bug

Compilation fails with:

After Constant Folding:
fn main f9 {
  b0(v0: [Field; 7]):
    v849 = cast Field 5 as u8
    v850 = truncate u8 68 to 8 bits, max_bit_size: 9
    v851 = mul v849, v850
    v852 = truncate v851 to 8 bits, max_bit_size: 16
    v853 = cast Field 340 as u8
    v854 = eq v852, v853
    constrain v854
    v855 = not Field 0
    constrain v855
    v856 = allocate
    store [Field 0, Field 0, Field 0, Field 0, Field 0] at v856
    v857 = allocate
    store Field 0 at v857
    v858 = eq v845, Field 3637726918731233354960448572465528704217843406233123660822069175839457651784
    constrain v858
    return unit 0
}

The application panicked (crashed).
Message:  internal error: entered unreachable code: ICE: Truncates are only ever applied to the result of a binary op
Location: crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs:486

Notice that v850 is a truncate performed on a numeric constant. This should instead be removed by constant folding and simplified to, in this case, u8 68.

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@joss-aztec joss-aztec added the bug Something isn't working label Jun 9, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 9, 2023
@joss-aztec
Copy link
Contributor Author

Also affects test named bit_shifts_comptime

@joss-aztec
Copy link
Contributor Author

bit_shifts_comptime now passes following #1568. poseidonsponge_x5_254 fails for a different reason now.

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working refactor ssa
Projects
Archived in project
Development

No branches or pull requests

1 participant