Skip to content

Commit 07fd587

Browse files
kevmooCommit Queue
authored andcommitted
pkg-compiler: drop Pair class, use Record
Change-Id: I19b05ffc6bd8e87e58990a62a21b8a2986fe9f54 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382760 Commit-Queue: Nate Biggs <[email protected]> Auto-Submit: Kevin Moore <[email protected]> Reviewed-by: Nate Biggs <[email protected]>
1 parent 6d72e53 commit 07fd587

File tree

6 files changed

+32
-64
lines changed

6 files changed

+32
-64
lines changed

pkg/compiler/lib/src/common/codegen.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class CodegenImpact extends WorldImpact {
4242
throw UnsupportedError('CodegenImpact.writeToDataSink');
4343
}
4444

45-
Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks {
46-
return const <Pair<DartType, DartType>>[];
45+
Iterable<(DartType, DartType)> get typeVariableBoundsSubtypeChecks {
46+
return const <(DartType, DartType)>[];
4747
}
4848

4949
Iterable<String> get constSymbols => const <String>[];
@@ -71,7 +71,7 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
7171

7272
@override
7373
final MemberEntity member;
74-
Set<Pair<DartType, DartType>>? _typeVariableBoundsSubtypeChecks;
74+
Set<(DartType, DartType)>? _typeVariableBoundsSubtypeChecks;
7575
Set<String>? _constSymbols;
7676
List<Set<ClassEntity>>? _specializedGetInterceptors;
7777
bool _usesInterceptor = false;
@@ -116,7 +116,7 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
116116
.readListOrNull(() => ConstantUse.readFromDataSource(source))
117117
?.toSet();
118118
final typeVariableBoundsSubtypeChecks = source.readListOrNull(() {
119-
return Pair(source.readDartType(), source.readDartType());
119+
return (source.readDartType(), source.readDartType());
120120
})?.toSet();
121121
final constSymbols = source.readStringsOrNull()?.toSet();
122122
final specializedGetInterceptors = source.readListOrNull(() {
@@ -161,10 +161,10 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
161161
sink.writeList(typeUses, (TypeUse use) => use.writeToDataSink(sink));
162162
sink.writeList(
163163
constantUses, (ConstantUse use) => use.writeToDataSink(sink));
164-
sink.writeListOrNull<Pair<DartType, DartType>>(
165-
_typeVariableBoundsSubtypeChecks, (pair) {
166-
sink.writeDartType(pair.a);
167-
sink.writeDartType(pair.b);
164+
sink.writeListOrNull<(DartType, DartType)>(_typeVariableBoundsSubtypeChecks,
165+
(pair) {
166+
sink.writeDartType(pair.$1);
167+
sink.writeDartType(pair.$2);
168168
});
169169
sink.writeStringsOrNull(_constSymbols);
170170
sink.writeListOrNull(_specializedGetInterceptors, sink.writeClasses);
@@ -184,12 +184,11 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
184184

185185
void registerTypeVariableBoundsSubtypeCheck(
186186
DartType subtype, DartType supertype) {
187-
(_typeVariableBoundsSubtypeChecks ??= {})
188-
.add(Pair<DartType, DartType>(subtype, supertype));
187+
(_typeVariableBoundsSubtypeChecks ??= {}).add((subtype, supertype));
189188
}
190189

191190
@override
192-
Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks {
191+
Iterable<(DartType, DartType)> get typeVariableBoundsSubtypeChecks {
193192
return _typeVariableBoundsSubtypeChecks ?? const {};
194193
}
195194

pkg/compiler/lib/src/inferrer/builder.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import '../universe/member_hierarchy.dart';
3030
import '../universe/record_shape.dart';
3131
import '../universe/selector.dart';
3232
import '../universe/side_effects.dart';
33-
import '../util/util.dart';
3433
import 'engine.dart';
3534
import 'locals_handler.dart';
3635
import 'type_graph_nodes.dart';
@@ -704,24 +703,24 @@ class KernelTypeGraphBuilder extends ir.VisitorDefault<TypeInformation?>
704703
@override
705704
TypeInformation visitMapLiteral(ir.MapLiteral node) {
706705
return createMapTypeInformation(
707-
node, node.entries.map((e) => Pair(visit(e.key)!, visit(e.value)!)),
706+
node, node.entries.map((e) => (visit(e.key)!, visit(e.value)!)),
708707
isConst: node.isConst,
709708
keyStaticType: _elementMap.getDartType(node.keyType),
710709
valueStaticType: _elementMap.getDartType(node.valueType));
711710
}
712711

713-
TypeInformation createMapTypeInformation(ir.TreeNode node,
714-
Iterable<Pair<TypeInformation, TypeInformation>> entryTypes,
712+
TypeInformation createMapTypeInformation(
713+
ir.TreeNode node, Iterable<(TypeInformation, TypeInformation)> entryTypes,
715714
{required bool isConst,
716715
required DartType keyStaticType,
717716
required DartType valueStaticType}) {
718717
return _inferrer.concreteTypes.putIfAbsent(node, () {
719718
List<TypeInformation> keyTypes = [];
720719
List<TypeInformation> valueTypes = [];
721720

722-
for (Pair<TypeInformation, TypeInformation> entryType in entryTypes) {
723-
keyTypes.add(entryType.a);
724-
valueTypes.add(entryType.b);
721+
for ((TypeInformation, TypeInformation) entryType in entryTypes) {
722+
keyTypes.add(entryType.$1);
723+
valueTypes.add(entryType.$2);
725724
}
726725

727726
final type = isConst ? _types.constMapType : _types.mapType;
@@ -2297,10 +2296,8 @@ class TypeInformationConstantVisitor
22972296

22982297
@override
22992298
TypeInformation visitMapConstant(ir.MapConstant node) {
2300-
return builder.createMapTypeInformation(
2301-
ConstantReference(expression, node),
2302-
node.entries
2303-
.map((e) => Pair(visitConstant(e.key), visitConstant(e.value))),
2299+
return builder.createMapTypeInformation(ConstantReference(expression, node),
2300+
node.entries.map((e) => (visitConstant(e.key), visitConstant(e.value))),
23042301
isConst: true,
23052302
keyStaticType: builder._elementMap.getDartType(node.keyType),
23062303
valueStaticType: builder._elementMap.getDartType(node.valueType));

pkg/compiler/lib/src/js/rewrite_async.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'dart:math' show max;
1010
import 'package:js_shared/synced/async_status_codes.dart' as status_codes;
1111

1212
import '../common.dart';
13-
import '../util/util.dart' show Pair;
1413
import 'js.dart' as js;
1514

1615
/// Rewrites a [js.Fun] with async/sync*/async* functions and await and yield
@@ -65,7 +64,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor<Object?> {
6564
/// are on the way to target (i.e. more nested than the jump target).
6665
List<js.Node> jumpTargets = [];
6766

68-
List<Pair<String, String>> variableRenamings = [];
67+
List<(String, String)> variableRenamings = [];
6968

7069
late final PreTranslationAnalysis analysis;
7170

@@ -1559,7 +1558,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor<Object?> {
15591558
// block so shadow any catch variable bindings that might collide with
15601559
// this one so that references to this binding do not get renamed.
15611560
variableRenamings
1562-
.add(Pair(catchPart.declaration.name, catchPart.declaration.name));
1561+
.add((catchPart.declaration.name, catchPart.declaration.name));
15631562
translatedCatchPart =
15641563
js.Catch(catchPart.declaration, translateToBlock(catchPart.body));
15651564
variableRenamings.removeLast();
@@ -1615,7 +1614,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor<Object?> {
16151614
// section 12.14.
16161615
String errorRename = freshName(catchPart.declaration.name);
16171616
localVariables.add(js.VariableDeclaration(errorRename));
1618-
variableRenamings.add(Pair(catchPart.declaration.name, errorRename));
1617+
variableRenamings.add((catchPart.declaration.name, errorRename));
16191618
addStatement(js.js.statement("# = #;", [errorRename, currentError]));
16201619
visitStatement(catchPart.body);
16211620
variableRenamings.removeLast();
@@ -1695,7 +1694,7 @@ abstract class AsyncRewriterBase extends js.NodeVisitor<Object?> {
16951694
@override
16961695
js.Expression visitVariableUse(js.VariableUse node) {
16971696
for (final renaming in variableRenamings.reversed) {
1698-
if (renaming.a == node.name) return js.VariableUse(renaming.b);
1697+
if (renaming.$1 == node.name) return js.VariableUse(renaming.$2);
16991698
}
17001699
return node;
17011700
}

pkg/compiler/lib/src/js_backend/impact_transformer.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import '../universe/feature.dart';
1818
import '../universe/selector.dart';
1919
import '../universe/use.dart';
2020
import '../universe/world_impact.dart' show TransformedWorldImpact, WorldImpact;
21-
import '../util/util.dart';
2221
import 'backend_impact.dart';
2322
import 'backend_usage.dart';
2423
import 'interceptor_data.dart';
@@ -122,10 +121,9 @@ class CodegenImpactTransformer {
122121
}
123122
}
124123

125-
for (Pair<DartType, DartType> check
126-
in impact.typeVariableBoundsSubtypeChecks) {
124+
for ((DartType, DartType) check in impact.typeVariableBoundsSubtypeChecks) {
127125
_rtiChecksBuilder.registerTypeVariableBoundsSubtypeCheck(
128-
check.a, check.b);
126+
check.$1, check.$2);
129127
}
130128

131129
for (StaticUse staticUse in impact.staticUses) {

pkg/compiler/lib/src/util/util.dart

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,6 @@ void writeJsonEscapedCharsOn(String string, StringSink buffer) {
231231
buffer.write(string);
232232
}
233233

234-
class Pair<A, B> {
235-
final A a;
236-
final B b;
237-
238-
Pair(this.a, this.b);
239-
240-
@override
241-
int get hashCode => 13 * a.hashCode + 17 * b.hashCode;
242-
243-
@override
244-
bool operator ==(var other) {
245-
if (identical(this, other)) return true;
246-
if (other is! Pair) return false;
247-
return a == other.a && b == other.b;
248-
}
249-
250-
@override
251-
String toString() => '($a,$b)';
252-
}
253-
254234
int longestCommonPrefixLength(List<Object?> a, List<Object?> b) {
255235
int index = 0;
256236
for (; index < a.length && index < b.length; index++) {

pkg/compiler/test/sourcemaps/tools/source_mapping_test_viewer.dart

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
library source_mapping.test.viewer;
99

1010
import 'dart:async';
11+
1112
import 'package:_fe_analyzer_shared/src/util/filenames.dart';
12-
import 'package:compiler/src/util/util.dart';
13-
import 'source_mapping_tester.dart';
13+
1414
import '../helpers/sourcemap_helper.dart';
1515
import '../helpers/sourcemap_html_helper.dart';
1616
import '../helpers/sourcemap_html_templates.dart';
17+
import 'source_mapping_tester.dart';
1718

1819
const String DEFAULT_OUTPUT_PATH = 'out.js.map.html';
1920

@@ -91,27 +92,21 @@ class OutputConfigurations implements Configurations {
9192
final Iterable<String> configs;
9293
@override
9394
final Iterable<String> files;
94-
final Map<Pair, String> pathMap = {};
95-
final Map<Pair, Uri> uriMap = {};
95+
final Map<(String, String), String> pathMap = {};
96+
final Map<(String, String), Uri> uriMap = {};
9697

9798
OutputConfigurations(this.configs, this.files);
9899

99100
void registerPathUri(String config, String file, String path, Uri uri) {
100-
Pair key = Pair(config, file);
101+
var key = (config, file);
101102
pathMap[key] = path;
102103
uriMap[key] = uri;
103104
}
104105

105-
Uri? getUri(String config, String file) {
106-
Pair key = Pair(config, file);
107-
return uriMap[key];
108-
}
106+
Uri? getUri(String config, String file) => uriMap[(config, file)];
109107

110108
@override
111-
String getPath(String config, String file) {
112-
Pair key = Pair(config, file);
113-
return pathMap[key]!;
114-
}
109+
String getPath(String config, String file) => pathMap[(config, file)]!;
115110
}
116111

117112
Future<Measurement> runTest(

0 commit comments

Comments
 (0)