Chromium Code Reviews| 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 library closureToClassMapper; | 5 library closureToClassMapper; |
| 6 | 6 |
| 7 import 'common/names.dart' show Identifiers; | 7 import 'common/names.dart' show Identifiers; |
| 8 import 'common/resolution.dart' show ParsingContext, Resolution; | 8 import 'common/resolution.dart' show ParsingContext, Resolution; |
| 9 import 'common/tasks.dart' show CompilerTask; | 9 import 'common/tasks.dart' show CompilerTask; |
| 10 import 'common.dart'; | 10 import 'common.dart'; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 Compiler compiler; | 34 Compiler compiler; |
| 35 ClosureTask(Compiler compiler) | 35 ClosureTask(Compiler compiler) |
| 36 : compiler = compiler, | 36 : compiler = compiler, |
| 37 super(compiler.measurer); | 37 super(compiler.measurer); |
| 38 | 38 |
| 39 String get name => "Closure Simplifier"; | 39 String get name => "Closure Simplifier"; |
| 40 | 40 |
| 41 DiagnosticReporter get reporter => compiler.reporter; | 41 DiagnosticReporter get reporter => compiler.reporter; |
| 42 | 42 |
| 43 ClosureClassMap getMemberMap(MemberElement member) { | 43 ClosureClassMap getMemberMap(MemberElement member) { |
| 44 return getClosureToClassMapping(member.resolvedAst); | 44 return getClosureToClassMapping(member); |
| 45 } | 45 } |
| 46 | 46 |
| 47 ClosureClassMap getLocalFunctionMap(LocalFunctionElement localFunction) { | 47 ClosureClassMap getLocalFunctionMap(LocalFunctionElement localFunction) { |
| 48 return getClosureToClassMapping(localFunction.resolvedAst); | 48 return getClosureToClassMapping(localFunction); |
| 49 } | 49 } |
| 50 | 50 |
| 51 /// Returns the [ClosureClassMap] computed for [resolvedAst]. | 51 /// Returns the [ClosureClassMap] computed for [resolvedAst]. |
| 52 ClosureClassMap getClosureToClassMapping(ResolvedAst resolvedAst) { | 52 ClosureClassMap getClosureToClassMapping(Element element) { |
| 53 return measure(() { | 53 return measure(() { |
|
Johnni Winther
2017/06/02 16:39:27
I suspect that you need to add `element = element.
Emily Fortuna
2017/06/05 17:33:59
hm. I ran all the tests and they passed without th
| |
| 54 Element element = resolvedAst.element; | |
| 55 if (element.isGenerativeConstructorBody) { | 54 if (element.isGenerativeConstructorBody) { |
| 56 ConstructorBodyElement constructorBody = element; | 55 ConstructorBodyElement constructorBody = element; |
| 57 element = constructorBody.constructor; | 56 element = constructorBody.constructor; |
| 58 } | 57 } |
| 59 ClosureClassMap closureClassMap = _closureMappingCache[element]; | 58 ClosureClassMap closureClassMap = _closureMappingCache[element]; |
| 60 assert( | 59 assert(closureClassMap != null, |
| 61 closureClassMap != null, | 60 failedAt(element, "No ClosureClassMap computed for ${element}.")); |
| 62 failedAt(resolvedAst.element, | |
| 63 "No ClosureClassMap computed for ${element}.")); | |
| 64 return closureClassMap; | 61 return closureClassMap; |
| 65 }); | 62 }); |
| 66 } | 63 } |
| 67 | 64 |
| 68 /// Create [ClosureClassMap]s for all live members. | 65 /// Create [ClosureClassMap]s for all live members. |
| 69 void createClosureClasses(ClosedWorldRefiner closedWorldRefiner) { | 66 void createClosureClasses(ClosedWorldRefiner closedWorldRefiner) { |
| 70 compiler.enqueuer.resolution.processedEntities | 67 compiler.enqueuer.resolution.processedEntities |
| 71 .forEach((MemberElement element) { | 68 .forEach((MemberElement element) { |
| 72 ResolvedAst resolvedAst = element.resolvedAst; | 69 ResolvedAst resolvedAst = element.resolvedAst; |
| 73 if (element.isAbstract) return; | 70 if (element.isAbstract) return; |
| 74 if (element.isField && | 71 if (element.isField && |
| 75 !element.isInstanceMember && | 72 !element.isInstanceMember && |
| 76 resolvedAst.body == null) { | 73 resolvedAst.body == null) { |
| 77 // Skip top-level/static fields without an initializer. | 74 // Skip top-level/static fields without an initializer. |
| 78 return; | 75 return; |
| 79 } | 76 } |
| 80 computeClosureToClassMapping(resolvedAst, closedWorldRefiner); | 77 computeClosureToClassMapping(element, closedWorldRefiner); |
| 81 }); | 78 }); |
| 82 } | 79 } |
| 83 | 80 |
| 84 ClosureClassMap computeClosureToClassMapping( | 81 ClosureClassMap computeClosureToClassMapping( |
| 85 ResolvedAst resolvedAst, ClosedWorldRefiner closedWorldRefiner) { | 82 Element element, ClosedWorldRefiner closedWorldRefiner) { |
| 86 return measure(() { | 83 return measure(() { |
| 87 Element element = resolvedAst.element; | |
| 88 ClosureClassMap cached = _closureMappingCache[element]; | 84 ClosureClassMap cached = _closureMappingCache[element]; |
| 89 if (cached != null) return cached; | 85 if (cached != null) return cached; |
| 90 if (resolvedAst.kind != ResolvedAstKind.PARSED) { | 86 if (element.resolvedAst.kind != ResolvedAstKind.PARSED) { |
| 91 return _closureMappingCache[element] = | 87 return _closureMappingCache[element] = |
| 92 new ClosureClassMap(null, null, null, new ThisLocal(element)); | 88 new ClosureClassMap(null, null, null, new ThisLocal(element)); |
| 93 } | 89 } |
| 94 return reporter.withCurrentElement(element.implementation, () { | 90 return reporter.withCurrentElement(element.implementation, () { |
| 95 Node node = resolvedAst.node; | 91 Node node = element.resolvedAst.node; |
| 96 TreeElements elements = resolvedAst.elements; | 92 TreeElements elements = element.resolvedAst.elements; |
| 97 | 93 |
| 98 ClosureTranslator translator = new ClosureTranslator( | 94 ClosureTranslator translator = new ClosureTranslator( |
| 99 compiler, closedWorldRefiner, elements, _closureMappingCache); | 95 compiler, closedWorldRefiner, elements, _closureMappingCache); |
| 100 | 96 |
| 101 // The translator will store the computed closure-mappings inside the | 97 // The translator will store the computed closure-mappings inside the |
| 102 // cache. One for given node and one for each nested closure. | 98 // cache. One for given node and one for each nested closure. |
| 103 if (node is FunctionExpression) { | 99 if (node is FunctionExpression) { |
| 104 translator.translateFunction(element, node); | 100 translator.translateFunction(element, node); |
| 105 } else if (element.isSynthesized) { | 101 } else if (element.isSynthesized) { |
| 106 reporter.internalError( | 102 reporter.internalError( |
| 107 element, "Unexpected synthesized element: $element"); | 103 element, "Unexpected synthesized element: $element"); |
| 108 _closureMappingCache[element] = | 104 _closureMappingCache[element] = |
| 109 new ClosureClassMap(null, null, null, new ThisLocal(element)); | 105 new ClosureClassMap(null, null, null, new ThisLocal(element)); |
| 110 } else { | 106 } else { |
| 111 assert(element.isField, | 107 assert(element.isField, |
| 112 failedAt(element, "Expected $element to be a field.")); | 108 failedAt(element, "Expected $element to be a field.")); |
| 113 Node initializer = resolvedAst.body; | 109 Node initializer = element.resolvedAst.body; |
| 114 if (initializer != null) { | 110 if (initializer != null) { |
| 115 // The lazy initializer of a static. | 111 // The lazy initializer of a static. |
| 116 translator.translateLazyInitializer(element, node, initializer); | 112 translator.translateLazyInitializer(element, node, initializer); |
| 117 } else { | 113 } else { |
| 118 assert( | 114 assert( |
| 119 element.isInstanceMember, | 115 element.isInstanceMember, |
| 120 failedAt( | 116 failedAt( |
| 121 element, | 117 element, |
| 122 "Expected $element (${element.runtimeType}) " | 118 "Expected $element (${element.runtimeType}) " |
| 123 "to be an instance field.")); | 119 "to be an instance field.")); |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1131 ThisLocal thisElement = null; | 1127 ThisLocal thisElement = null; |
| 1132 if (element.isInstanceMember || element.isGenerativeConstructor) { | 1128 if (element.isInstanceMember || element.isGenerativeConstructor) { |
| 1133 thisElement = new ThisLocal(element); | 1129 thisElement = new ThisLocal(element); |
| 1134 } | 1130 } |
| 1135 closureData = new ClosureClassMap(null, null, null, thisElement); | 1131 closureData = new ClosureClassMap(null, null, null, thisElement); |
| 1136 if (element is MethodElement) { | 1132 if (element is MethodElement) { |
| 1137 needsRti = compiler.options.enableTypeAssertions || | 1133 needsRti = compiler.options.enableTypeAssertions || |
| 1138 compiler.backend.rtiNeed.methodNeedsRti(element); | 1134 compiler.backend.rtiNeed.methodNeedsRti(element); |
| 1139 } | 1135 } |
| 1140 } | 1136 } |
| 1137 closureMappingCache[element] = closureData; | |
| 1141 closureMappingCache[element.declaration] = closureData; | 1138 closureMappingCache[element.declaration] = closureData; |
| 1142 if (closureData.callElement != null) { | 1139 if (closureData.callElement != null) { |
| 1143 closureMappingCache[closureData.callElement] = closureData; | 1140 closureMappingCache[closureData.callElement] = closureData; |
| 1144 } | 1141 } |
| 1145 | 1142 |
| 1146 inNewScope(node, () { | 1143 inNewScope(node, () { |
| 1147 // If the method needs RTI, or checked mode is set, we need to | 1144 // If the method needs RTI, or checked mode is set, we need to |
| 1148 // escape the potential type variables used in that closure. | 1145 // escape the potential type variables used in that closure. |
| 1149 if (needsRti) { | 1146 if (needsRti) { |
| 1150 analyzeTypeVariables(element.type); | 1147 analyzeTypeVariables(element.type); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1240 /// | 1237 /// |
| 1241 /// Move the below classes to a JS model eventually. | 1238 /// Move the below classes to a JS model eventually. |
| 1242 /// | 1239 /// |
| 1243 abstract class JSEntity implements Entity { | 1240 abstract class JSEntity implements Entity { |
| 1244 Entity get declaredEntity; | 1241 Entity get declaredEntity; |
| 1245 } | 1242 } |
| 1246 | 1243 |
| 1247 abstract class PrivatelyNamedJSEntity implements JSEntity { | 1244 abstract class PrivatelyNamedJSEntity implements JSEntity { |
| 1248 Entity get rootOfScope; | 1245 Entity get rootOfScope; |
| 1249 } | 1246 } |
| OLD | NEW |