| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class World { | 7 class World { |
| 8 final Compiler compiler; | 8 final Compiler compiler; |
| 9 final FullFunctionSet allFunctions; | 9 final FullFunctionSet allFunctions; |
| 10 final Set<Element> functionsCalledInLoop = new Set<Element>(); | 10 final Set<Element> functionsCalledInLoop = new Set<Element>(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 void addFunctionCalledInLoop(Element element) { | 200 void addFunctionCalledInLoop(Element element) { |
| 201 functionsCalledInLoop.add(element.declaration); | 201 functionsCalledInLoop.add(element.declaration); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool isCalledInLoop(Element element) { | 204 bool isCalledInLoop(Element element) { |
| 205 return functionsCalledInLoop.contains(element.declaration); | 205 return functionsCalledInLoop.contains(element.declaration); |
| 206 } | 206 } |
| 207 | 207 |
| 208 SideEffects getSideEffectsOfElement(Element element) { | 208 SideEffects getSideEffectsOfElement(Element element) { |
| 209 // The type inferrer (where the side effects are being computed), |
| 210 // does not see generative constructor bodies because they are |
| 211 // created by the backend. Also, it does not make any distinction |
| 212 // between a constructor and its body for side effects. This |
| 213 // implies that currently, the side effects of a constructor body |
| 214 // contain the side effects of the initializers. |
| 215 assert(!element.isGenerativeConstructorBody()); |
| 209 return sideEffects.putIfAbsent(element.declaration, () { | 216 return sideEffects.putIfAbsent(element.declaration, () { |
| 210 return new SideEffects(); | 217 return new SideEffects(); |
| 211 }); | 218 }); |
| 212 } | 219 } |
| 213 | 220 |
| 214 void registerSideEffects(Element element, SideEffects effects) { | 221 void registerSideEffects(Element element, SideEffects effects) { |
| 215 sideEffects[element.declaration] = effects; | 222 sideEffects[element.declaration] = effects; |
| 216 } | 223 } |
| 217 | 224 |
| 218 SideEffects getSideEffectsOfSelector(Selector selector) { | 225 SideEffects getSideEffectsOfSelector(Selector selector) { |
| 219 // We're not tracking side effects of closures. | 226 // We're not tracking side effects of closures. |
| 220 if (selector.isClosureCall()) { | 227 if (selector.isClosureCall()) { |
| 221 return new SideEffects(); | 228 return new SideEffects(); |
| 222 } | 229 } |
| 223 SideEffects sideEffects = new SideEffects.empty(); | 230 SideEffects sideEffects = new SideEffects.empty(); |
| 224 for (Element e in allFunctions.filter(selector)) { | 231 for (Element e in allFunctions.filter(selector)) { |
| 225 if (e.isField()) { | 232 if (e.isField()) { |
| 226 if (selector.isGetter()) { | 233 if (selector.isGetter()) { |
| 227 sideEffects.setDependsOnInstancePropertyStore(); | 234 sideEffects.setDependsOnInstancePropertyStore(); |
| 228 } else if (selector.isSetter()) { | 235 } else if (selector.isSetter()) { |
| 229 sideEffects.setChangesInstanceProperty(); | 236 sideEffects.setChangesInstanceProperty(); |
| 230 } | 237 } |
| 231 } | 238 } |
| 232 sideEffects.add(getSideEffectsOfElement(e)); | 239 sideEffects.add(getSideEffectsOfElement(e)); |
| 233 } | 240 } |
| 234 return sideEffects; | 241 return sideEffects; |
| 235 } | 242 } |
| 236 } | 243 } |
| OLD | NEW |