[record_use] Test external functions vm/wasm

Closes: https://github.com/dart-lang/native/issues/2961

TEST=pkg/compiler/test/record_use/record_use_test.dart
TEST=pkg/dart2wasm/test/record_use_test.dart
TEST=pkg/vm/test/transformations/record_use_test.dart

Change-Id: I0f15dac909a8ddff271ba06b16bada74120839d2
Cq-Include-Trybots: luci.dart.try:dart2wasm-asserts-linux-chrome-try,dart2wasm-asserts-minified-linux-d8-try,dart2wasm-linux-chrome-try,dart2wasm-linux-d8-try,dart2wasm-linux-firefox-try,dart2wasm-linux-jscm-chrome-try,dart2wasm-linux-optimized-jsc-try,pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart2js-canary-linux-try,dart2js-hostasserts-linux-d8-try,dart2js-linux-chrome-try,dart2js-linux-firefox-try,dart2js-mac-chrome-try,dart2js-mac-safari-try,dart2js-minified-csp-linux-chrome-try,dart2js-minified-linux-d8-try,dart2js-unit-linux-x64-release-try,dart2js-win-chrome-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/483640
Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Daco Harkes
2026-02-27 02:17:03 -08:00
committed by Commit Queue
parent b5c437b03f
commit 3036eed396
4 changed files with 130 additions and 1 deletions
@@ -231,4 +231,4 @@ Future<String?> compileWithUsages({
.toString();
}
const Set<String> dart2jsNotSupported = {};
const Set<String> dart2jsNotSupported = {'external_function.dart'};
@@ -0,0 +1,18 @@
// Copyright (c) 2026, 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 'package:meta/meta.dart' show RecordUse;
void main() {
print(someExternalFunction(6));
print(SomeClass.someExternalStaticMethod(7));
}
@RecordUse()
external int someExternalFunction(int k);
class SomeClass {
@RecordUse()
external static int someExternalStaticMethod(int k);
}
@@ -0,0 +1,28 @@
library #lib;
import self as self;
import "dart:core" as core;
import "package:meta/meta.dart" as meta;
import "package:meta/meta.dart" show RecordUse;
abstract class SomeClass extends core::Object {
[@vm.inferred-return-type.metadata=int]
[@vm.unboxing-info.metadata=(i)->i]
@#C1
external static method someExternalStaticMethod([@vm.inferred-arg-type.metadata=dart.core::_Smi (value: 7)] core::int k) → core::int;
}
[@vm.inferred-return-type.metadata=dart.core::Null? (value: null)]
static method main() → void {
core::print([@vm.inferred-type.metadata=int] self::someExternalFunction(6));
core::print([@vm.inferred-type.metadata=int] self::SomeClass::someExternalStaticMethod(7));
}
[@vm.inferred-return-type.metadata=int]
[@vm.unboxing-info.metadata=(i)->i]
@#C1
external static method someExternalFunction([@vm.inferred-arg-type.metadata=dart.core::_Smi (value: 6)] core::int k) → core::int;
constants {
#C1 = meta::RecordUse {}
}
@@ -0,0 +1,83 @@
{
"constants": [
{
"type": "int",
"value": 6
},
{
"type": "int",
"value": 7
}
],
"definitions": [
{
"path": [
{
"kind": "class",
"name": "SomeClass"
},
{
"disambiguators": [
"static"
],
"kind": "method",
"name": "someExternalStaticMethod"
}
],
"uri": "package:record_use_test/external_function.dart"
},
{
"path": [
{
"disambiguators": [
"static"
],
"kind": "method",
"name": "someExternalFunction"
}
],
"uri": "package:record_use_test/external_function.dart"
}
],
"loading_units": [
{
"name": "1"
}
],
"metadata": {
"comment": "Recorded usages of objects tagged with a `RecordUse` annotation.",
"version": "0.4.0"
},
"uses": {
"static_calls": [
{
"definition_index": 0,
"uses": [
{
"loading_unit_indices": [
0
],
"positional": [
1
],
"type": "with_arguments"
}
]
},
{
"definition_index": 1,
"uses": [
{
"loading_unit_indices": [
0
],
"positional": [
0
],
"type": "with_arguments"
}
]
}
]
}
}