-
Notifications
You must be signed in to change notification settings - Fork 232
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
chore: Allow count of elements in repeated-element array syntax to be any static Field #2386
Conversation
@jfecher, сan you check this and give me a hint? |
@f01dab1e, #445 is only for array expressions like let foo = {
let mut result = [];
for _ in 0 .. length {
result = result.push_back(1);
}
result.as_array()
}; We could even break this up and add this function to the std library: // Free function in std::array
fn repeated<T>(element: T, length: Field) -> [T] {
let mut result = [];
for _ in 0 .. length {
result = result.push_back(1);
}
result
}
// New method in std::slice
impl<T> [T] {
fn as_array<N>(self) -> [T; N] {
assert(self.len() == N);
... now somehow return an array without using [elem; len] syntax ...
}
} Hmm we may need a builtin for converting a slice to an array since I don't see how you can write |
@jfecher, how to handle a case like this? fn main(x : Field) {
let x = [x];
let n = x.as_array();
} The application panicked (crashed).
Message: Non-numeric type variable used in expression expecting a value
Location: crates/noirc_frontend/src/monomorphization/mod.rs:626
|
@f01dab1e I'm not sure. I'd think |
@jfecher, closed by mistake, can you open it? |
What is the status of this PR and can the issue and PR title be updated given we don't have comptime? |
This was blocked by the fact that we had no way to indicate the type (size cannot be inferred from the context), now it's blocked by the same thing, but there's an open pull request after which we can resume work, but we encounter another problem, that the method with desugaring will break the formatter. |
Description
WIP
Problem
Resolves #445
Summary
WIP
PR Checklist
cargo fmt
on default settings.