[dart2js] migrate powerset_bits.dart

Change-Id: I7abd6781a657ea2564ba08e3b7d4e8274ae3939b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252413
Reviewed-by: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Sigmund Cherem 2022-07-22 17:58:56 +00:00 committed by Commit Bot
parent 13a6684fe3
commit ec51bf0a9a
3 changed files with 30 additions and 43 deletions

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a // 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. // BSD-style license that can be found in the LICENSE file.
// @dart = 2.10
import '../../common/elements.dart' show CommonElements; import '../../common/elements.dart' show CommonElements;
import '../../constants/values.dart'; import '../../constants/values.dart';
import '../../elements/entities.dart'; import '../../elements/entities.dart';
@ -11,7 +9,7 @@ import '../../elements/names.dart';
import '../../elements/types.dart'; import '../../elements/types.dart';
import '../../ir/class_relation.dart'; import '../../ir/class_relation.dart';
import '../../universe/selector.dart'; import '../../universe/selector.dart';
import '../../world.dart'; import '../../world_interfaces.dart';
import '../abstract_value_domain.dart'; import '../abstract_value_domain.dart';
/// This class is used to store bits information about class entities. /// This class is used to store bits information about class entities.
@ -172,7 +170,7 @@ class PowersetBitsDomain {
// TODO(coam): This currently returns null if we are not sure if it's a primitive. // TODO(coam): This currently returns null if we are not sure if it's a primitive.
// It could be improved because we can also tell when we're certain it's not a primitive. // It could be improved because we can also tell when we're certain it's not a primitive.
PrimitiveConstantValue getPrimitiveValue(int value) { PrimitiveConstantValue? getPrimitiveValue(int value) {
if (isDefinitelyTrue(value)) { if (isDefinitelyTrue(value)) {
return TrueConstantValue(); return TrueConstantValue();
} }
@ -355,7 +353,7 @@ class PowersetBitsDomain {
} }
ClassInfo _computeClassInfo(ClassEntity cls) { ClassInfo _computeClassInfo(ClassEntity cls) {
ClassInfo classInfo = _storedClassInfo[cls]; ClassInfo? classInfo = _storedClassInfo[cls];
if (classInfo != null) { if (classInfo != null) {
return classInfo; return classInfo;
} }
@ -442,7 +440,10 @@ class PowersetBitsDomain {
} }
int createFromStaticType(DartType type, int createFromStaticType(DartType type,
{ClassRelation classRelation = ClassRelation.subtype, bool nullable}) { {ClassRelation classRelation = ClassRelation.subtype,
required bool nullable}) {
// TODO(48820): Remove after sound null safety is enabled.
// ignore: unnecessary_null_comparison
assert(nullable != null); assert(nullable != null);
if ((classRelation == ClassRelation.subtype || if ((classRelation == ClassRelation.subtype ||
@ -481,8 +482,6 @@ class PowersetBitsDomain {
int _createFromStaticType( int _createFromStaticType(
DartType type, ClassRelation classRelation, bool nullable) { DartType type, ClassRelation classRelation, bool nullable) {
assert(nullable != null);
int finish(int value, bool isPrecise) { int finish(int value, bool isPrecise) {
// [isPrecise] is ignored since we only treat singleton partitions as // [isPrecise] is ignored since we only treat singleton partitions as
// precise. // precise.
@ -576,26 +575,21 @@ class PowersetBitsDomain {
int get emptyType => powersetBottom; int get emptyType => powersetBottom;
int _constMapType; late final int constMapType =
int get constMapType => _constMapType ??=
createNonNullSubtype(commonElements.constMapLiteralClass); createNonNullSubtype(commonElements.constMapLiteralClass);
int get constSetType => otherValue; int get constSetType => otherValue;
int _constListType; late final int constListType =
int get constListType => _constListType ??=
createNonNullExact(commonElements.jsUnmodifiableArrayClass); createNonNullExact(commonElements.jsUnmodifiableArrayClass);
int _fixedListType; late final int fixedListType =
int get fixedListType => createNonNullExact(commonElements.jsFixedArrayClass);
_fixedListType ??= createNonNullExact(commonElements.jsFixedArrayClass);
int _growableListType; late final int growableListType =
int get growableListType => _growableListType ??=
createNonNullExact(commonElements.jsExtendableArrayClass); createNonNullExact(commonElements.jsExtendableArrayClass);
int _mutableArrayType; late final int mutableArrayType =
int get mutableArrayType => _mutableArrayType ??=
createNonNullSubtype(commonElements.jsMutableArrayClass); createNonNullSubtype(commonElements.jsMutableArrayClass);
int get nullType => nullValue; int get nullType => nullValue;
@ -605,33 +599,21 @@ class PowersetBitsDomain {
// TODO(fishythefish): Support tracking late sentinels in the powerset domain. // TODO(fishythefish): Support tracking late sentinels in the powerset domain.
int get lateSentinelType => powersetBottom; int get lateSentinelType => powersetBottom;
int _mapType; late final int mapType = createNonNullSubtype(commonElements.mapLiteralClass);
int get mapType =>
_mapType ??= createNonNullSubtype(commonElements.mapLiteralClass);
int _setType; late final int setType = createNonNullSubtype(commonElements.setLiteralClass);
int get setType =>
_setType ??= createNonNullSubtype(commonElements.setLiteralClass);
int _listType; late final int listType = createNonNullExact(commonElements.jsArrayClass);
int get listType =>
_listType ??= createNonNullExact(commonElements.jsArrayClass);
int _stringType; late final int stringType =
int get stringType => createNonNullSubtype(commonElements.jsStringClass);
_stringType ??= createNonNullSubtype(commonElements.jsStringClass);
int _numType; late final int numType = createNonNullSubclass(commonElements.jsNumberClass);
int get numType =>
_numType ??= createNonNullSubclass(commonElements.jsNumberClass);
int _numNotIntType; late final int numNotIntType =
int get numNotIntType => createNonNullExact(commonElements.jsNumNotIntClass);
_numNotIntType ??= createNonNullExact(commonElements.jsNumNotIntClass);
int _intType; late final int intType = createNonNullSubtype(commonElements.jsIntClass);
int get intType =>
_intType ??= createNonNullSubtype(commonElements.jsIntClass);
int get positiveIntType => intType; int get positiveIntType => intType;
int get uint32Type => intType; int get uint32Type => intType;
@ -639,9 +621,8 @@ class PowersetBitsDomain {
int get boolType => boolValue; int get boolType => boolValue;
int _functionType; late final int functionType =
int get functionType => createNonNullSubtype(commonElements.functionClass);
_functionType ??= createNonNullSubtype(commonElements.functionClass);
int get typeType => otherValue; int get typeType => otherValue;
} }

View file

@ -48,6 +48,7 @@ abstract class JClosedWorld implements interfaces.JClosedWorld {
InterceptorData get interceptorData; InterceptorData get interceptorData;
@override
JElementEnvironment get elementEnvironment; JElementEnvironment get elementEnvironment;
@override @override
@ -105,6 +106,7 @@ abstract class JClosedWorld implements interfaces.JClosedWorld {
Iterable<ClassEntity> mixinUsesOf(ClassEntity cls); Iterable<ClassEntity> mixinUsesOf(ClassEntity cls);
/// Returns `true` if [cls] is mixed into a live class. /// Returns `true` if [cls] is mixed into a live class.
@override
bool isUsedAsMixin(ClassEntity cls); bool isUsedAsMixin(ClassEntity cls);
/// Returns `true` if any live class that mixes in [cls] implements [type]. /// Returns `true` if any live class that mixes in [cls] implements [type].

View file

@ -23,10 +23,14 @@ abstract class JClosedWorld implements World {
DartTypes get dartTypes; DartTypes get dartTypes;
ElementEnvironment get elementEnvironment;
NativeData get nativeData; NativeData get nativeData;
AnnotationsData get annotationsData; AnnotationsData get annotationsData;
bool isUsedAsMixin(ClassEntity cls);
bool includesClosureCall(Selector selector, AbstractValue? receiver); bool includesClosureCall(Selector selector, AbstractValue? receiver);
Iterable<MemberEntity> locateMembers( Iterable<MemberEntity> locateMembers(