Files
sdk/tests/language/function/direct_invocation_test.dart
T
Ömer Sinan Ağacan dbee089237 [dart2wasm] Devirtualize closure calls based on TFA direct-call metadata
Use the TFA direct-call metadata to directly call a closure in function
invocations.

Closes #55231.

Tested: existing tests cover the new code paths, but I also added a new
test.
Change-Id: Ib5f26b10efd77570e256196b4bfb07e6bef800c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397260
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
2024-12-11 10:46:20 +00:00

36 lines
802 B
Dart

// Copyright (c) 2024, 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.
// Test using TFA's direct-call metadata in function invocations.
import "package:expect/expect.dart";
int f(int x, [int? y]) => x;
// Calls `f` directly.
int test1(int cb(int a)) => cb(1);
class A {
int f(int x, [int? y]) => x;
}
// Calls `A.f` directly.
int test2(int cb(int a)) => cb(2);
class B {
int nested() {
int cb1(int x, [int? y]) => x;
return test3(cb1);
}
}
// Calls the nested closure `cb1` directly.
int test3(int cb(int a)) => cb(3);
void main() {
Expect.equals(test1(f), 1);
Expect.equals(test2(A().f), 2);
Expect.equals(B().nested(), 3);
}