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

Functions not fully inlined #1659

Closed
joss-aztec opened this issue Jun 13, 2023 · 8 comments · Fixed by #1675
Closed

Functions not fully inlined #1659

joss-aztec opened this issue Jun 13, 2023 · 8 comments · Fixed by #1675
Labels
bug Something isn't working refactor ssa

Comments

@joss-aztec
Copy link
Contributor

Aim

Test named 7_function should compile

Expected Behavior

^

Bug

Compilation crashes with:

The application panicked (crashed).
Message:  internal error: entered unreachable code: ICE: Should have been in cache Instruction { instruction: Id(122), position: 0, typ: Numeric(Unsigned { bit_size: 8 }) }
Location: crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs:345

The exact reasoning for this crash I haven't yet investigated. However, what is clearly suspicious is that many function calls to non-instrinsics remain in the SSA that is handed to ACIR gen.

After Dead Instruction Elimination:
fn main f0 {
  b0(v0: u32, v1: u32, v2: Field, v3: [u32; 9], v4: [u32; 9]):
    v93 = add v0, u32 2
    v94 = truncate v93 to 32 bits, max_bit_size: 33
    call f1(v94, v0)
    call f2(v94, v0)
    call f3(v94, v0, v94, v0, u32 61, v0, v94, v0, v94, v0, u32 61, v0)
    v97 = call f4(v2)
    v99 = add v97, v2
    v100 = eq v99, Field 4
    constrain v100
    call f5(v2)
    call f6(v2)
    v101 = cast v0 as Field
    call f7(v101, v1)
    v102 = call f8()
    v103 = array_get v102, index Field 0
    v104 = eq v103, Field 0
    constrain v104
    v109 = call f9([v47, v49, v51])
    v110 = eq [v47, v49, v51], v109
    constrain v110
    v113 = call f9([v111, v49, v51])
    v114 = eq v109, v113
    v115 = not v114
    constrain v115
    v116, v117 = call f10(v0, v1)
    v118 = cast Field 54 as u32
    v119 = add v116, v118
    v120 = truncate v119 to 32 bits, max_bit_size: 33
    v121 = eq v117, v120
    constrain v121
    v122, v123 = call f11()
    v124 = cast Field 2 as u32
    v125 = add v122, v124
    v126 = truncate v125 to 32 bits, max_bit_size: 33
    v127 = eq v123, v126
    constrain v127
    call f12(v1, v1)
    v128 = call f14(v3)
    v129 = call f14(v4)
    v130 = call f13(v128, v129)
    v131 = array_get v130, index Field 0
    v132 = array_get v3, index Field 0
    v133 = cast v132 as Field
    v134 = eq v131, v133
    constrain v134
    return 
}
fn test_multiple4 f1 {
  b0(v0: u32, v1: u32):
    v6 = add v1, u32 2
    v7 = truncate v6 to 32 bits, max_bit_size: 33
    v8 = eq v0, v7
    constrain v8
    return 
}
fn test_multiple5 f2 {
  b0(v0: u32, v1: u32):
    v6 = add v1, u32 2
    v7 = truncate v6 to 32 bits, max_bit_size: 33
    v8 = eq v0, v7
    constrain v8
    return 
}
fn test_multiple6 f3 {
  b0(v0: u32, v1: u32, v2: u32, v3: u32, v4: u32, v5: u32, v6: u32, v7: u32, v8: u32, v9: u32, v10: u32, v11: u32):
    call f1(v0, v1)
    call f2(v4, v5)
    v15 = eq v6, v10
    constrain v15
    return 
}
fn f2 f4 {
  b0(v0: Field):
    v7 = add v0, Field 2
    return v7
}
fn test0 f5 {
  b0(v0: Field):
    v9 = call f4(v0)
    v10 = eq v9, Field 3
    constrain v10
    return 
}
fn test1 f6 {
  b0(v0: Field):
    v9 = call f17(v0)
    v10 = eq v9, Field 4
    constrain v10
    return 
}
fn test2 f7 {
  b0(v0: Field, v1: u32):
    v11 = cast v1 as Field
    v12 = add v0, v11
    v13 = eq v12, Field 2⁶
    constrain v13
    v14 = cast v1 as Field
    v15 = call f16(v0, v14)
    v16 = eq v15, Field 714924299
    constrain v16
    return 
}
fn bar f8 {
  b0():
    v4 = call f15([Field 0])
    return v4
}
fn test3 f9 {
  b0(v0: [u8; 3]):
    v41 = eq [v35, v37, v39], v0
    constrain v41
    return [v35, v37, v39]
}
fn test_multiple f10 {
  b0(v0: u32, v1: u32):
    return v1, v0
}
fn test_multiple2 f11 {
  b0():
    v4 = cast Field 5 as u32
    v5 = cast Field 7 as u32
    return v4, v5
}
fn test_multiple3 f12 {
  b0(v0: u32, v1: u32):
    v3 = eq v0, v1
    constrain v3
    return 
}
fn first f13 {
  b0(v0: [Field; 9], v1: [Field; 9]):
    return v0
}

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 13, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 13, 2023
@joss-aztec
Copy link
Contributor Author

Test named array_len also affected.

@joss-aztec
Copy link
Contributor Author

Test named merkle_insert also affected.

@joss-aztec
Copy link
Contributor Author

And pedersen_check

@joss-aztec
Copy link
Contributor Author

poseidon_bn254_hash

@joss-aztec
Copy link
Contributor Author

poseidonsponge_x5_254

@joss-aztec
Copy link
Contributor Author

simple_shield

@joss-aztec
Copy link
Contributor Author

to_be_bytes

@joss-aztec
Copy link
Contributor Author

to_le_bytes

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

Successfully merging a pull request may close this issue.

1 participant