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

Side by Side Diff: pkg/front_end/lib/src/incremental_resolved_ast_generator_impl.dart

Issue 2644953002: Store a file state in the incremental resolved AST generator. (Closed)
Patch Set: Additional testing logic Created 3 years, 11 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/src/context/context.dart'; 9 import 'package:analyzer/src/context/context.dart';
10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 10 import 'package:analyzer/src/dart/analysis/byte_store.dart';
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 class IncrementalResolvedAstGeneratorImpl 45 class IncrementalResolvedAstGeneratorImpl
46 implements IncrementalResolvedAstGenerator { 46 implements IncrementalResolvedAstGenerator {
47 driver.AnalysisDriverScheduler _scheduler; 47 driver.AnalysisDriverScheduler _scheduler;
48 final _fileRepository = new FileRepository(); 48 final _fileRepository = new FileRepository();
49 _ResourceProviderProxy _resourceProvider; 49 _ResourceProviderProxy _resourceProvider;
50 driver.AnalysisDriver _driver; 50 driver.AnalysisDriver _driver;
51 bool _isInitialized = false; 51 bool _isInitialized = false;
52 final ProcessedOptions _options; 52 final ProcessedOptions _options;
53 final Uri _source; 53 final Uri _source;
54 bool _schedulerStarted = false; 54 bool _schedulerStarted = false;
55 final _fileState = <Uri, String>{};
55 56
56 IncrementalResolvedAstGeneratorImpl(this._source, this._options); 57 IncrementalResolvedAstGeneratorImpl(this._source, this._options);
57 58
58 @override 59 @override
59 Future<DeltaLibraries> computeDelta() async { 60 Future<DeltaLibraries> computeDelta() async {
60 if (!_isInitialized) { 61 if (!_isInitialized) {
61 await init(); 62 await init();
62 } 63 }
63 // The analysis driver doesn't currently support an asynchronous file API, 64 // The analysis driver doesn't currently support an asynchronous file API,
64 // so we have to find all the files first to read their contents. 65 // so we have to find all the files first to read their contents.
65 // TODO(paulberry): this is an unnecessary source of duplicate work and 66 // TODO(paulberry): this is an unnecessary source of duplicate work and
66 // should be eliminated ASAP. 67 // should be eliminated ASAP.
67 var graph = await graphForProgram([_source], _options); 68 var graph =
69 await graphForProgram([_source], _options, fileReader: _fileReader);
70 // TODO(paulberry): collect no-longer-referenced files from _fileState and
71 // _fileRepository.
68 var libraries = <Uri, ResolvedLibrary>{}; 72 var libraries = <Uri, ResolvedLibrary>{};
69 if (!_schedulerStarted) { 73 if (!_schedulerStarted) {
70 _scheduler.start(); 74 _scheduler.start();
71 _schedulerStarted = true; 75 _schedulerStarted = true;
72 } 76 }
73 // The driver will request files from dart:, even though it actually uses 77 // The driver will request files from dart:, even though it actually uses
74 // the data from the summary. TODO(paulberry): fix this. 78 // the data from the summary. TODO(paulberry): fix this.
75 _fileRepository.store(Uri.parse('dart:core'), ''); 79 _fileRepository.store(Uri.parse('dart:core'), '');
76 for (var libraryCycle in graph.topologicallySortedCycles) { 80 for (var libraryCycle in graph.topologicallySortedCycles) {
77 for (var libraryUri in libraryCycle.libraries.keys) { 81 for (var libraryUri in libraryCycle.libraries.keys) {
78 var libraryNode = libraryCycle.libraries[libraryUri]; 82 var libraryNode = libraryCycle.libraries[libraryUri];
79 var libraryContents =
80 await _options.fileSystem.entityForUri(libraryUri).readAsString();
81 _fileRepository.store(libraryUri, libraryContents);
82 for (var partUri in libraryNode.parts) { 83 for (var partUri in libraryNode.parts) {
83 var partContents = 84 // TODO(paulberry): resolve the part URI.
84 await _options.fileSystem.entityForUri(partUri).readAsString(); 85 _fileReader(partUri, partUri);
85 _fileRepository.store(partUri, partContents);
86 } 86 }
87 } 87 }
88 for (var libraryUri in libraryCycle.libraries.keys) { 88 for (var libraryUri in libraryCycle.libraries.keys) {
89 var libraryNode = libraryCycle.libraries[libraryUri]; 89 var libraryNode = libraryCycle.libraries[libraryUri];
90 var result = 90 var result =
91 await _driver.getResult(_fileRepository.pathForUri(libraryUri)); 91 await _driver.getResult(_fileRepository.pathForUri(libraryUri));
92 // TODO(paulberry): handle errors. 92 // TODO(paulberry): handle errors.
93 var definingCompilationUnit = result.unit; 93 var definingCompilationUnit = result.unit;
94 var partUnits = <Uri, CompilationUnit>{}; 94 var partUnits = <Uri, CompilationUnit>{};
95 for (var partUri in libraryNode.parts) { 95 for (var partUri in libraryNode.parts) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 _isInitialized = true; 143 _isInitialized = true;
144 } 144 }
145 145
146 @override 146 @override
147 void invalidate(String path) { 147 void invalidate(String path) {
148 throw new UnimplementedError(); 148 throw new UnimplementedError();
149 } 149 }
150 150
151 @override 151 @override
152 void invalidateAll() { 152 void invalidateAll() {
153 _fileState.clear();
154 _fileRepository.clearContents();
153 // TODO(paulberry): verify that this has an effect (requires a multi-file 155 // TODO(paulberry): verify that this has an effect (requires a multi-file
154 // test). 156 // test).
155 if (_isInitialized) { 157 if (_isInitialized) {
156 _driver.knownFiles.forEach(_driver.changeFile); 158 _driver.knownFiles.forEach(_driver.changeFile);
157 } 159 }
158 } 160 }
161
162 Future<String> _fileReader(Uri originalUri, Uri resolvedUri) async {
163 String contents = _fileState[resolvedUri] ??=
164 await _options.fileSystem.entityForUri(resolvedUri).readAsString();
165 _fileRepository.store(originalUri, contents);
166 return contents;
167 }
159 } 168 }
160 169
161 class _DartSdkProxy implements DartSdk { 170 class _DartSdkProxy implements DartSdk {
162 final PackageBundle summary; 171 final PackageBundle summary;
163 172
164 final AnalysisContext context; 173 final AnalysisContext context;
165 174
166 _DartSdkProxy(this.summary, this.context); 175 _DartSdkProxy(this.summary, this.context);
167 176
168 @override 177 @override
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 class _SourceProxy extends BasicSource { 290 class _SourceProxy extends BasicSource {
282 @override 291 @override
283 final String fullName; 292 final String fullName;
284 293
285 _SourceProxy(Uri uri, this.fullName) : super(uri); 294 _SourceProxy(Uri uri, this.fullName) : super(uri);
286 295
287 int get modificationStamp => 0; 296 int get modificationStamp => 0;
288 297
289 noSuchMethod(Invocation invocation) => unimplemented(); 298 noSuchMethod(Invocation invocation) => unimplemented();
290 } 299 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/dependency_grapher_impl.dart ('k') | pkg/front_end/test/incremental_resolved_ast_generator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698