mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
92e5746494
This is a reland of commit 1755f89092
Can land after (or with) the Flutter PR:
https://github.com/flutter/engine/pull/40434
Original change's description:
> [vm/ffi] Add class modifiers
>
> Adds class modifiers to `dart:ffi`.
>
> Migrates all user-defined subclasses of `Struct`, `Union`, `Opaque`,
> and `AbiSpecificInteger` to be `final class`es.
>
> Does not remove the manual error checking, so some errors will show up
> twice now in language version 3.0. In language version <3.0, only the
> FFI-specific error will show up.
>
> In a follow-up CL, we will try to make the language-errors to show up
> also <3.0 so that we can remove the FFI-specific errors.
>
> Examples of duplicated errors:
> pkg/analyzer/test/src/diagnostics/subtype_of_ffi_class_test.dart
>
> TEST=pkg/analyzer/test/ (for the analyzer)
> TEST=pkg/front_end/testcases/ (for the CFE)
> TEST=test/ffi/ (for the VM)
>
> CoreLibraryReviewExempt: No need for dart2js to review.
> Bug: https://github.com/dart-lang/sdk/issues/51683
> Change-Id: I2964ceccb7db59fbdaf6be5319f5e4ec2dabe0f3
> Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-win-release-try,pkg-mac-release-try,vm-precomp-ffi-qemu-linux-release-riscv64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-reload-rollback-linux-debug-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289223
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Devon Carew <devoncarew@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Reviewed-by: Jackson Gardner <jacksongardner@google.com>
> Reviewed-by: Lasse Nielsen <lrn@google.com>
> Commit-Queue: Daco Harkes <dacoharkes@google.com>
TEST=pkg/analyzer/test/ (for the analyzer)
TEST=pkg/front_end/testcases/ (for the CFE)
TEST=test/ffi/ (for the VM)
CoreLibraryReviewExempt: No need for dart2js to review.
Bug: https://github.com/dart-lang/sdk/issues/51683
Change-Id: I2ee3f0ac31d4162068a2346a06320029b2263ee2
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-win-release-try,pkg-mac-release-try,vm-precomp-ffi-qemu-linux-release-riscv64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-reload-rollback-linux-debug-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289781
Reviewed-by: Devon Carew <devoncarew@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
71 lines
1.6 KiB
Dart
71 lines
1.6 KiB
Dart
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
Future<void> main() async {
|
|
final contents = [
|
|
header,
|
|
for (final size in sizes) generateSize(size),
|
|
].join('\n');
|
|
|
|
final uri = Platform.script.resolve('dart/benchmark_generated.dart');
|
|
|
|
await File.fromUri(uri).writeAsString(contents);
|
|
}
|
|
|
|
const sizes = [
|
|
1,
|
|
32,
|
|
1024,
|
|
1024 * 32,
|
|
];
|
|
|
|
const header =
|
|
'''// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
import 'FfiStructCopy.dart';
|
|
''';
|
|
|
|
String generateSize(int size) => '''
|
|
final class Struct${size}Bytes extends Struct {
|
|
@Array($size)
|
|
external Array<Uint8> a0;
|
|
}
|
|
|
|
final class Struct${size}BytesWrapper extends Struct {
|
|
external Struct${size}Bytes nested;
|
|
}
|
|
|
|
final class Copy${size}Bytes extends StructCopyBenchmark {
|
|
@override
|
|
Pointer<Struct${size}BytesWrapper> from = nullptr;
|
|
@override
|
|
Pointer<Struct${size}BytesWrapper> to = nullptr;
|
|
|
|
Copy${size}Bytes() : super('FfiStructCopy.Copy${size}Bytes');
|
|
|
|
@override
|
|
int get copySizeInBytes => sizeOf<Struct${size}BytesWrapper>();
|
|
|
|
@override
|
|
void setup(int batchSize) {
|
|
from = calloc(batchSize);
|
|
to = calloc(batchSize);
|
|
}
|
|
|
|
@override
|
|
void run(int batchSize) {
|
|
for (int i = 0; i < batchSize; i++) {
|
|
to[i].nested = from[i].nested;
|
|
}
|
|
}
|
|
}
|
|
''';
|