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

Unified Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2479323003: Adding check or trust type checks to builder_kernel.dart. (Closed)
Patch Set: . Created 4 years, 1 month 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
Index: pkg/compiler/lib/src/ssa/builder_kernel.dart
diff --git a/pkg/compiler/lib/src/ssa/builder_kernel.dart b/pkg/compiler/lib/src/ssa/builder_kernel.dart
index 6183f3f0d4b94b20eba12d886b0df92944d3b88a..c90ab776f47acb7c2445b6e805fa6379f25776db 100644
--- a/pkg/compiler/lib/src/ssa/builder_kernel.dart
+++ b/pkg/compiler/lib/src/ssa/builder_kernel.dart
@@ -17,7 +17,9 @@ import '../kernel/kernel.dart';
import '../resolution/tree_elements.dart';
import '../tree/dartstring.dart';
import '../types/masks.dart';
+import '../universe/call_structure.dart' show CallStructure;
import '../universe/selector.dart';
+import '../universe/use.dart' show TypeUse;
import 'graph_builder.dart';
import 'kernel_ast_adapter.dart';
import 'kernel_string_builder.dart';
@@ -25,6 +27,7 @@ import 'locals_handler.dart';
import 'loop_handler.dart';
import 'nodes.dart';
import 'ssa_branch_builder.dart';
+import 'type_builder.dart';
class SsaKernelBuilderTask extends CompilerTask {
final JavaScriptBackend backend;
@@ -62,6 +65,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
SourceInformationBuilder sourceInformationBuilder;
KernelAstAdapter astAdapter;
LoopHandler<ir.Node> loopHandler;
+ TypeBuilder typeBuilder;
KernelSsaBuilder(
this.targetElement,
@@ -72,6 +76,7 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
Kernel kernel) {
this.compiler = compiler;
this.loopHandler = new KernelLoopHandler(this);
+ typeBuilder = new TypeBuilder(this);
graph.element = targetElement;
// TODO(het): Should sourceInformationBuilder be in GraphBuilder?
this.sourceInformationBuilder =
@@ -118,10 +123,17 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
closeFunction();
}
+ /// Pops the most recent instruction from the stack and 'boolifies' it.
+ ///
+ /// Boolification is checking if the value is '=== true'.
@override
HInstruction popBoolified() {
HInstruction value = pop();
- // TODO(het): add boolean conversion type check
+ if (typeBuilder.checkOrTrustTypes) {
+ return typeBuilder.potentiallyCheckOrTrustType(
+ value, compiler.coreTypes.boolType,
+ kind: HTypeConversion.BOOLEAN_CONVERSION_CHECK);
+ }
HInstruction result = new HBoolify(value, backend.boolType);
add(result);
return result;
@@ -137,6 +149,22 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
graph.finalize();
}
+ HTypeConversion buildFunctionTypeConversion(
+ HInstruction original, DartType type, int kind) {
+ String name =
+ kind == HTypeConversion.CAST_TYPE_CHECK ? '_asCheck' : '_assertCheck';
+
+ List<HInstruction> arguments = <HInstruction>[
+ buildFunctionType(type),
+ original
+ ];
+ _pushDynamicInvocation(null, null, arguments,
+ selector: new Selector.call(
+ new Name(name, astAdapter.jsHelperLibrary), CallStructure.ONE_ARG));
+
+ return new HTypeConversion(type, kind, original.instructionType, pop());
+ }
+
/// Builds a SSA graph for [procedure].
void buildProcedure(ir.Procedure procedure) {
openFunction();
@@ -158,12 +186,24 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
graph.finalize();
}
+ /// Pushes a boolean checking [expression] against null.
+ pushCheckNull(HInstruction expression) {
+ push(new HIdentity(
+ expression, graph.addConstantNull(compiler), null, backend.boolType));
+ }
+
@override
void defaultExpression(ir.Expression expression) {
// TODO(het): This is only to get tests working
stack.add(graph.addConstantNull(compiler));
}
+ /// Returns the current source element.
+ ///
+ /// The returned element is a declaration element.
+ @override
+ Element get sourceElement => astAdapter.getElement(target);
Siggi Cherem (dart-lang) 2016/11/14 18:30:21 let's add a small TODO here that we need to update
Emily Fortuna 2016/11/14 19:03:39 Done.
+
@override
void visitBlock(ir.Block block) {
assert(!isAborted());
@@ -197,9 +237,10 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
if (returnStatement.expression == null) {
value = graph.addConstantNull(compiler);
} else {
+ assert(target is ir.Procedure);
returnStatement.expression.accept(this);
- value = pop();
- // TODO(het): Check or trust the type of value
+ value = typeBuilder.potentiallyCheckOrTrustType(pop(),
+ astAdapter.getFunctionReturnType((target as ir.Procedure).function));
}
// TODO(het): Add source information
// TODO(het): Set a return value instead of closing the function when we
@@ -591,8 +632,10 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
astAdapter.returnTypeOf(staticTarget));
pop();
} else {
- // TODO(het): check or trust type
- add(new HStaticStore(astAdapter.getMember(staticTarget), value));
+ add(new HStaticStore(
+ astAdapter.getMember(staticTarget),
+ typeBuilder.potentiallyCheckOrTrustType(
+ value, astAdapter.getDartType(staticTarget.setterType))));
}
stack.add(value);
}
@@ -647,8 +690,10 @@ class KernelSsaBuilder extends ir.Visitor with GraphBuilder {
}
stack.add(value);
- // TODO(het): check or trust type
- localsHandler.updateLocal(local, value);
+ localsHandler.updateLocal(
+ local,
+ typeBuilder.potentiallyCheckOrTrustType(
+ value, astAdapter.getDartType(variable.type)));
}
// TODO(het): Also extract type arguments

Powered by Google App Engine
This is Rietveld 408576698