Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'dart:collection' | 7 import 'dart:collection' |
| 8 show LinkedHashMap, | 8 show LinkedHashMap, |
| 9 LinkedHashSet; | 9 LinkedHashSet; |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 if (deferredLibraries.isEmpty) return; | 76 if (deferredLibraries.isEmpty) return; |
| 77 | 77 |
| 78 // TODO(ahe): Enforce the following invariants on | 78 // TODO(ahe): Enforce the following invariants on |
| 79 // [deferredElements] and [eagerElements]: | 79 // [deferredElements] and [eagerElements]: |
| 80 // 1. Only static or top-level elements are recorded. | 80 // 1. Only static or top-level elements are recorded. |
| 81 // 2. Only implementation is stored. | 81 // 2. Only implementation is stored. |
| 82 Map<LibraryElement, Set<Element>> deferredElements = | 82 Map<LibraryElement, Set<Element>> deferredElements = |
| 83 new LinkedHashMap<LibraryElement, Set<Element>>(); | 83 new LinkedHashMap<LibraryElement, Set<Element>>(); |
| 84 Set<Element> eagerElements = new LinkedHashSet<Element>(); | 84 Set<Element> eagerElements = new LinkedHashSet<Element>(); |
| 85 | 85 |
| 86 // Iterate through the local members of the main script. Create | 86 // Iterate through live local members of the main script. Create |
| 87 // a root-set of elements that must be loaded eagerly | 87 // a root-set of elements that must be loaded eagerly |
| 88 // (everything that is directly referred to from the main | 88 // (everything that is directly referred to from the main |
| 89 // script, but not imported from a deferred library), as well as | 89 // script, but not imported from a deferred library), as well as |
| 90 // root-sets for deferred libraries. | 90 // root-sets for deferred libraries. |
| 91 mainApp.forEachLocalMember((Element e) { | 91 mainApp.forEachLocalMember((Element e) { |
| 92 for (Element dependency in allElementsResolvedFrom(e)) { | 92 if (compiler.enqueuer.resolution.isLive(e)) { |
| 93 if (isExplicitlyDeferred(dependency)) { | 93 for (Element dependency in allElementsResolvedFrom(e)) { |
| 94 Set<Element> deferredElementsFromLibrary = | 94 if (isExplicitlyDeferred(dependency)) { |
| 95 deferredElements.putIfAbsent( | 95 Set<Element> deferredElementsFromLibrary = |
| 96 dependency.getLibrary(), | 96 deferredElements.putIfAbsent( |
| 97 () => new LinkedHashSet<Element>()); | 97 dependency.getLibrary(), |
| 98 deferredElementsFromLibrary.add(dependency); | 98 () => new LinkedHashSet<Element>()); |
| 99 } else if (dependency.getLibrary() != mainApp) { | 99 deferredElementsFromLibrary.add(dependency); |
| 100 eagerElements.add(dependency.implementation); | 100 } else if (dependency.getLibrary() != mainApp) { |
| 101 eagerElements.add(dependency.implementation); | |
| 102 } | |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 }); | 105 }); |
| 104 | 106 |
| 105 // Also add "global" dependencies to the eager root-set. These | 107 // Also add "global" dependencies to the eager root-set. These |
| 106 // are things that the backend need but cannot associate with a | 108 // are things that the backend need but cannot associate with a |
| 107 // particular element, for example, startRootIsolate. This set | 109 // particular element, for example, startRootIsolate. This set |
| 108 // also contains elements for which we lack precise information. | 110 // also contains elements for which we lack precise information. |
| 109 eagerElements.addAll(compiler.globalDependencies.otherDependencies); | 111 eagerElements.addAll(compiler.globalDependencies.otherDependencies); |
| 110 | 112 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 // When instantiating a class, we record a reference to the | 148 // When instantiating a class, we record a reference to the |
| 147 // constructor, not the class itself. We must add all the | 149 // constructor, not the class itself. We must add all the |
| 148 // instance members of the constructor's class (see below). | 150 // instance members of the constructor's class (see below). |
| 149 result.addAll( | 151 result.addAll( |
| 150 allElementsResolvedFrom(element.getEnclosingClass().implementation)); | 152 allElementsResolvedFrom(element.getEnclosingClass().implementation)); |
| 151 } | 153 } |
| 152 if (element.isClass()) { | 154 if (element.isClass()) { |
| 153 // If we see a class, add everything its instance members refer | 155 // If we see a class, add everything its instance members refer |
| 154 // to. Static members are not relevant. | 156 // to. Static members are not relevant. |
| 155 ClassElement cls = element.declaration; | 157 ClassElement cls = element.declaration; |
| 156 cls.forEachLocalMember((Element e) { | 158 // Make sure that class has been used - type has been computed. |
| 157 if (!e.isInstanceMember()) return; | 159 if (cls.thisType != null) { |
|
ahe
2013/08/08 11:36:51
Can you revert this part of the change now?
| |
| 158 result.addAll(DependencyCollector.collect(e.implementation, compiler)); | 160 cls.forEachLocalMember((Element e) { |
| 159 }); | |
| 160 if (cls.implementation != cls) { | |
| 161 // TODO(ahe): Why doesn't ClassElement.forEachLocalMember do this? | |
| 162 cls.implementation.forEachLocalMember((Element e) { | |
| 163 if (!e.isInstanceMember()) return; | 161 if (!e.isInstanceMember()) return; |
| 164 result.addAll(DependencyCollector.collect(e.implementation, | 162 result.addAll(DependencyCollector.collect(e.implementation, compiler)) ; |
| 165 compiler)); | |
| 166 }); | 163 }); |
| 164 if (cls.implementation != cls) { | |
| 165 // TODO(ahe): Why doesn't ClassElement.forEachLocalMember do this? | |
| 166 cls.implementation.forEachLocalMember((Element e) { | |
| 167 if (!e.isInstanceMember()) return; | |
| 168 result.addAll(DependencyCollector.collect(e.implementation, | |
| 169 compiler)); | |
| 170 }); | |
| 171 } | |
| 172 for (var type in cls.allSupertypes) { | |
| 173 result.add(type.element.implementation); | |
| 174 } | |
| 175 result.add(cls.implementation); | |
| 167 } | 176 } |
| 168 for (var type in cls.allSupertypes) { | |
| 169 result.add(type.element.implementation); | |
| 170 } | |
| 171 result.add(cls.implementation); | |
| 172 } else if (Elements.isStaticOrTopLevel(element) | 177 } else if (Elements.isStaticOrTopLevel(element) |
| 173 || element.isConstructor()) { | 178 || element.isConstructor()) { |
| 174 result.addAll(DependencyCollector.collect(element, compiler)); | 179 result.addAll(DependencyCollector.collect(element, compiler)); |
| 175 } | 180 } |
| 176 // Other elements, in particular instance members, are ignored as | 181 // Other elements, in particular instance members, are ignored as |
| 177 // they are processed as part of the class. | 182 // they are processed as part of the class. |
| 178 return result; | 183 return result; |
| 179 } | 184 } |
| 180 | 185 |
| 181 void addTransitiveClosureTo(Set<Element> elements) { | 186 void addTransitiveClosureTo(Set<Element> elements) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 compiler.enqueuer.resolution.getCachedElements(element); | 247 compiler.enqueuer.resolution.getCachedElements(element); |
| 243 if (elements == null) return new LinkedHashSet<Element>(); | 248 if (elements == null) return new LinkedHashSet<Element>(); |
| 244 Node node = element.parseNode(compiler); | 249 Node node = element.parseNode(compiler); |
| 245 if (node == null) return new LinkedHashSet<Element>(); | 250 if (node == null) return new LinkedHashSet<Element>(); |
| 246 var collector = new DependencyCollector(elements, compiler); | 251 var collector = new DependencyCollector(elements, compiler); |
| 247 node.accept(collector); | 252 node.accept(collector); |
| 248 collector.dependencies.addAll(elements.otherDependencies); | 253 collector.dependencies.addAll(elements.otherDependencies); |
| 249 return collector.dependencies; | 254 return collector.dependencies; |
| 250 } | 255 } |
| 251 } | 256 } |
| OLD | NEW |