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

Support var.len #258

Open
katat opened this issue Jan 4, 2025 · 3 comments · May be fixed by #262
Open

Support var.len #258

katat opened this issue Jan 4, 2025 · 3 comments · May be fixed by #262
Labels

Comments

@katat
Copy link
Collaborator

katat commented Jan 4, 2025

It will be handy to directly obtain the length of an array variable.

For example

fn init_arr(const LEN: Field) -> [Field; LEN + 2] {
 return [0; LEN + 2];
}

fn main() {
  let arr = init_arr(10);
  assert_eq(arr.len, 12);

  // should also support being used to instantiate functions in mast phase
  let arr2 = init_arr(arr.len);
  assert_eq(arr2.len, 14);
}
@katat katat added the easy label Jan 4, 2025
@cyberbono3
Copy link

let me take it

@cyberbono3 cyberbono3 linked a pull request Jan 14, 2025 that will close this issue
@mimoo
Copy link
Contributor

mimoo commented Jan 16, 2025

I think .len() would be better, or even a len() builtin function that works on any type :D

@cyberbono3
Copy link

cyberbono3 commented Jan 21, 2025

I think .len() would be better, or even a len() builtin function that works on any type :D

I am adding new builtin len function into BUILTIN_FN_NAMES

I am debugging now this test to find out where assert_fn_eq gets invoked, but it looks like it is not called anywhere.

#[test]
fn test_array_len() {
    let code = r#"
        fn main(pub xx: Field) {
            let aa = xx + 1;
            assert_eq(aa, xx);
        }
    "#;

    if let Err(err) = mast_pass(code) {
        println!("err: {:?}", err);
    }

    assert_eq!(1, 2);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants