-
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
[Breaking Change Request] [vm/ffi] Disallow empty structs #44622
Comments
@dcharkes Please make an announcement to https://groups.google.com/a/dartlang.org/g/announce cc @Hixie @matanlurey @vsmenon for review and approval. |
I have no opinion on this and thus no objection. |
lgtm |
I don't work in this area, no comment. |
Announcement sent: https://groups.google.com/a/dartlang.org/g/announce/c/kZOGrc6-rIg |
Is there a rough ETA for these changes? Considering that the apis haven't landed yet and that Dart 2.12 was announced for "early 2021", I'm a bit worried about how little time we might have to migrate. Is there any way to get the |
Approved |
Issue: #44622 Issue: #43974 TEST=samples/ffi/sqlite/lib/src/bindings/types.dart TEST=tests/ffi/vmspecific_static_checks_test.dart Change-Id: Ib9e72df6a07b1bc2b72a7db66f945652814baf51 Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,analyzer-nnbd-linux-release-try,front-end-linux-release-x64-try,front-end-nnbd-linux-release-x64-try,benchmark-linux-try,dart-sdk-linux-try,pkg-linux-release-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64-try,vm-kernel-nnbd-win-debug-x64-try,vm-kernel-win-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178984 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Clement Skau <cskau@google.com>
I've landed the new API in master. Deprecating the old API will take some time, because this has to roll into Flutter first. |
This CL migrates empty `Struct`s to `Opaque` native types. It stops using `.ref` on `Pointer`s to these types. And stops using `.ref` on `Pointer<Utf8>` which will be migrated in `package:ffi`. Issue: #44622 Issue: #43974 Change-Id: I3aa256af7d4ceaa8ee37b1b2ada71f870f43617b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179181 Reviewed-by: Vyacheslav Egorov <vegorov@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com>
This CL adds fields to `Struct`s which should not be empty or removes the structs. Issue: #44622 Issue: #43974 TEST=tests/ffi/vmspecific_static_checks_test.dart Change-Id: I4a684bd96e3ed16a3fd0dd17019aeabf64ef074a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179182 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This can only be landed when `Allocator` and `Opaque` have rolled into Flutter/engine, that into Flutter/flutter, and that into g3. flutter/flutter/commit/a706cd211240f27be3b61f06d70f958c7a4156fe Deletes all the copies of `_CallocAllocator` and uses the one from `package:ffi` instead. Issue: #44622 Issue: #43974 Issue: #44621 Issue: #38721 Change-Id: I50b3b4c31a2b839b35e3e057bd54f463b90bc55e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179540 Reviewed-by: Aske Simon Christensen <askesc@google.com>
Issue: #44621 Issue: #44622 Change-Id: I9689db63a5b47946b501fac9df63cc86811d6e41 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179764 Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
@simolus3 We will deprecate support for empty structs and add |
That's relieving to hear, thank you! |
Changes `Utf8` and `Utf16` to extend `Opaque` instead of `Struct`. This means `.ref` is no longer available and `Pointer<Utf(..)>` should be used. See [breaking change #44622](dart-lang/sdk#44622) for more info. Removes `allocate` and `free`. Instead, introduces `calloc` which implements the new `Allocator` interface. See [breaking change #44621](dart-lang/sdk#44621) for more info. This pre-release requires Dart `2.12.0-265.0.dev` or greater.
This can only be landed when `Allocator`, `Opaque`, and `AllocatorAlloc` have rolled into Flutter/engine, that into Flutter/flutter, and into g3. Deletes all the copies of `_CallocAllocator` and uses the one from `package:ffi` instead. Bug: #44622 Bug: #43974 Bug: #44621 Bug: #38721 Change-Id: I486034b379b5a63cad4aefd503ccd0f2ce5dd45e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180188 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Aske Simon Christensen <askesc@google.com>
Update 2021-01-22: We will deprecate empty structs as of Dart 2.12 and remove support for them in 2.13.
Summary
Disallow defining subclasses of
Struct
without fields.sdk/tests/ffi/vmspecific_static_checks_test.dart
Line 486 in 897b1a2
Introduce the
Opaque
native type to represent opaque C types.Motivation
allocate<Utf8>()
and allocating 0 bytes of native memory ([vm/ffi] Deprecate empty structs #43974, Making Utf8/Utf16 a subclass of Struct is misleading dart-archive/ffi#34).Impact
Definitions need to be migrated from
extends Struct
toextends Opaque
.Use sites can no longer use
.ref
to pass around 'references' with types such asUtf8
. Instead,Pointer<Utf8>
needs to be passed around.Migration of package:ffi
Proposed changes:
Migration of users of package:ffi
Example migrations:
Discussion
We could change the
NativeType
hierarchy to the following and reduce the amount of custom checks in the analyzer and common frontend (forsizeOf
,Pointer.elementAt
andAllocator.call
).sizeOf
,Pointer.elementAt
(would become an extension method) andAllocator.call
)The text was updated successfully, but these errors were encountered: