noir icon indicating copy to clipboard operation
noir copied to clipboard

Allow using `u16` for array sizes

Open michaeljklein opened this issue 4 months ago • 2 comments

Problem

It's currently impossible to use u16 for array sizes, but it would be useful for many arrays (u16::MAX == 65535)

#[test]
fn numeric_generic_u16_array_size() {
    let src = r#"
    fn len<let N: u32>(_arr: [Field; N]) -> u32 {
        N
    }

    pub fn foo<let N: u16>() -> u32 {
        let fields: [Field; N] = [0; N];
        len(fields)
    }
    "#;
    let errors = get_program_errors(src);
    assert_eq!(errors.len(), 2);
    assert!(matches!(
        errors[0].0,
        CompilationError::TypeError(TypeCheckError::TypeKindMismatch { .. }),
    ));
    assert!(matches!(
        errors[1].0,
        CompilationError::TypeError(TypeCheckError::TypeKindMismatch { .. }),
    ));
}

Happy Case

Support u16 as an array size (as above)

Workaround

Yes

Workaround Description

A u16 cast to a u32 can be used as the array size, but there's a performance impact

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

michaeljklein avatar Oct 08 '24 13:10 michaeljklein