-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[vm/ffi] FfiNative
return types treatment inconsistent with asFunction
#49518
Comments
@dcharkes The code you are quoting is not executed but rather there for generating expectation files of what the transformer produces. So there's no issue with this code. It doesn't really matter whether its |
If we add static linking, this will be transformed to an immediate FFI call that does not do a type check on the result value, allowing non I've disallowed that behavior in the linked CL, so I had to update the transformer test to make it pass again. |
Whether one uses static or dynamic linking shouldn't change any behavior. Whether we trust the types written by the developer is another question entirely: If user writes Coming back to the test itself: It just checks how the transform handles returning Maybe I misunderstand the concern here? |
For
Agreed, it is a choice we make. I assume we made that choice consciously for I propose we stick to |
Thanks for the explanation - it's the inconsistency you're concerned about (though that's not related to the test that is quoted in this issue). I'd like to avoid a situation where we do more checking for |
Yes, sorry for the confusion. Thanks for helping me clarify. 😄
By removing the inconsistency (by only allowing
By only allowing If we want to avoid those user-written |
FfiNative
unsound return typesFfiNative
return types treatment inconsistent with asFunction
This CL fixes two issues. 1. `FfiNative`s now check the Dart and native type for compatiblity. 2. Both `FfiNative`, `asFunction`, and `lookupFunction` check the type correspondence between native and Dart type with a subtype check of the expected Dart type and the provided Dart type. For functions, any return type is a subtype of a void type. This is fine for Dart, but not for native calls. This CL manually checks the return type for void. This CL does not fix the inconsistency between `asFunction` and `FfiNative` with regard to allowing more strict return types than `Object` for `Handle`s Issue: #49518 Analyzer fixes in follow up CL. TEST=tests/ffi/vmspecific_static_checks_ffinative_test.dart Closes: #49471 Change-Id: Ibc7bd6a1a0db59cc5fa5d755d76999fd7e9a06a4 Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252601 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
This reverts commit 206fdf1. Reason for revert: Flutter issues are caught by this CL, preventing Flutter from building. flutter/flutter#108309 Original change's description: > [cfe/ffi] Improve FFI call mismatched types compile errors > > This CL fixes two issues. > > 1. `FfiNative`s now check the Dart and native type for compatiblity. > 2. Both `FfiNative`, `asFunction`, and `lookupFunction` check the type > correspondence between native and Dart type with a subtype check of > the expected Dart type and the provided Dart type. For functions, > any return type is a subtype of a void type. This is fine for Dart, > but not for native calls. This CL manually checks the return type > for void. > > This CL does not fix the inconsistency between `asFunction` and > `FfiNative` with regard to allowing more strict return types than > `Object` for `Handle`s > Issue: #49518 > > Analyzer fixes in follow up CL. > > TEST=tests/ffi/vmspecific_static_checks_ffinative_test.dart > > Closes: #49471 > Change-Id: Ibc7bd6a1a0db59cc5fa5d755d76999fd7e9a06a4 > Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252601 > Reviewed-by: Martin Kustermann <kustermann@google.com> > Commit-Queue: Daco Harkes <dacoharkes@google.com> TBR=kustermann@google.com,dacoharkes@google.com Change-Id: Id82b129d491adcc94cdd685a0a0f6a43248c71f2 No-Presubmit: true No-Tree-Checks: true No-Try: true Issue: #49518 Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252662 Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This is a reland of commit 206fdf1 Original change's description: > [cfe/ffi] Improve FFI call mismatched types compile errors > > This CL fixes two issues. > > 1. `FfiNative`s now check the Dart and native type for compatiblity. > 2. Both `FfiNative`, `asFunction`, and `lookupFunction` check the type > correspondence between native and Dart type with a subtype check of > the expected Dart type and the provided Dart type. For functions, > any return type is a subtype of a void type. This is fine for Dart, > but not for native calls. This CL manually checks the return type > for void. > > This CL does not fix the inconsistency between `asFunction` and > `FfiNative` with regard to allowing more strict return types than > `Object` for `Handle`s > Issue: #49518 > > Analyzer fixes in follow up CL. > > TEST=tests/ffi/vmspecific_static_checks_ffinative_test.dart > > Closes: #49471 > Change-Id: Ibc7bd6a1a0db59cc5fa5d755d76999fd7e9a06a4 > Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252601 > Reviewed-by: Martin Kustermann <kustermann@google.com> > Commit-Queue: Daco Harkes <dacoharkes@google.com> TEST=tests/ffi/vmspecific_static_checks_ffinative_test.dart Change-Id: Ic1efba45ae8ff2585fc67fdf63c653ce090d0337 Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,analyzer-mac-release-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252663 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
https://dart-review.googlesource.com/c/sdk/+/252601/6/pkg/vm/testcases/transformations/ffi/ffinative.dart
asFunction
andlookupFunction
do not allow the return type to be sticter thanObject
when the native type isHandle
.The old
native
s do allow the return type to be stricter thanObject
.It would be good to update
FfiNative
s to be consistent withasFunction
, but that would make them inconsistent with oldnative
s.The text was updated successfully, but these errors were encountered: