sdk icon indicating copy to clipboard operation
sdk copied to clipboard

proposed breaking change to dart:ffi: stop reifying Pointer<T>

Open mraleph opened this issue 2 years ago • 3 comments

I propose we stop reifying underlying element type for Pointer<T> objects in preparation to unboxing pointer or migrating FFI to views. I am filing this issue for discussion.

Currently Pointer<T> objects are carrying their reified type around, but most of the APIs are based on the static type.

I propose we fix any APIs that are still using dynamic type and switch Pointer<T> factory to produce Pointer<Never> instead.

/cc @dcharkes @mkustermann

mraleph avatar Sep 09 '22 12:09 mraleph

Background:

  • https://github.com/dart-lang/language/blob/spec_update_views_aug22/working/1426-extension-types/feature-specification-views.md

dcharkes avatar Sep 09 '22 13:09 dcharkes

most of the APIs are based on the static type.

Correct, we migrated almost everything to extension methods.

I see elementAt is still a method, but it is documented that it requires a compile-time constant for the type argument and transformed in the CFE. I don't remember why it is not an extension method, it probably should be.

We own all the constructors, and Pointer cannot be extended, so we should be able to ensure all pointers will have Never as type argument at runtime. I can whip up a CL to do that (including patch files, kernel-gen in CFE, IL-gen in VM, and direct Pointer object creation in VM).

@eernstg I'd love to know if defining Pointer (with a type argument) as a view on int would work with your proposal for views.

dcharkes avatar Sep 09 '22 13:09 dcharkes

as a view on int

One interesting consideration here is that int will be too wide for 32-bit ARM. We need something like _int32, a hidden type which reifies to int when boxed but can also be stored in a smaller unboxed location.

mraleph avatar Sep 10 '22 12:09 mraleph

The merged CL seems to have caused a regression: https://github.com/dart-lang/sdk/issues/50678.

knopp avatar Dec 10 '22 19:12 knopp

@knopp Thank you for the report. We are already aware, a fix is on its way

mkustermann avatar Dec 10 '22 20:12 mkustermann

@knopp We have identified the issue with the CL, was fixed in e3e355e16a8b67ba6a1d7a83f837e8e69cf71534.

I see elementAt is still a method, but it is documented that it requires a compile-time constant for the type argument and transformed in the CFE. I don't remember why it is not an extension method, it probably should be.

@dcharkes should we go ahead and do that before Dart 3?

mkustermann avatar Dec 14 '22 11:12 mkustermann

I can confirm that https://github.com/dart-lang/sdk/commit/e3e355e16a8b67ba6a1d7a83f837e8e69cf71534 fixes the error for me. Thanks!

knopp avatar Dec 14 '22 11:12 knopp

I see elementAt is still a method, but it is documented that it requires a compile-time constant for the type argument and transformed in the CFE. I don't remember why it is not an extension method, it probably should be.

@dcharkes should we go ahead and do that before Dart 3?

I've filed https://github.com/dart-lang/sdk/issues/50714 to track this.

This issue can be closed.

dcharkes avatar Dec 14 '22 11:12 dcharkes