Skip to content

Commit 441b4d8

Browse files
author
Dart CI
committed
Version 2.19.0-228.0.dev
Merge 76169b5 into dev
2 parents 5d47306 + 76169b5 commit 441b4d8

File tree

8 files changed

+84
-66
lines changed

8 files changed

+84
-66
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: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.10
6-
75
library js_backend.interceptor_data;
86

97
import '../common/elements.dart'
@@ -16,8 +14,9 @@ import '../js/js.dart' as jsAst;
1614
import '../serialization/serialization.dart';
1715
import '../universe/class_set.dart';
1816
import '../universe/selector.dart';
19-
import '../world.dart' show JClosedWorld;
20-
import 'namer.dart' show ModularNamer, suffixForGetInterceptor;
17+
import '../world_interfaces.dart' show JClosedWorld;
18+
import 'namer_interfaces.dart' show ModularNamer;
19+
import 'namer_migrated.dart' show suffixForGetInterceptor;
2120
import 'native_data.dart';
2221

2322
abstract class InterceptorData {
@@ -175,18 +174,13 @@ class InterceptorDataImpl implements InterceptorData {
175174

176175
@override
177176
bool isInterceptedMixinSelector(
178-
Selector selector, AbstractValue mask, JClosedWorld closedWorld) {
179-
Set<MemberEntity> elements =
180-
_interceptedMixinElements.putIfAbsent(selector.name, () {
181-
Set<MemberEntity> elements = interceptedMembers[selector.name];
182-
if (elements == null) return null;
183-
return elements
184-
.where((element) => classesMixedIntoInterceptedClasses
185-
.contains(element.enclosingClass))
186-
.toSet();
187-
});
188-
189-
if (elements == null) return false;
177+
Selector selector, AbstractValue? mask, JClosedWorld closedWorld) {
178+
Set<MemberEntity> elements = _interceptedMixinElements[selector.name] ??=
179+
(interceptedMembers[selector.name]
180+
?.where((element) => classesMixedIntoInterceptedClasses
181+
.contains(element.enclosingClass))
182+
.toSet() ??
183+
const {});
190184
if (elements.isEmpty) return false;
191185
return elements.any((element) {
192186
return selector.applies(element) &&
@@ -215,21 +209,21 @@ class InterceptorDataImpl implements InterceptorData {
215209
@override
216210
Set<ClassEntity> getInterceptedClassesOn(
217211
String name, JClosedWorld closedWorld) {
218-
Set<MemberEntity> intercepted = interceptedMembers[name];
212+
final intercepted = interceptedMembers[name];
219213
if (intercepted == null) return _noClasses;
220214
return _interceptedClassesCache.putIfAbsent(name, () {
221215
// Populate the cache by running through all the elements and
222216
// determine if the given selector applies to them.
223217
Set<ClassEntity> result = {};
224218
for (MemberEntity element in intercepted) {
225-
ClassEntity classElement = element.enclosingClass;
219+
final classElement = element.enclosingClass!;
226220
if (_isCompileTimeOnlyClass(classElement)) continue;
227221
if (_nativeData.isNativeOrExtendsNative(classElement) ||
228222
interceptedClasses.contains(classElement)) {
229223
result.add(classElement);
230224
}
231225
if (classesMixedIntoInterceptedClasses.contains(classElement)) {
232-
Set<ClassEntity> nativeSubclasses =
226+
final nativeSubclasses =
233227
nativeSubclassesOfMixin(classElement, closedWorld);
234228
if (nativeSubclasses != null) result.addAll(nativeSubclasses);
235229
}
@@ -238,16 +232,15 @@ class InterceptorDataImpl implements InterceptorData {
238232
});
239233
}
240234

241-
Set<ClassEntity> nativeSubclassesOfMixin(
235+
Set<ClassEntity>? nativeSubclassesOfMixin(
242236
ClassEntity mixin, JClosedWorld closedWorld) {
243237
Iterable<ClassEntity> uses = closedWorld.mixinUsesOf(mixin);
244-
Set<ClassEntity> result = null;
238+
Set<ClassEntity>? result;
245239
for (ClassEntity use in uses) {
246240
closedWorld.classHierarchy.forEachStrictSubclassOf(use,
247241
(ClassEntity subclass) {
248242
if (_nativeData.isNativeOrExtendsNative(subclass)) {
249-
if (result == null) result = {};
250-
result.add(subclass);
243+
(result ??= {}).add(subclass);
251244
}
252245
return IterationStep.CONTINUE;
253246
});
@@ -256,7 +249,7 @@ class InterceptorDataImpl implements InterceptorData {
256249
}
257250

258251
@override
259-
bool isInterceptedClass(ClassEntity element) {
252+
bool isInterceptedClass(ClassEntity? element) {
260253
if (element == null) return false;
261254
if (_nativeData.isNativeOrExtendsNative(element)) return true;
262255
if (interceptedClasses.contains(element)) return true;
@@ -275,7 +268,7 @@ class InterceptorDataImpl implements InterceptorData {
275268

276269
if (!closedWorld.dartTypes.treatAsRawType(type)) return false;
277270
if (type is FutureOrType) return false;
278-
InterfaceType interfaceType = type;
271+
final interfaceType = type as InterfaceType;
279272
ClassEntity classElement = interfaceType.element;
280273
if (isInterceptedClass(classElement)) return false;
281274
return closedWorld.classHierarchy.hasOnlySubclasses(classElement);
@@ -320,7 +313,7 @@ class InterceptorDataBuilderImpl implements InterceptorDataBuilder {
320313
if (member.name == Identifiers.call) return;
321314
// All methods on [Object] are shadowed by [Interceptor].
322315
if (cls == _commonElements.objectClass) return;
323-
Set<MemberEntity> set = _interceptedElements[member.name] ??= {};
316+
final set = _interceptedElements[member.name!] ??= {};
324317
set.add(member);
325318
});
326319

@@ -337,7 +330,7 @@ class InterceptorDataBuilderImpl implements InterceptorDataBuilder {
337330
(ClassEntity cls, MemberEntity member) {
338331
// All methods on [Object] are shadowed by [Interceptor].
339332
if (cls == _commonElements.objectClass) return;
340-
Set<MemberEntity> set = _interceptedElements[member.name] ??= {};
333+
final set = _interceptedElements[member.name!] ??= {};
341334
set.add(member);
342335
});
343336
}
@@ -386,12 +379,11 @@ class OneShotInterceptorData {
386379
OneShotInterceptor interceptor =
387380
interceptors[key] ??= OneShotInterceptor(key, selector);
388381
interceptor.classes.addAll(classes);
389-
registerSpecializedGetInterceptor(classes, namer);
382+
registerSpecializedGetInterceptor(classes);
390383
return namer.nameForOneShotInterceptor(selector, classes);
391384
}
392385

393-
void registerSpecializedGetInterceptor(
394-
Set<ClassEntity> classes, ModularNamer namer) {
386+
void registerSpecializedGetInterceptor(Iterable<ClassEntity> classes) {
395387
if (classes.contains(_commonElements.jsInterceptorClass)) {
396388
// We can't use a specialized [getInterceptorMethod], so we make
397389
// 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.

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 19
2929
PATCH 0
30-
PRERELEASE 227
30+
PRERELEASE 228
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)