| OLD | NEW |
| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 : this.compiler = backend.compiler, | 1127 : this.compiler = backend.compiler, |
| 1128 this.infoReporter = backend.compiler.dumpInfoTask, | 1128 this.infoReporter = backend.compiler.dumpInfoTask, |
| 1129 this.backend = backend, | 1129 this.backend = backend, |
| 1130 this.constantSystem = backend.constantSystem, | 1130 this.constantSystem = backend.constantSystem, |
| 1131 this.rti = backend.rti { | 1131 this.rti = backend.rti { |
| 1132 assert(target.isImplementation); | 1132 assert(target.isImplementation); |
| 1133 graph.element = target; | 1133 graph.element = target; |
| 1134 localsHandler = new LocalsHandler(this, target, null); | 1134 localsHandler = new LocalsHandler(this, target, null); |
| 1135 sourceElementStack.add(target); | 1135 sourceElementStack.add(target); |
| 1136 sourceInformationBuilder = | 1136 sourceInformationBuilder = |
| 1137 sourceInformationFactory.createBuilderForContext(target); | 1137 sourceInformationFactory.createBuilderForContext(resolvedAst); |
| 1138 graph.sourceInformation = | 1138 graph.sourceInformation = |
| 1139 sourceInformationBuilder.buildVariableDeclaration(); | 1139 sourceInformationBuilder.buildVariableDeclaration(); |
| 1140 } | 1140 } |
| 1141 | 1141 |
| 1142 BackendHelpers get helpers => backend.helpers; | 1142 BackendHelpers get helpers => backend.helpers; |
| 1143 | 1143 |
| 1144 RuntimeTypesEncoder get rtiEncoder => backend.rtiEncoder; | 1144 RuntimeTypesEncoder get rtiEncoder => backend.rtiEncoder; |
| 1145 | 1145 |
| 1146 DiagnosticReporter get reporter => compiler.reporter; | 1146 DiagnosticReporter get reporter => compiler.reporter; |
| 1147 | 1147 |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 (mask == null || mask.isNullable)) { | 1528 (mask == null || mask.isNullable)) { |
| 1529 addWithPosition( | 1529 addWithPosition( |
| 1530 new HFieldGet(null, providedArguments[0], backend.dynamicType, | 1530 new HFieldGet(null, providedArguments[0], backend.dynamicType, |
| 1531 isAssignable: false), | 1531 isAssignable: false), |
| 1532 currentNode); | 1532 currentNode); |
| 1533 } | 1533 } |
| 1534 List<HInstruction> compiledArguments = completeSendArgumentsList( | 1534 List<HInstruction> compiledArguments = completeSendArgumentsList( |
| 1535 function, selector, providedArguments, currentNode); | 1535 function, selector, providedArguments, currentNode); |
| 1536 enterInlinedMethod(function, functionResolvedAst, compiledArguments, | 1536 enterInlinedMethod(function, functionResolvedAst, compiledArguments, |
| 1537 instanceType: instanceType); | 1537 instanceType: instanceType); |
| 1538 inlinedFrom(function, () { | 1538 inlinedFrom(functionResolvedAst, () { |
| 1539 if (!isReachable) { | 1539 if (!isReachable) { |
| 1540 emitReturn(graph.addConstantNull(compiler), null); | 1540 emitReturn(graph.addConstantNull(compiler), null); |
| 1541 } else { | 1541 } else { |
| 1542 doInline(functionResolvedAst); | 1542 doInline(functionResolvedAst); |
| 1543 } | 1543 } |
| 1544 }); | 1544 }); |
| 1545 leaveInlinedMethod(); | 1545 leaveInlinedMethod(); |
| 1546 } | 1546 } |
| 1547 | 1547 |
| 1548 if (meetsHardConstraints() && heuristicSayGoodToGo()) { | 1548 if (meetsHardConstraints() && heuristicSayGoodToGo()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1565 return false; | 1565 return false; |
| 1566 } | 1566 } |
| 1567 TypesInferrer inferrer = compiler.typesTask.typesInferrer; | 1567 TypesInferrer inferrer = compiler.typesTask.typesInferrer; |
| 1568 return inferrer.isCalledOnce(element); | 1568 return inferrer.isCalledOnce(element); |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 bool isCalledOnce(Element element) { | 1571 bool isCalledOnce(Element element) { |
| 1572 return allInlinedFunctionsCalledOnce && isFunctionCalledOnce(element); | 1572 return allInlinedFunctionsCalledOnce && isFunctionCalledOnce(element); |
| 1573 } | 1573 } |
| 1574 | 1574 |
| 1575 inlinedFrom(Element element, f()) { | 1575 inlinedFrom(ResolvedAst resolvedAst, f()) { |
| 1576 Element element = resolvedAst.element; |
| 1576 assert(element is FunctionElement || element is VariableElement); | 1577 assert(element is FunctionElement || element is VariableElement); |
| 1577 return reporter.withCurrentElement(element, () { | 1578 return reporter.withCurrentElement(element.implementation, () { |
| 1578 // The [sourceElementStack] contains declaration elements. | 1579 // The [sourceElementStack] contains declaration elements. |
| 1579 SourceInformationBuilder oldSourceInformationBuilder = | 1580 SourceInformationBuilder oldSourceInformationBuilder = |
| 1580 sourceInformationBuilder; | 1581 sourceInformationBuilder; |
| 1581 sourceInformationBuilder = | 1582 sourceInformationBuilder = |
| 1582 sourceInformationBuilder.forContext(element.implementation); | 1583 sourceInformationBuilder.forContext(resolvedAst); |
| 1583 sourceElementStack.add(element.declaration); | 1584 sourceElementStack.add(element.declaration); |
| 1584 var result = f(); | 1585 var result = f(); |
| 1585 sourceInformationBuilder = oldSourceInformationBuilder; | 1586 sourceInformationBuilder = oldSourceInformationBuilder; |
| 1586 sourceElementStack.removeLast(); | 1587 sourceElementStack.removeLast(); |
| 1587 return result; | 1588 return result; |
| 1588 }); | 1589 }); |
| 1589 } | 1590 } |
| 1590 | 1591 |
| 1591 /** | 1592 /** |
| 1592 * Return null so it is simple to remove the optional parameters completely | 1593 * Return null so it is simple to remove the optional parameters completely |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 localsHandler.updateLocal( | 1986 localsHandler.updateLocal( |
| 1986 localsHandler.getTypeVariableAsLocal(variable), | 1987 localsHandler.getTypeVariableAsLocal(variable), |
| 1987 graph.addConstantNull(compiler)); | 1988 graph.addConstantNull(compiler)); |
| 1988 } | 1989 } |
| 1989 } | 1990 } |
| 1990 } | 1991 } |
| 1991 | 1992 |
| 1992 // For redirecting constructors, the fields will be initialized later | 1993 // For redirecting constructors, the fields will be initialized later |
| 1993 // by the effective target. | 1994 // by the effective target. |
| 1994 if (!callee.isRedirectingGenerative) { | 1995 if (!callee.isRedirectingGenerative) { |
| 1995 inlinedFrom(callee, () { | 1996 inlinedFrom(constructorRecolvedAst, () { |
| 1996 buildFieldInitializers( | 1997 buildFieldInitializers( |
| 1997 callee.enclosingClass.implementation, fieldValues); | 1998 callee.enclosingClass.implementation, fieldValues); |
| 1998 }); | 1999 }); |
| 1999 } | 2000 } |
| 2000 | 2001 |
| 2001 int index = 0; | 2002 int index = 0; |
| 2002 FunctionSignature params = callee.functionSignature; | 2003 FunctionSignature params = callee.functionSignature; |
| 2003 params.orderedForEachParameter((ParameterElement parameter) { | 2004 params.orderedForEachParameter((ParameterElement parameter) { |
| 2004 HInstruction argument = compiledArguments[index++]; | 2005 HInstruction argument = compiledArguments[index++]; |
| 2005 // Because we are inlining the initializer, we must update | 2006 // Because we are inlining the initializer, we must update |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 // A super initializer or constructor redirection. | 2114 // A super initializer or constructor redirection. |
| 2114 foundSuperOrRedirect = true; | 2115 foundSuperOrRedirect = true; |
| 2115 ast.Send call = link.head; | 2116 ast.Send call = link.head; |
| 2116 assert(ast.Initializers.isSuperConstructorCall(call) || | 2117 assert(ast.Initializers.isSuperConstructorCall(call) || |
| 2117 ast.Initializers.isConstructorRedirect(call)); | 2118 ast.Initializers.isConstructorRedirect(call)); |
| 2118 FunctionElement target = elements[call].implementation; | 2119 FunctionElement target = elements[call].implementation; |
| 2119 CallStructure callStructure = | 2120 CallStructure callStructure = |
| 2120 elements.getSelector(call).callStructure; | 2121 elements.getSelector(call).callStructure; |
| 2121 Link<ast.Node> arguments = call.arguments; | 2122 Link<ast.Node> arguments = call.arguments; |
| 2122 List<HInstruction> compiledArguments; | 2123 List<HInstruction> compiledArguments; |
| 2123 inlinedFrom(constructor, () { | 2124 inlinedFrom(resolvedAst, () { |
| 2124 compiledArguments = | 2125 compiledArguments = |
| 2125 makeStaticArgumentList(callStructure, arguments, target); | 2126 makeStaticArgumentList(callStructure, arguments, target); |
| 2126 }); | 2127 }); |
| 2127 inlineSuperOrRedirect( | 2128 inlineSuperOrRedirect( |
| 2128 backend.frontend.getResolvedAst(target.declaration), | 2129 backend.frontend.getResolvedAst(target.declaration), |
| 2129 compiledArguments, | 2130 compiledArguments, |
| 2130 constructorResolvedAsts, | 2131 constructorResolvedAsts, |
| 2131 fieldValues, | 2132 fieldValues, |
| 2132 constructor); | 2133 constructor); |
| 2133 } else { | 2134 } else { |
| 2134 // A field initializer. | 2135 // A field initializer. |
| 2135 ast.SendSet init = link.head; | 2136 ast.SendSet init = link.head; |
| 2136 Link<ast.Node> arguments = init.arguments; | 2137 Link<ast.Node> arguments = init.arguments; |
| 2137 assert(!arguments.isEmpty && arguments.tail.isEmpty); | 2138 assert(!arguments.isEmpty && arguments.tail.isEmpty); |
| 2138 inlinedFrom(constructor, () { | 2139 inlinedFrom(resolvedAst, () { |
| 2139 visit(arguments.head); | 2140 visit(arguments.head); |
| 2140 }); | 2141 }); |
| 2141 fieldValues[elements[init]] = pop(); | 2142 fieldValues[elements[init]] = pop(); |
| 2142 } | 2143 } |
| 2143 } | 2144 } |
| 2144 } | 2145 } |
| 2145 | 2146 |
| 2146 if (!foundSuperOrRedirect) { | 2147 if (!foundSuperOrRedirect) { |
| 2147 // No super initializer found. Try to find the default constructor if | 2148 // No super initializer found. Try to find the default constructor if |
| 2148 // the class is not Object. | 2149 // the class is not Object. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 fieldValues[member] = graph.addConstantNull(compiler); | 2196 fieldValues[member] = graph.addConstantNull(compiler); |
| 2196 } | 2197 } |
| 2197 } else { | 2198 } else { |
| 2198 ast.Node right = initializer; | 2199 ast.Node right = initializer; |
| 2199 ResolvedAst savedResolvedAst = resolvedAst; | 2200 ResolvedAst savedResolvedAst = resolvedAst; |
| 2200 resolvedAst = fieldResolvedAst; | 2201 resolvedAst = fieldResolvedAst; |
| 2201 // In case the field initializer uses closures, run the | 2202 // In case the field initializer uses closures, run the |
| 2202 // closure to class mapper. | 2203 // closure to class mapper. |
| 2203 compiler.closureToClassMapper | 2204 compiler.closureToClassMapper |
| 2204 .computeClosureToClassMapping(resolvedAst); | 2205 .computeClosureToClassMapping(resolvedAst); |
| 2205 inlinedFrom(member, () => right.accept(this)); | 2206 inlinedFrom(fieldResolvedAst, () => right.accept(this)); |
| 2206 resolvedAst = savedResolvedAst; | 2207 resolvedAst = savedResolvedAst; |
| 2207 fieldValues[member] = pop(); | 2208 fieldValues[member] = pop(); |
| 2208 } | 2209 } |
| 2209 }); | 2210 }); |
| 2210 }); | 2211 }); |
| 2211 } | 2212 } |
| 2212 | 2213 |
| 2213 /** | 2214 /** |
| 2214 * Build the factory function corresponding to the constructor | 2215 * Build the factory function corresponding to the constructor |
| 2215 * [functionElement]: | 2216 * [functionElement]: |
| (...skipping 6383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8599 const _LoopTypeVisitor(); | 8600 const _LoopTypeVisitor(); |
| 8600 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; | 8601 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; |
| 8601 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; | 8602 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; |
| 8602 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; | 8603 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; |
| 8603 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; | 8604 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; |
| 8604 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8605 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 8605 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8606 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 8606 int visitSwitchStatement(ast.SwitchStatement node) => | 8607 int visitSwitchStatement(ast.SwitchStatement node) => |
| 8607 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; | 8608 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; |
| 8608 } | 8609 } |
| OLD | NEW |