-
Notifications
You must be signed in to change notification settings - Fork 8
feat!: Improved array lowering #2109
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
Conversation
* The old `array` type is now called `value_array` and lives in a separate extension * The default `array` is now a linear type. Additional `clone` and `discard` operations follow in a separate PR * To avoid code duplication, array operations and values are now defined generically over a new `ArrayKind` trait that is instantiated with `Array` (the linear one) and `VArray` (the copyable one) to generate the `array` and `value_array` extensions Closes #2066 BREAKING CHANGE: `std.collections.array` is now a linear type, even if the contained elements are copyable. Use the new `std.collections.value_array` for an array with the previous copyable semantics.
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-rs-v0.16.0 #2109 +/- ##
======================================================
- Coverage 83.05% 82.90% -0.15%
======================================================
Files 219 227 +8
Lines 41385 42288 +903
Branches 37533 38387 +854
======================================================
+ Hits 34372 35060 +688
- Misses 5186 5360 +174
- Partials 1827 1868 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Since the array type is now linear following #2097, we need to change the signature of the `array.get` op to give the passed array back to the user. BREAKING CHANGE: `std.collections.array.get` now also returns the passed array as an extra output
Closes #2067 An `array<n, T>` is now lowered to a struct `{ptr, usize}` where `ptr` is a heap allocated pointer of size at least `n * sizeof(T)` and the `usize` is an offset pointing to the first element (i.e. the first element is at `ptr + offset * sizeof(T)`). The rational behind the additional offset is the `pop_left` operation which bumps the offset instead of mutating the pointer. This way, we can still free the original pointer when the array is discarded after a pop. BREAKING CHANGE: Removed old lowering for value arrays
* Renamed `ArrayOpBuilder` trait to `GenericOpBuilder` whose methods are generic over the array implementation * Defined new `ArrayOpBuilder` and `VArrayOpBuilder` traits that are implemented in terms of the generic version. I moved those into the `array` and `value_array` modules respectively, so they don't come into scope at the same time * Moved `all_array_ops` ops function out of the tests module so we can reuse it across other tests (in particular getting rid of the code duplication in `hugr-llvm::extension::collections::array::test` BREAKING CHANGE: `ArrayOpBuilder` was moved from `hugr_core::std_extensions::collections::array::op_builder` to `hugr_core::std_extensions::collections::array`
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.
lets gooooo
Feature branch for improved array lowering.
array
type is now calledvalue_array
and lives in a separate extensionarray
is now a linear type with additionalclone
anddiscard
operationsArrayKind
trait that is instantiated withArray
(the linear one) andVArray
(the copyable one) to generate thearray
andvalue_array
extensionsarray<n, T>
is now lowered to a fat pointer{ptr, usize}
whereptr
is a heap allocated pointer of size at leastn * sizeof(T)
and theusize
is an offset pointing to the first element (i.e. the first element is atptr + offset * sizeof(T)
). The rational behind the additional offset is thepop_left
operation which bumps the offset instead of mutating the pointer. This way, we can still free the original pointer when the array is discarded after a pop.Tracked PRs:
array.get
give back the passed array #2110BREAKING CHANGE:
std.collections.array
is now a linear type, even if the contained elements are copyable. Use the newstd.collections.value_array
for an array with the previous copyable semantics.BREAKING CHANGE:
std.collections.array.get
now also returns the passed array as an extra outputBREAKING CHANGE:
ArrayOpBuilder
was moved fromhugr_core::std_extensions::collections::array::op_builder
tohugr_core::std_extensions::collections::array
.