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

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: Address comments. Created 8 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 | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/builder.dart
diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart
index d9995d5249d86d2a650a7b81f3f2dea15f9f8523..a1d3a1999c056ef662575e1ceb55a01fde1c2b9e 100644
--- a/lib/compiler/implementation/ssa/builder.dart
+++ b/lib/compiler/implementation/ssa/builder.dart
@@ -367,21 +367,25 @@ class LocalsHandler {
*
* Invariant: [function] must be an implementation element.
*/
- void startFunction(FunctionElement function,
- FunctionExpression node) {
- assert(invariant(node, function.isImplementation));
+ void startFunction(Element element, Expression node) {
+ assert(invariant(node, element.isImplementation));
Compiler compiler = builder.compiler;
closureData = compiler.closureToClassMapper.computeClosureToClassMapping(
- node, builder.elements);
- FunctionSignature signature = function.computeSignature(compiler);
- signature.orderedForEachParameter((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.orderedForEachParameter((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);
@@ -396,12 +400,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);
@@ -930,19 +934,15 @@ 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);
HInstruction value = pop();
value = potentiallyCheckType(value, variable);
close(new HReturn(value)).addSuccessor(graph.exit);
- graph.finalize();
- return graph;
+ return closeFunction();
}
/**
@@ -1411,38 +1411,43 @@ class SsaBuilder extends ResolvedVisitor implements Visitor {
*
* Invariant: [functionElement] must be the implementation element.
*/
- void openFunction(FunctionElement functionElement,
- FunctionExpression node) {
- assert(invariant(functionElement, functionElement.isImplementation));
+ void openFunction(Element element, Expression node) {
+ assert(invariant(element, element.isImplementation));
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.orderedForEachParameter((Element element) {
- if (elements.isParameterChecked(element)) {
- addParameterCheckInstruction(element);
- }
- });
+ if (element is FunctionElement) {
+ FunctionElement functionElement = element;
+ FunctionSignature params = functionElement.computeSignature(compiler);
+ params.orderedForEachParameter((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.orderedForEachParameter((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.orderedForEachParameter((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.
- var enclosing = functionElement.enclosingElement;
- if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) {
+ var enclosing = element.enclosingElement;
+ if (element.isConstructor() && compiler.world.needsRti(enclosing)) {
enclosing.typeVariables.forEach((TypeVariableType typeVariable) {
HParameterValue param = new HParameterValue(typeVariable.element);
add(param);
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698