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

Unified Diff: sdk/lib/_internal/compiler/implementation/library_loader.dart

Issue 350693007: Load patches via callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix caching_compiler Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/library_loader.dart
diff --git a/sdk/lib/_internal/compiler/implementation/library_loader.dart b/sdk/lib/_internal/compiler/implementation/library_loader.dart
index c9b2d5c4f3938fed74fcefb0f1b57f879876c97f..dfb3258e055c11ccafa8a6642882fce642a84e14 100644
--- a/sdk/lib/_internal/compiler/implementation/library_loader.dart
+++ b/sdk/lib/_internal/compiler/implementation/library_loader.dart
@@ -2,7 +2,30 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of dart2js;
+library dart2js.library_loader;
+
+import 'dart:async';
+import 'dart2jslib.dart'
+ show Compiler,
+ CompilerTask,
+ MessageKind,
+ Script,
+ invariant;
+import 'elements/elements.dart'
+ show CompilationUnitElement,
+ Element,
+ LibraryElement,
+ PrefixElement;
+import 'elements/modelx.dart'
+ show CompilationUnitElementX,
+ DeferredLoaderGetterElementX,
+ ErroneousElementX,
+ LibraryElementX,
+ PrefixElementX;
+import 'helpers/helpers.dart';
+import 'native_handler.dart' as native;
+import 'tree/tree.dart';
+import 'util/util.dart' show Link, LinkBuilder;
/**
* [CompilerTask] for loading libraries and setting up the import/export scopes.
@@ -97,8 +120,8 @@ part of dart2js;
* point to the 'packages' folder.
*
*/
-abstract class LibraryLoader extends CompilerTask {
- LibraryLoader(Compiler compiler) : super(compiler);
+abstract class LibraryLoaderTask implements CompilerTask {
+ factory LibraryLoaderTask(Compiler compiler) = _LibraryLoaderTask;
/**
* Loads the library specified by the [resolvedUri] and returns its
@@ -108,15 +131,29 @@ abstract class LibraryLoader extends CompilerTask {
* [LibraryElement] for the library and computes the import/export scope,
* loading and computing the import/export scopes of all required libraries in
* the process. The method handles cyclic dependency between libraries.
- *
- * This is the main entry point for [LibraryLoader].
*/
Future<LibraryElement> loadLibrary(Uri resolvedUri);
- // TODO(johnniwinther): Remove this when patches don't need special parsing.
- Future registerLibraryFromTag(LibraryDependencyHandler handler,
- LibraryElement library,
- LibraryDependency tag);
+ /// Reset the library loader task to prepare for compilation. This is used
+ /// for incremental compilation.
+ void reset();
+
+ /// Reuse [library] from a previous compilation. This is used for incremental
+ /// compilation.
+ void reuseLibrary(LibraryElement library);
+}
+
+/// Handle for creating synthesized/patch libraries during library loading.
+abstract class LibraryLoader {
+ /// This method must be called when a new synthesized/patch library has been
+ /// created to ensure that [library] will part of library dependency graph
+ /// used for computing import/export scopes.
+ void registerNewLibrary(LibraryElement library);
+
+ /// This method must be called when a new synthesized/patch library has been
+ /// scanned in order to process the library tags in [library] and thus handle
+ /// imports/exports/parts in the synthesized/patch library.
+ Future processLibraryTags(LibraryElement library);
}
/**
@@ -205,8 +242,8 @@ class HideFilter extends CombinatorFilter {
* [LibraryLoader] and [LibraryLoaderTask] is made to hide internal members from
* the [LibraryLoader] interface.
*/
-class LibraryLoaderTask extends LibraryLoader {
- LibraryLoaderTask(Compiler compiler) : super(compiler);
+class _LibraryLoaderTask extends CompilerTask implements LibraryLoaderTask {
+ _LibraryLoaderTask(Compiler compiler) : super(compiler);
String get name => 'LibraryLoader';
final Map<Uri, LibraryElement> libraryResourceUriMap =
@@ -216,12 +253,25 @@ class LibraryLoaderTask extends LibraryLoader {
LibraryDependencyHandler currentHandler;
+ void reset() {
+ assert(currentHandler == null);
+ libraryResourceUriMap.clear();
+ libraryNames.clear();
+ }
+
+ void reuseLibrary(LibraryElement library) {
+ String name = library.getLibraryOrScriptName();
+ Uri resourceUri = library.entryCompilationUnit.script.resourceUri;
+ libraryResourceUriMap[resourceUri] = library;
+ libraryNames[name] = library;
+ }
+
Future<LibraryElement> loadLibrary(Uri resolvedUri) {
return measure(() {
assert(currentHandler == null);
// TODO(johnniwinther): Ensure that currentHandler correctly encloses the
// loading of a library cluster.
- currentHandler = new LibraryDependencyHandler(compiler);
+ currentHandler = new LibraryDependencyHandler(this);
return createLibrary(currentHandler, null, resolvedUri)
.then((LibraryElement library) {
return compiler.withCurrentElement(library, () {
@@ -270,7 +320,7 @@ class LibraryLoaderTask extends LibraryLoader {
var libraryDependencies = new LinkBuilder<LibraryDependency>();
Uri base = library.entryCompilationUnit.script.readableUri;
- // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
+ // TODO(johnniwinther): Reverse the tag list on access and cache the result.
return Future.forEach(library.tags.reverse().toList(), (LibraryTag tag) {
return compiler.withCurrentElement(library, () {
if (tag.isImport) {
@@ -301,17 +351,11 @@ class LibraryLoaderTask extends LibraryLoader {
}
});
}).then((_) {
- // TODO(johnniwinther): Move callback to after patching.
- compiler.onLibraryScanned(library);
- return compiler.withCurrentElement(library, () {
- checkDuplicatedLibraryName(library);
- // Apply patch, if any.
- if (library.isPlatformLibrary) {
- return patchDartLibrary(handler, library, library.canonicalUri.path);
- }
- });
+ return compiler.onLibraryScanned(library, handler);
}).then((_) {
return compiler.withCurrentElement(library, () {
+ checkDuplicatedLibraryName(library);
+
// Import dart:core if not already imported.
if (!importsDartCore && !isDartCore(library.canonicalUri)) {
return loadCoreLibrary(handler).then((LibraryElement coreLibrary) {
@@ -320,7 +364,6 @@ class LibraryLoaderTask extends LibraryLoader {
}
});
}).then((_) {
- // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
return Future.forEach(libraryDependencies.toLink().toList(), (tag) {
return compiler.withCurrentElement(library, () {
return registerLibraryFromTag(handler, library, tag);
@@ -386,16 +429,6 @@ class LibraryLoaderTask extends LibraryLoader {
});
}
- Future patchDartLibrary(LibraryDependencyHandler handler,
- LibraryElement library,
- String dartLibraryPath) {
- if (library.isPatched) return new Future.value();
- Uri patchUri = compiler.resolvePatchUri(dartLibraryPath);
- if (patchUri == null) return new Future.value();
-
- return compiler.patchParser.patchLibrary(handler, patchUri, library);
- }
-
/**
* Handle a part tag in the scope of [library]. The [resolvedUri] given is
* used as is, any URI resolution should be done beforehand.
@@ -465,7 +498,6 @@ class LibraryLoaderTask extends LibraryLoader {
if (script == null) return null;
LibraryElement element = new LibraryElementX(script, resolvedUri);
compiler.withCurrentElement(element, () {
- compiler.onLibraryCreated(element);
handler.registerNewLibrary(element);
native.maybeEnableNative(compiler, element);
compiler.libraries[resolvedUri.toString()] = element;
@@ -807,8 +839,8 @@ class LibraryDependencyNode {
* libraries and to compute their import/export scopes through a fixed-point
* algorithm.
*/
-class LibraryDependencyHandler {
- final Compiler compiler;
+class LibraryDependencyHandler implements LibraryLoader {
+ final _LibraryLoaderTask task;
/**
* Newly loaded libraries and their corresponding node in the library
@@ -819,7 +851,9 @@ class LibraryDependencyHandler {
Map<LibraryElement, LibraryDependencyNode> nodeMap =
new Map<LibraryElement, LibraryDependencyNode>();
- LibraryDependencyHandler(Compiler this.compiler);
+ LibraryDependencyHandler(this.task);
+
+ Compiler get compiler => task.compiler;
/// The libraries loaded with this handler.
Iterable<LibraryElement> get loadedLibraries => nodeMap.keys;
@@ -908,6 +942,7 @@ class LibraryDependencyHandler {
*/
void registerNewLibrary(LibraryElement library) {
nodeMap[library] = new LibraryDependencyNode(library);
+ compiler.onLibraryCreated(library);
}
/**
@@ -917,4 +952,8 @@ class LibraryDependencyHandler {
void registerLibraryExports(LibraryElement library) {
nodeMap[library].registerInitialExports();
}
+
+ Future processLibraryTags(LibraryElement library) {
+ return task.processLibraryTags(this, library);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698