Skip to content
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

[vm/ffi] Allocate Array with TypedData #54512

Open
dcharkes opened this issue Jan 4, 2024 · 0 comments
Open

[vm/ffi] Allocate Array with TypedData #54512

dcharkes opened this issue Jan 4, 2024 · 0 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug

Comments

@dcharkes
Copy link
Contributor

dcharkes commented Jan 4, 2024

In [vm/ffi] TypedData constructors for Struct and Union addressing #45697, structs and unions can are automatically backed by a typed data on the default constructor.

We should consider doing similar for fixed-size arrays.

Things to consider:

  • We already use the Array constructor for annotations.

API sketch:

void main() {
  // Allocates a typed data which fits `Coordinate[4]`.
  final a = Array<Coordinate>.typedData(4);

  // Allocates a typed data which fits `Coordinate[2][2]`.
  final a = Array<Array<Coordinate>>.typedData(2, 2);
}

final class Coordinate extends Struct {
  // ...
}

If we could somehow distinguish annotation call sites from normal code, we could possibly reuse the existing constructor:

void main() {
  // Allocates a typed data which fits `Coordinate[4]`.
  final a = Array<Coordinate>(4);

  // Allocates a typed data which fits `Coordinate[2][2]`.
  final a = Array<Array<Coordinate>>(2, 2);
}

cc @mkustermann

Workaround for compile-time length arrays

After https://dart-review.googlesource.com/c/sdk/+/342763 lands.

Define a wrapper struct, allocate that as typed data, and read the array out:

main() {
  final Array<MyStruct> a = HelperStruct().inlineArray;
}

class HelperStruct extends Struct {
  @Array(10)
  external Array<Struct> inlineArray;
}
@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Jan 4, 2024
@a-siva a-siva added type-enhancement A request for a change that isn't a bug P3 A lower priority bug or feature request triaged Issue has been triaged by sub team labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants