[dart2js] Prep interceptor_data.dart for migration.

Change-Id: If3db12dd0fb02c09906503150525d2381c65f2ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260244
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Auto-Submit: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Nate Biggs 2022-09-21 19:56:01 +00:00
parent 46bc947e75
commit 3a7e7430dc
7 changed files with 66 additions and 40 deletions

View file

@ -152,8 +152,7 @@ class CodegenImpactTransformer {
}
for (Set<ClassEntity> classes in impact.specializedGetInterceptors) {
_oneShotInterceptorData.registerSpecializedGetInterceptor(
classes, _namer);
_oneShotInterceptorData.registerSpecializedGetInterceptor(classes);
}
if (impact.usesInterceptor) {

View file

@ -16,8 +16,9 @@ import '../js/js.dart' as jsAst;
import '../serialization/serialization.dart';
import '../universe/class_set.dart';
import '../universe/selector.dart';
import '../world.dart' show JClosedWorld;
import 'namer.dart' show ModularNamer, suffixForGetInterceptor;
import '../world_interfaces.dart' show JClosedWorld;
import 'namer_interfaces.dart' show ModularNamer;
import 'namer_migrated.dart' show suffixForGetInterceptor;
import 'native_data.dart';
abstract class InterceptorData {
@ -386,12 +387,11 @@ class OneShotInterceptorData {
OneShotInterceptor interceptor =
interceptors[key] ??= OneShotInterceptor(key, selector);
interceptor.classes.addAll(classes);
registerSpecializedGetInterceptor(classes, namer);
registerSpecializedGetInterceptor(classes);
return namer.nameForOneShotInterceptor(selector, classes);
}
void registerSpecializedGetInterceptor(
Set<ClassEntity> classes, ModularNamer namer) {
void registerSpecializedGetInterceptor(Set<ClassEntity> classes) {
if (classes.contains(_commonElements.jsInterceptorClass)) {
// We can't use a specialized [getInterceptorMethod], so we make
// sure we emit the one with all checks.

View file

@ -35,6 +35,10 @@ import '../util/util.dart';
import '../world.dart' show JClosedWorld;
import 'deferred_holder_expression.dart';
import 'native_data.dart';
import 'namer_interfaces.dart' as interfaces;
import 'namer_migrated.dart';
export 'namer_migrated.dart' show suffixForGetInterceptor;
part 'field_naming_mixin.dart';
part 'frequency_namer.dart';
@ -1554,38 +1558,6 @@ class _TypeConstantRepresentationVisitor extends DartTypeVisitor<String, Null> {
'FutureOr<${_represent(type.typeArgument)}>';
}
/// Returns a unique suffix for an intercepted accesses to [classes]. This is
/// used as the suffix for emitted interceptor methods and as the unique key
/// used to distinguish equivalences of sets of intercepted classes.
String suffixForGetInterceptor(CommonElements commonElements,
NativeData nativeData, Iterable<ClassEntity> classes) {
String abbreviate(ClassEntity cls) {
if (cls == commonElements.objectClass) return "o";
if (cls == commonElements.jsStringClass) return "s";
if (cls == commonElements.jsArrayClass) return "a";
if (cls == commonElements.jsNumNotIntClass) return "d";
if (cls == commonElements.jsIntClass) return "i";
if (cls == commonElements.jsNumberClass) return "n";
if (cls == commonElements.jsNullClass) return "u";
if (cls == commonElements.jsBoolClass) return "b";
if (cls == commonElements.jsInterceptorClass) return "I";
return cls.name;
}
List<String> names = classes
.where((cls) => !nativeData.isNativeOrExtendsNative(cls))
.map(abbreviate)
.toList();
// There is one dispatch mechanism for all native classes.
if (classes.any((cls) => nativeData.isNativeOrExtendsNative(cls))) {
names.add("x");
}
// Sort the names of the classes after abbreviating them to ensure
// the suffix is stable and predictable for the suggested names.
names.sort();
return names.join();
}
/// Generator of names for [ConstantValue] values.
///
/// The names are stable under perturbations of the source. The name is either
@ -2133,7 +2105,7 @@ class MinifiedFixedNames extends FixedNames {
}
/// Namer interface that can be used in modular code generation.
abstract class ModularNamer {
abstract class ModularNamer implements interfaces.ModularNamer {
FixedNames get fixedNames;
/// Returns a variable use for accessing constants.
@ -2241,6 +2213,7 @@ abstract class ModularNamer {
/// Property name used for the one-shot interceptor method for the given
/// [selector] and return-type specialization.
@override
jsAst.Name nameForOneShotInterceptor(
Selector selector, Set<ClassEntity> classes);

View file

@ -0,0 +1,12 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../elements/entities.dart';
import '../js/js.dart' as jsAst;
import '../universe/selector.dart' show Selector;
abstract class ModularNamer {
jsAst.Name nameForOneShotInterceptor(
Selector selector, Set<ClassEntity> classes);
}

View file

@ -0,0 +1,39 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../common/elements.dart';
import '../elements/entities.dart';
import '../js_backend/native_data.dart';
/// Returns a unique suffix for an intercepted accesses to [classes]. This is
/// used as the suffix for emitted interceptor methods and as the unique key
/// used to distinguish equivalences of sets of intercepted classes.
String suffixForGetInterceptor(CommonElements commonElements,
NativeData nativeData, Iterable<ClassEntity> classes) {
String abbreviate(ClassEntity cls) {
if (cls == commonElements.objectClass) return "o";
if (cls == commonElements.jsStringClass) return "s";
if (cls == commonElements.jsArrayClass) return "a";
if (cls == commonElements.jsNumNotIntClass) return "d";
if (cls == commonElements.jsIntClass) return "i";
if (cls == commonElements.jsNumberClass) return "n";
if (cls == commonElements.jsNullClass) return "u";
if (cls == commonElements.jsBoolClass) return "b";
if (cls == commonElements.jsInterceptorClass) return "I";
return cls.name;
}
List<String> names = classes
.where((cls) => !nativeData.isNativeOrExtendsNative(cls))
.map(abbreviate)
.toList();
// There is one dispatch mechanism for all native classes.
if (classes.any((cls) => nativeData.isNativeOrExtendsNative(cls))) {
names.add("x");
}
// Sort the names of the classes after abbreviating them to ensure
// the suffix is stable and predictable for the suggested names.
names.sort();
return names.join();
}

View file

@ -107,6 +107,7 @@ abstract class JClosedWorld implements interfaces.JClosedWorld {
Iterable<ClassEntity> commonSupertypesOf(Iterable<ClassEntity> classes);
/// Returns an iterable over the live mixin applications that mixin [cls].
@override
Iterable<ClassEntity> mixinUsesOf(ClassEntity cls);
/// Returns `true` if [cls] is mixed into a live class.

View file

@ -45,6 +45,8 @@ abstract class JClosedWorld implements World {
bool fieldNeverChanges(MemberEntity element);
Selector getSelector(ir.Expression node);
Iterable<ClassEntity> mixinUsesOf(ClassEntity cls);
}
// TODO(48820): Move back to `world.dart` when migrated.