dart-lang/sdk

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

Closed this issue · 8 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

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.

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.

knopp commented

The merged CL seems to have caused a regression: #50678.

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

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

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?

knopp commented

I can confirm that e3e355e fixes the error for me. Thanks!

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 #50714 to track this.

This issue can be closed.