diff --git a/pkg/compiler/lib/src/constants/expressions.dart b/pkg/compiler/lib/src/constants/expressions.dart index 095bec3a79e..0a6c24ba792 100644 --- a/pkg/compiler/lib/src/constants/expressions.dart +++ b/pkg/compiler/lib/src/constants/expressions.dart @@ -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"); } diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart index 1c392c83c5b..74a2a5ccd4d 100644 --- a/pkg/compiler/lib/src/deferred_load.dart +++ b/pkg/compiler/lib/src/deferred_load.dart @@ -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); diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart index ee278b1a712..e976c820d5c 100644 --- a/pkg/compiler/lib/src/elements/types.dart +++ b/pkg/compiler/lib/src/elements/types.dart @@ -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) - 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(DartTypeVisitor 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(DartTypeVisitor 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(DartTypeVisitor 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 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 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 seenTypeVariables = new Set(); 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 @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 extends AbstractTypeRelation { 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 @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 abstract class SubtypeVisitor extends MoreSpecificVisitor { 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 @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 @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; } diff --git a/pkg/compiler/lib/src/inferrer/builder_kernel.dart b/pkg/compiler/lib/src/inferrer/builder_kernel.dart index 4c49acbfc61..48e3b9278dd 100644 --- a/pkg/compiler/lib/src/inferrer/builder_kernel.dart +++ b/pkg/compiler/lib/src/inferrer/builder_kernel.dart @@ -1692,7 +1692,7 @@ class KernelTypeGraphBuilder extends ir.Visitor { 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 { diff --git a/pkg/compiler/lib/src/inferrer/inferrer_engine.dart b/pkg/compiler/lib/src/inferrer/inferrer_engine.dart index a4accabea2e..98c43b294b3 100644 --- a/pkg/compiler/lib/src/inferrer/inferrer_engine.dart +++ b/pkg/compiler/lib/src/inferrer/inferrer_engine.dart @@ -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; diff --git a/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart b/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart index f674734c23a..af0410dc183 100644 --- a/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart +++ b/pkg/compiler/lib/src/inferrer/type_graph_nodes.dart @@ -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; } diff --git a/pkg/compiler/lib/src/inferrer/type_system.dart b/pkg/compiler/lib/src/inferrer/type_system.dart index c5c32cf4b97..2e05bac84b7 100644 --- a/pkg/compiler/lib/src/inferrer/type_system.dart +++ b/pkg/compiler/lib/src/inferrer/type_system.dart @@ -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; } diff --git a/pkg/compiler/lib/src/ir/visitors.dart b/pkg/compiler/lib/src/ir/visitors.dart index bd6d406acd6..a59308ffc8a 100644 --- a/pkg/compiler/lib/src/ir/visitors.dart +++ b/pkg/compiler/lib/src/ir/visitors.dart @@ -258,11 +258,11 @@ class Constantifier extends ir.ExpressionVisitor { 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 = '?'; diff --git a/pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart b/pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart index c577600b416..46b78b21af6 100644 --- a/pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart +++ b/pkg/compiler/lib/src/js_backend/checked_mode_helpers.dart @@ -58,7 +58,7 @@ class TypeVariableCheckedModeHelper extends CheckedModeHelper { @override void generateAdditionalArguments(SsaCodeGenerator codegen, ModularNamer namer, HTypeConversion node, List 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 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 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'; } diff --git a/pkg/compiler/lib/src/js_backend/codegen_listener.dart b/pkg/compiler/lib/src/js_backend/codegen_listener.dart index f7d02de1699..f4ae36cd873 100644 --- a/pkg/compiler/lib/src/js_backend/codegen_listener.dart +++ b/pkg/compiler/lib/src/js_backend/codegen_listener.dart @@ -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); } diff --git a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart index 16be5f2ae92..2a547ec54b9 100644 --- a/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart +++ b/pkg/compiler/lib/src/js_backend/custom_elements_analysis.dart @@ -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? diff --git a/pkg/compiler/lib/src/js_backend/impact_transformer.dart b/pkg/compiler/lib/src/js_backend/impact_transformer.dart index 8de9a4bbd04..3e0b43284f4 100644 --- a/pkg/compiler/lib/src/js_backend/impact_transformer.dart +++ b/pkg/compiler/lib/src/js_backend/impact_transformer.dart @@ -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); diff --git a/pkg/compiler/lib/src/js_backend/interceptor_data.dart b/pkg/compiler/lib/src/js_backend/interceptor_data.dart index db85765872a..867c379de79 100644 --- a/pkg/compiler/lib/src/js_backend/interceptor_data.dart +++ b/pkg/compiler/lib/src/js_backend/interceptor_data.dart @@ -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; diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart index fd7df4d752c..aaabd51c762 100644 --- a/pkg/compiler/lib/src/js_backend/namer.dart +++ b/pkg/compiler/lib/src/js_backend/namer.dart @@ -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; } diff --git a/pkg/compiler/lib/src/js_backend/resolution_listener.dart b/pkg/compiler/lib/src/js_backend/resolution_listener.dart index c7817539ee1..9d16126033a 100644 --- a/pkg/compiler/lib/src/js_backend/resolution_listener.dart +++ b/pkg/compiler/lib/src/js_backend/resolution_listener.dart @@ -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)); diff --git a/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart b/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart index 9c9fd786d7a..a303026cbdd 100644 --- a/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart +++ b/pkg/compiler/lib/src/js_backend/runtime_types_resolution.dart @@ -1055,7 +1055,7 @@ class RuntimeTypesNeedBuilderImpl implements RuntimeTypesNeedBuilder { void processChecks(Set 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; diff --git a/pkg/compiler/lib/src/js_emitter/native_emitter.dart b/pkg/compiler/lib/src/js_emitter/native_emitter.dart index 7be3f0d2140..c520f5c783d 100644 --- a/pkg/compiler/lib/src/js_emitter/native_emitter.dart +++ b/pkg/compiler/lib/src/js_emitter/native_emitter.dart @@ -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); diff --git a/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart index fcc0a7e3b32..94fe17af853 100644 --- a/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart +++ b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart @@ -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 = diff --git a/pkg/compiler/lib/src/kernel/kernel_impact.dart b/pkg/compiler/lib/src/kernel/kernel_impact.dart index ae1ed020a7e..ac71d58cf63 100644 --- a/pkg/compiler/lib/src/kernel/kernel_impact.dart +++ b/pkg/compiler/lib/src/kernel/kernel_impact.dart @@ -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)); } } diff --git a/pkg/compiler/lib/src/native/behavior.dart b/pkg/compiler/lib/src/native/behavior.dart index b97e29459d4..0e2aa4b3f37 100644 --- a/pkg/compiler/lib/src/native/behavior.dart +++ b/pkg/compiler/lib/src/native/behavior.dart @@ -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); } diff --git a/pkg/compiler/lib/src/native/enqueue.dart b/pkg/compiler/lib/src/native/enqueue.dart index 766bfa0e76d..e08baadadc7 100644 --- a/pkg/compiler/lib/src/native/enqueue.dart +++ b/pkg/compiler/lib/src/native/enqueue.dart @@ -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}'); diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart index 0688ba9ec70..b696a674f97 100644 --- a/pkg/compiler/lib/src/ssa/builder_kernel.dart +++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart @@ -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 || diff --git a/pkg/compiler/lib/src/ssa/codegen.dart b/pkg/compiler/lib/src/ssa/codegen.dart index e94ffa59a57..856e4fc847a 100644 --- a/pkg/compiler/lib/src/ssa/codegen.dart +++ b/pkg/compiler/lib/src/ssa/codegen.dart @@ -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); diff --git a/pkg/compiler/lib/src/ssa/nodes.dart b/pkg/compiler/lib/src/ssa/nodes.dart index 90297a25593..edbcb6789e0 100644 --- a/pkg/compiler/lib/src/ssa/nodes.dart +++ b/pkg/compiler/lib/src/ssa/nodes.dart @@ -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([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([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; diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart index 2f691659b99..8c278408473 100644 --- a/pkg/compiler/lib/src/ssa/optimize.dart +++ b/pkg/compiler/lib/src/ssa/optimize.dart @@ -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; diff --git a/pkg/compiler/lib/src/ssa/type_builder.dart b/pkg/compiler/lib/src/ssa/type_builder.dart index 0b77dbd1a31..06429cfc64c 100644 --- a/pkg/compiler/lib/src/ssa/type_builder.dart +++ b/pkg/compiler/lib/src/ssa/type_builder.dart @@ -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 inputs = []; 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( diff --git a/pkg/compiler/lib/src/ssa/types.dart b/pkg/compiler/lib/src/ssa/types.dart index 17953298438..201fca60a23 100644 --- a/pkg/compiler/lib/src/ssa/types.dart +++ b/pkg/compiler/lib/src/ssa/types.dart @@ -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; diff --git a/tests/compiler/dart2js/analyses/dart2js_allowed.json b/tests/compiler/dart2js/analyses/dart2js_allowed.json index ff6c98ad732..f62235b9744 100644 --- a/tests/compiler/dart2js/analyses/dart2js_allowed.json +++ b/tests/compiler/dart2js/analyses/dart2js_allowed.json @@ -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 }, diff --git a/tests/compiler/dart2js/equivalence/check_helpers.dart b/tests/compiler/dart2js/equivalence/check_helpers.dart index ee1aa145b3b..8c3bb3fba04 100644 --- a/tests/compiler/dart2js/equivalence/check_helpers.dart +++ b/tests/compiler/dart2js/equivalence/check_helpers.dart @@ -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('>'); diff --git a/tests/compiler/dart2js/model/type_substitution_test.dart b/tests/compiler/dart2js/model/type_substitution_test.dart index 35730ab196c..85c578494a7 100644 --- a/tests/compiler/dart2js/model/type_substitution_test.dart +++ b/tests/compiler/dart2js/model/type_substitution_test.dart @@ -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');