noir icon indicating copy to clipboard operation
noir copied to clipboard

Handle slices in ssa

Open guipublic opened this issue 3 years ago • 1 comments

Slices can now be used as function arguments. When a function using slice is parsed, we identify the array lengths of the arguments passed by the caller and generate a 'templated' version of the function if it does not exist. The arguments length are also pushed to a (call) stack in the Memory object which uses it when somebody request the length of an array. When the parsing is completed, we pop the stack. I also added an array_len() function in the std:lib that can be used to iterate over slices. (cf. ex. in test 10_slices)

The matrix multiplication example cannot yet be implemented in Noir and raises interesting issues: We would need to compute the square root of the array length: a user should be able to use non-determinism to compute it and provide it to Noir using the state management feature. We could also provide a math std lib that implements some common computations We could also support Array of arrays (or struct, or tuple) We cannot instantiate in a function an array of the same length of the input slices, which is annoying.

guipublic avatar Aug 10 '22 15:08 guipublic

We cannot instantiate in a function an array of the same length of the input slices, which is annoying.

Once for loops return values we could do something like the following:

fn foo(array: []Field) -> Field {
    // Perhaps we should also add for-each loops to noir
    let array_of_same_len = for i in 0 .. std::array_len(array) {
        array[i] + 5
    };
    array_of_same_len[0] * 2
}

jfecher avatar Aug 10 '22 17:08 jfecher

Closing as we now have monomorphisation

kevaundray avatar Nov 29 '22 16:11 kevaundray