-
Notifications
You must be signed in to change notification settings - Fork 219
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
feat: Adding support for global arrays #826
feat: Adding support for global arrays #826
Conversation
* master: (223 commits) chore(noir): Release 0.5.0 (noir-lang#1202) chore(ci): Utilize new workflow to build binaries (noir-lang#1250) chore(ssa refactor): Fix loading from mutable parameters (noir-lang#1248) fix(wasm): add std after dependencies (noir-lang#1245) chore(ssa refactor): Fix no returns & duplicate main (noir-lang#1243) chore(ssa refactor): Implement intrinsics (noir-lang#1241) chore(ssa refactor): Implement first-class functions (noir-lang#1238) chore: address clippy warnings (noir-lang#1239) chore(ssa refactor): Implement function calls (noir-lang#1235) chore(ssa refactor): Implement mutable and immutable variables (noir-lang#1234) chore(ssa refactor): Fix recursive printing of blocks (noir-lang#1230) feat(noir): added assert keyword (noir-lang#1227) chore(ssa refactor): Implement ssa-gen for indexing, cast, constrain, if, unary (noir-lang#1225) feat(noir): added `distinct` keyword (noir-lang#1219) chore(nargo): update panic message to suggest searching for similar issues (noir-lang#1224) chore(ssa refactor): Update how instruction result types are retrieved (noir-lang#1222) chore(ssa refactor): Implement ssa-gen for binary, block, tuple, extract-tuple-field, and semi expressions (noir-lang#1217) chore: add RUST_BACKTRACE environment variable to nix config (noir-lang#1216) chore(ssa): Add intial control flow graph (noir-lang#1200) chore(ssa refactor): Handle codegen for literals (noir-lang#1209) ...
I've merged master back into this branch to address the merge conflicts which have popped up over time. Thanks for your work on this @michaelneuder!
|
May need to test this PR with some of the aztec 3 work. In particular we started allowing constructor expressions as globals as well but did not check them thoroughly since we wanted to allow function calls within for convenience. We'll need to add constructor expressions to this check and see if there's any code that breaks once they get restricted a bit by this check. |
superceded by #1054 |
Related issue(s)
Resolves #439. Done in collaboration and with the guidance of @vezenovm :-)
Description
Summary of changes
There are 3 components of the change:
parser
--- inglobal_type_annotation
we need to expand the set of allowed types to include the array type and we also expand theglobal_declaration
function to take any expression.resolver
--- we changeresolve_global_let
to (1) match against literals, (2a) if that literal isArrayLiteral::Standard
, check that each element of the array is also literal, (2b) if that literal isArrayLiteral::Repeated
, check that the repeated type is a literal. This means thatresolve_global_let
now returns aVec<ResolverError>
in the same way thatresolve_struct_fields
andresolve_function
do. These errors are then propagated up to the def collecteddef_collector
--- inresolve_globals
we now check the return errors fromresolve_global_let
, if there are errors, we extend the set of current errors, thusresolve_globals
now takes a new paramerrors: &mut Vec<FileDiagnostic>
that is passed in duringcollect
.Dependency additions / changes
N/A
Test additions / changes
We test this in
crates/nargo/tests/test_data/global_consts/src/main.nr
, where we define a number of bad globals. Importantly, we needed to test that a global array can not have global elements as brought up by @jfecher in #439 (comment).Valid global arrays
successfully compile.
The following invalid globals, if uncommented, will result in compilation errors.
When these are uncommented, the following compiler error is shown to the user, as expected.
Checklist
cargo fmt
with default settings.