[record_use] Support Set constants

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

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: I806ccc1c18c9ce106ac5106f4ca1c2237655d95f
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/+/488300
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes
2026-03-17 01:46:44 -07:00
committed by Commit Queue
parent 786e90791d
commit a5edb1208f
6 changed files with 138 additions and 6 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ vars = {
"i18n_rev": "de7e11b7cc231d8daf6e49dc12690d7339241691",
"leak_tracker_rev": "f5620600a5ce1c44f65ddaa02001e200b096e14c", # rolled manually
"material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e",
"native_rev": "ac1144e65a4621b9f94324f307bc3437b5b74f66", # rolled manually while record_use is experimental
"native_rev": "7d803f16c4d5a34844b3572962c78715c4ddcecf", # rolled manually while record_use is experimental
"protobuf_rev": "d5639f45b8468fba684b076b9403ccd5f2290056",
"pub_rev": "74408212b5348003381bc63f3b59274aaa23cfa3", # rolled manually
"shelf_rev": "900731b313dabf48927a82f2124e5a996c4a3d05",
@@ -457,9 +457,7 @@ class RecordUseValueConverter {
ListConstantValue() => _findListValue(constant),
ConstructedConstantValue() => findInstanceValue(constant),
DoubleConstantValue() => record_use.DoubleConstant(constant.doubleValue),
SetConstantValue() => record_use.UnsupportedConstant(
'Set literals are not supported for recording.',
),
SetConstantValue() => _findSetValue(constant),
RecordConstantValue() => _findRecordValue(constant),
InstantiationConstantValue() => _findValue(constant.function),
FunctionConstantValue() => record_use.UnsupportedConstant(
@@ -494,6 +492,14 @@ class RecordUseValueConverter {
return record_use.ListConstant(result);
}
record_use.SetConstant _findSetValue(SetConstantValue constant) {
final result = <record_use.Constant>[];
for (final constantValue in constant.values) {
result.add(_findValue(constantValue));
}
return record_use.SetConstant(result);
}
record_use.RecordConstant _findRecordValue(RecordConstantValue constant) {
final positional = <record_use.Constant>[];
for (var i = 0; i < constant.shape.positionalFieldCount; i++) {
@@ -266,8 +266,8 @@ Constant evaluateConstant(ast.Constant constant) => switch (constant) {
// The following are not supported, but theoretically could be, so they
// are listed explicitly here.
ast.AuxiliaryConstant() => _unsupported('AuxiliaryConstant'),
ast.SetConstant() => UnsupportedConstant(
'Set literals are not supported for recording.',
ast.SetConstant() => SetConstant(
constant.entries.map(evaluateConstant).toList(),
),
ast.InstantiationConstant() => evaluateConstant(constant.tearOffConstant),
ast.TearOffConstant() => UnsupportedConstant(
@@ -0,0 +1,13 @@
// 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() {
recorded(const {1, 2, 3});
recorded(const {'a', 'b'});
}
@RecordUse()
void recorded(Object arg) {}
@@ -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;
[@vm.inferred-return-type.metadata=dart.core::Null? (value: null)]
static method main() → void {
self::recorded(#C4);
self::recorded(#C7);
}
[@vm.inferred-return-type.metadata=dart.core::Null? (value: null)]
[@vm.unboxing-info.metadata=[!regcc]]
@#C8
static method recorded([@vm.inferred-arg-type.metadata=dart._compact_hash::_ConstSet] core::Object arg) → void {}
constants {
#C1 = 1
#C2 = 2
#C3 = 3
#C4 = <core::int>{#C1, #C2, #C3}
#C5 = "a"
#C6 = "b"
#C7 = <core::String>{#C5, #C6}
#C8 = meta::RecordUse {}
}
@@ -0,0 +1,85 @@
{
"constants": [
{
"type": "int",
"value": 1
},
{
"type": "int",
"value": 2
},
{
"type": "int",
"value": 3
},
{
"type": "string",
"value": "a"
},
{
"type": "string",
"value": "b"
},
{
"type": "set",
"value": [
3,
4
]
},
{
"type": "set",
"value": [
0,
1,
2
]
}
],
"definitions": [
{
"path": [
{
"disambiguators": [
"static"
],
"kind": "method",
"name": "recorded"
}
],
"uri": "package:record_use_test/set_const.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_index": 0,
"positional": [
5
],
"type": "with_arguments"
},
{
"loading_unit_index": 0,
"positional": [
6
],
"type": "with_arguments"
}
]
}
]
}
}