Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: pkg/analyzer/lib/src/context/context.dart

Issue 1144023009: Adapt the existing incremental resolution implementation to the new model. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/instrumentation/instrumentation.dart';
10 import 'package:analyzer/src/cancelable_future.dart'; 11 import 'package:analyzer/src/cancelable_future.dart';
11 import 'package:analyzer/src/context/cache.dart'; 12 import 'package:analyzer/src/context/cache.dart';
12 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
13 import 'package:analyzer/src/generated/constant.dart'; 14 import 'package:analyzer/src/generated/constant.dart';
14 import 'package:analyzer/src/generated/element.dart'; 15 import 'package:analyzer/src/generated/element.dart';
15 import 'package:analyzer/src/generated/engine.dart' 16 import 'package:analyzer/src/generated/engine.dart'
16 hide 17 hide
17 AnalysisCache, 18 AnalysisCache,
18 CachePartition, 19 CachePartition,
19 SdkCachePartition, 20 SdkCachePartition,
20 UniversalCachePartition, 21 UniversalCachePartition,
21 WorkManager; 22 WorkManager;
22 import 'package:analyzer/src/generated/error.dart'; 23 import 'package:analyzer/src/generated/error.dart';
23 import 'package:analyzer/src/generated/html.dart' as ht; 24 import 'package:analyzer/src/generated/html.dart' as ht;
25 import 'package:analyzer/src/generated/incremental_resolver.dart';
24 import 'package:analyzer/src/generated/java_core.dart'; 26 import 'package:analyzer/src/generated/java_core.dart';
25 import 'package:analyzer/src/generated/java_engine.dart'; 27 import 'package:analyzer/src/generated/java_engine.dart';
26 import 'package:analyzer/src/generated/resolver.dart'; 28 import 'package:analyzer/src/generated/resolver.dart';
27 import 'package:analyzer/src/generated/scanner.dart'; 29 import 'package:analyzer/src/generated/scanner.dart';
28 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 30 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
29 import 'package:analyzer/src/generated/source.dart'; 31 import 'package:analyzer/src/generated/source.dart';
30 import 'package:analyzer/src/generated/utilities_collection.dart'; 32 import 'package:analyzer/src/generated/utilities_collection.dart';
31 import 'package:analyzer/src/task/dart.dart'; 33 import 'package:analyzer/src/task/dart.dart';
32 import 'package:analyzer/src/task/dart_work_manager.dart'; 34 import 'package:analyzer/src/task/dart_work_manager.dart';
33 import 'package:analyzer/src/task/driver.dart'; 35 import 'package:analyzer/src/task/driver.dart';
(...skipping 15 matching lines...) Expand all
49 * it should be free of side effects so that it doesn't cause reentrant changes 51 * it should be free of side effects so that it doesn't cause reentrant changes
50 * to the analysis state. 52 * to the analysis state.
51 */ 53 */
52 typedef T PendingFutureComputer<T>(CacheEntry entry); 54 typedef T PendingFutureComputer<T>(CacheEntry entry);
53 55
54 /** 56 /**
55 * An [AnalysisContext] in which analysis can be performed. 57 * An [AnalysisContext] in which analysis can be performed.
56 */ 58 */
57 class AnalysisContextImpl implements InternalAnalysisContext { 59 class AnalysisContextImpl implements InternalAnalysisContext {
58 /** 60 /**
61 * The next context identifier.
62 */
63 static int _NEXT_ID = 0;
64
65 /**
66 * The unique identifier of this context.
67 */
68 final int _id = _NEXT_ID++;
69
70 /**
59 * A client-provided name used to identify this context, or `null` if the 71 * A client-provided name used to identify this context, or `null` if the
60 * client has not provided a name. 72 * client has not provided a name.
61 */ 73 */
62 String name; 74 String name;
63 75
64 /** 76 /**
65 * The set of analysis options controlling the behavior of this context. 77 * The set of analysis options controlling the behavior of this context.
66 */ 78 */
67 AnalysisOptionsImpl _options = new AnalysisOptionsImpl(); 79 AnalysisOptionsImpl _options = new AnalysisOptionsImpl();
68 80
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 } 984 }
973 } 985 }
974 if (notify && changed) { 986 if (notify && changed) {
975 _onSourcesChangedController 987 _onSourcesChangedController
976 .add(new SourcesChangedEvent.changedContent(source, newContents)); 988 .add(new SourcesChangedEvent.changedContent(source, newContents));
977 } 989 }
978 return changed; 990 return changed;
979 } 991 }
980 992
981 @override 993 @override
994 void invalidateLibraryHints(Source librarySource) {
995 List<Source> sources = _cache.getValue(librarySource, UNITS);
996 if (sources != null) {
997 for (Source source in sources) {
998 getCacheEntry(source).setState(HINTS, CacheState.INVALID);
999 }
1000 }
1001 }
1002
1003 @override
982 bool isClientLibrary(Source librarySource) { 1004 bool isClientLibrary(Source librarySource) {
983 CacheEntry entry = _cache.get(librarySource); 1005 CacheEntry entry = _cache.get(librarySource);
984 return entry.getValue(IS_CLIENT) && entry.getValue(IS_LAUNCHABLE); 1006 return entry.getValue(IS_CLIENT) && entry.getValue(IS_LAUNCHABLE);
985 } 1007 }
986 1008
987 @override 1009 @override
988 bool isServerLibrary(Source librarySource) { 1010 bool isServerLibrary(Source librarySource) {
989 CacheEntry entry = _cache.get(librarySource); 1011 CacheEntry entry = _cache.get(librarySource);
990 return !entry.getValue(IS_CLIENT) && entry.getValue(IS_LAUNCHABLE); 1012 return !entry.getValue(IS_CLIENT) && entry.getValue(IS_LAUNCHABLE);
991 } 1013 }
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 */ 1716 */
1695 void _sourceRemoved(Source source) { 1717 void _sourceRemoved(Source source) {
1696 _cache.remove(source); 1718 _cache.remove(source);
1697 _removeFromPriorityOrder(source); 1719 _removeFromPriorityOrder(source);
1698 } 1720 }
1699 1721
1700 /** 1722 /**
1701 * TODO(scheglov) A hackish, limited incremental resolution implementation. 1723 * TODO(scheglov) A hackish, limited incremental resolution implementation.
1702 */ 1724 */
1703 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) { 1725 bool _tryPoorMansIncrementalResolution(Source unitSource, String newCode) {
1704 // TODO(brianwilkerson) Implement this. 1726 return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() {
1705 return false; 1727 incrementalResolutionValidation_lastUnitSource = null;
1706 // return PerformanceStatistics.incrementalAnalysis.makeCurrentWhile(() { 1728 incrementalResolutionValidation_lastLibrarySource = null;
1707 // incrementalResolutionValidation_lastUnitSource = null; 1729 incrementalResolutionValidation_lastUnit = null;
1708 // incrementalResolutionValidation_lastLibrarySource = null; 1730 // prepare the entry
1709 // incrementalResolutionValidation_lastUnit = null; 1731 CacheEntry sourceEntry = _cache.get(unitSource);
1710 // // prepare the entry 1732 if (sourceEntry == null) {
1711 // cache.CacheEntry entry = _cache.get(unitSource); 1733 return false;
1712 // if (entry == null) { 1734 }
1713 // return false; 1735 // prepare the (only) library source
1714 // } 1736 List<Source> librarySources = getLibrariesContaining(unitSource);
1715 // // prepare the (only) library source 1737 if (librarySources.length != 1) {
1716 // List<Source> librarySources = getLibrariesContaining(unitSource); 1738 return false;
1717 // if (librarySources.length != 1) { 1739 }
1718 // return false; 1740 Source librarySource = librarySources[0];
1719 // } 1741 CacheEntry unitEntry =
1720 // Source librarySource = librarySources[0]; 1742 _cache.get(new LibrarySpecificUnit(librarySource, unitSource));
1721 // // prepare the library element 1743 if (unitEntry == null) {
1722 // LibraryElement libraryElement = getLibraryElement(librarySource); 1744 return false;
1723 // if (libraryElement == null) { 1745 }
1724 // return false; 1746 // prepare the library element
1725 // } 1747 LibraryElement libraryElement = getLibraryElement(librarySource);
1726 // // prepare the existing unit 1748 if (libraryElement == null) {
1727 // CompilationUnit oldUnit = 1749 return false;
1728 // getResolvedCompilationUnit2(unitSource, librarySource); 1750 }
1729 // if (oldUnit == null) { 1751 // prepare the existing unit
1730 // return false; 1752 CompilationUnit oldUnit =
1731 // } 1753 getResolvedCompilationUnit2(unitSource, librarySource);
1732 // // do resolution 1754 if (oldUnit == null) {
1733 // Stopwatch perfCounter = new Stopwatch()..start(); 1755 return false;
1734 // PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( 1756 }
1735 // typeProvider, unitSource, entry, oldUnit, 1757 // do resolution
1736 // analysisOptions.incrementalApi, analysisOptions); 1758 Stopwatch perfCounter = new Stopwatch()..start();
1737 // bool success = resolver.resolve(newCode); 1759 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver(
1738 // AnalysisEngine.instance.instrumentationService.logPerformance( 1760 typeProvider, unitSource, null, sourceEntry, unitEntry, oldUnit,
1739 // AnalysisPerformanceKind.INCREMENTAL, perfCounter, 1761 analysisOptions.incrementalApi, analysisOptions);
1740 // 'success=$success,context_id=$_id,code_length=${newCode.length}'); 1762 bool success = resolver.resolve(newCode);
1741 // if (!success) { 1763 AnalysisEngine.instance.instrumentationService.logPerformance(
1742 // return false; 1764 AnalysisPerformanceKind.INCREMENTAL, perfCounter,
1743 // } 1765 'success=$success,context_id=$_id,code_length=${newCode.length}');
1744 // // if validation, remember the result, but throw it away 1766 if (!success) {
1745 // if (analysisOptions.incrementalValidation) { 1767 return false;
1746 // incrementalResolutionValidation_lastUnitSource = oldUnit.element.sourc e; 1768 }
1747 // incrementalResolutionValidation_lastLibrarySource = 1769 // if validation, remember the result, but throw it away
1748 // oldUnit.element.library.source; 1770 if (analysisOptions.incrementalValidation) {
1749 // incrementalResolutionValidation_lastUnit = oldUnit; 1771 incrementalResolutionValidation_lastUnitSource = oldUnit.element.source;
1750 // return false; 1772 incrementalResolutionValidation_lastLibrarySource =
1751 // } 1773 oldUnit.element.library.source;
1752 // // prepare notice 1774 incrementalResolutionValidation_lastUnit = oldUnit;
1753 // { 1775 return false;
1754 // LineInfo lineInfo = getLineInfo(unitSource); 1776 }
1755 // ChangeNoticeImpl notice = _getNotice(unitSource); 1777 // prepare notice
1756 // notice.resolvedDartUnit = oldUnit; 1778 {
1757 // notice.setErrors(entry.allErrors, lineInfo); 1779 ChangeNoticeImpl notice = getNotice(unitSource);
1758 // } 1780 notice.resolvedDartUnit = oldUnit;
1759 // // OK 1781 AnalysisErrorInfo errorInfo = getErrors(unitSource);
1760 // return true; 1782 notice.setErrors(errorInfo.errors, errorInfo.lineInfo);
1761 // }); 1783 }
1784 // schedule
1785 dartWorkManager.unitIncrementallyResolved(librarySource, unitSource);
1786 // OK
1787 return true;
1788 });
1762 } 1789 }
1763 1790
1764 /** 1791 /**
1765 * Check the cache for any invalid entries (entries whose modification time 1792 * Check the cache for any invalid entries (entries whose modification time
1766 * does not match the modification time of the source associated with the 1793 * does not match the modification time of the source associated with the
1767 * entry). Invalid entries will be marked as invalid so that the source will 1794 * entry). Invalid entries will be marked as invalid so that the source will
1768 * be re-analyzed. Return `true` if at least one entry was invalid. 1795 * be re-analyzed. Return `true` if at least one entry was invalid.
1769 */ 1796 */
1770 bool _validateCacheConsistency() { 1797 bool _validateCacheConsistency() {
1771 int consistencyCheckStart = JavaSystem.nanoTime(); 1798 int consistencyCheckStart = JavaSystem.nanoTime();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 PendingFuture pendingFuture = 2024 PendingFuture pendingFuture =
1998 new PendingFuture<T>(_context, target, computeValue); 2025 new PendingFuture<T>(_context, target, computeValue);
1999 if (!pendingFuture.evaluate(entry)) { 2026 if (!pendingFuture.evaluate(entry)) {
2000 _context._pendingFutureTargets 2027 _context._pendingFutureTargets
2001 .putIfAbsent(target, () => <PendingFuture>[]) 2028 .putIfAbsent(target, () => <PendingFuture>[])
2002 .add(pendingFuture); 2029 .add(pendingFuture);
2003 } 2030 }
2004 return pendingFuture.future; 2031 return pendingFuture.future;
2005 } 2032 }
2006 } 2033 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698