| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 ImportElementImpl importElement = new ImportElementImpl(-1); | 827 ImportElementImpl importElement = new ImportElementImpl(-1); |
| 828 importElement.importedLibrary = importLibraryMap[coreLibrarySource]; | 828 importElement.importedLibrary = importLibraryMap[coreLibrarySource]; |
| 829 importElement.synthetic = true; | 829 importElement.synthetic = true; |
| 830 imports.add(importElement); | 830 imports.add(importElement); |
| 831 } | 831 } |
| 832 // | 832 // |
| 833 // Populate the library element. | 833 // Populate the library element. |
| 834 // | 834 // |
| 835 libraryElement.imports = imports; | 835 libraryElement.imports = imports; |
| 836 libraryElement.exports = exports; | 836 libraryElement.exports = exports; |
| 837 // See commentary in the computation of the LIBRARY_CYCLE result |
| 838 // for details on library cycle invalidation. |
| 839 libraryElement.invalidateLibraryCycles(); |
| 837 // | 840 // |
| 838 // Record outputs. | 841 // Record outputs. |
| 839 // | 842 // |
| 840 outputs[LIBRARY_ELEMENT2] = libraryElement; | 843 outputs[LIBRARY_ELEMENT2] = libraryElement; |
| 841 outputs[BUILD_DIRECTIVES_ERRORS] = errors; | 844 outputs[BUILD_DIRECTIVES_ERRORS] = errors; |
| 842 } | 845 } |
| 843 | 846 |
| 844 /** | 847 /** |
| 845 * Return a map from the names of the inputs of this kind of task to the task | 848 * Return a map from the names of the inputs of this kind of task to the task |
| 846 * input descriptors describing those inputs for a task with the | 849 * input descriptors describing those inputs for a task with the |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 | 1838 |
| 1836 ComputeLibraryCycleTask( | 1839 ComputeLibraryCycleTask( |
| 1837 InternalAnalysisContext context, AnalysisTarget target) | 1840 InternalAnalysisContext context, AnalysisTarget target) |
| 1838 : super(context, target); | 1841 : super(context, target); |
| 1839 | 1842 |
| 1840 @override | 1843 @override |
| 1841 TaskDescriptor get descriptor => DESCRIPTOR; | 1844 TaskDescriptor get descriptor => DESCRIPTOR; |
| 1842 | 1845 |
| 1843 @override | 1846 @override |
| 1844 void internalPerform() { | 1847 void internalPerform() { |
| 1848 // The computation of library cycles is necessarily non-local, since we |
| 1849 // in general have to look at all of the reachable libraries |
| 1850 // in order to find the strongly connected components. Repeating this |
| 1851 // computation for every node would be quadratic. The libraryCycle getter |
| 1852 // will avoid this by computing the library cycles for every reachable |
| 1853 // library and recording it in the element model. This means that this |
| 1854 // task implicitly produces the output for many other targets. This |
| 1855 // can't be expressed in the task model right now: instead, we just |
| 1856 // run tasks for those other targets, and they pick up the recorded |
| 1857 // version off of the element model. Unfortunately, this means that |
| 1858 // the task model will not handle the invalidation of the recorded |
| 1859 // results for us. Instead, we must explicitly invalidate the recorded |
| 1860 // library cycle information when we add or subtract edges from the |
| 1861 // import/export graph. Any update that changes the |
| 1862 // import/export graph will induce a recomputation of the LIBRARY_ELEMENT2 |
| 1863 // result for the changed node. This recomputation is responsible for |
| 1864 // conservatively invalidating the library cycle information recorded |
| 1865 // in the element model. The LIBRARY_CYCLE results that have been cached |
| 1866 // by the task model are conservatively invalidated by the |
| 1867 // IMPORT_EXPORT_SOURCE_CLOSURE dependency below. If anything reachable |
| 1868 // from a node is changed, its LIBRARY_CYCLE results will be re-computed |
| 1869 // here (possibly re-using the result from the element model if invalidation |
| 1870 // did not cause it to be erased). In summary, task model dependencies |
| 1871 // on the import/export source closure ensure that this method will be |
| 1872 // re-run if anything reachable from this target has been invalidated, |
| 1873 // and the invalidation code (invalidateLibraryCycles) will ensure that |
| 1874 // element model results will be re-used here only if they are still valid. |
| 1845 if (context.analysisOptions.strongMode) { | 1875 if (context.analysisOptions.strongMode) { |
| 1846 LibraryElementImpl library = getRequiredInput(LIBRARY_ELEMENT_INPUT); | 1876 LibraryElementImpl library = getRequiredInput(LIBRARY_ELEMENT_INPUT); |
| 1847 List<LibraryElement> component = library.libraryCycle; | 1877 List<LibraryElement> component = library.libraryCycle; |
| 1848 Set<LibraryElement> filter = new Set<LibraryElement>.from(component); | 1878 Set<LibraryElement> filter = new Set<LibraryElement>.from(component); |
| 1849 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>(); | 1879 Set<CompilationUnitElement> deps = new Set<CompilationUnitElement>(); |
| 1850 void addLibrary(l) { | 1880 void addLibrary(l) { |
| 1851 if (!filter.contains(l)) { | 1881 if (!filter.contains(l)) { |
| 1852 deps.addAll(l.units); | 1882 deps.addAll(l.units); |
| 1853 } | 1883 } |
| 1854 } | 1884 } |
| 1855 for (LibraryElement l in component) { | 1885 for (LibraryElement l in component) { |
| 1856 l.importedLibraries.forEach(addLibrary); | 1886 l.importedLibraries.forEach(addLibrary); |
| 1857 l.exportedLibraries.forEach(addLibrary); | 1887 l.exportedLibraries.forEach(addLibrary); |
| 1858 } | 1888 } |
| 1859 | |
| 1860 // | 1889 // |
| 1861 // Record outputs. | 1890 // Record outputs. |
| 1862 // | 1891 // |
| 1863 outputs[LIBRARY_CYCLE] = component; | 1892 outputs[LIBRARY_CYCLE] = component; |
| 1864 outputs[LIBRARY_CYCLE_UNITS] = component.expand((l) => l.units).toList(); | 1893 outputs[LIBRARY_CYCLE_UNITS] = component.expand((l) => l.units).toList(); |
| 1865 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.toList(); | 1894 outputs[LIBRARY_CYCLE_DEPENDENCIES] = deps.toList(); |
| 1866 } else { | 1895 } else { |
| 1867 outputs[LIBRARY_CYCLE] = []; | 1896 outputs[LIBRARY_CYCLE] = []; |
| 1868 outputs[LIBRARY_CYCLE_UNITS] = []; | 1897 outputs[LIBRARY_CYCLE_UNITS] = []; |
| 1869 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; | 1898 outputs[LIBRARY_CYCLE_DEPENDENCIES] = []; |
| (...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4545 | 4574 |
| 4546 @override | 4575 @override |
| 4547 bool moveNext() { | 4576 bool moveNext() { |
| 4548 if (_newSources.isEmpty) { | 4577 if (_newSources.isEmpty) { |
| 4549 return false; | 4578 return false; |
| 4550 } | 4579 } |
| 4551 currentTarget = _newSources.removeLast(); | 4580 currentTarget = _newSources.removeLast(); |
| 4552 return true; | 4581 return true; |
| 4553 } | 4582 } |
| 4554 } | 4583 } |
| OLD | NEW |