[dart2js] Migrate more serialization dependencies

Change-Id: If58b5b2c61a0bcc59ca4401285fd01254cc80497
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/248523
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams
2022-06-15 14:18:48 +00:00
committed by Commit Bot
parent 91222348ce
commit 2d1e5d29c8
17 changed files with 156 additions and 38 deletions
@@ -10,7 +10,7 @@ import '../common.dart';
import '../constants/values.dart'
show ConstantValue, DeferredGlobalConstantValue;
import '../elements/entities.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../options.dart';
// TODO(48820): Move OutputUnit and compareImportEntities back here.
+1 -1
View File
@@ -24,7 +24,7 @@ import '../js_model/js_world.dart';
import '../js_model/locals.dart';
import '../native/behavior.dart';
import '../options.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/call_structure.dart';
import '../universe/selector.dart';
import '../universe/side_effects.dart';
@@ -9,7 +9,7 @@ import '../../elements/entities.dart';
import '../../elements/names.dart';
import '../../elements/types.dart' show DartType;
import '../../ir/class_relation.dart';
import '../../serialization/serialization.dart';
import '../../serialization/serialization_interfaces.dart';
import '../../universe/selector.dart';
import '../../universe/world_builder.dart';
import '../../universe/use.dart';
@@ -15,7 +15,7 @@ import '../../elements/entities.dart';
import '../../elements/names.dart';
import '../../elements/types.dart';
import '../../ir/class_relation.dart';
import '../../serialization/serialization.dart';
import '../../serialization/serialization_interfaces.dart';
import '../../universe/class_hierarchy.dart';
import '../../universe/selector.dart' show Selector;
import '../../universe/use.dart' show DynamicUse;
+1 -1
View File
@@ -9,7 +9,7 @@ import '../elements/entities.dart';
import '../elements/names.dart';
import '../elements/types.dart' show DartType;
import '../ir/class_relation.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/selector.dart';
import '../universe/world_builder.dart';
import '../universe/use.dart';
@@ -10,7 +10,7 @@ import '../elements/entities.dart';
import '../elements/types.dart';
import '../ir/runtime_type_analysis.dart';
import '../kernel/kernel_strategy.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/feature.dart';
import '../util/util.dart' show Setlet;
import 'backend_impact.dart';
@@ -10,7 +10,7 @@ import 'package:front_end/src/api_unstable/dart2js.dart' show $A;
import '../common/elements.dart' show JCommonElements;
import '../elements/entities.dart';
import '../js/js.dart' as js;
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../util/util.dart';
import '../js_emitter/model.dart';
import '../constants/values.dart' show ConstantValue;
@@ -14,13 +14,13 @@ import '../elements/entity_utils.dart';
import '../elements/types.dart';
import '../ir/scope_visitor.dart';
import '../js_model/elements.dart' show JField;
import '../js_model/js_world_builder.dart';
import '../js_model/js_world_builder.dart' show JsToFrontendMap;
import '../kernel/element_map.dart';
import '../kernel/kernel_strategy.dart';
import '../kernel/kelements.dart' show KClass, KField, KConstructor;
import '../kernel/kernel_world.dart';
import '../options.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/member_usage.dart';
/// AllocatorAnalysis
@@ -9,7 +9,7 @@ import 'dart:collection' show Queue;
import '../common.dart';
import '../elements/entities.dart';
import '../inferrer/abstract_value_domain.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/selector.dart';
import '../universe/side_effects.dart';
import '../world.dart';
@@ -13,7 +13,7 @@ import '../elements/entities.dart';
import '../elements/types.dart';
import '../inferrer/abstract_value_domain.dart';
import '../js/js.dart' as jsAst;
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/class_set.dart';
import '../universe/selector.dart';
import '../world.dart' show JClosedWorld;
@@ -10,7 +10,7 @@ import '../common/names.dart' show Identifiers, Selectors;
import '../elements/entities.dart';
import '../inferrer/types.dart';
import '../kernel/no_such_method_resolver.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
/// [NoSuchMethodRegistry] and [NoSuchMethodData] categorizes `noSuchMethod`
/// implementations.
@@ -16,7 +16,7 @@ import '../ir/runtime_type_analysis.dart';
import '../kernel/kelements.dart';
import '../kernel/kernel_world.dart';
import '../options.dart';
import '../serialization/serialization.dart';
import '../serialization/serialization_interfaces.dart';
import '../universe/class_hierarchy.dart';
import '../universe/class_set.dart';
import '../universe/feature.dart';
@@ -7,6 +7,7 @@ import 'package:kernel/ast.dart' as ir show DartType, Member, TreeNode;
import '../constants/values.dart' show ConstantValue;
import '../elements/entities.dart';
import '../elements/types.dart' show DartType;
import '../inferrer/abstract_value_domain.dart' show AbstractValue;
export 'tags.dart';
@@ -61,9 +62,17 @@ abstract class DataSinkWriter {
void writeClass(covariant ClassEntity value); // IndexedClass
void writeClassOrNull(covariant ClassEntity? value); // IndexedClass
void writeClasses(Iterable<ClassEntity> values, {bool allowNull = false});
void writeClassMap<V>(Map<ClassEntity, V>? map, void f(V value),
{bool allowNull = false});
void writeTypeVariable(
covariant TypeVariableEntity value); // IndexedTypeVariable
void writeMember(covariant MemberEntity member); // IndexMember
void writeMemberOrNull(covariant MemberEntity? member); // IndexMember
void writeMembers(Iterable<MemberEntity>? values, {bool allowNull = false});
void writeMemberMap<V>(
Map<MemberEntity, V>? map, void f(MemberEntity member, V value),
{bool allowNull = false});
@@ -89,6 +98,19 @@ abstract class DataSinkWriter {
{bool allowNull = false});
void writeConstant(ConstantValue value);
void writeConstantOrNull(ConstantValue? value);
void writeConstantMap<V>(Map<ConstantValue, V>? map, void f(V value),
{bool allowNull = false});
void writeValueOrNull<E>(E? value, void f(E value));
void writeImport(ImportEntity import);
void writeImportOrNull(ImportEntity? import);
void writeImports(Iterable<ImportEntity>? values, {bool allowNull = false});
void writeImportMap<V>(Map<ImportEntity, V>? map, void f(V value),
{bool allowNull = false});
void writeAbstractValue(AbstractValue value);
}
/// Migrated interface for methods of DataSourceReader.
@@ -112,8 +134,17 @@ abstract class DataSourceReader {
ClassEntity readClass(); // IndexedClass
ClassEntity? readClassOrNull(); // IndexedClass
List<E> readClasses<E extends ClassEntity>();
List<E>? readClassesOrNull<E extends ClassEntity>();
Map<K, V> readClassMap<K extends ClassEntity, V>(V f());
Map<K, V>? readClassMapOrNull<K extends ClassEntity, V>(V f());
TypeVariableEntity readTypeVariable(); // IndexedTypeVariable
MemberEntity readMember();
MemberEntity? readMemberOrNull();
List<E> readMembers<E extends MemberEntity>();
List<E>? readMembersOrNull<E extends MemberEntity>();
Map<K, V> readMemberMap<K extends MemberEntity, V>(V f(MemberEntity member));
Map<K, V>? readMemberMapOrNull<K extends MemberEntity, V>(
V f(MemberEntity member));
@@ -140,6 +171,20 @@ abstract class DataSourceReader {
List<E>? readListOrNull<E extends Object>(E f());
ConstantValue readConstant();
ConstantValue? readConstantOrNull();
Map<K, V> readConstantMap<K extends ConstantValue, V>(V f());
Map<K, V>? readConstantMapOrNull<K extends ConstantValue, V>(V f());
E? readValueOrNull<E>(E f());
ImportEntity readImport();
ImportEntity? readImportOrNull();
List<ImportEntity> readImports();
List<ImportEntity>? readImportsOrNull();
Map<ImportEntity, V> readImportMap<V>(V f());
Map<ImportEntity, V>? readImportMapOrNull<V>(V f());
AbstractValue readAbstractValue();
E readWithSource<E>(DataSourceReader source, E f());
E readWithOffset<E>(int offset, E f());
+14 -1
View File
@@ -151,6 +151,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readValueOrNull].
@override
void writeValueOrNull<E>(E value, void f(E value)) {
writeBool(value != null);
if (value != null) {
@@ -766,6 +767,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readClasses].
@override
void writeClasses(Iterable<ClassEntity> values, {bool allowNull = false}) {
if (values == null) {
assert(allowNull);
@@ -784,6 +786,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readClassMap].
@override
void writeClassMap<V>(Map<ClassEntity, V> map, void f(V value),
{bool allowNull = false}) {
if (map == null) {
@@ -799,6 +802,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
}
/// Writes a reference to the indexed member [value] to this data sink.
@override
void writeMember(IndexedMember value) {
_entityWriter.writeMemberToDataSink(this, value);
}
@@ -808,6 +812,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readMemberOrNull].
@override
void writeMemberOrNull(IndexedMember value) {
writeBool(value != null);
if (value != null) {
@@ -820,6 +825,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readMembers].
@override
void writeMembers(Iterable<MemberEntity> values, {bool allowNull = false}) {
if (values == null) {
assert(allowNull);
@@ -1048,6 +1054,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
}
/// Writes the potentially `null` constant [value] to this data sink.
@override
void writeConstantOrNull(ConstantValue value) {
writeBool(value != null);
if (value != null) {
@@ -1079,6 +1086,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readConstantMap].
@override
void writeConstantMap<V>(Map<ConstantValue, V> map, void f(V value),
{bool allowNull = false}) {
if (map == null) {
@@ -1122,6 +1130,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
}
/// Writes the import [value] to this data sink.
@override
void writeImport(ImportEntity value) {
_writeDataKind(DataKind.import);
_writeImport(value);
@@ -1140,6 +1149,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
}
/// Writes the potentially `null` import [value] to this data sink.
@override
void writeImportOrNull(ImportEntity value) {
writeBool(value != null);
if (value != null) {
@@ -1152,6 +1162,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readImports].
@override
void writeImports(Iterable<ImportEntity> values, {bool allowNull = false}) {
if (values == null) {
assert(allowNull);
@@ -1170,7 +1181,8 @@ class DataSinkWriter implements migrated.DataSinkWriter {
///
/// This is a convenience method to be used together with
/// [DataSourceReader.readImportMap].
void writeImportMap<V>(Map<ImportEntity, V> map, void f(V value),
@override
void writeImportMap<V>(Map<ImportEntity, V> /*?*/ map, void f(V value),
{bool allowNull = false}) {
if (map == null) {
assert(allowNull);
@@ -1187,6 +1199,7 @@ class DataSinkWriter implements migrated.DataSinkWriter {
/// Writes an abstract [value] to this data sink.
///
/// This feature is only available a [CodegenWriter] has been registered.
@override
void writeAbstractValue(AbstractValue value) {
assert(_codegenWriter != null,
"Can not serialize an AbstractValue without a registered codegen writer.");
+81 -21
View File
@@ -273,6 +273,7 @@ class DataSourceReader implements migrated.DataSourceReader {
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeValueOrNull].
@override
E readValueOrNull<E>(E f()) {
bool hasValue = readBool();
if (hasValue) {
@@ -982,13 +983,23 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a list of references to indexed classes from this data source.
/// If [emptyAsNull] is `true`, `null` is returned instead of an empty list.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeClasses].
List<E> readClasses<E extends ClassEntity>({bool emptyAsNull = false}) {
@override
List<E> readClasses<E extends ClassEntity>() {
return readClassesOrNull<E>() ?? List.empty();
}
/// Reads a list of references to indexed classes from this data source.
/// `null` is returned instead of an empty list.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeClasses].
@override
List<E> readClassesOrNull<E extends ClassEntity>() {
int count = readInt();
if (count == 0 && emptyAsNull) return null;
if (count == 0) return null;
List<E> list = List<E>.filled(count, null);
for (int i = 0; i < count; i++) {
ClassEntity cls = readClass();
@@ -998,15 +1009,25 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a map from indexed classes to [V] values from this data source,
/// calling [f] to read each value from the data source. If [emptyAsNull] is
/// `true`, `null` is returned instead of an empty map.
/// calling [f] to read each value from the data source.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeClassMap].
Map<K, V> readClassMap<K extends ClassEntity, V>(V f(),
{bool emptyAsNull = false}) {
@override
Map<K, V> readClassMap<K extends ClassEntity, V>(V f()) {
return readClassMapOrNull<K, V>(f) ?? {};
}
/// Reads a map from indexed classes to [V] values from this data source,
/// calling [f] to read each value from the data source. `null` is returned if
/// the map is empty.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeClassMap].
@override
Map<K, V> /*?*/ readClassMapOrNull<K extends ClassEntity, V>(V f()) {
int count = readInt();
if (count == 0 && emptyAsNull) return null;
if (count == 0) return null;
Map<K, V> map = {};
for (int i = 0; i < count; i++) {
ClassEntity cls = readClass();
@@ -1017,12 +1038,14 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a reference to an indexed member from this data source.
@override
IndexedMember /*!*/ readMember() {
return _entityReader.readMemberFromDataSource(this, entityLookup);
}
/// Reads a reference to a potentially `null` indexed member from this data
/// source.
@override
IndexedMember readMemberOrNull() {
bool hasValue = readBool();
if (hasValue) {
@@ -1035,6 +1058,7 @@ class DataSourceReader implements migrated.DataSourceReader {
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeMembers].
@override
List<E /*!*/ > readMembers<E extends MemberEntity /*!*/ >() {
return readMembersOrNull() ?? List.empty();
}
@@ -1044,6 +1068,7 @@ class DataSourceReader implements migrated.DataSourceReader {
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeMembers].
@override
List<E /*!*/ > readMembersOrNull<E extends MemberEntity /*!*/ >() {
int count = readInt();
if (count == 0) return null;
@@ -1263,6 +1288,7 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a potentially `null` constant value from this data source.
@override
ConstantValue readConstantOrNull() {
bool hasClass = readBool();
if (hasClass) {
@@ -1288,15 +1314,25 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a map from constant values to [V] values from this data source,
/// calling [f] to read each value from the data source. If [emptyAsNull] is
/// `true`, `null` is returned instead of an empty map.
/// calling [f] to read each value from the data source.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeConstantMap].
Map<K, V> readConstantMap<K extends ConstantValue, V>(V f(),
{bool emptyAsNull = false}) {
@override
Map<K, V> readConstantMap<K extends ConstantValue, V>(V f()) {
return readConstantMapOrNull<K, V>(f) ?? {};
}
/// Reads a map from constant values to [V] values from this data source,
/// calling [f] to read each value from the data source. `null` is returned
/// instead of an empty map.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeConstantMap].
@override
Map<K, V> /*?*/ readConstantMapOrNull<K extends ConstantValue, V>(V f()) {
int count = readInt();
if (count == 0 && emptyAsNull) return null;
if (count == 0) return null;
Map<K, V> map = {};
for (int i = 0; i < count; i++) {
ConstantValue key = readConstant();
@@ -1334,6 +1370,7 @@ class DataSourceReader implements migrated.DataSourceReader {
return BigInt.parse(readString());
}
@override
ImportEntity readImport() {
_checkDataKind(DataKind.import);
return _readImport();
@@ -1353,6 +1390,7 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a potentially `null` import from this data source.
@override
ImportEntity readImportOrNull() {
bool hasClass = readBool();
if (hasClass) {
@@ -1361,14 +1399,24 @@ class DataSourceReader implements migrated.DataSourceReader {
return null;
}
/// Reads a list of imports from this data source. If [emptyAsNull] is
/// `true`, `null` is returned instead of an empty list.
/// Reads a list of imports from this data source.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeImports].
List<ImportEntity> readImports({bool emptyAsNull = false}) {
@override
List<ImportEntity> readImports() {
return readImportsOrNull() ?? const [];
}
/// Reads a list of imports from this data source.
/// `null` is returned instead of an empty list.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeImports].
@override
List<ImportEntity> /*?*/ readImportsOrNull() {
int count = readInt();
if (count == 0 && emptyAsNull) return null;
if (count == 0) return null;
List<ImportEntity> list = List<ImportEntity>.filled(count, null);
for (int i = 0; i < count; i++) {
list[i] = readImport();
@@ -1377,14 +1425,25 @@ class DataSourceReader implements migrated.DataSourceReader {
}
/// Reads a map from imports to [V] values from this data source,
/// calling [f] to read each value from the data source. If [emptyAsNull] is
/// `true`, `null` is returned instead of an empty map.
/// calling [f] to read each value from the data source.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeImportMap].
Map<ImportEntity, V> readImportMap<V>(V f(), {bool emptyAsNull = false}) {
@override
Map<ImportEntity, V> readImportMap<V>(V f()) {
return readImportMapOrNull<V>(f) ?? {};
}
/// Reads a map from imports to [V] values from this data source, calling [f]
/// to read each value from the data source. `null` is returned if the map is
/// empty map.
///
/// This is a convenience method to be used together with
/// [DataSinkWriter.writeImportMap].
@override
Map<ImportEntity, V> /*?*/ readImportMapOrNull<V>(V f()) {
int count = readInt();
if (count == 0 && emptyAsNull) return null;
if (count == 0) return null;
Map<ImportEntity, V> map = {};
for (int i = 0; i < count; i++) {
ImportEntity key = readImport();
@@ -1397,6 +1456,7 @@ class DataSourceReader implements migrated.DataSourceReader {
/// Reads an [AbstractValue] from this data source.
///
/// This feature is only available a [CodegenReader] has been registered.
@override
AbstractValue readAbstractValue() {
assert(
_codegenReader != null,
@@ -9,7 +9,7 @@ import 'dart:math' as Math;
import '../common.dart';
import '../constants/values.dart';
import '../elements/entities.dart';
import '../js_model/closure.dart';
import '../js_model/closure.dart' show JRecordField;
import '../serialization/serialization_interfaces.dart';
import '../util/enumset.dart';
import 'call_structure.dart';
+2 -2
View File
@@ -23,8 +23,8 @@ import '../constants/values.dart';
import '../elements/types.dart';
import '../elements/entities.dart';
import '../inferrer/abstract_value_domain.dart';
import '../serialization/serialization.dart';
import '../js_model/closure.dart';
import '../serialization/serialization_interfaces.dart';
import '../js_model/closure.dart' show JRecordField;
import '../util/util.dart' show equalElements, Hashing;
import 'call_structure.dart' show CallStructure;
import 'selector.dart' show Selector;