You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation states that these Field methods should return slices, but that is not the case when applied to constants. The compiler will apply an optimization to precompute the result but it will return it in an array instead of a slice.
I also think the documentation is a bit outdated on to_le_bits/to_be_bits (see here) because it says it returns an array, but the stdlib definition returns a slice.
Expected Behavior
to_be_bytes/to_le_bytes should return a slice consistently, regardless if it's applied to a constant or not.
error: Index out of bounds, array has size 7, but index was 7
┌─ /home/ggiraldez/Scratchpad/to_radix/src/main.nr:10:18
│
10 │ std::println(a1[7]);
│ -----
│
= Call stack:
1. /home/ggiraldez/Scratchpad/to_radix/src/main.nr:10:18
Aborting due to 1 previous error
But this program (with the appropriate inputs defined):
use dep::std;
fn main(x: Field) {
let mut a = x.to_le_bytes(7);
let mut a1 = a.push_back(123);
std::println(a.len());
std::println(a1.len());
std::println(a1[7]);
}
Attempting to compile or execute the above program will fail with the error mentioned above.
Installation Method
None
Nargo Version
No response
Additional Context
As stated above, this happens because the compiler will apply an optimization when resolving a ToRadix intrinsic used on a constant value. The relevant code is here.
Would you like to submit a PR for this Issue?
Yes
Support Needs
No response
The text was updated successfully, but these errors were encountered:
# Description
The compiler optimizes uses of the `ToRadix` intrinsic applied to
constants by precomputing the results.
## Problem\*
Resolves#4048
The optimization produces a fixed sized array instead of a slice.
## Summary\*
The PR changes the `constant_to_radix` function to produce a slice and
generates a tuple with the length and the slice itself, which fits the
internal representation of slices in SSA.
## Additional Context
This was found and fixed during the implementation of the debugger (see
#3015).
## Documentation\*
Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.
# PR Checklist\*
- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
Aim
The documentation states that these
Field
methods should return slices, but that is not the case when applied to constants. The compiler will apply an optimization to precompute the result but it will return it in an array instead of a slice.I also think the documentation is a bit outdated on
to_le_bits
/to_be_bits
(see here) because it says it returns an array, but the stdlib definition returns a slice.Expected Behavior
to_be_bytes
/to_le_bytes
should return a slice consistently, regardless if it's applied to a constant or not.Bug
Given this program:
Fails compilation with this error:
But this program (with the appropriate inputs defined):
Produce the expected output:
To Reproduce
Attempting to compile or execute the above program will fail with the error mentioned above.
Installation Method
None
Nargo Version
No response
Additional Context
As stated above, this happens because the compiler will apply an optimization when resolving a
ToRadix
intrinsic used on a constant value. The relevant code is here.Would you like to submit a PR for this Issue?
Yes
Support Needs
No response
The text was updated successfully, but these errors were encountered: