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] ☂️ Exploration of dart:ffi2 using new language features #54504

Open
4 tasks
dcharkes opened this issue Jan 3, 2024 · 1 comment
Open
4 tasks
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 3, 2024

Dart has gotten a fair amount of new language features since the dart:ffi API was designed. The most notable recent feature is extension types. We should explore whether it would be worth introducing a new FFI API that would leverage new language features.

Things to explore:

  • Pointers as extension types on int.
  • Structs and unions as extension types on Pointer and TypedData.
  • Integer native types as views on int, and floating native types as views on double.
  • Only writing a single signature for FFI calls by leveraging native types being views on Dart types.

There are a lot of technical complexities to consider as well:

  • Pointer addresses on 32 bit are not 64 bit integers.
  • Structs and Unions rely on using a TypedDataBase which is not visible in the user type hierarchy.
  • Structs and Unions can have constructors allocating a typed data that uses its size in bytes.
  • FFI calls can do typed data unwrapping, but expressing a type hierarchy between typed data and pointers with extension types seems not feasible (especially if pointers are already an extension type on int)

Related issues:

@mit-mit mit-mit added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jan 3, 2024
@parlough parlough added library-ffi area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jan 3, 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
@mkustermann
Copy link
Member

Structs and Unions rely on using a TypedDataBase which is not visible in the user type hierarchy.

As discussed offline, most likely we'd make the views on top of typed data and require converting the pointers (via Pointer.asTypedList()). So we'd avoid the allocation of struct/union/array objects at the expense of allocating a typed data view object.

The FooStruct foo = Pointer<FooStruct>.ref would then internally create the typed list and return the view on it.

@lrhn lrhn removed the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Feb 18, 2025
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

6 participants