[dart2js] prepare to migrate kernel/env.dart

This makes kernel/env.dart fully ready for migration.

Change-Id: I1baa5bc7280236e5e2dfdfb060525752eb68c2d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260067
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Sigmund Cherem 2022-09-20 20:08:37 +00:00 committed by Commit Bot
parent a263aeee33
commit 755f124fcd
3 changed files with 27 additions and 12 deletions

View file

@ -60,6 +60,7 @@ import 'element_map_interfaces.dart' as interfaces
show
KernelElementEnvironment,
KernelToElementMapForClassHierarchy,
KernelToElementMapForEnv,
KernelToElementMapForImpactData,
KernelToElementMapForKernelImpact,
KernelToElementMapForNativeData,
@ -74,6 +75,7 @@ import 'kernel_impact.dart';
class KernelToElementMap
implements
interfaces.KernelToElementMapForClassHierarchy,
interfaces.KernelToElementMapForEnv,
interfaces.KernelToElementMapForImpactData,
interfaces.KernelToElementMapForNativeData,
interfaces.KernelToElementMapForDeferredLoading,
@ -287,6 +289,7 @@ class KernelToElementMap
return types.interfaceType(getClass(cls), getDartTypes(typeArguments));
}
@override
LibraryEntity getLibrary(ir.Library node) => getLibraryInternal(node);
/// Returns the [ClassEntity] corresponding to the class [node].
@ -1210,6 +1213,7 @@ class KernelToElementMap
}
/// Converts [annotations] into a list of [ConstantValue]s.
@override
List<ConstantValue> getMetadata(
ir.StaticTypeContext staticTypeContext, List<ir.Expression> annotations) {
if (annotations.isEmpty) return const <ConstantValue>[];

View file

@ -14,6 +14,7 @@ import 'package:kernel/ast.dart' as ir
Expression,
Field,
InterfaceType,
Library,
LibraryDependency,
LocalFunction,
Member,
@ -31,6 +32,7 @@ import '../elements/entities.dart'
ConstructorEntity,
FieldEntity,
FunctionEntity,
LibraryEntity,
Local,
MemberEntity,
ImportEntity;
@ -166,6 +168,13 @@ abstract class KernelToElementMapForJsModel implements IrToElementMap {
set envIsClosed(bool v);
}
abstract class KernelToElementMapForEnv implements IrToElementMap {
ir.TypeEnvironment get typeEnvironment;
LibraryEntity getLibrary(ir.Library node);
List<ConstantValue> getMetadata(
ir.StaticTypeContext staticTypeContext, List<ir.Expression> annotations);
}
// Members which dart2js ignores.
bool memberIsIgnorable(ir.Member node, {ir.Class? cls}) {
if (node is! ir.Procedure) return false;

View file

@ -26,8 +26,8 @@ import '../js_model/element_map.dart';
import '../js_model/env.dart';
import '../ordered_typeset.dart';
import '../universe/member_usage.dart';
import 'element_map.dart';
import 'element_map_interfaces.dart' show memberIsIgnorable;
import 'element_map_interfaces.dart'
show memberIsIgnorable, KernelToElementMapForEnv;
import 'env_interfaces.dart' as interfaces;
@ -206,14 +206,14 @@ class KLibraryData implements interfaces.KLibraryData {
KLibraryData(this.library);
Iterable<ConstantValue> getMetadata(KernelToElementMap elementMap) {
Iterable<ConstantValue> getMetadata(KernelToElementMapForEnv elementMap) {
return _metadata ??= elementMap.getMetadata(
ir.StaticTypeContext.forAnnotations(
library, elementMap.typeEnvironment),
library.annotations);
}
Iterable<ImportEntity> getImports(KernelToElementMap elementMap) {
Iterable<ImportEntity> getImports(KernelToElementMapForEnv elementMap) {
if (imports == null) {
List<ir.LibraryDependency> dependencies = library.dependencies;
if (dependencies.isEmpty) {
@ -257,7 +257,7 @@ abstract class KClassEnv implements interfaces.KClassEnv {
bool get isMixinApplicationWithMembers;
/// Ensures that all members have been computed for [cls].
void ensureMembers(KernelToElementMap elementMap);
void ensureMembers(KernelToElementMapForEnv elementMap);
/// Return the [MemberEntity] for the member [name] in the class.
MemberEntity lookupMember(IrToElementMap elementMap, Name name);
@ -339,11 +339,11 @@ class KClassEnvImpl implements KClassEnv {
}
@override
void ensureMembers(KernelToElementMap elementMap) {
void ensureMembers(KernelToElementMapForEnv elementMap) {
_ensureMaps(elementMap);
}
void _ensureMaps(KernelToElementMap elementMap) {
void _ensureMaps(KernelToElementMapForEnv elementMap) {
if (_memberMap != null) return;
_memberMap = <Name, ir.Member>{};
@ -580,7 +580,8 @@ class KClassDataImpl implements KClassData {
bool isCallTypeComputed = false;
@override
Iterable<ConstantValue> getMetadata(covariant KernelToElementMap elementMap) {
Iterable<ConstantValue> getMetadata(
covariant KernelToElementMapForEnv elementMap) {
return _metadata ??= elementMap.getMetadata(
ir.StaticTypeContext.forAnnotations(
node.enclosingLibrary, elementMap.typeEnvironment),
@ -626,7 +627,8 @@ abstract class KMemberDataImpl implements KMemberData {
KMemberDataImpl(this.node);
@override
Iterable<ConstantValue> getMetadata(covariant KernelToElementMap elementMap) {
Iterable<ConstantValue> getMetadata(
covariant KernelToElementMapForEnv elementMap) {
return _metadata ??= elementMap.getMetadata(
ir.StaticTypeContext(node, elementMap.typeEnvironment),
node.annotations);
@ -658,7 +660,7 @@ abstract class KFunctionDataMixin implements KFunctionData {
@override
List<TypeVariableType> /*!*/ getFunctionTypeVariables(
covariant KernelToElementMap elementMap) {
covariant KernelToElementMapForEnv elementMap) {
if (_typeVariables == null) {
if (functionNode.typeParameters.isEmpty) {
_typeVariables = const <TypeVariableType>[];
@ -693,7 +695,7 @@ class KFunctionDataImpl extends KMemberDataImpl
KFunctionDataImpl(ir.Member node, this.functionNode) : super(node);
@override
FunctionType getFunctionType(covariant KernelToElementMap elementMap) {
FunctionType getFunctionType(covariant KernelToElementMapForEnv elementMap) {
return _type ??= elementMap.getFunctionType(functionNode);
}
@ -793,7 +795,7 @@ class KFieldDataImpl extends KMemberDataImpl implements KFieldData {
ir.Field get node => super.node;
@override
DartType getFieldType(covariant KernelToElementMap elementMap) {
DartType getFieldType(covariant KernelToElementMapForEnv elementMap) {
return _type ??= elementMap.getDartType(node.type);
}