Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 'common.dart'; | 7 import 'common.dart'; |
| 8 import 'common/backend_api.dart' show | 8 import 'common/backend_api.dart' show |
| 9 Backend; | 9 Backend; |
| 10 import 'common/tasks.dart' show | 10 import 'common/tasks.dart' show |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 ElementKind, | 25 ElementKind, |
| 26 Elements, | 26 Elements, |
| 27 ExportElement, | 27 ExportElement, |
| 28 FunctionElement, | 28 FunctionElement, |
| 29 ImportElement, | 29 ImportElement, |
| 30 LibraryElement, | 30 LibraryElement, |
| 31 MetadataAnnotation, | 31 MetadataAnnotation, |
| 32 PrefixElement, | 32 PrefixElement, |
| 33 ScopeContainerElement, | 33 ScopeContainerElement, |
| 34 TypedefElement; | 34 TypedefElement; |
| 35 import 'enqueue.dart' show | |
| 36 WorldImpact; | |
| 35 import 'js_backend/js_backend.dart' show | 37 import 'js_backend/js_backend.dart' show |
| 36 JavaScriptBackend; | 38 JavaScriptBackend; |
| 37 import 'resolution/resolution.dart' show | 39 import 'resolution/resolution.dart' show |
| 38 AnalyzableElementX; | 40 AnalyzableElementX; |
| 39 import 'resolution/tree_elements.dart' show | 41 import 'resolution/tree_elements.dart' show |
| 40 TreeElements; | 42 TreeElements; |
| 41 import 'tree/tree.dart' as ast; | 43 import 'tree/tree.dart' as ast; |
| 42 import 'tree/tree.dart' show | 44 import 'tree/tree.dart' show |
| 43 Import, | 45 Import, |
| 44 LibraryTag, | 46 LibraryTag, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 /// | 292 /// |
| 291 /// The collected dependent elements and constants are are added to | 293 /// The collected dependent elements and constants are are added to |
| 292 /// [elements] and [constants] respectively. | 294 /// [elements] and [constants] respectively. |
| 293 void collectDependencies(Element element) { | 295 void collectDependencies(Element element) { |
| 294 // TODO(johnniwinther): Remove this when [AbstractFieldElement] has been | 296 // TODO(johnniwinther): Remove this when [AbstractFieldElement] has been |
| 295 // removed. | 297 // removed. |
| 296 if (element is! AstElement) return; | 298 if (element is! AstElement) return; |
| 297 AstElement astElement = element; | 299 AstElement astElement = element; |
| 298 | 300 |
| 299 // TODO(sigurdm): We want to be more specific about this - need a better | 301 // TODO(sigurdm): We want to be more specific about this - need a better |
| 300 // way to query "liveness". | 302 // way to query "liveness". |
|
sigurdm
2015/10/14 08:00:36
Move this TODO into the else-branch.
Johnni Winther
2015/10/14 08:42:16
Done.
| |
| 301 if (astElement is! TypedefElement && | 303 if (astElement.isTypedef) { |
| 302 !compiler.enqueuer.resolution.hasBeenProcessed(astElement)) { | 304 TypedefElement typdef = astElement; |
| 303 return; | 305 collectTypeDependencies(typdef.thisType); |
| 306 } else { | |
| 307 astElement = element.analyzableElement.declaration; | |
|
sigurdm
2015/10/14 08:00:36
AstElement analyzableElement = astElement.analyzab
Johnni Winther
2015/10/14 08:42:16
Done.
| |
| 308 if (!compiler.enqueuer.resolution.hasBeenProcessed(astElement)) { | |
| 309 return; | |
| 310 } | |
| 311 | |
| 312 WorldImpact worldImpact = | |
| 313 compiler.resolution.getWorldImpact(astElement); | |
| 314 elements.addAll(worldImpact.staticUses); | |
| 315 elements.addAll(worldImpact.closures); | |
| 316 for (DartType type in worldImpact.typeLiterals) { | |
| 317 if (type.isTypedef || type.isInterfaceType) { | |
| 318 elements.add(type.element); | |
| 319 } | |
| 320 } | |
| 321 for (InterfaceType type in worldImpact.instantiatedTypes) { | |
| 322 elements.add(type.element); | |
| 323 } | |
| 324 | |
| 325 TreeElements treeElements = astElement.resolvedAst.elements; | |
| 326 assert(treeElements != null); | |
| 327 | |
| 328 for (DartType type in treeElements.requiredTypes) { | |
| 329 collectTypeDependencies(type); | |
| 330 } | |
| 331 | |
| 332 treeElements.forEachConstantNode((Node node, _) { | |
| 333 // Explicitly depend on the backend constants. | |
| 334 ConstantValue value = | |
| 335 backend.constants.getConstantValueForNode(node, treeElements); | |
| 336 if (value != null) { | |
| 337 // TODO(johnniwinther): Assert that all constants have values when | |
| 338 // these are directly evaluated. | |
| 339 constants.add(value); | |
| 340 } | |
| 341 }); | |
| 304 } | 342 } |
| 305 | |
| 306 TreeElements treeElements = astElement.resolvedAst.elements; | |
| 307 | |
| 308 assert(treeElements != null); | |
| 309 | |
| 310 for (Element dependency in treeElements.allElements) { | |
| 311 if (dependency.isLocal && !dependency.isFunction) continue; | |
| 312 if (dependency.isErroneous) continue; | |
| 313 if (dependency.isTypeVariable) continue; | |
| 314 | |
| 315 elements.add(dependency); | |
| 316 } | |
| 317 | |
| 318 for (DartType type in treeElements.requiredTypes) { | |
| 319 collectTypeDependencies(type); | |
| 320 } | |
| 321 | |
| 322 treeElements.forEachConstantNode((Node node, _) { | |
| 323 // Explicitly depend on the backend constants. | |
| 324 ConstantValue value = | |
| 325 backend.constants.getConstantValueForNode(node, treeElements); | |
| 326 if (value != null) { | |
| 327 // TODO(johnniwinther): Assert that all constants have values when | |
| 328 // these are directly evaluated. | |
| 329 constants.add(value); | |
| 330 } | |
| 331 }); | |
| 332 elements.addAll(treeElements.otherDependencies); | |
| 333 } | 343 } |
| 334 | 344 |
| 335 // TODO(sigurdm): How is metadata on a patch-class handled? | 345 // TODO(sigurdm): How is metadata on a patch-class handled? |
| 336 for (MetadataAnnotation metadata in element.metadata) { | 346 for (MetadataAnnotation metadata in element.metadata) { |
| 337 ConstantValue constant = | 347 ConstantValue constant = |
| 338 backend.constants.getConstantValueForMetadata(metadata); | 348 backend.constants.getConstantValueForMetadata(metadata); |
| 339 if (constant != null) { | 349 if (constant != null) { |
| 340 constants.add(constant); | 350 constants.add(constant); |
| 341 } | 351 } |
| 342 } | 352 } |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 () => <String, dynamic>{"name": description.importingLibraryName, | 866 () => <String, dynamic>{"name": description.importingLibraryName, |
| 857 "imports": <String, List<String>>{}}); | 867 "imports": <String, List<String>>{}}); |
| 858 | 868 |
| 859 libraryMap["imports"][description.prefix] = outputUnits.map( | 869 libraryMap["imports"][description.prefix] = outputUnits.map( |
| 860 (OutputUnit outputUnit) { | 870 (OutputUnit outputUnit) { |
| 861 return backend.deferredPartFileName(outputUnit.name); | 871 return backend.deferredPartFileName(outputUnit.name); |
| 862 }).toList(); | 872 }).toList(); |
| 863 }); | 873 }); |
| 864 return mapping; | 874 return mapping; |
| 865 } | 875 } |
| 876 | |
| 877 /// Creates a textual representation of the output unit content. | |
| 878 String dump() { | |
| 879 Map<OutputUnit, List<String>> elementMap = <OutputUnit, List<String>>{}; | |
| 880 Map<OutputUnit, List<String>> constantMap = | |
| 881 <OutputUnit, List<String>>{}; | |
| 882 _elementToOutputUnit.forEach((Element element, OutputUnit output) { | |
| 883 elementMap.putIfAbsent(output, () => <String>[]).add('$element'); | |
| 884 }); | |
| 885 _constantToOutputUnit.forEach((ConstantValue value, OutputUnit output) { | |
| 886 constantMap.putIfAbsent(output, () => <String>[]) | |
| 887 .add(value.toStructuredString()); | |
| 888 }); | |
| 889 | |
| 890 StringBuffer sb = new StringBuffer(); | |
| 891 for (OutputUnit outputUnit in allOutputUnits) { | |
| 892 sb.write(outputUnit.name); | |
| 893 List<String> elements = elementMap[outputUnit]; | |
| 894 if (elements != null) { | |
| 895 sb.write('\n elements:'); | |
| 896 for (String element in elements..sort()) { | |
| 897 sb.write('\n $element'); | |
| 898 } | |
| 899 } | |
| 900 List<String> constants = constantMap[outputUnit]; | |
| 901 if (constants != null) { | |
| 902 sb.write('\n constants:'); | |
| 903 for (String value in constants..sort()) { | |
| 904 sb.write('\n $value'); | |
| 905 } | |
| 906 } | |
| 907 } | |
| 908 return sb.toString(); | |
| 909 } | |
| 910 | |
| 866 } | 911 } |
| 867 | 912 |
| 868 class ImportDescription { | 913 class ImportDescription { |
| 869 /// Relative uri to the importing library. | 914 /// Relative uri to the importing library. |
| 870 final String importingUri; | 915 final String importingUri; |
| 871 /// The prefix this import is imported as. | 916 /// The prefix this import is imported as. |
| 872 final String prefix; | 917 final String prefix; |
| 873 final LibraryElement _importingLibrary; | 918 final LibraryElement _importingLibrary; |
| 874 | 919 |
| 875 ImportDescription(ImportElement import, | 920 ImportDescription(ImportElement import, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 935 return result; | 980 return result; |
| 936 } | 981 } |
| 937 | 982 |
| 938 bool operator ==(other) { | 983 bool operator ==(other) { |
| 939 if (other is! _DeclaredDeferredImport) return false; | 984 if (other is! _DeclaredDeferredImport) return false; |
| 940 return declaration == other.declaration; | 985 return declaration == other.declaration; |
| 941 } | 986 } |
| 942 | 987 |
| 943 int get hashCode => declaration.hashCode * 17; | 988 int get hashCode => declaration.hashCode * 17; |
| 944 } | 989 } |
| OLD | NEW |