pkg-compiler: drop Pair class, use Record
Change-Id: I19b05ffc6bd8e87e58990a62a21b8a2986fe9f54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382760
Commit-Queue: Nate Biggs <natebiggs@google.com>
Auto-Submit: Kevin Moore <kevmoo@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
diff --git a/pkg/compiler/lib/src/common/codegen.dart b/pkg/compiler/lib/src/common/codegen.dart
index 1416fa2..6b3edcf 100644
--- a/pkg/compiler/lib/src/common/codegen.dart
+++ b/pkg/compiler/lib/src/common/codegen.dart
@@ -42,8 +42,8 @@
throw UnsupportedError('CodegenImpact.writeToDataSink');
}
- Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks {
- return const <Pair<DartType, DartType>>[];
+ Iterable<(DartType, DartType)> get typeVariableBoundsSubtypeChecks {
+ return const <(DartType, DartType)>[];
}
Iterable<String> get constSymbols => const <String>[];
@@ -71,7 +71,7 @@
@override
final MemberEntity member;
- Set<Pair<DartType, DartType>>? _typeVariableBoundsSubtypeChecks;
+ Set<(DartType, DartType)>? _typeVariableBoundsSubtypeChecks;
Set<String>? _constSymbols;
List<Set<ClassEntity>>? _specializedGetInterceptors;
bool _usesInterceptor = false;
@@ -116,7 +116,7 @@
.readListOrNull(() => ConstantUse.readFromDataSource(source))
?.toSet();
final typeVariableBoundsSubtypeChecks = source.readListOrNull(() {
- return Pair(source.readDartType(), source.readDartType());
+ return (source.readDartType(), source.readDartType());
})?.toSet();
final constSymbols = source.readStringsOrNull()?.toSet();
final specializedGetInterceptors = source.readListOrNull(() {
@@ -161,10 +161,10 @@
sink.writeList(typeUses, (TypeUse use) => use.writeToDataSink(sink));
sink.writeList(
constantUses, (ConstantUse use) => use.writeToDataSink(sink));
- sink.writeListOrNull<Pair<DartType, DartType>>(
- _typeVariableBoundsSubtypeChecks, (pair) {
- sink.writeDartType(pair.a);
- sink.writeDartType(pair.b);
+ sink.writeListOrNull<(DartType, DartType)>(_typeVariableBoundsSubtypeChecks,
+ (pair) {
+ sink.writeDartType(pair.$1);
+ sink.writeDartType(pair.$2);
});
sink.writeStringsOrNull(_constSymbols);
sink.writeListOrNull(_specializedGetInterceptors, sink.writeClasses);
@@ -184,12 +184,11 @@
void registerTypeVariableBoundsSubtypeCheck(
DartType subtype, DartType supertype) {
- (_typeVariableBoundsSubtypeChecks ??= {})
- .add(Pair<DartType, DartType>(subtype, supertype));
+ (_typeVariableBoundsSubtypeChecks ??= {}).add((subtype, supertype));
}
@override
- Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks {
+ Iterable<(DartType, DartType)> get typeVariableBoundsSubtypeChecks {
return _typeVariableBoundsSubtypeChecks ?? const {};
}
diff --git a/pkg/compiler/lib/src/inferrer/builder.dart b/pkg/compiler/lib/src/inferrer/builder.dart
index 0da9108..00b28db 100644
--- a/pkg/compiler/lib/src/inferrer/builder.dart
+++ b/pkg/compiler/lib/src/inferrer/builder.dart
@@ -30,7 +30,6 @@
import '../universe/record_shape.dart';
import '../universe/selector.dart';
import '../universe/side_effects.dart';
-import '../util/util.dart';
import 'engine.dart';
import 'locals_handler.dart';
import 'type_graph_nodes.dart';
@@ -704,14 +703,14 @@
@override
TypeInformation visitMapLiteral(ir.MapLiteral node) {
return createMapTypeInformation(
- node, node.entries.map((e) => Pair(visit(e.key)!, visit(e.value)!)),
+ node, node.entries.map((e) => (visit(e.key)!, visit(e.value)!)),
isConst: node.isConst,
keyStaticType: _elementMap.getDartType(node.keyType),
valueStaticType: _elementMap.getDartType(node.valueType));
}
- TypeInformation createMapTypeInformation(ir.TreeNode node,
- Iterable<Pair<TypeInformation, TypeInformation>> entryTypes,
+ TypeInformation createMapTypeInformation(
+ ir.TreeNode node, Iterable<(TypeInformation, TypeInformation)> entryTypes,
{required bool isConst,
required DartType keyStaticType,
required DartType valueStaticType}) {
@@ -719,9 +718,9 @@
List<TypeInformation> keyTypes = [];
List<TypeInformation> valueTypes = [];
- for (Pair<TypeInformation, TypeInformation> entryType in entryTypes) {
- keyTypes.add(entryType.a);
- valueTypes.add(entryType.b);
+ for ((TypeInformation, TypeInformation) entryType in entryTypes) {
+ keyTypes.add(entryType.$1);
+ valueTypes.add(entryType.$2);
}
final type = isConst ? _types.constMapType : _types.mapType;
@@ -2297,10 +2296,8 @@
@override
TypeInformation visitMapConstant(ir.MapConstant node) {
- return builder.createMapTypeInformation(
- ConstantReference(expression, node),
- node.entries
- .map((e) => Pair(visitConstant(e.key), visitConstant(e.value))),
+ return builder.createMapTypeInformation(ConstantReference(expression, node),
+ node.entries.map((e) => (visitConstant(e.key), visitConstant(e.value))),
isConst: true,
keyStaticType: builder._elementMap.getDartType(node.keyType),
valueStaticType: builder._elementMap.getDartType(node.valueType));
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index f30fbcb..c48253c 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -10,7 +10,6 @@
import 'package:js_shared/synced/async_status_codes.dart' as status_codes;
import '../common.dart';
-import '../util/util.dart' show Pair;
import 'js.dart' as js;
/// Rewrites a [js.Fun] with async/sync*/async* functions and await and yield
@@ -65,7 +64,7 @@
/// are on the way to target (i.e. more nested than the jump target).
List<js.Node> jumpTargets = [];
- List<Pair<String, String>> variableRenamings = [];
+ List<(String, String)> variableRenamings = [];
late final PreTranslationAnalysis analysis;
@@ -1559,7 +1558,7 @@
// block so shadow any catch variable bindings that might collide with
// this one so that references to this binding do not get renamed.
variableRenamings
- .add(Pair(catchPart.declaration.name, catchPart.declaration.name));
+ .add((catchPart.declaration.name, catchPart.declaration.name));
translatedCatchPart =
js.Catch(catchPart.declaration, translateToBlock(catchPart.body));
variableRenamings.removeLast();
@@ -1615,7 +1614,7 @@
// section 12.14.
String errorRename = freshName(catchPart.declaration.name);
localVariables.add(js.VariableDeclaration(errorRename));
- variableRenamings.add(Pair(catchPart.declaration.name, errorRename));
+ variableRenamings.add((catchPart.declaration.name, errorRename));
addStatement(js.js.statement("# = #;", [errorRename, currentError]));
visitStatement(catchPart.body);
variableRenamings.removeLast();
@@ -1695,7 +1694,7 @@
@override
js.Expression visitVariableUse(js.VariableUse node) {
for (final renaming in variableRenamings.reversed) {
- if (renaming.a == node.name) return js.VariableUse(renaming.b);
+ if (renaming.$1 == node.name) return js.VariableUse(renaming.$2);
}
return node;
}
diff --git a/pkg/compiler/lib/src/js_backend/impact_transformer.dart b/pkg/compiler/lib/src/js_backend/impact_transformer.dart
index 9f50c14..7d8184d 100644
--- a/pkg/compiler/lib/src/js_backend/impact_transformer.dart
+++ b/pkg/compiler/lib/src/js_backend/impact_transformer.dart
@@ -18,7 +18,6 @@
import '../universe/selector.dart';
import '../universe/use.dart';
import '../universe/world_impact.dart' show TransformedWorldImpact, WorldImpact;
-import '../util/util.dart';
import 'backend_impact.dart';
import 'backend_usage.dart';
import 'interceptor_data.dart';
@@ -122,10 +121,9 @@
}
}
- for (Pair<DartType, DartType> check
- in impact.typeVariableBoundsSubtypeChecks) {
+ for ((DartType, DartType) check in impact.typeVariableBoundsSubtypeChecks) {
_rtiChecksBuilder.registerTypeVariableBoundsSubtypeCheck(
- check.a, check.b);
+ check.$1, check.$2);
}
for (StaticUse staticUse in impact.staticUses) {
diff --git a/pkg/compiler/lib/src/util/util.dart b/pkg/compiler/lib/src/util/util.dart
index 6370f5f..78d0cf2 100644
--- a/pkg/compiler/lib/src/util/util.dart
+++ b/pkg/compiler/lib/src/util/util.dart
@@ -231,26 +231,6 @@
buffer.write(string);
}
-class Pair<A, B> {
- final A a;
- final B b;
-
- Pair(this.a, this.b);
-
- @override
- int get hashCode => 13 * a.hashCode + 17 * b.hashCode;
-
- @override
- bool operator ==(var other) {
- if (identical(this, other)) return true;
- if (other is! Pair) return false;
- return a == other.a && b == other.b;
- }
-
- @override
- String toString() => '($a,$b)';
-}
-
int longestCommonPrefixLength(List<Object?> a, List<Object?> b) {
int index = 0;
for (; index < a.length && index < b.length; index++) {
diff --git a/pkg/compiler/test/sourcemaps/tools/source_mapping_test_viewer.dart b/pkg/compiler/test/sourcemaps/tools/source_mapping_test_viewer.dart
index 3adaa09..03e032f 100644
--- a/pkg/compiler/test/sourcemaps/tools/source_mapping_test_viewer.dart
+++ b/pkg/compiler/test/sourcemaps/tools/source_mapping_test_viewer.dart
@@ -8,12 +8,13 @@
library source_mapping.test.viewer;
import 'dart:async';
+
import 'package:_fe_analyzer_shared/src/util/filenames.dart';
-import 'package:compiler/src/util/util.dart';
-import 'source_mapping_tester.dart';
+
import '../helpers/sourcemap_helper.dart';
import '../helpers/sourcemap_html_helper.dart';
import '../helpers/sourcemap_html_templates.dart';
+import 'source_mapping_tester.dart';
const String DEFAULT_OUTPUT_PATH = 'out.js.map.html';
@@ -91,27 +92,21 @@
final Iterable<String> configs;
@override
final Iterable<String> files;
- final Map<Pair, String> pathMap = {};
- final Map<Pair, Uri> uriMap = {};
+ final Map<(String, String), String> pathMap = {};
+ final Map<(String, String), Uri> uriMap = {};
OutputConfigurations(this.configs, this.files);
void registerPathUri(String config, String file, String path, Uri uri) {
- Pair key = Pair(config, file);
+ var key = (config, file);
pathMap[key] = path;
uriMap[key] = uri;
}
- Uri? getUri(String config, String file) {
- Pair key = Pair(config, file);
- return uriMap[key];
- }
+ Uri? getUri(String config, String file) => uriMap[(config, file)];
@override
- String getPath(String config, String file) {
- Pair key = Pair(config, file);
- return pathMap[key]!;
- }
+ String getPath(String config, String file) => pathMap[(config, file)]!;
}
Future<Measurement> runTest(