-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[vm/ffi] working with Pointer<NativeType> (where NativeType is not a concrete subtype of NativeType) #37254
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
Comments
@dcharkes : Want to look at this? There's no dependency on the API refactoring. |
Looks like I'll conjure up a CL to fix this. |
Or do we want to support working with So this is more an API design question. extension on Pointer<Pointer<T>> {
void store(Pointer<T> value);
Pointer<T> load();
}
Pointer<Int8> innerTyped = allocate();
Pointer<NativeType> innerUntyped = allocate();
Pointer<Pointer<Int8>> outerTyped = allocate();
Pointer<Pointer<NativeType>> outerUntyped = allocate();
outerTyped.store(innerTyped); // This will always work
innerTyped = outerTyped.load(); // This will always work
outerUntyped.store(innerUntyped); // This should work // currently rejected by VM assertion
innerUntyped = outerUntyped.load(); // This should work // currently rejected by VM assertion
outerUntyped.store(innerTyped); // This should work // currently rejected by frontend transformation
innerTyped = outerUntyped.load(); // Implicit downcast, will fail at runtime now, will fail statically when NNBD lands
outerTyped.store(innerUntyped); ; // Implicit downcast, will fail at runtime now, will fail statically when NNBD lands
innerUntyped = outerTyped.load(); // This should work // currently rejected by frontend transformation Our frontend transformation currently partially supports untyped Edit: Thanks @lrhn for clarifying! The extension on Pointer<Pointer<T>> {
void store(Pointer<exactly T> value);
Pointer<exactly T> load();
} |
Including the differentiation between static and runtime types the following tables describe all possible scenarios:
I've added all of these in a regression test in https://dart-review.googlesource.com/c/sdk/+/107281. In our current implementation, our frontend rejects many combinations. Moreover, we completely prohibit obtaining a edit: |
Issue: #37254 Change-Id: Ic8ede0f8b7a6de0a6862ef8748a7330232950239 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107281 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Samir Jindel <[email protected]> Reviewed-by: Lasse R.H. Nielsen <[email protected]>
Example:
Crashes in Debug mode:
/cc @dcharkes
The text was updated successfully, but these errors were encountered: