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

Unified Diff: lib/compiler/implementation/ssa/builder.dart

Issue 10913133: Allow closures inside lazy initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
Index: lib/compiler/implementation/ssa/builder.dart
diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
index a943931c4c895f8a3d53cb31547b1e9233463806..8067947dee815c3f06c947729027e390302962e1 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -173,6 +173,7 @@ class SsaBuilderTask extends CompilerTask {
}
assert(graph.isValid());
if (kind !== ElementKind.FIELD) {
+ FunctionElement functionElement = element;
bool inLoop = functionsCalledInLoop.contains(element);
if (!inLoop) {
Selector selector = selectorsCalledInLoop[element.name];
@@ -183,7 +184,8 @@ class SsaBuilderTask extends CompilerTask {
// If there is an estimate of the parameter types assume these types when
kasperl 2012/09/10 13:44:29 Long line. NYF.
floitsch 2012/10/09 16:06:44 Has been fixed in the mean-time.
// compiling.
OptionalParameterTypes defaultValueTypes = null;
- FunctionSignature signature = element.computeSignature(compiler);
+ FunctionSignature signature =
+ functionElement.computeSignature(compiler);
if (signature.optionalParameterCount > 0) {
defaultValueTypes =
new OptionalParameterTypes(signature.optionalParameterCount);
@@ -340,20 +342,24 @@ class LocalsHandler {
updateLocal(boxElement, newBox);
}
- void startFunction(FunctionElement function,
- FunctionExpression node) {
+ void startFunction(Element element, Expression node) {
Compiler compiler = builder.compiler;
closureData = compiler.closureToClassMapper.computeClosureToClassMapping(
- node, builder.elements);
- FunctionSignature signature = function.computeSignature(compiler);
- signature.forEachParameter((Element element) {
- HInstruction parameter = new HParameterValue(element);
- builder.add(parameter);
- builder.parameters[element] = parameter;
- directLocals[element] = parameter;
- parameter.guaranteedType =
- builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element));
- });
+ element, node, builder.elements);
+
+ if (element is FunctionElement) {
+ FunctionElement functionElement = element;
+ FunctionSignature params = functionElement.computeSignature(compiler);
+ params.forEachParameter((Element parameterElement) {
+ HInstruction parameter = new HParameterValue(parameterElement);
+ builder.add(parameter);
+ builder.parameters[parameterElement] = parameter;
+ directLocals[parameterElement] = parameter;
+ parameter.guaranteedType =
+ builder.mapInferredType(
+ typesTask.getGuaranteedTypeOfElement(parameterElement));
+ });
+ }
enterScope(node);
@@ -368,12 +374,12 @@ class LocalsHandler {
HInstruction thisInstruction = new HThis();
builder.add(thisInstruction);
updateLocal(closureData.closureElement, thisInstruction);
- } else if (function.isInstanceMember()
- || function.isGenerativeConstructor()) {
+ } else if (element.isInstanceMember()
+ || element.isGenerativeConstructor()) {
// Once closures have been mapped to classes their instance members might
// not have any thisElement if the closure was created inside a static
// context.
- ClassElement cls = function.getEnclosingClass();
+ ClassElement cls = element.getEnclosingClass();
DartType type = cls.computeType(builder.compiler);
HInstruction thisInstruction = new HThis(new HBoundedType.nonNull(type));
builder.add(thisInstruction);
@@ -890,17 +896,13 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
}
HGraph buildLazyInitializer(VariableElement variable) {
- HBasicBlock block = graph.addNewBlock();
- open(graph.entry);
- close(new HGoto()).addSuccessor(block);
- open(block);
SendSet node = variable.parseNode(compiler);
+ openFunction(variable, node);
Link<Node> link = node.arguments;
assert(!link.isEmpty() && link.tail.isEmpty());
visit(link.head);
close(new HReturn(pop())).addSuccessor(graph.exit);
- graph.finalize();
- return graph;
+ return closeFunction();
}
/**
@@ -1313,38 +1315,43 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
localsHandler.updateLocal(checkResultElement, check);
}
- void openFunction(FunctionElement functionElement,
- FunctionExpression node) {
+ void openFunction(Element element, Expression node) {
HBasicBlock block = graph.addNewBlock();
open(graph.entry);
- localsHandler.startFunction(functionElement, node);
+ localsHandler.startFunction(element, node);
close(new HGoto()).addSuccessor(block);
open(block);
- FunctionSignature params = functionElement.computeSignature(compiler);
- params.forEachParameter((Element element) {
- if (elements.isParameterChecked(element)) {
- addParameterCheckInstruction(element);
- }
- });
+ if (element is FunctionElement) {
+ FunctionElement functionElement = element;
+ FunctionSignature params = functionElement.computeSignature(compiler);
+ params.forEachParameter((Element parameterElement) {
+ if (elements.isParameterChecked(parameterElement)) {
+ addParameterCheckInstruction(parameterElement);
+ }
+ });
- // Put the type checks in the first successor of the entry,
- // because that is where the type guards will also be inserted.
- // This way we ensure that a type guard will dominate the type
- // check.
- params.forEachParameter((Element element) {
- HInstruction newParameter = potentiallyCheckType(
- localsHandler.directLocals[element], element);
- localsHandler.directLocals[element] = newParameter;
- });
+ // Put the type checks in the first successor of the entry,
+ // because that is where the type guards will also be inserted.
+ // This way we ensure that a type guard will dominate the type
+ // check.
+ params.forEachParameter((Element element) {
+ HInstruction newParameter = potentiallyCheckType(
+ localsHandler.directLocals[element], element);
+ localsHandler.directLocals[element] = newParameter;
+ });
+ } else {
+ // Otherwise it is a lazy initializer which does not have parameters.
+ assert(element is VariableElement);
+ }
// Add the type parameters of the class as parameters of this
// method.
- if (functionElement.isFactoryConstructor()
- || functionElement.isGenerativeConstructor()) {
- ClassElement cls = functionElement.enclosingElement;
+ if (element.isFactoryConstructor()
+ || element.isGenerativeConstructor()) {
+ ClassElement cls = element.enclosingElement;
cls.typeVariables.forEach((TypeVariableType typeVariable) {
HParameterValue param = new HParameterValue(typeVariable.element);
add(param);
@@ -2717,7 +2724,7 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
List<HInstruction> argumentValues]) {
Element helper =
compiler.findHelper(const SourceString('throwNoSuchMethod'));
- Constant receiverConstant =
+ Constant receiverConstant =
constantSystem.createString(new DartString.empty(), diagnosticNode);
HInstruction receiver = graph.addConstant(receiverConstant);
DartString dartString = new DartString.literal(methodName);

Powered by Google App Engine
This is Rietveld 408576698