noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
878 stars 190 forks source link

Move evaluation of the array_len builtin from monomorphization to SSA/acir-gen #1736

Closed jfecher closed 1 year ago

jfecher commented 1 year ago

Problem

The monomorphization pass currently contains a check to evaluate the array_len builtin function. This is somewhat odd as it is the only thing the pass will attempt to evaluate. This has caused bugs in the past (#562, #1354), primarily from functions like to_be_bytes that return an array of unknown length (they should be returning slices instead).

Happy Case

We could make array_len a builtin instead and leave the function call in for ssa to optimize if the type is known. This would also more easily allow it to be used for slice types with unknown lengths when they are added. Any calls to array_len remaining in acir_gen can be easily evaluated there as well.

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

jfecher commented 1 year ago

Completed in #2070