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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1408783004: dart2js cps: Support --trust-primitives and --trust-type-annotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge Created 5 years, 2 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 | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_tracer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index 9f2ad07848b1c694769e936095049a85586fa190..6d8676e59209d3c0aad37acbca8e06d06c05d295 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -53,6 +53,8 @@ import '../util/util.dart';
import 'package:js_runtime/shared/embedded_names.dart'
show JsBuiltin, JsGetName;
import '../constants/values.dart';
+import 'type_mask_system.dart' show
+ TypeMaskSystem;
typedef void IrBuilderCallback(Element element, ir.FunctionDefinition irNode);
@@ -76,7 +78,8 @@ class IrBuilderTask extends CompilerTask {
String get name => 'CPS builder';
- ir.FunctionDefinition buildNode(AstElement element) {
+ ir.FunctionDefinition buildNode(AstElement element,
+ TypeMaskSystem typeMaskSystem) {
return measure(() {
bailoutMessage = null;
@@ -88,7 +91,8 @@ class IrBuilderTask extends CompilerTask {
IrBuilderVisitor builder =
new JsIrBuilderVisitor(
- elementsMapping, compiler, sourceInformationBuilder);
+ elementsMapping, compiler, sourceInformationBuilder,
+ typeMaskSystem);
ir.FunctionDefinition irNode = builder.buildExecutable(element);
if (irNode == null) {
bailoutMessage = builder.bailoutMessage;
@@ -127,6 +131,7 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
final TreeElements elements;
final Compiler compiler;
final SourceInformationBuilder sourceInformationBuilder;
+ final TypeMaskSystem typeMaskSystem;
/// A map from try statements in the source to analysis information about
/// them.
@@ -157,7 +162,8 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
/// Construct a top-level visitor.
IrBuilderVisitor(this.elements,
this.compiler,
- this.sourceInformationBuilder);
+ this.sourceInformationBuilder,
+ this.typeMaskSystem);
DiagnosticReporter get reporter => compiler.reporter;
@@ -409,6 +415,21 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
closureScope: getClosureScopeForNode(node));
}
+ /// If compiling with trusted type annotations, assumes that [value] is
+ /// now known to be `null` or an instance of [type].
+ ///
+ /// This is also where we should add type checks in checked mode, but this
+ /// is not supported yet.
+ ir.Primitive checkType(ir.Primitive value, DartType dartType) {
+ if (!compiler.trustTypeAnnotations) return value;
+ TypeMask type = typeMaskSystem.subtypesOf(dartType).nullable();
+ return irBuilder.buildRefinement(value, type);
+ }
+
+ ir.Primitive checkTypeVsElement(ir.Primitive value, TypedElement element) {
+ return checkType(value, element.type);
+ }
+
ir.Primitive visitVariableDefinitions(ast.VariableDefinitions node) {
assert(irBuilder.isOpen);
for (ast.Node definition in node.definitions.nodes) {
@@ -420,6 +441,7 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
assert(!definition.arguments.isEmpty);
assert(definition.arguments.tail.isEmpty);
initialValue = visit(definition.arguments.head);
+ initialValue = checkTypeVsElement(initialValue, element);
} else {
assert(definition is ast.Identifier);
}
@@ -1402,7 +1424,9 @@ abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
LocalElement element,
ast.Node rhs,
_) {
- return irBuilder.buildLocalVariableSet(element, visit(rhs));
+ ir.Primitive value = visit(rhs);
+ value = checkTypeVsElement(value, element);
+ return irBuilder.buildLocalVariableSet(element, value);
}
@override
@@ -2530,8 +2554,9 @@ class JsIrBuilderVisitor extends IrBuilderVisitor {
JsIrBuilderVisitor(TreeElements elements,
Compiler compiler,
- SourceInformationBuilder sourceInformationBuilder)
- : super(elements, compiler, sourceInformationBuilder);
+ SourceInformationBuilder sourceInformationBuilder,
+ TypeMaskSystem typeMaskSystem)
+ : super(elements, compiler, sourceInformationBuilder, typeMaskSystem);
/// Builds the IR for creating an instance of the closure class corresponding
@@ -2684,7 +2709,8 @@ class JsIrBuilderVisitor extends IrBuilderVisitor {
return new JsIrBuilderVisitor(
context.resolvedAst.elements,
compiler,
- sourceInformationBuilder.forContext(context));
+ sourceInformationBuilder.forContext(context),
+ typeMaskSystem);
}
/// Builds the IR for an [expression] taken from a different [context].
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698