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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2678193002: Not task based analysis. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 import 'package:analyzer/context/declared_variables.dart'; 9 import 'package:analyzer/context/declared_variables.dart';
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
11 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement; 11 import 'package:analyzer/dart/element/element.dart' show CompilationUnitElement;
12 import 'package:analyzer/error/error.dart'; 12 import 'package:analyzer/error/error.dart';
13 import 'package:analyzer/error/listener.dart'; 13 import 'package:analyzer/error/listener.dart';
14 import 'package:analyzer/exception/exception.dart'; 14 import 'package:analyzer/exception/exception.dart';
15 import 'package:analyzer/file_system/file_system.dart'; 15 import 'package:analyzer/file_system/file_system.dart';
16 import 'package:analyzer/src/dart/analysis/analysis_impl.dart';
16 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 17 import 'package:analyzer/src/dart/analysis/byte_store.dart';
17 import 'package:analyzer/src/dart/analysis/file_state.dart'; 18 import 'package:analyzer/src/dart/analysis/file_state.dart';
18 import 'package:analyzer/src/dart/analysis/file_tracker.dart'; 19 import 'package:analyzer/src/dart/analysis/file_tracker.dart';
19 import 'package:analyzer/src/dart/analysis/index.dart'; 20 import 'package:analyzer/src/dart/analysis/index.dart';
20 import 'package:analyzer/src/dart/analysis/library_context.dart'; 21 import 'package:analyzer/src/dart/analysis/library_context.dart';
21 import 'package:analyzer/src/dart/analysis/search.dart'; 22 import 'package:analyzer/src/dart/analysis/search.dart';
22 import 'package:analyzer/src/dart/analysis/status.dart'; 23 import 'package:analyzer/src/dart/analysis/status.dart';
23 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart'; 24 import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
24 import 'package:analyzer/src/generated/engine.dart' 25 import 'package:analyzer/src/generated/engine.dart'
25 show AnalysisContext, AnalysisEngine, AnalysisOptions; 26 show AnalysisContext, AnalysisEngine, AnalysisOptions;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 * from file paths. 129 * from file paths.
129 */ 130 */
130 SourceFactory _sourceFactory; 131 SourceFactory _sourceFactory;
131 132
132 /** 133 /**
133 * The declared environment variables. 134 * The declared environment variables.
134 */ 135 */
135 final DeclaredVariables declaredVariables = new DeclaredVariables(); 136 final DeclaredVariables declaredVariables = new DeclaredVariables();
136 137
137 /** 138 /**
139 * If `true`, then analysis should be done without using tasks model.
140 */
141 final bool analyzeWithoutTasks;
142
143 /**
138 * The salt to mix into all hashes used as keys for serialized data. 144 * The salt to mix into all hashes used as keys for serialized data.
139 */ 145 */
140 final Uint32List _salt = new Uint32List(1 + AnalysisOptions.signatureLength); 146 final Uint32List _salt = new Uint32List(1 + AnalysisOptions.signatureLength);
141 147
142 /** 148 /**
143 * The set of priority files, that should be analyzed sooner. 149 * The set of priority files, that should be analyzed sooner.
144 */ 150 */
145 final _priorityFiles = new LinkedHashSet<String>(); 151 final _priorityFiles = new LinkedHashSet<String>();
146 152
147 /** 153 /**
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 */ 233 */
228 AnalysisDriver( 234 AnalysisDriver(
229 this._scheduler, 235 this._scheduler,
230 PerformanceLog logger, 236 PerformanceLog logger,
231 this._resourceProvider, 237 this._resourceProvider,
232 this._byteStore, 238 this._byteStore,
233 this._contentOverlay, 239 this._contentOverlay,
234 this.name, 240 this.name,
235 SourceFactory sourceFactory, 241 SourceFactory sourceFactory,
236 this._analysisOptions, 242 this._analysisOptions,
237 {PackageBundle sdkBundle}) 243 {PackageBundle sdkBundle,
244 this.analyzeWithoutTasks: false})
238 : _logger = logger, 245 : _logger = logger,
239 _sourceFactory = sourceFactory.clone(), 246 _sourceFactory = sourceFactory.clone(),
240 _sdkBundle = sdkBundle { 247 _sdkBundle = sdkBundle {
241 _testView = new AnalysisDriverTestView(this); 248 _testView = new AnalysisDriverTestView(this);
242 _createFileTracker(logger); 249 _createFileTracker(logger);
243 _scheduler._add(this); 250 _scheduler._add(this);
244 _search = new Search(this); 251 _search = new Search(this);
245 } 252 }
246 253
247 /** 254 /**
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 if (bytes != null) { 697 if (bytes != null) {
691 return _getAnalysisResultFromBytes(file, bytes); 698 return _getAnalysisResultFromBytes(file, bytes);
692 } 699 }
693 } 700 }
694 701
695 // We need the fully resolved unit, or the result is not cached. 702 // We need the fully resolved unit, or the result is not cached.
696 return _logger.run('Compute analysis result for $path', () { 703 return _logger.run('Compute analysis result for $path', () {
697 FileState file = _fileTracker.verifyApiSignature(path); 704 FileState file = _fileTracker.verifyApiSignature(path);
698 705
699 // Prepare the library file - the file itself, or the known library. 706 // Prepare the library file - the file itself, or the known library.
700 FileState libraryFile = getLibraryFile(file); 707 FileState library = getLibraryFile(file);
701 if (libraryFile == null) { 708 if (library == null) {
702 return null; 709 return null;
703 } 710 }
704 711
705 try { 712 try {
706 LibraryContext libraryContext = _createLibraryContext(libraryFile); 713 LibraryContext libraryContext = _createLibraryContext(library);
707 try { 714 try {
708 var resolutionResult = 715 CompilationUnit resolvedUnit;
709 libraryContext.resolveUnit(libraryFile.source, file.source); 716 List<int> bytes;
710 CompilationUnit resolvedUnit = resolutionResult.resolvedUnit; 717 if (analyzeWithoutTasks) {
711 List<AnalysisError> errors = resolutionResult.errors; 718 AnalyzerImpl analyzer = new AnalyzerImpl(analysisOptions,
712 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit); 719 sourceFactory, _fileTracker.fsState, libraryContext.store);
720 Map<FileState, UnitAnalysisResult> results =
721 analyzer.analyze(library);
722 UnitAnalysisResult fileResult = results[file];
723 resolvedUnit = fileResult.unit;
713 724
714 // Store the result into the cache. 725 // Store the result into the cache.
715 List<int> bytes; 726 bytes = _storeResolvedUnit(
716 { 727 library, file, resolvedUnit, fileResult.errors);
717 bytes = new AnalysisDriverResolvedUnitBuilder( 728 } else {
718 errors: errors 729 ResolutionResult resolutionResult =
719 .map((error) => new AnalysisDriverUnitErrorBuilder( 730 libraryContext.resolveUnit(library.source, file.source);
720 offset: error.offset, 731 resolvedUnit = resolutionResult.resolvedUnit;
721 length: error.length, 732 List<AnalysisError> errors = resolutionResult.errors;
722 uniqueName: error.errorCode.uniqueName, 733
723 message: error.message, 734 // Store the result into the cache.
724 correction: error.correction)) 735 bytes = _storeResolvedUnit(library, file, resolvedUnit, errors);
725 .toList(),
726 index: index)
727 .toBuffer();
728 String key = _getResolvedUnitKey(libraryFile, file);
729 _byteStore.put(key, bytes);
730 } 736 }
731 737
732 // Return the result, full or partial. 738 // Return the result, full or partial.
733 _logger.writeln('Computed new analysis result.'); 739 _logger.writeln('Computed new analysis result.');
734 AnalysisResult result = _getAnalysisResultFromBytes(file, bytes, 740 AnalysisResult result = _getAnalysisResultFromBytes(file, bytes,
735 content: withUnit ? file.content : null, 741 content: withUnit ? file.content : null,
736 withErrors: _fileTracker.addedFiles.contains(path), 742 withErrors: _fileTracker.addedFiles.contains(path),
737 resolvedUnit: withUnit ? resolvedUnit : null); 743 resolvedUnit: withUnit ? resolvedUnit : null);
738 if (withUnit && _priorityFiles.contains(path)) { 744 if (withUnit && _priorityFiles.contains(path)) {
739 _priorityResults[path] = result; 745 _priorityResults[path] = result;
740 } 746 }
741 return result; 747 return result;
742 } finally { 748 } finally {
743 libraryContext.dispose(); 749 libraryContext.dispose();
744 } 750 }
745 } catch (exception, stackTrace) { 751 } catch (exception, stackTrace) {
746 String contextKey = 752 String contextKey =
747 _storeExceptionContext(path, libraryFile, exception, stackTrace); 753 _storeExceptionContext(path, library, exception, stackTrace);
748 throw new _ExceptionState(exception, stackTrace, contextKey); 754 throw new _ExceptionState(exception, stackTrace, contextKey);
749 } 755 }
750 }); 756 });
751 } 757 }
752 758
753 AnalysisDriverUnitIndex _computeIndex(String path) { 759 AnalysisDriverUnitIndex _computeIndex(String path) {
754 AnalysisResult analysisResult = _computeAnalysisResult(path, 760 AnalysisResult analysisResult = _computeAnalysisResult(path,
755 withUnit: false, asIsIfPartWithoutLibrary: true); 761 withUnit: false, asIsIfPartWithoutLibrary: true);
756 return analysisResult._index; 762 return analysisResult._index;
757 } 763 }
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 String sec = _twoDigits(time.second); 1108 String sec = _twoDigits(time.second);
1103 String ms = _threeDigits(time.millisecond); 1109 String ms = _threeDigits(time.millisecond);
1104 String key = 'exception_${time.year}$m$d' '_$h$min$sec' + '_$ms'; 1110 String key = 'exception_${time.year}$m$d' '_$h$min$sec' + '_$ms';
1105 1111
1106 _byteStore.put(key, bytes); 1112 _byteStore.put(key, bytes);
1107 return key; 1113 return key;
1108 } catch (_) { 1114 } catch (_) {
1109 return null; 1115 return null;
1110 } 1116 }
1111 } 1117 }
1118
1119 /**
1120 * Store the fully resolved results for the [file] in the [library] into the
1121 * cache and return the stored bytes.
1122 */
1123 List<int> _storeResolvedUnit(FileState library, FileState file,
1124 CompilationUnit resolvedUnit, List<AnalysisError> errors) {
1125 AnalysisDriverUnitIndexBuilder index = indexUnit(resolvedUnit);
1126
1127 String key = _getResolvedUnitKey(library, file);
1128 List<int> bytes = new AnalysisDriverResolvedUnitBuilder(
1129 errors: errors
1130 .map((error) => new AnalysisDriverUnitErrorBuilder(
1131 offset: error.offset,
1132 length: error.length,
1133 uniqueName: error.errorCode.uniqueName,
1134 message: error.message,
1135 correction: error.correction))
1136 .toList(),
1137 index: index)
1138 .toBuffer();
1139 _byteStore.put(key, bytes);
1140 return bytes;
1141 }
1112 } 1142 }
1113 1143
1114 /** 1144 /**
1115 * Priorities of [AnalysisDriver] work. The farther a priority to the beginning 1145 * Priorities of [AnalysisDriver] work. The farther a priority to the beginning
1116 * of the list, the earlier the corresponding [AnalysisDriver] should be asked 1146 * of the list, the earlier the corresponding [AnalysisDriver] should be asked
1117 * to perform work. 1147 * to perform work.
1118 */ 1148 */
1119 enum AnalysisDriverPriority { nothing, general, priority, interactive } 1149 enum AnalysisDriverPriority { nothing, general, priority, interactive }
1120 1150
1121 /** 1151 /**
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 libraryDeclarations.add(new TopLevelDeclarationInSource( 1782 libraryDeclarations.add(new TopLevelDeclarationInSource(
1753 file.source, declaration, isExported)); 1783 file.source, declaration, isExported));
1754 } 1784 }
1755 } 1785 }
1756 } 1786 }
1757 1787
1758 // We're not done yet. 1788 // We're not done yet.
1759 return false; 1789 return false;
1760 } 1790 }
1761 } 1791 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698