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

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

Issue 2638423002: Fix incremental kernel builder to handle multiple calls to computeDelta. (Closed)
Patch Set: 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/file_system/file_system.dart'; 7 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/src/context/context.dart'; 8 import 'package:analyzer/src/context/context.dart';
9 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 9 import 'package:analyzer/src/dart/analysis/byte_store.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart' as driver; 10 import 'package:analyzer/src/dart/analysis/driver.dart' as driver;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 implements IncrementalResolvedAstGenerator { 44 implements IncrementalResolvedAstGenerator {
45 driver.AnalysisDriverScheduler _scheduler; 45 driver.AnalysisDriverScheduler _scheduler;
46 final _pathToUriMap = <String, Uri>{}; 46 final _pathToUriMap = <String, Uri>{};
47 final _uriToPathMap = <Uri, String>{}; 47 final _uriToPathMap = <Uri, String>{};
48 final _fileContents = <String, String>{}; 48 final _fileContents = <String, String>{};
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 55
55 IncrementalResolvedAstGeneratorImpl(this._source, this._options); 56 IncrementalResolvedAstGeneratorImpl(this._source, this._options);
56 57
57 @override 58 @override
58 Future<DeltaLibraries> computeDelta() async { 59 Future<DeltaLibraries> computeDelta() async {
59 if (!_isInitialized) { 60 if (!_isInitialized) {
60 await init(); 61 await init();
61 } 62 }
62 // The analysis driver doesn't currently support an asynchronous file API, 63 // The analysis driver doesn't currently support an asynchronous file API,
63 // so we have to find all the files first to read their contents. 64 // so we have to find all the files first to read their contents.
64 // TODO(paulberry): this is an unnecessary source of duplicate work and 65 // TODO(paulberry): this is an unnecessary source of duplicate work and
65 // should be eliminated ASAP. 66 // should be eliminated ASAP.
66 var graph = await graphForProgram([_source], _options); 67 var graph = await graphForProgram([_source], _options);
67 var libraries = <Uri, ResolvedLibrary>{}; 68 var libraries = <Uri, ResolvedLibrary>{};
68 // TODO(paulberry): it should be possible to seed the driver using a URI, 69 // TODO(paulberry): it should be possible to seed the driver using a URI,
69 // not a file path. 70 // not a file path.
70 // TODO(paulberry): only start the scheduler the first time. 71 if (!_schedulerStarted) {
71 _scheduler.start(); 72 _scheduler.start();
73 _schedulerStarted = true;
74 }
72 _driver.addFile(_source.path); 75 _driver.addFile(_source.path);
73 for (var libraryCycle in graph.topologicallySortedCycles) { 76 for (var libraryCycle in graph.topologicallySortedCycles) {
74 for (var uri in libraryCycle.libraries.keys) { 77 for (var uri in libraryCycle.libraries.keys) {
75 var contents = 78 var contents =
76 await _options.fileSystem.entityForUri(uri).readAsString(); 79 await _options.fileSystem.entityForUri(uri).readAsString();
77 _storeVirtualFile(uri, uri.path, contents); 80 _storeVirtualFile(uri, uri.path, contents);
78 } 81 }
79 // The driver will request files from dart:, even though it actually uses 82 // The driver will request files from dart:, even though it actually uses
80 // the data from the summary. TODO(paulberry): fix this. 83 // the data from the summary. TODO(paulberry): fix this.
81 _storeVirtualFile(_DartSdkProxy._dartCoreSource.uri, 'core.dart', ''); 84 _storeVirtualFile(_DartSdkProxy._dartCoreSource.uri, 'core.dart', '');
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 _isInitialized = true; 126 _isInitialized = true;
124 } 127 }
125 128
126 @override 129 @override
127 void invalidate(String path) { 130 void invalidate(String path) {
128 throw new UnimplementedError(); 131 throw new UnimplementedError();
129 } 132 }
130 133
131 @override 134 @override
132 void invalidateAll() { 135 void invalidateAll() {
133 throw new UnimplementedError(); 136 // TODO(paulberry): verify that this has an effect (requires a multi-file
137 // test).
138 if (_isInitialized) {
139 _driver.knownFiles.forEach(_driver.changeFile);
140 }
134 } 141 }
135 142
136 void _storeVirtualFile(Uri uri, String path, String contents) { 143 void _storeVirtualFile(Uri uri, String path, String contents) {
137 _pathToUriMap[path] = uri; 144 _pathToUriMap[path] = uri;
138 _uriToPathMap[uri] = path; 145 _uriToPathMap[uri] = path;
139 _fileContents[path] = contents; 146 _fileContents[path] = contents;
140 } 147 }
141 } 148 }
142 149
143 class _DartSdkProxy implements DartSdk { 150 class _DartSdkProxy implements DartSdk {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 final Map<String, Uri> pathToUriMap; 245 final Map<String, Uri> pathToUriMap;
239 246
240 final Map<Uri, String> uriToPathMap; 247 final Map<Uri, String> uriToPathMap;
241 248
242 @override 249 @override
243 AnalysisContext context; 250 AnalysisContext context;
244 251
245 _SourceFactoryProxy(this.dartSdk, this.pathToUriMap, this.uriToPathMap); 252 _SourceFactoryProxy(this.dartSdk, this.pathToUriMap, this.uriToPathMap);
246 253
247 @override 254 @override
248 SourceFactory clone() => this; 255 SourceFactory clone() =>
256 new _SourceFactoryProxy(dartSdk, pathToUriMap, uriToPathMap);
249 257
250 @override 258 @override
251 Source forUri(String absoluteUri) { 259 Source forUri(String absoluteUri) {
252 if (absoluteUri == 'dart:core') return _DartSdkProxy._dartCoreSource; 260 if (absoluteUri == 'dart:core') return _DartSdkProxy._dartCoreSource;
253 Uri uri = Uri.parse(absoluteUri); 261 Uri uri = Uri.parse(absoluteUri);
254 assert(uriToPathMap.containsKey(uri)); 262 assert(uriToPathMap.containsKey(uri));
255 return new _SourceProxy(uri, uriToPathMap[uri]); 263 return new _SourceProxy(uri, uriToPathMap[uri]);
256 } 264 }
257 265
258 noSuchMethod(Invocation invocation) => unimplemented(); 266 noSuchMethod(Invocation invocation) => unimplemented();
(...skipping 12 matching lines...) Expand all
271 class _SourceProxy extends BasicSource { 279 class _SourceProxy extends BasicSource {
272 @override 280 @override
273 final String fullName; 281 final String fullName;
274 282
275 _SourceProxy(Uri uri, this.fullName) : super(uri); 283 _SourceProxy(Uri uri, this.fullName) : super(uri);
276 284
277 int get modificationStamp => 0; 285 int get modificationStamp => 0;
278 286
279 noSuchMethod(Invocation invocation) => unimplemented(); 287 noSuchMethod(Invocation invocation) => unimplemented();
280 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698