dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.04k stars 1.55k forks source link

[vm/ffi] Deprecate `Pointer.cast()`? #56214

Open dcharkes opened 1 month ago

dcharkes commented 1 month ago

Now that we no longer reify the type arguments of Pointer

we should consider whether .cast() can be replaced by simply as checks.

Currently, the runtime still have a type arguments vector at runtime

So if we use a normal cast, we could accidentally introduce runtime type checks if the compiler can't figure out that pointers are always instantiated with Never as type argument.

Conceptually speaking Pointer<T> should maybe be an extension type on PointerNever (now that we stopped reifying the type argument). But, we've introduced Pointers before extension types were added to Dart. Its probably not possible to now change Pointer to an extension type. 😄

Thanks @HosseinYousefi for the suggestion!

HosseinYousefi commented 1 month ago

Its probably not possible to now change Pointer to an extension type.

So maybe this change won't be breaking afterall!

dcharkes commented 1 month ago

If you want to get your hands dirty, feel free to give it a spin in the Dart SDK! 😄