Skip to content

Commit 3a7e743

Browse files
committed
[dart2js] Prep interceptor_data.dart for migration.
Change-Id: If3db12dd0fb02c09906503150525d2381c65f2ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260244 Reviewed-by: Sigmund Cherem <[email protected]> Auto-Submit: Nate Biggs <[email protected]>
1 parent 46bc947 commit 3a7e743

File tree

7 files changed

+66
-40
lines changed

7 files changed

+66
-40
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ class CodegenImpactTransformer {
152152
}
153153

154154
for (Set<ClassEntity> classes in impact.specializedGetInterceptors) {
155-
_oneShotInterceptorData.registerSpecializedGetInterceptor(
156-
classes, _namer);
155+
_oneShotInterceptorData.registerSpecializedGetInterceptor(classes);
157156
}
158157

159158
if (impact.usesInterceptor) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import '../js/js.dart' as jsAst;
1616
import '../serialization/serialization.dart';
1717
import '../universe/class_set.dart';
1818
import '../universe/selector.dart';
19-
import '../world.dart' show JClosedWorld;
20-
import 'namer.dart' show ModularNamer, suffixForGetInterceptor;
19+
import '../world_interfaces.dart' show JClosedWorld;
20+
import 'namer_interfaces.dart' show ModularNamer;
21+
import 'namer_migrated.dart' show suffixForGetInterceptor;
2122
import 'native_data.dart';
2223

2324
abstract class InterceptorData {
@@ -386,12 +387,11 @@ class OneShotInterceptorData {
386387
OneShotInterceptor interceptor =
387388
interceptors[key] ??= OneShotInterceptor(key, selector);
388389
interceptor.classes.addAll(classes);
389-
registerSpecializedGetInterceptor(classes, namer);
390+
registerSpecializedGetInterceptor(classes);
390391
return namer.nameForOneShotInterceptor(selector, classes);
391392
}
392393

393-
void registerSpecializedGetInterceptor(
394-
Set<ClassEntity> classes, ModularNamer namer) {
394+
void registerSpecializedGetInterceptor(Set<ClassEntity> classes) {
395395
if (classes.contains(_commonElements.jsInterceptorClass)) {
396396
// We can't use a specialized [getInterceptorMethod], so we make
397397
// sure we emit the one with all checks.

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

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import '../util/util.dart';
3535
import '../world.dart' show JClosedWorld;
3636
import 'deferred_holder_expression.dart';
3737
import 'native_data.dart';
38+
import 'namer_interfaces.dart' as interfaces;
39+
import 'namer_migrated.dart';
40+
41+
export 'namer_migrated.dart' show suffixForGetInterceptor;
3842

3943
part 'field_naming_mixin.dart';
4044
part 'frequency_namer.dart';
@@ -1554,38 +1558,6 @@ class _TypeConstantRepresentationVisitor extends DartTypeVisitor<String, Null> {
15541558
'FutureOr<${_represent(type.typeArgument)}>';
15551559
}
15561560

1557-
/// Returns a unique suffix for an intercepted accesses to [classes]. This is
1558-
/// used as the suffix for emitted interceptor methods and as the unique key
1559-
/// used to distinguish equivalences of sets of intercepted classes.
1560-
String suffixForGetInterceptor(CommonElements commonElements,
1561-
NativeData nativeData, Iterable<ClassEntity> classes) {
1562-
String abbreviate(ClassEntity cls) {
1563-
if (cls == commonElements.objectClass) return "o";
1564-
if (cls == commonElements.jsStringClass) return "s";
1565-
if (cls == commonElements.jsArrayClass) return "a";
1566-
if (cls == commonElements.jsNumNotIntClass) return "d";
1567-
if (cls == commonElements.jsIntClass) return "i";
1568-
if (cls == commonElements.jsNumberClass) return "n";
1569-
if (cls == commonElements.jsNullClass) return "u";
1570-
if (cls == commonElements.jsBoolClass) return "b";
1571-
if (cls == commonElements.jsInterceptorClass) return "I";
1572-
return cls.name;
1573-
}
1574-
1575-
List<String> names = classes
1576-
.where((cls) => !nativeData.isNativeOrExtendsNative(cls))
1577-
.map(abbreviate)
1578-
.toList();
1579-
// There is one dispatch mechanism for all native classes.
1580-
if (classes.any((cls) => nativeData.isNativeOrExtendsNative(cls))) {
1581-
names.add("x");
1582-
}
1583-
// Sort the names of the classes after abbreviating them to ensure
1584-
// the suffix is stable and predictable for the suggested names.
1585-
names.sort();
1586-
return names.join();
1587-
}
1588-
15891561
/// Generator of names for [ConstantValue] values.
15901562
///
15911563
/// The names are stable under perturbations of the source. The name is either
@@ -2133,7 +2105,7 @@ class MinifiedFixedNames extends FixedNames {
21332105
}
21342106

21352107
/// Namer interface that can be used in modular code generation.
2136-
abstract class ModularNamer {
2108+
abstract class ModularNamer implements interfaces.ModularNamer {
21372109
FixedNames get fixedNames;
21382110

21392111
/// Returns a variable use for accessing constants.
@@ -2241,6 +2213,7 @@ abstract class ModularNamer {
22412213

22422214
/// Property name used for the one-shot interceptor method for the given
22432215
/// [selector] and return-type specialization.
2216+
@override
22442217
jsAst.Name nameForOneShotInterceptor(
22452218
Selector selector, Set<ClassEntity> classes);
22462219

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../elements/entities.dart';
6+
import '../js/js.dart' as jsAst;
7+
import '../universe/selector.dart' show Selector;
8+
9+
abstract class ModularNamer {
10+
jsAst.Name nameForOneShotInterceptor(
11+
Selector selector, Set<ClassEntity> classes);
12+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import '../common/elements.dart';
6+
import '../elements/entities.dart';
7+
import '../js_backend/native_data.dart';
8+
9+
/// Returns a unique suffix for an intercepted accesses to [classes]. This is
10+
/// used as the suffix for emitted interceptor methods and as the unique key
11+
/// used to distinguish equivalences of sets of intercepted classes.
12+
String suffixForGetInterceptor(CommonElements commonElements,
13+
NativeData nativeData, Iterable<ClassEntity> classes) {
14+
String abbreviate(ClassEntity cls) {
15+
if (cls == commonElements.objectClass) return "o";
16+
if (cls == commonElements.jsStringClass) return "s";
17+
if (cls == commonElements.jsArrayClass) return "a";
18+
if (cls == commonElements.jsNumNotIntClass) return "d";
19+
if (cls == commonElements.jsIntClass) return "i";
20+
if (cls == commonElements.jsNumberClass) return "n";
21+
if (cls == commonElements.jsNullClass) return "u";
22+
if (cls == commonElements.jsBoolClass) return "b";
23+
if (cls == commonElements.jsInterceptorClass) return "I";
24+
return cls.name;
25+
}
26+
27+
List<String> names = classes
28+
.where((cls) => !nativeData.isNativeOrExtendsNative(cls))
29+
.map(abbreviate)
30+
.toList();
31+
// There is one dispatch mechanism for all native classes.
32+
if (classes.any((cls) => nativeData.isNativeOrExtendsNative(cls))) {
33+
names.add("x");
34+
}
35+
// Sort the names of the classes after abbreviating them to ensure
36+
// the suffix is stable and predictable for the suggested names.
37+
names.sort();
38+
return names.join();
39+
}

pkg/compiler/lib/src/world.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ abstract class JClosedWorld implements interfaces.JClosedWorld {
107107
Iterable<ClassEntity> commonSupertypesOf(Iterable<ClassEntity> classes);
108108

109109
/// Returns an iterable over the live mixin applications that mixin [cls].
110+
@override
110111
Iterable<ClassEntity> mixinUsesOf(ClassEntity cls);
111112

112113
/// Returns `true` if [cls] is mixed into a live class.

pkg/compiler/lib/src/world_interfaces.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ abstract class JClosedWorld implements World {
4545
bool fieldNeverChanges(MemberEntity element);
4646

4747
Selector getSelector(ir.Expression node);
48+
49+
Iterable<ClassEntity> mixinUsesOf(ClassEntity cls);
4850
}
4951

5052
// TODO(48820): Move back to `world.dart` when migrated.

0 commit comments

Comments
 (0)