Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart

Issue 14969040: Add a new flag to dart2js: --trust-type-annotations and implement it in the types inferrer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (revision 22848)
+++ sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (working copy)
@@ -113,12 +113,12 @@
throw 'Unsupported operation';
}
- bool get isNullable => true;
-
TypeMask intersection(TypeMask other, Compiler compiler) {
return other;
}
+ bool get isNullable => true;
+
String toString() => '$name sentinel type mask';
}
@@ -653,6 +653,18 @@
bool internalRecordType(Element analyzedElement,
TypeMask newType,
Map<Element, TypeMask> types) {
+ if (compiler.trustTypeAnnotations
+ // Parameters are being checked by the method, and we can
+ // therefore only trust their type after the checks.
+ || (compiler.enableTypeAssertions && !analyzedElement.isParameter())) {
+ var annotation = analyzedElement.computeType(compiler);
+ if (types == returnTypeOf) {
+ assert(annotation is FunctionType);
+ annotation = annotation.returnType;
+ }
+ newType = narrowType(newType, annotation);
+ }
+
// Fields and native methods of native classes are handled
// specially when querying for their type or return type.
if (isNativeElement(analyzedElement)) return false;
@@ -688,7 +700,15 @@
}
TypeMask returnType = returnTypeOf[element];
if (returnType == null) {
- return dynamicType;
+ if ((compiler.trustTypeAnnotations || compiler.enableTypeAssertions)
+ && (element.isFunction()
+ || element.isGetter()
+ || element.isFactoryConstructor())) {
+ returnType = narrowType(
+ dynamicType, element.computeType(compiler).returnType);
+ } else {
+ returnType = dynamicType;
+ }
}
assert(returnType != null);
return returnType;
@@ -753,7 +773,18 @@
}
TypeMask type = typeOf[element];
if (type == null) {
- return dynamicType;
+ if ((compiler.trustTypeAnnotations
+ && (element.isField()
+ || element.isParameter()
+ || element.isVariable()))
+ // Parameters are being checked by the method, and we can
+ // therefore only trust their type after the checks.
+ || (compiler.enableTypeAssertions
+ && (element.isField() || element.isVariable()))) {
+ type = narrowType(dynamicType, element.computeType(compiler));
+ } else {
+ type = dynamicType;
+ }
}
assert(type != null);
return type;
@@ -1254,6 +1285,7 @@
{bool isNullable: true}) {
if (annotation.isDynamic) return type;
if (annotation.isMalformed) return type;
+ if (annotation.isVoid) return nullType;
if (annotation.element == compiler.objectClass) return type;
TypeMask otherType;
if (annotation.kind == TypeKind.TYPEDEF
@@ -1338,6 +1370,10 @@
void update(Element local, TypeMask type) {
assert(type != null);
+ if (inferrer.compiler.trustTypeAnnotations
+ || inferrer.compiler.enableTypeAssertions) {
+ type = inferrer.narrowType(type, local.computeType(inferrer.compiler));
+ }
if (capturedAndBoxed.contains(local) || inTryBlock) {
// If a local is captured and boxed, or is set in a try block,
// we compute the LUB of its assignments.
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698