Handle fields with initializers in kernel_impact

- and use Feature.TYPE_VARIABLE_BOUNDS_CHECK only for new-expressions.

R=het@google.com

Review URL: https://codereview.chromium.org/2366263004 .
This commit is contained in:
Johnni Winther 2016-09-30 09:50:53 +02:00
parent 2e80071cfe
commit 93d7c65cc9
6 changed files with 36 additions and 4 deletions

View file

@ -3665,6 +3665,9 @@ class ResolverVisitor extends MappingVisitor<ResolutionResult> {
// TODO(johnniwinther): Handle this (potentially) erroneous case.
isValidAsConstant = false;
}
if (type.typeArguments.any((DartType type) => !type.isDynamic)) {
registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK);
}
redirectionTarget.computeType(resolution);
FunctionSignature targetSignature = redirectionTarget.functionSignature;
@ -3887,6 +3890,10 @@ class ResolverVisitor extends MappingVisitor<ResolutionResult> {
// TODO(johniwinther): Avoid registration of `type` in face of redirecting
// factory constructors.
registry.registerTypeUse(new TypeUse.instantiation(type));
InterfaceType interfaceType = type;
if (interfaceType.typeArguments.any((DartType type) => !type.isDynamic)) {
registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK);
}
}
ResolutionResult resolutionResult = const NoneResult();

View file

@ -430,16 +430,18 @@ class ResolverTask extends CompilerTask {
}
DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) {
DartType type = resolveReturnType(element, annotation);
DartType type = _resolveReturnType(element, annotation);
if (type.isVoid) {
reporter.reportErrorMessage(annotation, MessageKind.VOID_NOT_ALLOWED);
}
return type;
}
DartType resolveReturnType(Element element, TypeAnnotation annotation) {
DartType _resolveReturnType(Element element, TypeAnnotation annotation) {
if (annotation == null) return const DynamicType();
DartType result = visitorFor(element).resolveTypeAnnotation(annotation);
assert(invariant(annotation, result != null,
message: "No type computed for $annotation."));
if (result == null) {
// TODO(karklose): warning.
return const DynamicType();

View file

@ -222,7 +222,6 @@ class TypeResolver {
node, "Unexpected element kind ${element.kind}.");
}
if (addTypeVariableBoundsCheck) {
registry.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK);
visitor.addDeferredAction(visitor.enclosingElement,
() => checkTypeVariableBounds(node, type));
}

View file

@ -3738,7 +3738,7 @@ class SsaBuilder extends ast.Visitor
new Map<DartType, Set<DartType>>();
bool definitelyFails = false;
addTypeVariableBoundCheck(GenericType instance, DartType typeArgument,
void addTypeVariableBoundCheck(GenericType instance, DartType typeArgument,
TypeVariableType typeVariable, DartType bound) {
if (definitelyFails) return;

View file

@ -83,6 +83,9 @@ class KernelImpactBuilder extends ir.Visitor {
checkType(field.type);
if (field.initializer != null) {
visitNode(field.initializer);
if (!field.isConst) {
impactBuilder.registerFeature(Feature.LAZY_FIELD);
}
} else {
impactBuilder.registerFeature(Feature.FIELD_WITHOUT_INITIALIZER);
}

View file

@ -17,6 +17,7 @@ import 'package:compiler/src/ssa/kernel_impact.dart';
import 'package:compiler/src/serialization/equivalence.dart';
import 'package:compiler/src/universe/feature.dart';
import 'package:compiler/src/universe/use.dart';
import 'package:expect/expect.dart';
import '../memory_compiler.dart';
import '../serialization/test_helper.dart';
@ -60,7 +61,13 @@ main() {
testTopLevelFunctionTyped();
testTopLevelFunctionGet();
testTopLevelField();
testTopLevelFieldLazy();
testTopLevelFieldConst();
testTopLevelFieldFinal();
testTopLevelFieldTyped();
testTopLevelFieldGeneric1();
testTopLevelFieldGeneric2();
testTopLevelFieldGeneric3();
testDynamicInvoke(null);
testDynamicGet(null);
testDynamicSet(null);
@ -173,8 +180,21 @@ testTopLevelFunctionGet() => topLevelFunction1;
var topLevelField;
testTopLevelField() => topLevelField;
var topLevelFieldLazy = topLevelFunction1(null);
testTopLevelFieldLazy() => topLevelFieldLazy;
const topLevelFieldConst = 0;
testTopLevelFieldConst() => topLevelFieldConst;
final topLevelFieldFinal = topLevelFunction1(null);
testTopLevelFieldFinal() => topLevelFieldFinal;
int topLevelFieldTyped;
testTopLevelFieldTyped() => topLevelFieldTyped;
GenericClass topLevelFieldGeneric1;
testTopLevelFieldGeneric1() => topLevelFieldGeneric1;
GenericClass<dynamic, dynamic> topLevelFieldGeneric2;
testTopLevelFieldGeneric2() => topLevelFieldGeneric2;
GenericClass<int, String> topLevelFieldGeneric3;
testTopLevelFieldGeneric3() => topLevelFieldGeneric3;
testDynamicInvoke(o) {
o.f1(0);
o.f2(1);
@ -296,6 +316,7 @@ void checkElement(Compiler compiler, AstElement element) {
ResolutionImpact astImpact = compiler.resolution.getResolutionImpact(element);
astImpact = laxImpact(element, astImpact);
ResolutionImpact kernelImpact = build(compiler, element.resolvedAst);
Expect.isNotNull(kernelImpact, 'No impact computed for $element');
testResolutionImpactEquivalence(
astImpact, kernelImpact, const CheckStrategy());
}