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

Side by Side Diff: pkg/compiler/lib/src/library_loader.dart

Issue 1454383002: Add LibraryLoader.resetLibraries (Closed) Base URL: git@github.com:dart-lang/sdk.git@_temporary_fletch_patches
Patch Set: Created 5 years, 1 month 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 | « no previous file | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'dart2jslib.dart' show 9 import 'dart2jslib.dart' show
10 Compiler, 10 Compiler,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 Future<LibraryElement> loadLibrary(Uri resolvedUri); 148 Future<LibraryElement> loadLibrary(Uri resolvedUri);
149 149
150 /// Reset the library loader task to prepare for compilation. If provided, 150 /// Reset the library loader task to prepare for compilation. If provided,
151 /// libraries matching [reuseLibrary] are reused. 151 /// libraries matching [reuseLibrary] are reused.
152 /// 152 ///
153 /// This method is used for incremental compilation. 153 /// This method is used for incremental compilation.
154 void reset({bool reuseLibrary(LibraryElement library)}); 154 void reset({bool reuseLibrary(LibraryElement library)});
155 155
156 /// Asynchronous version of [reset]. 156 /// Asynchronous version of [reset].
157 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); 157 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library));
158
159 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list
160 /// of libraries that can be reused.
161 Future<Null> resetLibraries(
162 Future<Iterable<LibraryElement>> reuseLibraries(
Johnni Winther 2015/11/19 10:04:31 Maybe typedef this to make it more readable.
ahe 2015/11/19 11:20:56 I find typedefs less readable, but if you prefer a
Johnni Winther 2015/11/19 11:25:37 In this case where the signature is too long, I do
ahe 2015/11/19 11:33:13 OK. Calling it *Function helps a bit.
ahe 2016/01/08 10:25:23 Done.
163 Iterable<LibraryElement> libraries));
164
158 } 165 }
159 166
160 /// Handle for creating synthesized/patch libraries during library loading. 167 /// Handle for creating synthesized/patch libraries during library loading.
161 abstract class LibraryLoader { 168 abstract class LibraryLoader {
162 /// This method must be called when a new synthesized/patch library has been 169 /// This method must be called when a new synthesized/patch library has been
163 /// created to ensure that [library] will part of library dependency graph 170 /// created to ensure that [library] will part of library dependency graph
164 /// used for computing import/export scopes. 171 /// used for computing import/export scopes.
165 void registerNewLibrary(LibraryElement library); 172 void registerNewLibrary(LibraryElement library);
166 173
167 /// This method must be called when a new synthesized/patch library has been 174 /// This method must be called when a new synthesized/patch library has been
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 'Uncaught exception in reuseLibrary', exception, trace); 324 'Uncaught exception in reuseLibrary', exception, trace);
318 rethrow; 325 rethrow;
319 } 326 }
320 } 327 }
321 328
322 List<Future<LibraryElement>> reusedLibrariesFuture = 329 List<Future<LibraryElement>> reusedLibrariesFuture =
323 compiler.reuseLibraryTask.measure( 330 compiler.reuseLibraryTask.measure(
324 () => libraryCanonicalUriMap.values.map(wrapper).toList()); 331 () => libraryCanonicalUriMap.values.map(wrapper).toList());
325 332
326 return Future.wait(reusedLibrariesFuture).then( 333 return Future.wait(reusedLibrariesFuture).then(
327 (List<LibraryElement> reusedLibraries) { 334 (Iterable<LibraryElement> reusedLibraries) {
328 resetImplementation(reusedLibraries.where((e) => e != null)); 335 resetImplementation(reusedLibraries.where((e) => e != null));
329 }); 336 });
330 }); 337 });
331 } 338 }
332 339
340 Future<Null> resetLibraries(
341 Future<Iterable<LibraryElement>> reuseLibraries(
342 Iterable<LibraryElement> libraries)) {
343 assert(currentHandler == null);
344 return compiler.reuseLibraryTask.measure(() {
345 return new Future<Iterable<LibraryElement>>(() {
346 // Wrap in Future to shield against errors in user code.
347 return reuseLibraries(libraryCanonicalUriMap.values);
348 }).catchError((exception, StackTrace trace) {
349 compiler.diagnoseCrashInUserCode(
350 'Uncaught exception in reuseLibraries', exception, trace);
351 throw exception; // Async rethrow.
352 }).then((Iterable<LibraryElement> reusedLibraries) {
353 measure(() {
354 resetImplementation(reusedLibraries);
355 });
356 });
357 });
358 }
359
333 /// Insert [library] in the internal maps. Used for compiler reuse. 360 /// Insert [library] in the internal maps. Used for compiler reuse.
334 void mapLibrary(LibraryElement library) { 361 void mapLibrary(LibraryElement library) {
335 libraryCanonicalUriMap[library.canonicalUri] = library; 362 libraryCanonicalUriMap[library.canonicalUri] = library;
336 363
337 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; 364 Uri resourceUri = library.entryCompilationUnit.script.resourceUri;
338 libraryResourceUriMap[resourceUri] = library; 365 libraryResourceUriMap[resourceUri] = library;
339 366
340 String name = library.getLibraryOrScriptName(); 367 String name = library.getLibraryOrScriptName();
341 libraryNames[name] = library; 368 libraryNames[name] = library;
342 } 369 }
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1243 }
1217 suffixes.add(const Link<Uri>().prepend(canonicalUri)); 1244 suffixes.add(const Link<Uri>().prepend(canonicalUri));
1218 } 1245 }
1219 suffixChainMap[library] = suffixes; 1246 suffixChainMap[library] = suffixes;
1220 return; 1247 return;
1221 } 1248 }
1222 1249
1223 computeSuffixes(rootLibrary, const Link<Uri>()); 1250 computeSuffixes(rootLibrary, const Link<Uri>());
1224 } 1251 }
1225 } 1252 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698