[dart2js] Remove unnecessary DartType predicates and replace with

is-tests.

Change-Id: I520d0893793e291d009e31ff32980194278bb0b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125923
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Mayank Patke <fishythefish@google.com>
This commit is contained in:
Mayank Patke
2019-11-21 08:58:54 +00:00
committed by commit-bot@chromium.org
parent 2e32972929
commit 539b0093e1
30 changed files with 122 additions and 193 deletions
@@ -847,7 +847,7 @@ class TypeConstantExpression extends ConstantExpression {
final String name;
TypeConstantExpression(this.type, this.name) {
assert(type.isInterfaceType || type.isTypedef || type.isDynamic,
assert(type is InterfaceType || type is TypedefType || type is DynamicType,
"Unexpected type constant type: $type");
}
+1 -1
View File
@@ -317,7 +317,7 @@ abstract class DeferredLoadTask extends CompilerTask {
DartType type = typeUse.type;
switch (typeUse.kind) {
case TypeUseKind.TYPE_LITERAL:
if (type.isInterfaceType) {
if (type is InterfaceType) {
InterfaceType interface = type;
dependencies.addClass(
interface.element, typeUse.deferredImport);
+13 -76
View File
@@ -44,39 +44,6 @@ abstract class DartType {
/// Is `true` if this type should be treated as the dynamic type.
bool get treatAsDynamic => false;
/// Is `true` if this type is the dynamic type.
bool get isDynamic => false;
/// Is `true` if this type is an erased type.
bool get isErased => false;
/// Is `true` if this type is the any type.
bool get isAny => false;
/// Is `true` if this type is the void type.
bool get isVoid => false;
/// Is `true` if this type is an interface type.
bool get isInterfaceType => false;
/// Is `true` if this type is a typedef.
bool get isTypedef => false;
/// Is `true` if this type is a function type.
bool get isFunctionType => false;
/// Is `true` if this type is a type variable.
bool get isTypeVariable => false;
/// Is `true` if this type is a type variable declared on a function type
///
/// For instance `T` in
/// void Function<T>(T t)
bool get isFunctionTypeVariable => false;
/// Is `true` if this type is a `FutureOr` type.
bool get isFutureOr => false;
/// Whether this type contains a type variable.
bool get containsTypeVariables => false;
@@ -186,9 +153,6 @@ class InterfaceType extends DartType {
@override
bool get isTop => isObject;
@override
bool get isInterfaceType => true;
@override
bool get isObject {
return element.name == 'Object' &&
@@ -257,9 +221,6 @@ class TypedefType extends DartType {
@override
bool get isTop => unaliased.isTop;
@override
bool get isTypedef => true;
@override
bool get containsTypeVariables =>
typeArguments.any((type) => type.containsTypeVariables);
@@ -316,9 +277,6 @@ class TypeVariableType extends DartType {
TypeVariableType(this.element);
@override
bool get isTypeVariable => true;
@override
bool get containsTypeVariables => true;
@@ -378,9 +336,6 @@ class FunctionTypeVariable extends DartType {
_bound = value;
}
@override
bool get isFunctionTypeVariable => true;
@override
int get hashCode => index.hashCode * 19;
@@ -412,9 +367,6 @@ class VoidType extends DartType {
@override
bool get isTop => true;
@override
bool get isVoid => true;
@override
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
visitor.visitVoidType(this, argument);
@@ -436,9 +388,6 @@ class DynamicType extends DartType {
@override
bool get isTop => true;
@override
bool get isDynamic => true;
@override
bool get treatAsDynamic => true;
@@ -466,9 +415,6 @@ class ErasedType extends DartType {
@override
bool get treatAsDynamic => true;
@override
bool get isErased => true;
@override
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
visitor.visitErasedType(this, argument);
@@ -500,9 +446,6 @@ class AnyType extends DartType {
@override
bool get isTop => true;
@override
bool get isAny => true;
@override
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) =>
visitor.visitAnyType(this, argument);
@@ -565,9 +508,6 @@ class FunctionType extends DartType {
namedParameterTypes.forEach((type) => type.forEachTypeVariable(f));
}
@override
bool get isFunctionType => true;
FunctionType instantiate(List<DartType> arguments) {
return subst(arguments, typeVariables);
}
@@ -647,9 +587,6 @@ class FutureOrType extends DartType {
@override
bool get isTop => typeArgument.isTop;
@override
bool get isFutureOr => true;
@override
bool get containsTypeVariables => typeArgument.containsTypeVariables;
@@ -1573,11 +1510,11 @@ abstract class AbstractTypeRelation<T extends DartType>
bool visitTypeVariableType(TypeVariableType t, T s) {
// Identity check is handled in [isSubtype].
DartType bound = getTypeVariableBound(t.element);
if (bound.isTypeVariable) {
if (bound is TypeVariableType) {
// The bound is potentially cyclic so we need to be extra careful.
Set<TypeVariableEntity> seenTypeVariables = new Set<TypeVariableEntity>();
seenTypeVariables.add(t.element);
while (bound.isTypeVariable) {
while (bound is TypeVariableType) {
TypeVariableType typeVariable = bound;
if (bound == s) {
// [t] extends [s].
@@ -1599,7 +1536,7 @@ abstract class AbstractTypeRelation<T extends DartType>
@override
bool visitFunctionTypeVariable(FunctionTypeVariable t, DartType s) {
if (!s.isFunctionTypeVariable) return false;
if (s is! FunctionTypeVariable) return false;
return assumptions.isAssumed(t, s);
}
}
@@ -1608,10 +1545,10 @@ abstract class MoreSpecificVisitor<T extends DartType>
extends AbstractTypeRelation<T> {
bool isMoreSpecific(T t, T s) {
if (identical(t, s) ||
t.isAny ||
s.isAny ||
t is AnyType ||
s is AnyType ||
s.treatAsDynamic ||
s.isVoid ||
s is VoidType ||
s == commonElements.objectType ||
t == commonElements.nullType) {
return true;
@@ -1633,8 +1570,8 @@ abstract class MoreSpecificVisitor<T extends DartType>
@override
bool invalidFunctionReturnTypes(T t, T s) {
if (s.treatAsDynamic && t.isVoid) return true;
return !s.isVoid && !isMoreSpecific(t, s);
if (s.treatAsDynamic && t is VoidType) return true;
return s is! VoidType && !isMoreSpecific(t, s);
}
@override
@@ -1662,12 +1599,12 @@ abstract class MoreSpecificVisitor<T extends DartType>
abstract class SubtypeVisitor<T extends DartType>
extends MoreSpecificVisitor<T> {
bool isSubtype(DartType t, DartType s) {
if (t.isAny || s.isAny) return true;
if (s.isFutureOr) {
if (t is AnyType || s is AnyType) return true;
if (s is FutureOrType) {
FutureOrType sFutureOr = s;
if (isSubtype(t, sFutureOr.typeArgument)) {
return true;
} else if (t.isInterfaceType) {
} else if (t is InterfaceType) {
InterfaceType tInterface = t;
if (tInterface.element == commonElements.futureClass &&
isSubtype(
@@ -1710,7 +1647,7 @@ abstract class SubtypeVisitor<T extends DartType>
@override
bool visitFutureOrType(FutureOrType t, covariant DartType s) {
if (s.isFutureOr) {
if (s is FutureOrType) {
FutureOrType sFutureOr = s;
return isSubtype(t.typeArgument, sFutureOr.typeArgument);
}
@@ -1727,7 +1664,7 @@ abstract class PotentialSubtypeVisitor<T extends DartType>
@override
bool isSubtype(DartType t, DartType s) {
if (t.isAny || s.isAny) return true;
if (t is AnyType || s is AnyType) return true;
if (t is TypeVariableType || s is TypeVariableType) {
return true;
}
@@ -1692,7 +1692,7 @@ class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
DartType type = node.guard != null
? _elementMap.getDartType(node.guard)
: DynamicType();
if (type.isInterfaceType) {
if (type is InterfaceType) {
InterfaceType interfaceType = type;
mask = _types.nonNullSubtype(interfaceType.element);
} else {
@@ -387,11 +387,11 @@ class InferrerEngineImpl extends InferrerEngine {
mappedType = types.boolType;
} else if (type == commonElements.nullType) {
mappedType = types.nullType;
} else if (type.isVoid) {
} else if (type is VoidType) {
mappedType = types.nullType;
} else if (type.isDynamic) {
} else if (type is DynamicType) {
return types.dynamicType;
} else if (type.isInterfaceType) {
} else if (type is InterfaceType) {
mappedType = types.nonNullSubtype(type.element);
} else {
mappedType = types.dynamicType;
@@ -2275,21 +2275,21 @@ AbstractValue _narrowType(
AbstractValue otherType;
if (annotation.treatAsDynamic) {
return type;
} else if (annotation.isInterfaceType) {
InterfaceType interfaceType = annotation;
if (interfaceType.element == closedWorld.commonElements.objectClass) {
} else if (annotation is InterfaceType) {
if (annotation.element == closedWorld.commonElements.objectClass) {
return type;
}
otherType = abstractValueDomain.createNonNullSubtype(interfaceType.element);
} else if (annotation.isVoid) {
otherType = abstractValueDomain.createNonNullSubtype(annotation.element);
} else if (annotation is VoidType) {
return type;
} else if (annotation.isTypedef || annotation.isFunctionType) {
} else if (annotation is TypedefType || annotation is FunctionType) {
otherType = closedWorld.abstractValueDomain.functionType;
} else if (annotation.isFutureOr) {
} else if (annotation is FutureOrType) {
// TODO(johnniwinther): Narrow FutureOr types.
return type;
} else {
assert(annotation.isTypeVariable || annotation.isFunctionTypeVariable);
assert(
annotation is TypeVariableType || annotation is FunctionTypeVariable);
// TODO(ngeoffray): Narrow to bound.
return type;
}
@@ -318,14 +318,14 @@ class TypeSystem {
TypeInformation narrowType(TypeInformation type, DartType annotation,
{bool isNullable: true}) {
AbstractValue otherType;
if (annotation.isVoid) return type;
if (annotation is VoidType) return type;
if (annotation.treatAsDynamic) {
if (isNullable) return type;
// If the input is already narrowed to be not-null, there is no value
// in adding another narrowing node.
if (_isNonNullNarrow(type)) return type;
otherType = _abstractValueDomain.excludeNull(dynamicType.type);
} else if (annotation.isInterfaceType) {
} else if (annotation is InterfaceType) {
InterfaceType interface = annotation;
if (interface.element == _closedWorld.commonElements.objectClass) {
if (isNullable) return type;
@@ -335,13 +335,13 @@ class TypeSystem {
otherType =
_abstractValueDomain.createNonNullSubtype(interface.element);
}
} else if (annotation.isTypedef || annotation.isFunctionType) {
} else if (annotation is TypedefType || annotation is FunctionType) {
otherType = functionType.type;
} else if (annotation.isFutureOr) {
} else if (annotation is FutureOrType) {
// TODO(johnniwinther): Support narrowing of FutureOr.
return type;
} else {
assert(annotation.isTypeVariable);
assert(annotation is TypeVariableType);
// TODO(ngeoffray): Narrow to bound.
return type;
}
+2 -2
View File
@@ -258,11 +258,11 @@ class Constantifier extends ir.ExpressionVisitor<ConstantExpression> {
ConstantExpression visitTypeLiteral(ir.TypeLiteral node) {
String name;
DartType type = elementMap.getDartType(node.type);
if (type.isDynamic) {
if (type is DynamicType) {
name = 'dynamic';
} else if (type is InterfaceType) {
name = type.element.name;
} else if (type.isTypedef) {
} else if (type is TypedefType) {
// TODO(johnniwinther): Compute a name for the type literal? It is only
// used in error messages in the old SSA builder.
name = '?';
@@ -58,7 +58,7 @@ class TypeVariableCheckedModeHelper extends CheckedModeHelper {
@override
void generateAdditionalArguments(SsaCodeGenerator codegen, ModularNamer namer,
HTypeConversion node, List<jsAst.Expression> arguments) {
assert(node.typeExpression.isTypeVariable);
assert(node.typeExpression is TypeVariableType);
codegen.use(node.typeRepresentation);
arguments.add(codegen.pop());
}
@@ -73,7 +73,7 @@ class FunctionTypeRepresentationCheckedModeHelper extends CheckedModeHelper {
@override
void generateAdditionalArguments(SsaCodeGenerator codegen, ModularNamer namer,
HTypeConversion node, List<jsAst.Expression> arguments) {
assert(node.typeExpression.isFunctionType);
assert(node.typeExpression is FunctionType);
codegen.use(node.typeRepresentation);
arguments.add(codegen.pop());
}
@@ -88,7 +88,7 @@ class FutureOrRepresentationCheckedModeHelper extends CheckedModeHelper {
@override
void generateAdditionalArguments(SsaCodeGenerator codegen, ModularNamer namer,
HTypeConversion node, List<jsAst.Expression> arguments) {
assert(node.typeExpression.isFutureOr);
assert(node.typeExpression is FutureOrType);
codegen.use(node.typeRepresentation);
arguments.add(codegen.pop());
}
@@ -203,23 +203,23 @@ class CheckedModeHelpers {
String getCheckedModeHelperNameInternal(
DartType type, CommonElements commonElements,
{bool typeCast, bool nativeCheckOnly}) {
assert(!type.isTypedef);
assert(type is! TypedefType);
if (type.isTypeVariable) {
if (type is TypeVariableType) {
return typeCast
? 'subtypeOfRuntimeTypeCast'
: 'assertSubtypeOfRuntimeType';
}
if (type.isFunctionType) {
if (type is FunctionType) {
return typeCast ? 'functionTypeCast' : 'functionTypeCheck';
}
if (type.isFutureOr) {
if (type is FutureOrType) {
return typeCast ? 'futureOrCast' : 'futureOrCheck';
}
assert(type.isInterfaceType,
assert(type is InterfaceType,
failedAt(NO_LOCATION_SPANNABLE, "Unexpected type: $type"));
InterfaceType interfaceType = type;
ClassEntity element = interfaceType.element;
@@ -284,7 +284,7 @@ class CheckedModeHelpers {
return nativeCheck ? 'listSuperNative$suffix' : 'listSuper$suffix';
}
if (type.isInterfaceType && !type.treatAsRaw) {
if (type is InterfaceType && !type.treatAsRaw) {
return typeCast ? 'subtypeCast' : 'assertSubtype';
}
@@ -174,7 +174,7 @@ class CodegenEnqueuerListener extends EnqueuerListener {
// If the type is a web component, we need to ensure the constructors are
// available to 'upgrade' the native object.
TypeConstantValue type = constant;
if (type.representedType.isInterfaceType) {
if (type.representedType is InterfaceType) {
InterfaceType representedType = type.representedType;
_customElementsAnalysis.registerTypeConstant(representedType.element);
}
@@ -102,13 +102,13 @@ class CustomElementsResolutionAnalysis extends CustomElementsAnalysisBase {
}
void registerTypeLiteral(DartType type) {
if (type.isInterfaceType) {
if (type is InterfaceType) {
// TODO(sra): If we had a flow query from the type literal expression to
// the Type argument of the metadata lookup, we could tell if this type
// literal is really a demand for the metadata.
InterfaceType interfaceType = type;
join.selectedClasses.add(interfaceType.element);
} else if (type.isTypeVariable) {
} else if (type is TypeVariableType) {
// This is a type parameter of a parameterized class.
// TODO(sra): Is there a way to determine which types are bound to the
// parameter?
@@ -185,7 +185,7 @@ class JavaScriptImpactTransformer extends ImpactTransformer {
break;
case TypeUseKind.TYPE_LITERAL:
_customElementsResolutionAnalysis.registerTypeLiteral(type);
if (type.isTypeVariable) {
if (type is TypeVariableType) {
TypeVariableType typeVariable = type;
Entity typeDeclaration = typeVariable.element.typeDeclaration;
if (typeDeclaration is ClassEntity) {
@@ -332,9 +332,11 @@ class JavaScriptImpactTransformer extends ImpactTransformer {
type = _elementEnvironment.getUnaliasedType(type);
registerImpact(_impacts.typeCheck);
if (!type.treatAsRaw || type.containsTypeVariables || type.isFunctionType) {
if (!type.treatAsRaw ||
type.containsTypeVariables ||
type is FunctionType) {
registerImpact(_impacts.genericTypeCheck);
if (type.isTypeVariable) {
if (type is TypeVariableType) {
registerImpact(_impacts.typeVariableTypeCheck);
}
}
@@ -377,8 +379,8 @@ class CodegenImpactTransformer {
this._nativeEmitter);
void onIsCheckForCodegen(DartType type, TransformedWorldImpact transformed) {
if (type.isDynamic) return;
if (type.isVoid) return;
if (type is DynamicType) return;
if (type is VoidType) return;
type = type.unaliased;
_impacts.typeCheck.registerImpact(transformed, _elementEnvironment);
@@ -278,7 +278,7 @@ class InterceptorDataImpl implements InterceptorData {
// is mixed-in or in an implements clause.
if (!type.treatAsRaw) return false;
if (type.isFutureOr) return false;
if (type is FutureOrType) return false;
InterfaceType interfaceType = type;
ClassEntity classElement = interfaceType.element;
if (isInterceptedClass(classElement)) return false;
+4 -4
View File
@@ -1513,7 +1513,7 @@ class Namer extends ModularNamer {
@override
jsAst.Name operatorIsType(DartType type) {
if (type.isFunctionType) {
if (type is FunctionType) {
// TODO(erikcorry): Reduce from $isx to ix when we are minifying.
return new CompoundName([
new StringBackedName(fixedNames.operatorIsPrefix),
@@ -1617,7 +1617,7 @@ class Namer extends ModularNamer {
}
String getTypeRepresentationForTypeConstant(DartType type) {
if (type.isDynamic) return "dynamic";
if (type is DynamicType) return "dynamic";
if (type is TypedefType) {
return uniqueNameForTypeConstantElement(
type.element.library, type.element);
@@ -2178,11 +2178,11 @@ class FunctionTypeNamer extends BaseDartTypeVisitor {
}
bool _isSimpleFunctionType(FunctionType type) {
if (!type.returnType.isDynamic) return false;
if (type.returnType is! DynamicType) return false;
if (!type.optionalParameterTypes.isEmpty) return false;
if (!type.namedParameterTypes.isEmpty) return false;
for (DartType parameter in type.parameterTypes) {
if (!parameter.isDynamic) return false;
if (parameter is! DynamicType) return false;
}
return true;
}
@@ -270,7 +270,7 @@ class ResolutionEnqueuerListener extends EnqueuerListener {
..addAll(functionType.optionalParameterTypes)
..addAll(functionType.namedParameterTypes);
for (var type in allParameterTypes) {
if (type.isFunctionType || type.isTypedef) {
if (type is FunctionType || type is TypedefType) {
var closureConverter = _commonElements.closureConverter;
worldImpact.registerStaticUse(
new StaticUse.implicitInvoke(closureConverter));
@@ -1055,7 +1055,7 @@ class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder {
void processChecks(Set<DartType> checks) {
checks.forEach((DartType type) {
if (type.isInterfaceType) {
if (type is InterfaceType) {
InterfaceType itf = type;
if (!itf.treatAsRaw) {
potentiallyNeedTypeArguments(itf.element);
@@ -1067,7 +1067,7 @@ class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder {
Entity typeDeclaration = typeVariable.element.typeDeclaration;
potentiallyNeedTypeArguments(typeDeclaration);
});
if (type.isFunctionType) {
if (type is FunctionType) {
checkClosures(potentialSubtypeOf: type);
}
if (type is FutureOrType) {
@@ -1100,8 +1100,8 @@ class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder {
void checkFunction(Entity function, FunctionType type) {
for (FunctionTypeVariable typeVariable in type.typeVariables) {
DartType bound = typeVariable.bound;
if (!bound.isDynamic &&
!bound.isVoid &&
if (bound is! DynamicType &&
bound is! VoidType &&
bound != closedWorld.commonElements.objectType) {
potentiallyNeedTypeArguments(function);
break;
@@ -268,7 +268,7 @@ class NativeEmitter {
for (jsAst.Parameter stubParameter in stubParameters) {
if (stubParameter.name == name) {
type = type.unaliased;
if (type.isFunctionType) {
if (type is FunctionType) {
closureConverter ??= _emitterTask.emitter
.staticFunctionAccess(_commonElements.closureConverter);
@@ -240,7 +240,7 @@ class RuntimeTypeGenerator {
return new jsAst.VariableUse(_getVariableName(variable.element.name));
}
if (substitution.arguments.every((DartType type) => type.isDynamic)) {
if (substitution.arguments.every((DartType type) => type is DynamicType)) {
return emitter.generateFunctionThatReturnsNull();
} else {
jsAst.Expression value =
@@ -145,7 +145,7 @@ abstract class KernelImpactRegistryMixin implements ImpactRegistry {
@override
void registerParameterCheck(ir.DartType irType) {
DartType type = elementMap.getDartType(irType);
if (!type.isDynamic) {
if (type is! DynamicType) {
impactBuilder.registerTypeUse(new TypeUse.parameterCheck(type));
}
}
+2 -2
View File
@@ -815,7 +815,7 @@ abstract class BehaviorBuilder {
}
if (!trustJSInteropTypeAnnotations ||
type.isDynamic ||
type is DynamicType ||
type == commonElements.objectType) {
// By saying that only JS-interop types can be created, we prevent
// pulling in every other native type (e.g. all of dart:html) when a
@@ -882,7 +882,7 @@ abstract class BehaviorBuilder {
_behavior.typesReturned.add(!isJsInterop || trustJSInteropTypeAnnotations
? returnType
: commonElements.dynamicType);
if (!type.returnType.isVoid) {
if (type.returnType is! VoidType) {
// Declared types are nullable.
_behavior.typesReturned.add(commonElements.nullType);
}
+1 -1
View File
@@ -132,7 +132,7 @@ abstract class NativeEnqueuerBase implements NativeEnqueuer {
InterfaceType specType = _elementEnvironment.getRawType(type.element);
return _dartTypes.isSubtype(nativeType, specType);
}));
} else if (type.isDynamic) {
} else if (type is DynamicType) {
matchingClasses.addAll(_unusedClasses);
} else {
assert(type is VoidType, '$type was ${type.runtimeType}');
+3 -3
View File
@@ -1488,8 +1488,8 @@ class KernelSsaGraphBuilder extends ir.Visitor {
_elementMap);
HInstruction newParameter = localsHandler.directLocals[local];
DartType bound = _getDartTypeIfValid(typeParameter.bound);
if (!bound.isDynamic &&
!bound.isVoid &&
if (bound is! DynamicType &&
bound is! VoidType &&
bound != _commonElements.objectType) {
if (options.experimentNewRti) {
_checkTypeBound(newParameter, bound, local.name);
@@ -5525,7 +5525,7 @@ class KernelSsaGraphBuilder extends ir.Visitor {
/// Returns `true` if the checking of [type] is performed directly on the
/// object and not on an interceptor.
bool _hasDirectCheckFor(DartType type) {
if (!type.isInterfaceType) return false;
if (type is! InterfaceType) return false;
InterfaceType interfaceType = type;
ClassEntity element = interfaceType.element;
return element == _commonElements.stringClass ||
+7 -7
View File
@@ -2891,7 +2891,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
void checkType(HInstruction input, HInstruction interceptor, DartType type,
SourceInformation sourceInformation,
{bool negative: false}) {
if (type.isInterfaceType) {
if (type is InterfaceType) {
InterfaceType interfaceType = type;
ClassEntity element = interfaceType.element;
if (element == _commonElements.jsArrayClass) {
@@ -3102,7 +3102,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
_commonElements.isListSupertype(element)) {
handleListOrSupertypeCheck(input, interceptor, type, sourceInformation,
negative: negative);
} else if (type.isFunctionType) {
} else if (type is FunctionType) {
checkType(input, interceptor, type, sourceInformation,
negative: negative);
} else if ((input.isPrimitive(_abstractValueDomain).isPotentiallyTrue &&
@@ -3133,10 +3133,10 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
void visitTypeConversion(HTypeConversion node) {
assert(node.isTypeCheck || node.isCastCheck);
DartType type = node.typeExpression;
assert(!type.isTypedef);
assert(!type.isDynamic);
assert(!type.isVoid);
if (type.isFunctionType) {
assert(type is! TypedefType);
assert(type is! DynamicType);
assert(type is! VoidType);
if (type is FunctionType) {
// TODO(5022): We currently generate $isFunction checks for
// function types.
_registry
@@ -3546,7 +3546,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
TypeRecipe typeExpression = node.typeExpression;
if (envStructure is FullTypeEnvironmentStructure &&
typeExpression is TypeExpressionRecipe) {
if (typeExpression.type.isTypeVariable) {
if (typeExpression.type is TypeVariableType) {
TypeVariableType type = typeExpression.type;
int index = indexTypeVariable(
_closedWorld, _rtiSubstitutions, envStructure, type);
+13 -13
View File
@@ -1404,16 +1404,16 @@ abstract class HInstruction implements Spannable {
// Only the builder knows how to create [HTypeConversion]
// instructions with generics. It has the generic type context
// available.
assert(!type.isTypeVariable);
assert(type.treatAsRaw || type.isFunctionType);
if (type.isDynamic) return this;
if (type.isVoid) return this;
assert(type is! TypeVariableType);
assert(type.treatAsRaw || type is FunctionType);
if (type is DynamicType) return this;
if (type is VoidType) return this;
if (type == closedWorld.commonElements.objectType) return this;
if (type.isFunctionType || type.isFutureOr) {
if (type is FunctionType || type is FutureOrType) {
return new HTypeConversion(type, kind,
closedWorld.abstractValueDomain.dynamicType, this, sourceInformation);
}
assert(type.isInterfaceType);
assert(type is InterfaceType);
if (kind == HTypeConversion.TYPE_CHECK && !type.treatAsRaw) {
throw 'creating compound check to $type (this = ${this})';
} else {
@@ -3427,7 +3427,7 @@ class HIs extends HInstruction {
// TODO(sigmund): re-add `&& typeExpression.treatAsRaw` or something
// equivalent (which started failing once we allowed typeExpressions that
// contain type parameters matching the original bounds of the type).
assert((typeExpression.isFunctionType || typeExpression.isInterfaceType),
assert((typeExpression is FunctionType || typeExpression is InterfaceType),
"Unexpected raw is-test type: $typeExpression");
return new HIs.internal(typeExpression, [expression, interceptor],
RAW_CHECK, type, sourceInformation);
@@ -3554,7 +3554,7 @@ class HTypeConversion extends HCheck {
HInstruction input, SourceInformation sourceInformation)
: checkedType = type,
super(<HInstruction>[input], type) {
assert(typeExpression == null || !typeExpression.isTypedef);
assert(typeExpression == null || typeExpression is! TypedefType);
this.sourceElement = input.sourceElement;
this.sourceInformation = sourceInformation;
}
@@ -3563,13 +3563,13 @@ class HTypeConversion extends HCheck {
AbstractValue type, HInstruction input, HInstruction typeRepresentation)
: checkedType = type,
super(<HInstruction>[input, typeRepresentation], type) {
assert(!typeExpression.isTypedef);
assert(typeExpression is! TypedefType);
sourceElement = input.sourceElement;
}
bool get hasTypeRepresentation {
return typeExpression != null &&
typeExpression.isInterfaceType &&
typeExpression is InterfaceType &&
inputs.length > 1;
}
@@ -3615,10 +3615,10 @@ class HTypeConversion extends HCheck {
AbstractValueDomain abstractValueDomain = closedWorld.abstractValueDomain;
DartType type = typeExpression;
if (type != null) {
if (type.isTypeVariable) {
if (type is TypeVariableType) {
return false;
}
if (type.isFutureOr) {
if (type is FutureOrType) {
// `null` always passes type conversion.
if (checkedInput.isNull(abstractValueDomain).isDefinitelyTrue) {
return true;
@@ -3633,7 +3633,7 @@ class HTypeConversion extends HCheck {
}
return false;
}
if (type.isFunctionType) {
if (type is FunctionType) {
// `null` always passes type conversion.
if (checkedInput.isNull(abstractValueDomain).isDefinitelyTrue) {
return true;
+10 -10
View File
@@ -852,7 +852,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (!canInline) return;
if (inputPosition >= inputs.length) return;
HInstruction input = inputs[inputPosition++];
if (parameterType.unaliased.isFunctionType) {
if (parameterType.unaliased is FunctionType) {
// Must call the target since it contains a function conversion.
canInline = false;
return;
@@ -1093,11 +1093,11 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (!node.isRawCheck) {
return node;
} else if (type.isTypedef) {
} else if (type is TypedefType) {
return node;
} else if (type.isFunctionType) {
} else if (type is FunctionType) {
return node;
} else if (type.isFutureOr) {
} else if (type is FutureOrType) {
return node;
}
@@ -1174,7 +1174,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
rep.kind == TypeInfoExpressionKind.COMPLETE &&
rep.inputs.isEmpty) {
DartType type = rep.dartType;
if (type.isInterfaceType && type.treatAsRaw) {
if (type is InterfaceType && type.treatAsRaw) {
return node.checkedInput.convertType(_closedWorld, type, node.kind)
..sourceInformation = node.sourceInformation;
}
@@ -1427,9 +1427,9 @@ class SsaInstructionSimplifier extends HBaseVisitor
}
if (!fieldType.treatAsRaw ||
fieldType.isTypeVariable ||
fieldType.unaliased.isFunctionType ||
fieldType.unaliased.isFutureOr) {
fieldType is TypeVariableType ||
fieldType.unaliased is FunctionType ||
fieldType.unaliased is FutureOrType) {
// We cannot generate the correct type representation here, so don't
// inline this access.
// TODO(sra): If the input is such that we don't need a type check, we
@@ -3155,9 +3155,9 @@ class SsaTypeConversionInserter extends HBaseVisitor
DartType type = instruction.typeExpression;
if (!instruction.isRawCheck) {
return;
} else if (type.isTypedef) {
} else if (type is TypedefType) {
return;
} else if (type.isFutureOr) {
} else if (type is FutureOrType) {
return;
}
InterfaceType interfaceType = type;
+10 -10
View File
@@ -53,8 +53,8 @@ abstract class TypeBuilder {
if (type == null) return null;
type = builder.localsHandler.substInContext(type);
type = type.unaliased;
if (type.isDynamic) return null;
if (!type.isInterfaceType) return null;
if (type is DynamicType) return null;
if (type is! InterfaceType) return null;
if (type == _closedWorld.commonElements.objectType) return null;
// The type element is either a class or the void element.
ClassEntity element = (type as InterfaceType).element;
@@ -229,10 +229,10 @@ abstract class TypeBuilder {
HInstruction buildTypeArgumentRepresentations(
DartType type, MemberEntity sourceElement,
[SourceInformation sourceInformation]) {
assert(!type.isTypeVariable);
assert(type is! TypeVariableType);
// Compute the representation of the type arguments, including access
// to the runtime type information for type variables as instructions.
assert(type.isInterfaceType);
assert(type is InterfaceType);
InterfaceType interface = type;
List<HInstruction> inputs = <HInstruction>[];
for (DartType argument in interface.typeArguments) {
@@ -261,7 +261,7 @@ abstract class TypeBuilder {
return builder.graph.addConstantNull(_closedWorld);
}
if (argument.isTypeVariable) {
if (argument is TypeVariableType) {
return addTypeVariableReference(argument, sourceElement,
sourceInformation: sourceInformation);
}
@@ -433,7 +433,7 @@ abstract class TypeBuilder {
if (type == null) return original;
type = type.unaliased;
if (type.isInterfaceType && !type.treatAsRaw) {
if (type is InterfaceType && !type.treatAsRaw) {
InterfaceType interfaceType = type;
AbstractValue subtype =
_abstractValueDomain.createNullableSubtype(interfaceType.element);
@@ -443,14 +443,14 @@ abstract class TypeBuilder {
return new HTypeConversion.withTypeRepresentation(
type, kind, subtype, original, representations)
..sourceInformation = sourceInformation;
} else if (type.isTypeVariable) {
} else if (type is TypeVariableType) {
AbstractValue subtype = original.instructionType;
HInstruction typeVariable =
addTypeVariableReference(type, builder.sourceElement);
return new HTypeConversion.withTypeRepresentation(
type, kind, subtype, original, typeVariable)
..sourceInformation = sourceInformation;
} else if (type.isFunctionType || type.isFutureOr) {
} else if (type is FunctionType || type is FutureOrType) {
HInstruction reifiedType =
analyzeTypeArgument(type, builder.sourceElement);
// TypeMasks don't encode function types or FutureOr types.
@@ -473,8 +473,8 @@ abstract class TypeBuilder {
if (type == null) return original;
type = type.unaliased;
if (type.isDynamic) return original;
if (type.isVoid) return original;
if (type is DynamicType) return original;
if (type is VoidType) return original;
if (type == _closedWorld.commonElements.objectType) return original;
HInstruction reifiedType = analyzeTypeArgumentNewRti(
+3 -2
View File
@@ -4,6 +4,7 @@
import '../common_elements.dart' show CommonElements;
import '../elements/entities.dart';
import '../elements/types.dart';
import '../inferrer/abstract_value_domain.dart';
import '../inferrer/types.dart';
import '../native/behavior.dart';
@@ -49,9 +50,9 @@ class AbstractValueFactory {
if (type == SpecialType.JsObject) {
return abstractValueDomain
.createNonNullExact(commonElements.objectClass);
} else if (type.isVoid) {
} else if (type is VoidType) {
return abstractValueDomain.nullType;
} else if (type.isDynamic) {
} else if (type is DynamicType) {
return abstractValueDomain.dynamicType;
} else if (type == commonElements.nullType) {
return abstractValueDomain.nullType;
@@ -183,21 +183,12 @@
"third_party/pkg/dart2js_info/lib/binary_serialization.dart": {
"Dynamic invocation of 'cast'.": 1
},
"pkg/compiler/lib/src/inferrer/inferrer_engine.dart": {
"Dynamic access of 'isVoid'.": 1,
"Dynamic access of 'isDynamic'.": 1,
"Dynamic access of 'isInterfaceType'.": 1,
"Dynamic access of 'element'.": 1
},
"pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart": {
"Dynamic access of 'name'.": 1
},
"pkg/compiler/lib/src/universe/side_effects.dart": {
"Dynamic access of 'universe.side_effects::_flags'.": 1
},
"pkg/compiler/lib/src/native/enqueue.dart": {
"Dynamic access of 'isDynamic'.": 1
},
"pkg/compiler/lib/src/ssa/builder_kernel.dart": {
"Dynamic update to 'instantiatedTypes'.": 1,
"Dynamic update to 'sideEffects'.": 1,
@@ -206,8 +197,6 @@
"Dynamic invocation of 'addSuccessor'.": 1
},
"pkg/compiler/lib/src/ssa/types.dart": {
"Dynamic access of 'isVoid'.": 1,
"Dynamic access of 'isDynamic'.": 1,
"Dynamic access of 'treatAsDynamic'.": 1,
"Dynamic access of 'element'.": 1
},
@@ -458,7 +458,7 @@ class DartTypePrinter implements DartTypeVisitor {
@override
visitTypedefType(TypedefType type, _) {
sb.write(type.element.name);
if (type.typeArguments.any((type) => !type.isDynamic)) {
if (type.typeArguments.any((type) => type is! DynamicType)) {
sb.write('<');
visitTypes(type.typeArguments);
sb.write('>');
@@ -468,7 +468,7 @@ class DartTypePrinter implements DartTypeVisitor {
@override
visitInterfaceType(InterfaceType type, _) {
sb.write(type.element.name);
if (type.typeArguments.any((type) => !type.isDynamic)) {
if (type.typeArguments.any((type) => type is! DynamicType)) {
sb.write('<');
visitTypes(type.typeArguments);
sb.write('>');
@@ -121,24 +121,24 @@ testTypeSubstitution() async {
""");
InterfaceType Class_T_S = env["Class"];
Expect.isNotNull(Class_T_S);
Expect.isTrue(Class_T_S.isInterfaceType);
Expect.isTrue(Class_T_S is InterfaceType);
Expect.equals(2, Class_T_S.typeArguments.length);
DartType T = Class_T_S.typeArguments[0];
Expect.isNotNull(T);
Expect.isTrue(T.isTypeVariable);
Expect.isTrue(T is TypeVariableType);
DartType S = Class_T_S.typeArguments[1];
Expect.isNotNull(S);
Expect.isTrue(S.isTypeVariable);
Expect.isTrue(S is TypeVariableType);
DartType intType = env['int'];
Expect.isNotNull(intType);
Expect.isTrue(intType.isInterfaceType);
Expect.isTrue(intType is InterfaceType);
DartType StringType = env['String'];
Expect.isNotNull(StringType);
Expect.isTrue(StringType.isInterfaceType);
Expect.isTrue(StringType is InterfaceType);
ClassEntity ListClass = env.getElement('List');
ClassEntity MapClass = env.getElement('Map');