-
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: Make arrays and slices polymorphic over each other #2070
Conversation
I think I'll try to add rust's implicit coercion of array to slice. This should no longer be a breaking change afterward. Edit: Added |
This PR is currently held up by an error in
Any insight into this @sirasistant? |
Yes, fixed in #2080. The problem was that it was previously assumed that a Value::Array was always had Type::Array, which is no longer the case. Also improved a bit the brillig_slices test now that references have coherent typing! |
* fix: Initialize Value::Array of type Slice * test: improved brillig test after bug fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this! 🚀
@sirasistant I've pushed an array -> slice coercion so that this is no longer a breaking change. I think this recovers the lost ergonomics as well. It works by implicitly adding a |
* master: (53 commits) chore: Update `noir-source-resolver` to v1.1.3 (#1912) chore: Document `GeneratedAcir::more_than_eq_comparison` (#2085) chore: refresh ACIR test artifacts (#2091) feat: Add `deprecated` attribute (#2041) chore(ssa refactor): Implement `acir_gen` errors (#2071) chore: use witnesses from the generated acir in the ABI (#2095) fix: Fix methods not mutating fields (#2087) chore(nargo): Use Display impl for InputValue (#1990) feat: Make arrays and slices polymorphic over each other (#2070) feat: Remove an unnecessary witness in `mul_with_witness` (#2078) chore: document truncate (#2082) fix: avoid potential panic in `two_complement` (#2081) chore: Cleanup integration tests (#2074) chore: replace `Type::TypeVariable`, `Type::PolymorphicInteger`, and … (#2065) chore!: Require package names in `Nargo.toml` files (#2056) fix: Avoid non-determinism in defunctionalization (#2069) chore: change 'unnecessary pub' error to a warning (#2064) feat!: Update to ACVM 0.21.0 (#2051) chore: Rename execute tests for an accurate description (#2063) chore: Restore lost integration test (#2062) ...
* master: (75 commits) fix: Mutating a variable no longer mutates its copy (#2057) fix: Implement `.len()` in Acir-Gen (#2077) chore: clippy fixes (#2101) chore: Update `noir-source-resolver` to v1.1.3 (#1912) chore: Document `GeneratedAcir::more_than_eq_comparison` (#2085) chore: refresh ACIR test artifacts (#2091) feat: Add `deprecated` attribute (#2041) chore(ssa refactor): Implement `acir_gen` errors (#2071) chore: use witnesses from the generated acir in the ABI (#2095) fix: Fix methods not mutating fields (#2087) chore(nargo): Use Display impl for InputValue (#1990) feat: Make arrays and slices polymorphic over each other (#2070) feat: Remove an unnecessary witness in `mul_with_witness` (#2078) chore: document truncate (#2082) fix: avoid potential panic in `two_complement` (#2081) chore: Cleanup integration tests (#2074) chore: replace `Type::TypeVariable`, `Type::PolymorphicInteger`, and … (#2065) chore!: Require package names in `Nargo.toml` files (#2056) fix: Avoid non-determinism in defunctionalization (#2069) chore: change 'unnecessary pub' error to a warning (#2064) ...
* master: (75 commits) fix: Mutating a variable no longer mutates its copy (#2057) fix: Implement `.len()` in Acir-Gen (#2077) chore: clippy fixes (#2101) chore: Update `noir-source-resolver` to v1.1.3 (#1912) chore: Document `GeneratedAcir::more_than_eq_comparison` (#2085) chore: refresh ACIR test artifacts (#2091) feat: Add `deprecated` attribute (#2041) chore(ssa refactor): Implement `acir_gen` errors (#2071) chore: use witnesses from the generated acir in the ABI (#2095) fix: Fix methods not mutating fields (#2087) chore(nargo): Use Display impl for InputValue (#1990) feat: Make arrays and slices polymorphic over each other (#2070) feat: Remove an unnecessary witness in `mul_with_witness` (#2078) chore: document truncate (#2082) fix: avoid potential panic in `two_complement` (#2081) chore: Cleanup integration tests (#2074) chore: replace `Type::TypeVariable`, `Type::PolymorphicInteger`, and … (#2065) chore!: Require package names in `Nargo.toml` files (#2056) fix: Avoid non-determinism in defunctionalization (#2069) chore: change 'unnecessary pub' error to a warning (#2064) ...
Description
Problem*
Resolves #1963
Resolves #1931
Resolves #1842
Resolves #1354
Summary*
Instead of representing
Type::Array(size, elem)
as a separate type fromType::Slice(elem)
and allowing them to intermingle via subtyping, this PR removes the subtyping relationship and theType::Slice
variant entirely. Now, array literals have a polymorphic "MaybeConstant" size that can later be resolved to either aConstant
size (array) or aNotConstant
size (slice). This also means we no longer need type annotations to create slice literals.BREAKING CHANGES:
- Arrays and slices are no longer subtypes of each other. So if you have an array and you need to pass it to a function that only accepts a slice, you now need to add an explicit.as_slice()
.Documentation
This PR requires documentation updates when merged.
[a, b, c, ..]
can now resolve to either an array or a slice depending on how it is used.fn foo<T, N>(array_or_slice: [T; N])
syntax since slices are considered to be arrays internally of a non-constant size (implementation detail).Additional Context
I'm putting this PR out a bit early for visibility and because I need the CI to help find which tests need a
.as_slice()
to be added.PR Checklist*
cargo fmt
on default settings.