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

Side by Side Diff: lib/compiler/implementation/ssa/builder.dart

Issue 11086045: Revert "Allow closures inside lazy initializers." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/resolver.dart ('k') | lib/compiler/implementation/ssa/codegen.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class Interceptors { 5 class Interceptors {
6 Compiler compiler; 6 Compiler compiler;
7 Interceptors(Compiler this.compiler); 7 Interceptors(Compiler this.compiler);
8 8
9 SourceString mapOperatorToMethodName(Operator op) { 9 SourceString mapOperatorToMethodName(Operator op) {
10 String name = op.source.stringValue; 10 String name = op.source.stringValue;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 updateLocal(boxedVariable, oldValue); 360 updateLocal(boxedVariable, oldValue);
361 } 361 }
362 updateLocal(boxElement, newBox); 362 updateLocal(boxElement, newBox);
363 } 363 }
364 364
365 /** 365 /**
366 * Documentation wanted -- johnniwinther 366 * Documentation wanted -- johnniwinther
367 * 367 *
368 * Invariant: [function] must be an implementation element. 368 * Invariant: [function] must be an implementation element.
369 */ 369 */
370 void startFunction(Element element, Expression node) { 370 void startFunction(FunctionElement function,
371 assert(invariant(node, element.isImplementation)); 371 FunctionExpression node) {
372 assert(invariant(node, function.isImplementation));
372 Compiler compiler = builder.compiler; 373 Compiler compiler = builder.compiler;
373 closureData = compiler.closureToClassMapper.computeClosureToClassMapping( 374 closureData = compiler.closureToClassMapper.computeClosureToClassMapping(
374 element, node, builder.elements); 375 node, builder.elements);
375 376 FunctionSignature signature = function.computeSignature(compiler);
376 if (element is FunctionElement) { 377 signature.orderedForEachParameter((Element element) {
377 FunctionElement functionElement = element; 378 HInstruction parameter = new HParameterValue(element);
378 FunctionSignature params = functionElement.computeSignature(compiler); 379 builder.add(parameter);
379 params.orderedForEachParameter((Element parameterElement) { 380 builder.parameters[element] = parameter;
380 HInstruction parameter = new HParameterValue(parameterElement); 381 directLocals[element] = parameter;
381 builder.add(parameter); 382 parameter.guaranteedType =
382 builder.parameters[parameterElement] = parameter; 383 builder.mapInferredType(typesTask.getGuaranteedTypeOfElement(element));
383 directLocals[parameterElement] = parameter; 384 });
384 parameter.guaranteedType =
385 builder.mapInferredType(
386 typesTask.getGuaranteedTypeOfElement(parameterElement));
387 });
388 }
389 385
390 enterScope(node); 386 enterScope(node);
391 387
392 // If the freeVariableMapping is not empty, then this function was a 388 // If the freeVariableMapping is not empty, then this function was a
393 // nested closure that captures variables. Redirect the captured 389 // nested closure that captures variables. Redirect the captured
394 // variables to fields in the closure. 390 // variables to fields in the closure.
395 closureData.freeVariableMapping.forEach((Element from, Element to) { 391 closureData.freeVariableMapping.forEach((Element from, Element to) {
396 redirectElement(from, to); 392 redirectElement(from, to);
397 }); 393 });
398 if (closureData.isClosure()) { 394 if (closureData.isClosure()) {
399 // Inside closure redirect references to itself to [:this:]. 395 // Inside closure redirect references to itself to [:this:].
400 HInstruction thisInstruction = new HThis(); 396 HInstruction thisInstruction = new HThis();
401 builder.add(thisInstruction); 397 builder.add(thisInstruction);
402 updateLocal(closureData.closureElement, thisInstruction); 398 updateLocal(closureData.closureElement, thisInstruction);
403 } else if (element.isInstanceMember() 399 } else if (function.isInstanceMember()
404 || element.isGenerativeConstructor()) { 400 || function.isGenerativeConstructor()) {
405 // Once closures have been mapped to classes their instance members might 401 // Once closures have been mapped to classes their instance members might
406 // not have any thisElement if the closure was created inside a static 402 // not have any thisElement if the closure was created inside a static
407 // context. 403 // context.
408 ClassElement cls = element.getEnclosingClass(); 404 ClassElement cls = function.getEnclosingClass();
409 DartType type = cls.computeType(builder.compiler); 405 DartType type = cls.computeType(builder.compiler);
410 HInstruction thisInstruction = new HThis(new HBoundedType.nonNull(type)); 406 HInstruction thisInstruction = new HThis(new HBoundedType.nonNull(type));
411 builder.add(thisInstruction); 407 builder.add(thisInstruction);
412 directLocals[closureData.thisElement] = thisInstruction; 408 directLocals[closureData.thisElement] = thisInstruction;
413 } 409 }
414 } 410 }
415 411
416 bool hasValueForDirectLocal(Element element) { 412 bool hasValueForDirectLocal(Element element) {
417 assert(element !== null); 413 assert(element !== null);
418 assert(isAccessedDirectly(element)); 414 assert(isAccessedDirectly(element));
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 FunctionExpression function = functionElement.parseNode(compiler); 923 FunctionExpression function = functionElement.parseNode(compiler);
928 assert(function !== null); 924 assert(function !== null);
929 assert(!function.modifiers.isExternal()); 925 assert(!function.modifiers.isExternal());
930 assert(elements[function] !== null); 926 assert(elements[function] !== null);
931 openFunction(functionElement, function); 927 openFunction(functionElement, function);
932 function.body.accept(this); 928 function.body.accept(this);
933 return closeFunction(); 929 return closeFunction();
934 } 930 }
935 931
936 HGraph buildLazyInitializer(VariableElement variable) { 932 HGraph buildLazyInitializer(VariableElement variable) {
933 HBasicBlock block = graph.addNewBlock();
934 open(graph.entry);
935 close(new HGoto()).addSuccessor(block);
936 open(block);
937 SendSet node = variable.parseNode(compiler); 937 SendSet node = variable.parseNode(compiler);
938 openFunction(variable, node);
939 Link<Node> link = node.arguments; 938 Link<Node> link = node.arguments;
940 assert(!link.isEmpty() && link.tail.isEmpty()); 939 assert(!link.isEmpty() && link.tail.isEmpty());
941 visit(link.head); 940 visit(link.head);
942 HInstruction value = pop(); 941 HInstruction value = pop();
943 value = potentiallyCheckType(value, variable); 942 value = potentiallyCheckType(value, variable);
944 close(new HReturn(value)).addSuccessor(graph.exit); 943 close(new HReturn(value)).addSuccessor(graph.exit);
945 return closeFunction(); 944 graph.finalize();
945 return graph;
946 } 946 }
947 947
948 /** 948 /**
949 * Returns the constructor body associated with the given constructor or 949 * Returns the constructor body associated with the given constructor or
950 * creates a new constructor body, if none can be found. 950 * creates a new constructor body, if none can be found.
951 * 951 *
952 * Returns [:null:] if the constructor does not have a body. 952 * Returns [:null:] if the constructor does not have a body.
953 */ 953 */
954 ConstructorBodyElement getConstructorBody(FunctionElement constructor) { 954 ConstructorBodyElement getConstructorBody(FunctionElement constructor) {
955 assert(constructor.isGenerativeConstructor()); 955 assert(constructor.isGenerativeConstructor());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 ClosureClassMap closureData = localsHandler.closureData; 1404 ClosureClassMap closureData = localsHandler.closureData;
1405 Element checkResultElement = closureData.parametersWithSentinel[element]; 1405 Element checkResultElement = closureData.parametersWithSentinel[element];
1406 localsHandler.updateLocal(checkResultElement, check); 1406 localsHandler.updateLocal(checkResultElement, check);
1407 } 1407 }
1408 1408
1409 /** 1409 /**
1410 * Documentation wanted -- johnniwinther 1410 * Documentation wanted -- johnniwinther
1411 * 1411 *
1412 * Invariant: [functionElement] must be the implementation element. 1412 * Invariant: [functionElement] must be the implementation element.
1413 */ 1413 */
1414 void openFunction(Element element, Expression node) { 1414 void openFunction(FunctionElement functionElement,
1415 assert(invariant(element, element.isImplementation)); 1415 FunctionExpression node) {
1416 assert(invariant(functionElement, functionElement.isImplementation));
1416 HBasicBlock block = graph.addNewBlock(); 1417 HBasicBlock block = graph.addNewBlock();
1417 open(graph.entry); 1418 open(graph.entry);
1418 1419
1419 localsHandler.startFunction(element, node); 1420 localsHandler.startFunction(functionElement, node);
1420 close(new HGoto()).addSuccessor(block); 1421 close(new HGoto()).addSuccessor(block);
1421 1422
1422 open(block); 1423 open(block);
1423 1424
1424 if (element is FunctionElement) { 1425 FunctionSignature params = functionElement.computeSignature(compiler);
1425 FunctionElement functionElement = element; 1426 params.orderedForEachParameter((Element element) {
1426 FunctionSignature params = functionElement.computeSignature(compiler); 1427 if (elements.isParameterChecked(element)) {
1427 params.orderedForEachParameter((Element parameterElement) { 1428 addParameterCheckInstruction(element);
1428 if (elements.isParameterChecked(parameterElement)) { 1429 }
1429 addParameterCheckInstruction(parameterElement); 1430 });
1430 }
1431 });
1432 1431
1433 // Put the type checks in the first successor of the entry, 1432 // Put the type checks in the first successor of the entry,
1434 // because that is where the type guards will also be inserted. 1433 // because that is where the type guards will also be inserted.
1435 // This way we ensure that a type guard will dominate the type 1434 // This way we ensure that a type guard will dominate the type
1436 // check. 1435 // check.
1437 params.orderedForEachParameter((Element element) { 1436 params.orderedForEachParameter((Element element) {
1438 HInstruction newParameter = potentiallyCheckType( 1437 HInstruction newParameter = potentiallyCheckType(
1439 localsHandler.directLocals[element], element); 1438 localsHandler.directLocals[element], element);
1440 localsHandler.directLocals[element] = newParameter; 1439 localsHandler.directLocals[element] = newParameter;
1441 }); 1440 });
1442 } else {
1443 // Otherwise it is a lazy initializer which does not have parameters.
1444 assert(element is VariableElement);
1445 }
1446 1441
1447 // Add the type parameters of the class as parameters of this 1442 // Add the type parameters of the class as parameters of this
1448 // method. 1443 // method.
1449 var enclosing = element.enclosingElement; 1444 var enclosing = functionElement.enclosingElement;
1450 if (element.isConstructor() && compiler.world.needsRti(enclosing)) { 1445 if (functionElement.isConstructor() && compiler.world.needsRti(enclosing)) {
1451 enclosing.typeVariables.forEach((TypeVariableType typeVariable) { 1446 enclosing.typeVariables.forEach((TypeVariableType typeVariable) {
1452 HParameterValue param = new HParameterValue(typeVariable.element); 1447 HParameterValue param = new HParameterValue(typeVariable.element);
1453 add(param); 1448 add(param);
1454 localsHandler.directLocals[typeVariable.element] = param; 1449 localsHandler.directLocals[typeVariable.element] = param;
1455 }); 1450 });
1456 } 1451 }
1457 } 1452 }
1458 1453
1459 HInstruction potentiallyCheckType( 1454 HInstruction potentiallyCheckType(
1460 HInstruction original, Element sourceElement, 1455 HInstruction original, Element sourceElement,
(...skipping 2942 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 new HSubGraphBlockInformation(elseBranch.graph)); 4398 new HSubGraphBlockInformation(elseBranch.graph));
4404 4399
4405 HBasicBlock conditionStartBlock = conditionBranch.block; 4400 HBasicBlock conditionStartBlock = conditionBranch.block;
4406 conditionStartBlock.setBlockFlow(info, joinBlock); 4401 conditionStartBlock.setBlockFlow(info, joinBlock);
4407 SubGraph conditionGraph = conditionBranch.graph; 4402 SubGraph conditionGraph = conditionBranch.graph;
4408 HIf branch = conditionGraph.end.last; 4403 HIf branch = conditionGraph.end.last;
4409 assert(branch is HIf); 4404 assert(branch is HIf);
4410 branch.blockInformation = conditionStartBlock.blockFlow; 4405 branch.blockInformation = conditionStartBlock.blockFlow;
4411 } 4406 }
4412 } 4407 }
OLDNEW
« 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