Skip to content

[vm/ffi] Allow struct classes to override sizeOf #37842

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

Closed
sjindel-google opened this issue Aug 13, 2019 · 5 comments
Closed

[vm/ffi] Allow struct classes to override sizeOf #37842

sjindel-google opened this issue Aug 13, 2019 · 5 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@sjindel-google
Copy link
Contributor

Since all operations on structs are dispatched to the getters/settings (instance methods which can already be overriden) and the auto-generated #sizeOf, we can allow users to define custom struct classes by overriding sizeOf.

This would allow, for example, defining structs with different behavior (e.g. different fields) on different platforms.

@sjindel-google sjindel-google added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Aug 13, 2019
@dcharkes
Copy link
Contributor

This would allow, for example, defining structs with different behavior (e.g. different fields) on different platforms.

This would not allow people to access those fields right? Only to allocate the correct amount of memory and use elementAt. Or is there a way we can enable accessing fields which have different offsets or might not exist on various platforms?

@sjindel-google
Copy link
Contributor Author

You could write the fields by hand, or delegate them to different (generated) implementations depending on the platform.

@sjindel-google sjindel-google self-assigned this Sep 23, 2019
@dcharkes dcharkes added this to the D26 Release milestone Sep 30, 2019
@dcharkes dcharkes removed this from the D26 Release milestone Oct 7, 2019
@mkustermann
Copy link
Member

By allowing user-defined sizeOf, we also allow user-defined layout (i.e. number of fields, type of fields, offset/alignment of fields).

In order to generate the right machine code for Dart -> C and C -> Dart trampolines the VM has to know the exact struct layout for passing structs by value for the current ABI.

How would such struct classes work with by-value calls?

@sjindel-google
Copy link
Contributor Author

I had imagined that there might be some other functions in addition to sizeOf which describe the struct layout. But it's a very explicit and heavy-weight solution.

@mkustermann
Copy link
Member

IMHO we should remove this from the ffi MVP project and consider closing if we don't intend to implement this.

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
Projects
None yet
Development

No branches or pull requests

3 participants