Files
sdk/pkg/vm/testcases/transformations/ffi/finalizable_sync.dart
T
Daco Harkes 3156c5629d [cfe/ffi] Implement Finalizable
This CL implements `Finalizable` by means of a CFE transform.
The transform is implemented in the existing FFI transform to avoid the
overhead of traversing the AST an extra time. The FFI transform slows
down ~15-30% on Flutter Gallery. For more info see the design doc.

TEST=`dart pkg/vm/test/transformations/ffi_test.dart`

Design doc: go/dart-vm-finalizable

Bug: https://github.com/dart-lang/sdk/issues/47777

Change-Id: I0bf9dead90a61631b7f215dc19fbaa9e40e63c8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227501
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-02-05 11:54:59 +00:00

43 lines
955 B
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.
// @dart=2.16
import 'dart:ffi';
int doSomething() => 3;
class MyFinalizable implements Finalizable {
int use() {
return doSomething();
}
}
/// Should be transformed into:
///
/// ```
/// int useFinalizableSync(Finalizable finalizable) {
/// final result = doSomething();
/// _reachabilityFence(finalizable);
/// return result;
/// }
/// ```
int useFinalizableSync(Finalizable finalizable) {
return doSomething();
}
/// Should be transformed into:
///
/// ```
/// void main() {
/// final finalizable = MyFinalizable();
/// print(useFinalizableSync(finalizable));
/// _reachabilityFence(finalizable);
/// }
/// ```
void main() {
final finalizable = MyFinalizable();
print(useFinalizableSync(finalizable));
}