[cfe] Remove TypeEnvironment.*Type getters

The getters were returning types of undefined nullabilities.  Now the
nullability-aware getters on CoreTypes should be used instead.

Closes #38224.

Bug: http://dartbug.com/38224
Change-Id: I617a0ef8ee17ebd792c2bc1ec6477a5ee469fee1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118570
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
This commit is contained in:
Dmitry Stefantsov 2019-09-25 13:28:28 +00:00 committed by commit-bot@chromium.org
parent 463894f986
commit e034104f04
18 changed files with 171 additions and 145 deletions

View file

@ -220,9 +220,9 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
// Treat the properties of Object specially.
String nameString = node.name.name;
if (nameString == 'hashCode') {
return typeEnvironment.intType;
return typeEnvironment.coreTypes.intLegacyRawType;
} else if (nameString == 'runtimeType') {
return typeEnvironment.typeType;
return typeEnvironment.coreTypes.typeLegacyRawType;
}
return const ir.DynamicType();
}
@ -382,7 +382,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
ir.Procedure _objectEquals;
ir.Procedure get objectEquals =>
_objectEquals ??= _getMember(typeEnvironment.objectType.classNode, '==');
_objectEquals ??= _getMember(typeEnvironment.coreTypes.objectClass, '==');
/// Returns [receiverType] narrowed to enclosing class of [interfaceTarget].
///
@ -434,7 +434,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
/// [type].
bool isTypeApplicable(ir.DartType type) {
if (type is ir.DynamicType) return true;
if (type == typeEnvironment.rawFunctionType) return true;
if (type == typeEnvironment.coreTypes.functionLegacyRawType) return true;
if (type is ir.FunctionType) {
return isFunctionTypeApplicable(
type.typeParameters.length,
@ -636,7 +636,7 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
}
if (node.name.name == '==') {
// We use this special case to simplify generation of '==' checks.
return typeEnvironment.boolType;
return typeEnvironment.coreTypes.boolLegacyRawType;
}
return const ir.DynamicType();
}

View file

@ -98,34 +98,36 @@ abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {
}
@override
ir.DartType visitBoolLiteral(ir.BoolLiteral node) => typeEnvironment.boolType;
ir.DartType visitBoolLiteral(ir.BoolLiteral node) =>
typeEnvironment.coreTypes.boolLegacyRawType;
@override
ir.DartType visitCheckLibraryIsLoaded(ir.CheckLibraryIsLoaded node) =>
typeEnvironment.objectType;
typeEnvironment.coreTypes.objectLegacyRawType;
@override
ir.DartType visitStringLiteral(ir.StringLiteral node) =>
typeEnvironment.stringType;
typeEnvironment.coreTypes.stringLegacyRawType;
@override
ir.DartType visitStringConcatenation(ir.StringConcatenation node) {
return typeEnvironment.stringType;
return typeEnvironment.coreTypes.stringLegacyRawType;
}
@override
ir.DartType visitNullLiteral(ir.NullLiteral node) => typeEnvironment.nullType;
@override
ir.DartType visitIntLiteral(ir.IntLiteral node) => typeEnvironment.intType;
ir.DartType visitIntLiteral(ir.IntLiteral node) =>
typeEnvironment.coreTypes.intLegacyRawType;
@override
ir.DartType visitDoubleLiteral(ir.DoubleLiteral node) =>
typeEnvironment.doubleType;
typeEnvironment.coreTypes.doubleLegacyRawType;
@override
ir.DartType visitSymbolLiteral(ir.SymbolLiteral node) =>
typeEnvironment.symbolType;
typeEnvironment.coreTypes.symbolLegacyRawType;
@override
ir.DartType visitListLiteral(ir.ListLiteral node) {
@ -181,11 +183,11 @@ abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {
@override
ir.DartType visitLogicalExpression(ir.LogicalExpression node) =>
typeEnvironment.boolType;
typeEnvironment.coreTypes.boolLegacyRawType;
@override
ir.DartType visitNot(ir.Not node) {
return typeEnvironment.boolType;
return typeEnvironment.coreTypes.boolLegacyRawType;
}
@override
@ -195,11 +197,12 @@ abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {
@override
ir.DartType visitIsExpression(ir.IsExpression node) {
return typeEnvironment.boolType;
return typeEnvironment.coreTypes.boolLegacyRawType;
}
@override
ir.DartType visitTypeLiteral(ir.TypeLiteral node) => typeEnvironment.typeType;
ir.DartType visitTypeLiteral(ir.TypeLiteral node) =>
typeEnvironment.coreTypes.typeLegacyRawType;
@override
ir.DartType visitFunctionExpression(ir.FunctionExpression node) {

View file

@ -2651,7 +2651,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
/// Kernel represents `<T>` as `<T extends Object = dynamic>`. We can find
/// explicit bounds by looking for anything *except* that.
typeParameterHasExplicitBound(TypeParameter t) =>
t.bound != _types.objectType || t.defaultType != const DynamicType();
t.bound != _types.coreTypes.objectLegacyRawType ||
t.defaultType != const DynamicType();
// If any explicit bounds were passed, emit them.
if (typeFormals.any(typeParameterHasExplicitBound)) {
@ -3147,7 +3148,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
}
if (node is AsExpression && node.isTypeError) {
assert(node.getStaticType(_types) == _types.boolType);
assert(node.getStaticType(_types) == _types.coreTypes.boolLegacyRawType);
return runtimeCall('dtest(#)', [_visitExpression(node.operand)]);
}
@ -4317,7 +4318,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var rightType = right.getStaticType(_types);
if (_typeRep.binaryOperationIsPrimitive(leftType, rightType) ||
leftType == _types.stringType && op == '+') {
leftType == _types.coreTypes.stringLegacyRawType && op == '+') {
// Inline operations on primitive types where possible.
// TODO(jmesserly): inline these from dart:core instead of hardcoding
// the implementation details here.
@ -4923,9 +4924,11 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
if (jsExpr is js_ast.LiteralString && jsExpr.valueWithoutQuotes.isEmpty) {
continue;
}
parts.add(e.getStaticType(_types) == _types.stringType && !isNullable(e)
? jsExpr
: runtimeCall('str(#)', [jsExpr]));
parts.add(
e.getStaticType(_types) == _types.coreTypes.stringLegacyRawType &&
!isNullable(e)
? jsExpr
: runtimeCall('str(#)', [jsExpr]));
}
if (parts.isEmpty) return js.string('');
return js_ast.Expression.binary(parts, '+');
@ -4971,7 +4974,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
var lhs = _visitExpression(operand);
var typeofName = _typeRep.typeFor(type).primitiveTypeOf;
// Inline primitives other than int (which requires a Math.floor check).
if (typeofName != null && type != _types.intType) {
if (typeofName != null && type != _types.coreTypes.intLegacyRawType) {
return js.call('typeof # == #', [lhs, js.string(typeofName, "'")]);
} else {
return js.call('#.is(#)', [_emitType(type), lhs]);

View file

@ -1964,10 +1964,11 @@ class TypeBuilderConstraintGatherer extends TypeConstraintGatherer
InterfaceType get nullType => hierarchy.coreTypes.nullType;
@override
InterfaceType get objectType => hierarchy.coreTypes.objectLegacyRawType;
InterfaceType get objectLegacyRawType =>
hierarchy.coreTypes.objectLegacyRawType;
@override
InterfaceType get rawFunctionType =>
InterfaceType get functionLegacyRawType =>
hierarchy.coreTypes.functionLegacyRawType;
@override

View file

@ -1230,15 +1230,17 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
statement.message,
templateConstEvalInvalidType.withArguments(
message,
typeEnvironment.stringType,
typeEnvironment.coreTypes.stringLegacyRawType,
message.getType(typeEnvironment)));
}
}
} else {
report(
statement.condition,
templateConstEvalInvalidType.withArguments(condition,
typeEnvironment.boolType, condition.getType(typeEnvironment)));
templateConstEvalInvalidType.withArguments(
condition,
typeEnvironment.coreTypes.boolLegacyRawType,
condition.getType(typeEnvironment)));
}
}
@ -1303,7 +1305,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
'+',
receiver,
typeEnvironment.stringType,
typeEnvironment.coreTypes.stringLegacyRawType,
other.getType(typeEnvironment)));
}
}
@ -1323,7 +1325,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
op,
other,
typeEnvironment.intType,
typeEnvironment.coreTypes.intLegacyRawType,
other.getType(typeEnvironment)));
}
num receiverValue = (receiver as PrimitiveConstant<num>).value;
@ -1335,7 +1337,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
op,
receiver,
typeEnvironment.numType,
typeEnvironment.coreTypes.numLegacyRawType,
other.getType(typeEnvironment)));
}
} else if (receiver is DoubleConstant) {
@ -1346,7 +1348,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
op,
receiver,
typeEnvironment.intType,
typeEnvironment.coreTypes.intLegacyRawType,
receiver.getType(typeEnvironment)));
}
if (arguments.length == 0) {
@ -1367,7 +1369,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
op,
receiver,
typeEnvironment.numType,
typeEnvironment.coreTypes.numLegacyRawType,
other.getType(typeEnvironment)));
}
} else if (receiver is BoolConstant) {
@ -1420,7 +1422,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
node.operator,
left,
typeEnvironment.boolType,
typeEnvironment.coreTypes.boolLegacyRawType,
right.getType(typeEnvironment)));
}
return report(
@ -1441,7 +1443,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
templateConstEvalInvalidBinaryOperandType.withArguments(
node.operator,
left,
typeEnvironment.boolType,
typeEnvironment.coreTypes.boolLegacyRawType,
right.getType(typeEnvironment)));
}
return report(
@ -1479,8 +1481,10 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
} else {
return report(
node.condition,
templateConstEvalInvalidType.withArguments(condition,
typeEnvironment.boolType, condition.getType(typeEnvironment)));
templateConstEvalInvalidType.withArguments(
condition,
typeEnvironment.coreTypes.boolLegacyRawType,
condition.getType(typeEnvironment)));
}
}
@ -1746,7 +1750,7 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
}
if (constant is NullConstant) {
return makeBoolConstant(node.type == typeEnvironment.nullType ||
node.type == typeEnvironment.objectType ||
node.type == typeEnvironment.coreTypes.objectLegacyRawType ||
node.type is DynamicType);
}
return makeBoolConstant(
@ -1764,8 +1768,10 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
}
return report(
node,
templateConstEvalInvalidType.withArguments(constant,
typeEnvironment.boolType, constant.getType(typeEnvironment)));
templateConstEvalInvalidType.withArguments(
constant,
typeEnvironment.coreTypes.boolLegacyRawType,
constant.getType(typeEnvironment)));
}
@override
@ -1850,14 +1856,14 @@ class ConstantEvaluator extends RecursiveVisitor<Constant> {
bool isSubtype(Constant constant, DartType type) {
DartType constantType = constant.getType(typeEnvironment);
if (targetingJavaScript) {
if (constantType == typeEnvironment.intType &&
type == typeEnvironment.doubleType) {
if (constantType == typeEnvironment.coreTypes.intLegacyRawType &&
type == typeEnvironment.coreTypes.doubleLegacyRawType) {
// With JS semantics, an integer is also a double.
return true;
}
if (constantType == typeEnvironment.doubleType &&
type == typeEnvironment.intType) {
if (constantType == typeEnvironment.coreTypes.doubleLegacyRawType &&
type == typeEnvironment.coreTypes.intLegacyRawType) {
double value = (constant as DoubleConstant).value;
if (value.isFinite && value == value.truncateToDouble()) {
return true;

View file

@ -27,8 +27,8 @@ abstract class StandardBounds {
Class get futureClass;
Class get futureOrClass;
InterfaceType get nullType;
InterfaceType get objectType;
InterfaceType get rawFunctionType;
InterfaceType get objectLegacyRawType;
InterfaceType get functionLegacyRawType;
bool isSubtypeOf(DartType subtype, DartType supertype);
@ -74,10 +74,10 @@ abstract class StandardBounds {
}
// SLB(Object, T) = SLB(T, Object) = T if T is not void or dynamic.
if (type1 == objectType) {
if (type1 == objectLegacyRawType) {
return type2;
}
if (type2 == objectType) {
if (type2 == objectLegacyRawType) {
return type1;
}
@ -182,10 +182,10 @@ abstract class StandardBounds {
}
// SUB(Object, T) = SUB(T, Object) = Object if T is not void or dynamic.
if (type1 == objectType) {
if (type1 == objectLegacyRawType) {
return type1;
}
if (type2 == objectType) {
if (type2 == objectLegacyRawType) {
return type2;
}
@ -202,10 +202,10 @@ abstract class StandardBounds {
// The standard upper bound of a function type and an interface type T is
// the standard upper bound of Function and T.
if (type1 is FunctionType && type2 is InterfaceType) {
type1 = rawFunctionType;
type1 = functionLegacyRawType;
}
if (type2 is FunctionType && type1 is InterfaceType) {
type2 = rawFunctionType;
type2 = functionLegacyRawType;
}
// At this point type1 and type2 should both either be interface types or
@ -474,13 +474,13 @@ abstract class StandardBounds {
// C<T extends U, U extends List>, T gets resolved directly to List. Do
// we need to replicate that behavior?
return getStandardUpperBound(
Substitution.fromMap({type1.parameter: objectType})
Substitution.fromMap({type1.parameter: objectLegacyRawType})
.substituteType(type1.parameter.bound),
type2);
} else if (type2 is TypeParameterType) {
return getStandardUpperBound(
type1,
Substitution.fromMap({type2.parameter: objectType})
Substitution.fromMap({type2.parameter: objectLegacyRawType})
.substituteType(type2.parameter.bound));
} else {
// We should only be called when at least one of the types is a

View file

@ -2564,7 +2564,7 @@ abstract class TypeInferrerImpl extends TypeInferrer {
expectedType = (expectedType as InterfaceType).typeArguments[0];
}
if (expectedType is FunctionType) return true;
if (expectedType == typeSchemaEnvironment.rawFunctionType) {
if (expectedType == typeSchemaEnvironment.functionLegacyRawType) {
if (!typeSchemaEnvironment.isSubtypeOf(actualType, expectedType)) {
return true;
}

View file

@ -120,11 +120,11 @@ class TypeSchemaEnvironment extends HierarchyBasedTypeEnvironment
// TODO(paulberry): this matches what is defined in the spec. It would be
// nice if we could change kernel to match the spec and not have to
// override.
if (type1 == intType) {
if (type2 == intType) return type2;
if (type2 == doubleType) return type2;
if (type1 == coreTypes.intLegacyRawType) {
if (type2 == coreTypes.intLegacyRawType) return type2;
if (type2 == coreTypes.doubleLegacyRawType) return type2;
}
return numType;
return coreTypes.numLegacyRawType;
}
/// Infers a generic type, function, method, or list/map literal

View file

@ -2739,9 +2739,9 @@ class PropertyGet extends Expression {
// Treat the properties of Object specially.
String nameString = name.name;
if (nameString == 'hashCode') {
return types.intType;
return types.coreTypes.intLegacyRawType;
} else if (nameString == 'runtimeType') {
return types.typeType;
return types.coreTypes.typeLegacyRawType;
}
return const DynamicType();
}
@ -3257,7 +3257,7 @@ class MethodInvocation extends InvocationExpression {
}
if (name.name == '==') {
// We use this special case to simplify generation of '==' checks.
return types.boolType;
return types.coreTypes.boolLegacyRawType;
}
return const DynamicType();
}
@ -3497,7 +3497,8 @@ class Not extends Expression {
operand?.parent = this;
}
DartType getStaticType(TypeEnvironment types) => types.boolType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.boolLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitNot(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) => v.visitNot(this, arg);
@ -3525,7 +3526,8 @@ class LogicalExpression extends Expression {
right?.parent = this;
}
DartType getStaticType(TypeEnvironment types) => types.boolType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.boolLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitLogicalExpression(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3610,7 +3612,8 @@ class StringConcatenation extends Expression {
setParents(expressions, this);
}
DartType getStaticType(TypeEnvironment types) => types.stringType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.stringLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitStringConcatenation(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3838,7 +3841,8 @@ class IsExpression extends Expression {
operand?.parent = this;
}
DartType getStaticType(TypeEnvironment types) => types.boolType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.boolLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitIsExpression(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3945,7 +3949,8 @@ class StringLiteral extends BasicLiteral {
StringLiteral(this.value);
DartType getStaticType(TypeEnvironment types) => types.stringType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.stringLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitStringLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3961,7 +3966,8 @@ class IntLiteral extends BasicLiteral {
IntLiteral(this.value);
DartType getStaticType(TypeEnvironment types) => types.intType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.intLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitIntLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3973,7 +3979,8 @@ class DoubleLiteral extends BasicLiteral {
DoubleLiteral(this.value);
DartType getStaticType(TypeEnvironment types) => types.doubleType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.doubleLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitDoubleLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -3985,7 +3992,8 @@ class BoolLiteral extends BasicLiteral {
BoolLiteral(this.value);
DartType getStaticType(TypeEnvironment types) => types.boolType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.boolLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitBoolLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -4007,7 +4015,8 @@ class SymbolLiteral extends Expression {
SymbolLiteral(this.value);
DartType getStaticType(TypeEnvironment types) => types.symbolType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.symbolLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitSymbolLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -4022,7 +4031,8 @@ class TypeLiteral extends Expression {
TypeLiteral(this.type);
DartType getStaticType(TypeEnvironment types) => types.typeType;
DartType getStaticType(TypeEnvironment types) =>
types.coreTypes.typeLegacyRawType;
R accept<R>(ExpressionVisitor<R> v) => v.visitTypeLiteral(this);
R accept1<R, A>(ExpressionVisitor1<R, A> v, A arg) =>
@ -4395,7 +4405,7 @@ class CheckLibraryIsLoaded extends Expression {
CheckLibraryIsLoaded(this.import);
DartType getStaticType(TypeEnvironment types) {
return types.objectType;
return types.coreTypes.objectLegacyRawType;
}
R accept<R>(ExpressionVisitor<R> v) => v.visitCheckLibraryIsLoaded(this);
@ -6190,7 +6200,7 @@ class BoolConstant extends PrimitiveConstant<bool> {
R accept<R>(ConstantVisitor<R> v) => v.visitBoolConstant(this);
R acceptReference<R>(Visitor<R> v) => v.visitBoolConstantReference(this);
DartType getType(TypeEnvironment types) => types.boolType;
DartType getType(TypeEnvironment types) => types.coreTypes.boolLegacyRawType;
}
/// An integer constant on a non-JS target.
@ -6201,7 +6211,7 @@ class IntConstant extends PrimitiveConstant<int> {
R accept<R>(ConstantVisitor<R> v) => v.visitIntConstant(this);
R acceptReference<R>(Visitor<R> v) => v.visitIntConstantReference(this);
DartType getType(TypeEnvironment types) => types.intType;
DartType getType(TypeEnvironment types) => types.coreTypes.intLegacyRawType;
}
/// A double constant on a non-JS target or any numeric constant on a JS target.
@ -6216,7 +6226,8 @@ class DoubleConstant extends PrimitiveConstant<double> {
bool operator ==(Object other) =>
other is DoubleConstant && identical(value, other.value);
DartType getType(TypeEnvironment types) => types.doubleType;
DartType getType(TypeEnvironment types) =>
types.coreTypes.doubleLegacyRawType;
}
class StringConstant extends PrimitiveConstant<String> {
@ -6228,7 +6239,8 @@ class StringConstant extends PrimitiveConstant<String> {
R accept<R>(ConstantVisitor<R> v) => v.visitStringConstant(this);
R acceptReference<R>(Visitor<R> v) => v.visitStringConstantReference(this);
DartType getType(TypeEnvironment types) => types.stringType;
DartType getType(TypeEnvironment types) =>
types.coreTypes.stringLegacyRawType;
}
class SymbolConstant extends Constant {
@ -6256,7 +6268,8 @@ class SymbolConstant extends Constant {
other.name == name &&
other.libraryReference == libraryReference);
DartType getType(TypeEnvironment types) => types.symbolType;
DartType getType(TypeEnvironment types) =>
types.coreTypes.symbolLegacyRawType;
}
class MapConstant extends Constant {
@ -6530,7 +6543,7 @@ class TypeLiteralConstant extends Constant {
return other is TypeLiteralConstant && other.type == type;
}
DartType getType(TypeEnvironment types) => types.typeType;
DartType getType(TypeEnvironment types) => types.coreTypes.typeLegacyRawType;
}
class UnevaluatedConstant extends Constant {

View file

@ -245,7 +245,7 @@ super method declares ${superParameter.type}
}
// Permit any invocation on Function type.
if (receiver == environment.rawFunctionType &&
if (receiver == environment.coreTypes.functionLegacyRawType &&
where is MethodInvocation &&
where.name.name == 'call') {
return;

View file

@ -399,7 +399,7 @@ DartType convertSuperBoundedToRegularBounded(
return const BottomType();
} else if ((type is BottomType || isNull(typeEnvironment, type)) &&
!isCovariant) {
return typeEnvironment.objectType;
return typeEnvironment.coreTypes.objectLegacyRawType;
} else if (type is InterfaceType && type.classNode.typeParameters != null) {
List<DartType> replacedTypeArguments =
new List<DartType>(type.typeArguments.length);
@ -449,7 +449,7 @@ DartType convertSuperBoundedToRegularBounded(
bool isObject(TypeEnvironment typeEnvironment, DartType type) {
return type is InterfaceType &&
type.classNode == typeEnvironment.objectType.classNode;
type.classNode == typeEnvironment.coreTypes.objectClass;
}
bool isNull(TypeEnvironment typeEnvironment, DartType type) {

View file

@ -406,13 +406,13 @@ class TypeCheckingVisitor
@override
DartType visitBoolLiteral(BoolLiteral node) {
return environment.boolType;
return environment.coreTypes.boolLegacyRawType;
}
@override
DartType visitConditionalExpression(ConditionalExpression node) {
node.condition =
checkAndDowncastExpression(node.condition, environment.boolType);
node.condition = checkAndDowncastExpression(
node.condition, environment.coreTypes.boolLegacyRawType);
node.then = checkAndDowncastExpression(node.then, node.staticType);
node.otherwise =
checkAndDowncastExpression(node.otherwise, node.staticType);
@ -452,7 +452,7 @@ class TypeCheckingVisitor
@override
DartType visitDoubleLiteral(DoubleLiteral node) {
return environment.doubleType;
return environment.coreTypes.doubleLegacyRawType;
}
@override
@ -463,7 +463,7 @@ class TypeCheckingVisitor
@override
DartType visitIntLiteral(IntLiteral node) {
return environment.intType;
return environment.coreTypes.intLegacyRawType;
}
@override
@ -474,7 +474,7 @@ class TypeCheckingVisitor
@override
DartType visitIsExpression(IsExpression node) {
visitExpression(node.operand);
return environment.boolType;
return environment.coreTypes.boolLegacyRawType;
}
@override
@ -529,9 +529,11 @@ class TypeCheckingVisitor
@override
DartType visitLogicalExpression(LogicalExpression node) {
node.left = checkAndDowncastExpression(node.left, environment.boolType);
node.right = checkAndDowncastExpression(node.right, environment.boolType);
return environment.boolType;
node.left = checkAndDowncastExpression(
node.left, environment.coreTypes.boolLegacyRawType);
node.right = checkAndDowncastExpression(
node.right, environment.coreTypes.boolLegacyRawType);
return environment.coreTypes.boolLegacyRawType;
}
@override
@ -595,7 +597,7 @@ class TypeCheckingVisitor
var receiver = visitExpression(node.receiver);
if (node.name.name == '==') {
visitExpression(node.arguments.positional.single);
return environment.boolType;
return environment.coreTypes.boolLegacyRawType;
}
if (node.name.name == 'call' && receiver is FunctionType) {
return handleFunctionCall(node, receiver, node.arguments);
@ -646,7 +648,7 @@ class TypeCheckingVisitor
@override
DartType visitNot(Not node) {
visitExpression(node.operand);
return environment.boolType;
return environment.coreTypes.boolLegacyRawType;
}
@override
@ -685,7 +687,7 @@ class TypeCheckingVisitor
@override
DartType visitStringConcatenation(StringConcatenation node) {
node.expressions.forEach(visitExpression);
return environment.stringType;
return environment.coreTypes.stringLegacyRawType;
}
@override
@ -737,7 +739,7 @@ class TypeCheckingVisitor
@override
DartType visitStringLiteral(StringLiteral node) {
return environment.stringType;
return environment.coreTypes.stringLegacyRawType;
}
@override
@ -780,7 +782,7 @@ class TypeCheckingVisitor
@override
DartType visitSymbolLiteral(SymbolLiteral node) {
return environment.symbolType;
return environment.coreTypes.symbolLegacyRawType;
}
@override
@ -796,7 +798,7 @@ class TypeCheckingVisitor
@override
DartType visitTypeLiteral(TypeLiteral node) {
return environment.typeType;
return environment.coreTypes.typeLegacyRawType;
}
@override
@ -818,7 +820,7 @@ class TypeCheckingVisitor
@override
DartType visitCheckLibraryIsLoaded(CheckLibraryIsLoaded node) {
return environment.objectType;
return environment.coreTypes.objectLegacyRawType;
}
@override
@ -853,8 +855,8 @@ class TypeCheckingVisitor
@override
visitDoStatement(DoStatement node) {
visitStatement(node.body);
node.condition =
checkAndDowncastExpression(node.condition, environment.boolType);
node.condition = checkAndDowncastExpression(
node.condition, environment.coreTypes.boolLegacyRawType);
}
@override
@ -918,8 +920,8 @@ class TypeCheckingVisitor
visitForStatement(ForStatement node) {
node.variables.forEach(visitVariableDeclaration);
if (node.condition != null) {
node.condition =
checkAndDowncastExpression(node.condition, environment.boolType);
node.condition = checkAndDowncastExpression(
node.condition, environment.coreTypes.boolLegacyRawType);
}
node.updates.forEach(visitExpression);
visitStatement(node.body);
@ -932,8 +934,8 @@ class TypeCheckingVisitor
@override
visitIfStatement(IfStatement node) {
node.condition =
checkAndDowncastExpression(node.condition, environment.boolType);
node.condition = checkAndDowncastExpression(
node.condition, environment.coreTypes.boolLegacyRawType);
visitStatement(node.then);
if (node.otherwise != null) {
visitStatement(node.otherwise);
@ -993,8 +995,8 @@ class TypeCheckingVisitor
@override
visitWhileStatement(WhileStatement node) {
node.condition =
checkAndDowncastExpression(node.condition, environment.boolType);
node.condition = checkAndDowncastExpression(
node.condition, environment.coreTypes.boolLegacyRawType);
visitStatement(node.body);
}

View file

@ -32,23 +32,14 @@ abstract class TypeEnvironment extends SubtypeTester {
return new HierarchyBasedTypeEnvironment(coreTypes, hierarchy);
}
// TODO(dmitryas): Remove these getters, use the appropriate member of
// CoreTypes at the call sites instead.
InterfaceType get objectType => coreTypes.objectLegacyRawType;
InterfaceType get nullType => coreTypes.nullType;
InterfaceType get boolType => coreTypes.boolLegacyRawType;
InterfaceType get intType => coreTypes.intLegacyRawType;
InterfaceType get numType => coreTypes.numLegacyRawType;
InterfaceType get doubleType => coreTypes.doubleLegacyRawType;
InterfaceType get stringType => coreTypes.stringLegacyRawType;
InterfaceType get symbolType => coreTypes.symbolLegacyRawType;
InterfaceType get typeType => coreTypes.typeLegacyRawType;
InterfaceType get rawFunctionType => coreTypes.functionLegacyRawType;
Class get intClass => coreTypes.intClass;
Class get numClass => coreTypes.numClass;
Class get futureOrClass => coreTypes.futureOrClass;
InterfaceType get objectLegacyRawType => coreTypes.objectLegacyRawType;
InterfaceType get nullType => coreTypes.nullType;
InterfaceType get functionLegacyRawType => coreTypes.functionLegacyRawType;
InterfaceType literalListType(DartType elementType) {
return new InterfaceType(coreTypes.listClass, <DartType>[elementType]);
}
@ -144,8 +135,10 @@ abstract class TypeEnvironment extends SubtypeTester {
/// Otherwise `num` is returned.
DartType getTypeOfOverloadedArithmetic(DartType type1, DartType type2) {
if (type1 == type2) return type1;
if (type1 == doubleType || type2 == doubleType) return doubleType;
return numType;
if (type1 == coreTypes.doubleLegacyRawType ||
type2 == coreTypes.doubleLegacyRawType)
return coreTypes.doubleLegacyRawType;
return coreTypes.numLegacyRawType;
}
}
@ -153,9 +146,9 @@ abstract class TypeEnvironment extends SubtypeTester {
///
/// This lives in a separate class so it can be tested independently of the SDK.
abstract class SubtypeTester {
InterfaceType get objectType;
InterfaceType get objectLegacyRawType;
InterfaceType get nullType;
InterfaceType get rawFunctionType;
InterfaceType get functionLegacyRawType;
Class get futureOrClass;
InterfaceType futureType(DartType type);
@ -165,8 +158,11 @@ abstract class SubtypeTester {
/// Determines if the given type is at the top of the type hierarchy. May be
/// overridden in subclasses.
bool isTop(DartType type) =>
type is DynamicType || type is VoidType || type == objectType;
bool isTop(DartType type) {
return type is DynamicType ||
type is VoidType ||
type == objectLegacyRawType;
}
/// Can be use to collect type checks. To use:
/// 1. Rename `isSubtypeOf` to `_isSubtypeOf`.
@ -251,7 +247,7 @@ abstract class SubtypeTester {
return isSubtypeOf(subtype.bound, supertype);
}
if (subtype is FunctionType) {
if (supertype == rawFunctionType) return true;
if (supertype == functionLegacyRawType) return true;
if (supertype is FunctionType) {
return _isFunctionSubtypeOf(subtype, supertype);
}

View file

@ -2125,7 +2125,8 @@ class BytecodeGenerator extends RecursiveVisitor<Null> {
asm.emitPushConstant(cp.addType(type));
_genPushInstantiatorAndFunctionTypeArguments([type]);
asm.emitPushConstant(cp.addString(name));
bool isIntOk = typeEnvironment.isSubtypeOf(typeEnvironment.intType, type);
bool isIntOk = typeEnvironment.isSubtypeOf(
typeEnvironment.coreTypes.intLegacyRawType, type);
int subtypeTestCacheCpIndex = cp.addSubtypeTestCache();
asm.emitAssertAssignable(isIntOk ? 1 : 0, subtypeTestCacheCpIndex);
}

View file

@ -47,9 +47,9 @@ class RecognizedMethods {
DartType staticType(Expression expr) => getStaticType(expr, typeEnv);
bool isInt(DartType type) => type == typeEnv.intType;
bool isInt(DartType type) => type == typeEnv.coreTypes.intLegacyRawType;
bool isDouble(DartType type) => type == typeEnv.doubleType;
bool isDouble(DartType type) => type == typeEnv.coreTypes.doubleLegacyRawType;
Opcode specializedBytecodeFor(MethodInvocation node) {
final args = node.arguments;

View file

@ -1093,10 +1093,10 @@ class _ClassHierarchyCache implements TypeHierarchy {
// TODO(alexmarkov): handle function types properly
if (subType is FunctionType) {
subType = _typeFlowAnalysis.environment.rawFunctionType;
subType = _typeFlowAnalysis.environment.functionLegacyRawType;
}
if (superType is FunctionType) {
superType = _typeFlowAnalysis.environment.rawFunctionType;
superType = _typeFlowAnalysis.environment.functionLegacyRawType;
}
// TODO(alexmarkov): handle generic types properly.
assertx(subType is! TypeParameterType);
@ -1140,7 +1140,7 @@ class _ClassHierarchyCache implements TypeHierarchy {
// TODO(alexmarkov): handle function types properly
if (base is FunctionType) {
base = _typeFlowAnalysis.environment.rawFunctionType;
base = _typeFlowAnalysis.environment.functionLegacyRawType;
}
if (base is TypeParameterType) {
@ -1156,7 +1156,7 @@ class _ClassHierarchyCache implements TypeHierarchy {
// subtypes is too large
if (base == const DynamicType() ||
base == _typeFlowAnalysis.environment.objectType ||
base == _typeFlowAnalysis.environment.coreTypes.objectLegacyRawType ||
// TODO(alexmarkov): handle FutureOr more precisely (requires generics).
baseClass == _typeFlowAnalysis.environment.futureOrClass) {
return const AnyType();

View file

@ -710,23 +710,24 @@ class SummaryCollector extends RecursiveVisitor<TypeExpr> {
new Type.fromStatic(_staticDartType(node));
Type _cachedBoolType;
Type get _boolType =>
_cachedBoolType ??= new Type.cone(_environment.boolType);
Type get _boolType => _cachedBoolType ??=
new Type.cone(_environment.coreTypes.boolLegacyRawType);
Type _cachedDoubleType;
Type get _doubleType =>
_cachedDoubleType ??= new Type.cone(_environment.doubleType);
Type get _doubleType => _cachedDoubleType ??=
new Type.cone(_environment.coreTypes.doubleLegacyRawType);
Type _cachedIntType;
Type get _intType => _cachedIntType ??= new Type.cone(_environment.intType);
Type get _intType =>
_cachedIntType ??= new Type.cone(_environment.coreTypes.intLegacyRawType);
Type _cachedStringType;
Type get _stringType =>
_cachedStringType ??= new Type.cone(_environment.stringType);
Type get _stringType => _cachedStringType ??=
new Type.cone(_environment.coreTypes.stringLegacyRawType);
Type _cachedSymbolType;
Type get _symbolType =>
_cachedSymbolType ??= new Type.cone(_environment.symbolType);
Type get _symbolType => _cachedSymbolType ??=
new Type.cone(_environment.coreTypes.symbolLegacyRawType);
Type _cachedNullType;
Type get _nullType => _cachedNullType ??= new Type.nullable(new Type.empty());
@ -968,7 +969,7 @@ class SummaryCollector extends RecursiveVisitor<TypeExpr> {
if (node.name.name == 'call') {
final recvType = _staticDartType(node.receiver);
if ((recvType is FunctionType) ||
(recvType == _environment.rawFunctionType)) {
(recvType == _environment.functionLegacyRawType)) {
// Call to a Function.
return _staticType(node);
}
@ -1192,7 +1193,7 @@ class SummaryCollector extends RecursiveVisitor<TypeExpr> {
@override
TypeExpr visitTypeLiteral(TypeLiteral node) {
return new Type.cone(_environment.typeType);
return new Type.cone(_environment.coreTypes.typeLegacyRawType);
}
@override

View file

@ -130,7 +130,7 @@ class AnnotateKernel extends RecursiveVisitor<Null> {
_unreachableNodeMetadata = new UnreachableNodeMetadataRepository(),
_procedureAttributesMetadata =
new ProcedureAttributesMetadataRepository(),
_intType = _typeFlowAnalysis.environment.intType {
_intType = _typeFlowAnalysis.environment.coreTypes.intLegacyRawType {
component.addMetadataRepository(_inferredTypeMetadata);
component.addMetadataRepository(_unreachableNodeMetadata);
component.addMetadataRepository(_procedureAttributesMetadata);