Remove type inferrer from generators

The type inferrer is no longer used (and wasn't necessary to begin
with, it should have been exposed via the helper object instead).

Also some other tweaks that should help me avoid merge conflicts.

Change-Id: I1f2aade93f9c836cc02dac6c002f48156caf2c76
Reviewed-on: https://dart-review.googlesource.com/74063
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Peter von der Ahé <ahe@google.com>
This commit is contained in:
Peter von der Ahé
2018-09-10 09:05:59 +00:00
committed by commit-bot@chromium.org
parent c42bde5eac
commit e1fe4d48a5
7 changed files with 43 additions and 76 deletions
@@ -2285,8 +2285,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
}
}
if (name is Generator) {
push(name.buildTypeWithBuiltArguments(arguments,
typeInferrer: _typeInferrer));
push(name.buildTypeWithBuiltArguments(arguments));
} else if (name is TypeBuilder) {
push(name.build(library));
} else {
@@ -2898,7 +2897,7 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
LocatedMessage argMessage = checkArgumentsForFunction(
target.function, arguments, charOffset, typeParameters);
if (argMessage != null) {
var error = throwNoSuchMethodError(
Expression error = throwNoSuchMethodError(
forest.literalNull(null)..fileOffset = charOffset,
target.name.name,
arguments,
@@ -3598,13 +3597,12 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
@override
void endRethrowStatement(Token rethrowToken, Token endToken) {
debugEvent("RethrowStatement");
var error = inCatchBlock
push(new ExpressionStatementJudgment(new RethrowJudgment(inCatchBlock
? null
: buildProblem(fasta.messageRethrowNotCatch,
offsetForToken(rethrowToken), lengthForToken(rethrowToken))
.desugared;
push(new ExpressionStatementJudgment(
new RethrowJudgment(error)..fileOffset = offsetForToken(rethrowToken)));
.desugared)
..fileOffset = offsetForToken(rethrowToken)));
}
@override
@@ -45,8 +45,6 @@ import '../parser.dart' show lengthForToken, lengthOfSpan, offsetForToken;
import '../problems.dart' show unhandled, unsupported;
import '../type_inference/type_inferrer.dart' show TypeInferrer;
import 'constness.dart' show Constness;
import 'expression_generator_helper.dart' show ExpressionGeneratorHelper;
@@ -82,12 +80,9 @@ import 'kernel_ast_api.dart'
import 'kernel_builder.dart'
show
AccessErrorBuilder,
BuiltinTypeBuilder,
Declaration,
FunctionTypeAliasBuilder,
KernelClassBuilder,
KernelFunctionTypeAliasBuilder,
KernelTypeVariableBuilder;
KernelFunctionTypeAliasBuilder;
import 'kernel_expression_generator.dart'
show IncompleteSendGenerator, SendAccessGenerator;
@@ -220,7 +215,7 @@ abstract class Generator implements ExpressionGenerator {
}
DartType buildTypeWithBuiltArguments(List<DartType> arguments,
{bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
{bool nonInstanceAccessIsError: false}) {
helper.addProblem(templateNotAType.withArguments(token.lexeme),
offsetForToken(token), lengthForToken(token));
return const InvalidType();
@@ -241,13 +236,14 @@ abstract class Generator implements ExpressionGenerator {
assert(forest.argumentsTypeArguments(arguments).isEmpty);
forest.argumentsSetTypeArguments(arguments, typeArguments);
}
var error = helper.throwNoSuchMethodError(
forest.literalNull(token),
name == "" ? plainNameForRead : "${plainNameForRead}.$name",
arguments,
nameToken.charOffset);
return new InvalidConstructorInvocationJudgment(error, null, arguments);
return new InvalidConstructorInvocationJudgment(
helper.throwNoSuchMethodError(
forest.literalNull(token),
name == "" ? plainNameForRead : "${plainNameForRead}.$name",
arguments,
nameToken.charOffset),
null,
arguments);
}
bool get isThisPropertyAccess => false;
@@ -495,7 +491,7 @@ abstract class DeferredAccessGenerator implements Generator {
@override
buildPropertyAccess(
IncompleteSendGenerator send, int operatorOffset, bool isNullAware) {
var propertyAccess =
Object propertyAccess =
suffixGenerator.buildPropertyAccess(send, operatorOffset, isNullAware);
if (propertyAccess is Generator) {
return new DeferredAccessGenerator(
@@ -518,12 +514,11 @@ abstract class DeferredAccessGenerator implements Generator {
@override
DartType buildTypeWithBuiltArguments(List<DartType> arguments,
{bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
{bool nonInstanceAccessIsError: false}) {
helper.addProblem(
templateDeferredTypeAnnotation.withArguments(
suffixGenerator.buildTypeWithBuiltArguments(arguments,
nonInstanceAccessIsError: nonInstanceAccessIsError,
typeInferrer: typeInferrer),
nonInstanceAccessIsError: nonInstanceAccessIsError),
prefixGenerator.plainNameForRead),
offsetForToken(prefixGenerator.token),
lengthOfSpan(prefixGenerator.token, token));
@@ -576,23 +571,9 @@ abstract class TypeUseGenerator implements Generator {
@override
DartType buildTypeWithBuiltArguments(List<DartType> arguments,
{bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
var declaration = this.declaration;
{bool nonInstanceAccessIsError: false}) {
if (arguments != null) {
int expected = 0;
if (declaration is KernelClassBuilder) {
expected = declaration.target.typeParameters.length;
} else if (declaration is FunctionTypeAliasBuilder) {
expected = declaration.target.typeParameters.length;
} else if (declaration is KernelTypeVariableBuilder) {
// Type arguments on a type variable - error reported elsewhere.
} else if (declaration is BuiltinTypeBuilder) {
// Type arguments on a built-in type, for example, dynamic or void.
expected = 0;
} else {
return unhandled("${declaration.runtimeType}",
"TypeUseGenerator.buildType", offsetForToken(token), helper.uri);
}
int expected = declaration.typeVariablesCount;
if (arguments.length != expected) {
helper.warnTypeArgumentsMismatch(
declaration.name, expected, offsetForToken(token));
@@ -1087,12 +1068,12 @@ abstract class PrefixUseGenerator implements Generator {
@override
/* Expression | Generator | Initializer */ doInvocation(
int offset, Arguments arguments) {
var error = helper.wrapInLocatedProblem(
helper.evaluateArgumentsBefore(arguments, forest.literalNull(token)),
messageCantUsePrefixAsExpression.withLocation(
helper.uri, offsetForToken(token), lengthForToken(token)));
return new StaticInvocationJudgment(null, forest.castArguments(arguments),
desugaredError: error)
desugaredError: helper.wrapInLocatedProblem(
helper.evaluateArgumentsBefore(
arguments, forest.literalNull(token)),
messageCantUsePrefixAsExpression.withLocation(
helper.uri, offsetForToken(token), lengthForToken(token))))
..fileOffset = offset;
}
@@ -1172,7 +1153,7 @@ abstract class UnexpectedQualifiedUseGenerator implements Generator {
@override
DartType buildTypeWithBuiltArguments(List<DartType> arguments,
{bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
{bool nonInstanceAccessIsError: false}) {
Template<Message Function(String, String)> template = isUnresolved
? templateUnresolvedPrefixInTypeAnnotation
: templateNotAPrefixInTypeAnnotation;
@@ -301,7 +301,7 @@ abstract class KernelClassBuilder
declaration.setRedirectingFactoryBody(
targetBuilder.member, typeArguments);
} else {
var message = templateRedirectionTargetNotFound
Message message = templateRedirectionTargetNotFound
.withArguments(redirectionTarget.fullNameForErrors);
if (declaration.isConst) {
addProblem(message, declaration.charOffset, noLength);
@@ -794,7 +794,8 @@ abstract class KernelClassBuilder
]);
} else if (library.loader.target.backendTarget.strongMode &&
declaredFunction?.typeParameters != null) {
var substitutionMap = <TypeParameter, DartType>{};
Map<TypeParameter, DartType> substitutionMap =
<TypeParameter, DartType>{};
for (int i = 0; i < declaredFunction.typeParameters.length; ++i) {
substitutionMap[interfaceFunction.typeParameters[i]] =
new TypeParameterType(declaredFunction.typeParameters[i]);
@@ -862,7 +863,9 @@ abstract class KernelClassBuilder
// a type which is a subtype of the parameter it overrides.
} else {
// Report an error.
var declaredMemberName = '$name::${declaredMember.name.name}';
// TODO(ahe): The double-colon notation shouldn't be used in error
// messages.
String declaredMemberName = '$name::${declaredMember.name.name}';
Message message;
int fileOffset;
if (declaredParameter == null) {
@@ -31,8 +31,6 @@ import '../parser.dart' show lengthForToken, offsetForToken;
import '../problems.dart' show unhandled, unsupported;
import '../type_inference/type_inferrer.dart' show TypeInferrer;
import 'body_builder.dart' show noLocation;
import 'constness.dart' show Constness;
@@ -1122,14 +1120,6 @@ class KernelStaticAccessGenerator extends KernelGenerator
return write;
}
@override
DartType buildTypeWithBuiltArguments(List<DartType> arguments,
{bool nonInstanceAccessIsError: false, TypeInferrer typeInferrer}) {
return super.buildTypeWithBuiltArguments(arguments,
nonInstanceAccessIsError: nonInstanceAccessIsError,
typeInferrer: typeInferrer);
}
@override
Expression doInvocation(int offset, Arguments arguments) {
Expression error;
@@ -1581,8 +1581,7 @@ class ListLiteralJudgment extends ListLiteral implements ExpressionJudgment {
isVoidAllowed: typeArgument is VoidType);
}
}
var inferredType = new InterfaceType(listClass, [inferredTypeArgument]);
this.inferredType = inferredType;
inferredType = new InterfaceType(listClass, [inferredTypeArgument]);
return null;
}
}
@@ -2217,8 +2216,7 @@ class StaticInvocationJudgment extends StaticInvocation
: new FunctionType([], const DynamicType());
var inferenceResult = inferrer.inferInvocation(typeContext, fileOffset,
calleeType, calleeType.returnType, argumentJudgments);
var inferredType = inferenceResult.type;
this.inferredType = inferredType;
inferredType = inferenceResult.type;
if (desugaredError != null) {
parent.replaceChild(this, desugaredError);
parent = null;
@@ -2422,6 +2420,7 @@ class SymbolLiteralJudgment extends SymbolLiteral
/// Synthetic judgment class representing an attempt to invoke an unresolved
/// constructor, or a constructor that cannot be invoked, or a resolved
/// constructor with wrong number of arguments.
// TODO(ahe): Remove this?
class InvalidConstructorInvocationJudgment extends SyntheticExpressionJudgment {
final Member constructor;
final Arguments arguments;
@@ -7,8 +7,6 @@ library fasta.kernel_type_variable_builder;
import 'package:kernel/ast.dart'
show DartType, TypeParameter, TypeParameterType;
import '../deprecated_problems.dart' show deprecated_inputError;
import '../fasta_codes.dart' show templateTypeArgumentsOnTypeVariable;
import 'kernel_builder.dart'
@@ -66,11 +64,15 @@ class KernelTypeVariableBuilder
DartType buildTypesWithBuiltArguments(
LibraryBuilder library, List<DartType> arguments) {
if (arguments != null) {
return deprecated_inputError(null, null,
"Can't use type arguments with type parameter $parameter");
} else {
return buildType(library, null);
int charOffset = -1; // TODO(ahe): Provide these.
Uri fileUri = null; // TODO(ahe): Provide these.
library.addProblem(
templateTypeArgumentsOnTypeVariable.withArguments(name),
charOffset,
name.length,
fileUri);
}
return buildType(library, null);
}
KernelTypeBuilder asTypeBuilder() {
@@ -43,18 +43,12 @@ Severity rewriteSeverity(
// sites.
switch (path.substring(fastaPath.length + index)) {
case "command_line.dart":
case "command_line_reporting.dart":
case "deprecated_problems.dart":
case "entry_points.dart":
case "kernel/body_builder.dart":
case "kernel/expression_generator.dart":
case "kernel/kernel_expression_generator.dart":
case "kernel/kernel_expression_generator_impl.dart":
case "kernel/kernel_type_variable_builder.dart":
case "source/diet_listener.dart":
case "source/source_library_builder.dart":
case "source/source_loader.dart":
case "source/stack_listener.dart":
return severity;
}
} else if (code == msg.codeMissingExplicitTypeArguments) {