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 0e70958a74d6299085472ea2feec45a6f276cbfe..b783105d1a023e163aaac50f2e7525f7d34cc091 100644 |
--- a/sdk/lib/_internal/compiler/implementation/library_loader.dart |
+++ b/sdk/lib/_internal/compiler/implementation/library_loader.dart |
@@ -113,12 +113,13 @@ abstract class LibraryLoader extends CompilerTask { |
*/ |
// TODO(johnniwinther): Remove [canonicalUri] together with |
// [Compiler.scanBuiltinLibrary]. |
- LibraryElement loadLibrary(Uri resolvedUri, Node node, Uri canonicalUri); |
+ Future<LibraryElement> loadLibrary(Uri resolvedUri, Node node, |
+ Uri canonicalUri); |
// TODO(johnniwinther): Remove this when patches don't need special parsing. |
- void registerLibraryFromTag(LibraryDependencyHandler handler, |
- LibraryElement library, |
- LibraryDependency tag); |
+ Future registerLibraryFromTag(LibraryDependencyHandler handler, |
+ LibraryElement library, |
+ LibraryDependency tag); |
/** |
* Adds the elements in the export scope of [importedLibrary] to the import |
@@ -226,15 +227,15 @@ class LibraryLoaderTask extends LibraryLoader { |
LibraryDependencyHandler currentHandler; |
- LibraryElement loadLibrary(Uri resolvedUri, Node node, Uri canonicalUri) { |
- return measure(() { |
+ Future<LibraryElement> loadLibrary(Uri resolvedUri, Node node, Uri canonicalUri) { |
ahe
2013/06/26 07:02:00
Long line.
Bob Nystrom
2013/06/27 00:38:18
Done.
|
+ return measureAsync(() { |
ahe
2013/06/26 07:02:00
I think this should be measure
Bob Nystrom
2013/06/27 00:38:18
Done.
|
assert(currentHandler == null); |
currentHandler = new LibraryDependencyHandler(compiler); |
- LibraryElement library = |
- createLibrary(currentHandler, null, resolvedUri, node, canonicalUri); |
- currentHandler.computeExports(); |
- currentHandler = null; |
- return library; |
+ return createLibrary(currentHandler, null, resolvedUri, node, canonicalUri).then((library) { |
Bob Nystrom
2013/06/26 01:03:24
I'll fix these long lines.
ahe
2013/06/26 07:02:00
An then wrap this is in measure as well.
ahe
2013/06/26 07:02:00
Please restore the type of "library".
Bob Nystrom
2013/06/27 00:38:18
Done.
Bob Nystrom
2013/06/27 00:38:18
Done.
|
+ currentHandler.computeExports(); |
+ currentHandler = null; |
+ return library; |
+ }); |
}); |
} |
@@ -244,7 +245,7 @@ class LibraryLoaderTask extends LibraryLoader { |
* The imported/exported libraries are loaded and processed recursively but |
* the import/export scopes are not set up. |
*/ |
- void processLibraryTags(LibraryDependencyHandler handler, |
+ Future processLibraryTags(LibraryDependencyHandler handler, |
LibraryElement library) { |
int tagState = TagState.NO_TAG_SEEN; |
@@ -264,7 +265,8 @@ class LibraryLoaderTask extends LibraryLoader { |
bool importsDartCore = false; |
var libraryDependencies = new LinkBuilder<LibraryDependency>(); |
Uri base = library.entryCompilationUnit.script.uri; |
- for (LibraryTag tag in library.tags.reverse()) { |
+ |
+ return Future.forEach(library.tags.reverse(), (tag) { |
ahe
2013/06/26 07:02:00
I need to figure out what this does.
Bob Nystrom
2013/06/27 00:38:18
It should be semantically equivalent to the previo
|
if (tag.isImport) { |
Import import = tag; |
tagState = checkTag(TagState.IMPORT_OR_EXPORT, import); |
@@ -288,25 +290,27 @@ class LibraryLoaderTask extends LibraryLoader { |
StringNode uri = part.uri; |
Uri resolvedUri = base.resolve(uri.dartString.slowToString()); |
tagState = checkTag(TagState.SOURCE, part); |
- scanPart(part, resolvedUri, library); |
+ return scanPart(part, resolvedUri, library); |
} else { |
compiler.internalError("Unhandled library tag.", node: tag); |
} |
- } |
- |
- // Apply patch, if any. |
- if (library.isPlatformLibrary) { |
- patchDartLibrary(handler, library, library.canonicalUri.path); |
- } |
- |
- // Import dart:core if not already imported. |
- if (!importsDartCore && !isDartCore(library.canonicalUri)) { |
- handler.registerDependency(library, null, loadCoreLibrary(handler)); |
- } |
- |
- for (LibraryDependency tag in libraryDependencies.toLink()) { |
- registerLibraryFromTag(handler, library, tag); |
- } |
+ }).then((_) { |
+ // Apply patch, if any. |
+ if (library.isPlatformLibrary) { |
+ return patchDartLibrary(handler, library, library.canonicalUri.path); |
+ } |
+ }).then((_) { |
+ // Import dart:core if not already imported. |
+ if (!importsDartCore && !isDartCore(library.canonicalUri)) { |
+ return loadCoreLibrary(handler).then((coreLibrary) { |
+ handler.registerDependency(library, null, coreLibrary); |
+ }); |
+ } |
+ }).then((_) { |
+ return Future.forEach(libraryDependencies.toLink(), (tag) { |
+ return registerLibraryFromTag(handler, library, tag); |
+ }); |
+ }); |
} |
void checkDuplicatedLibraryName(LibraryElement library) { |
@@ -335,49 +339,53 @@ class LibraryLoaderTask extends LibraryLoader { |
/** |
* Lazily loads and returns the [LibraryElement] for the dart:core library. |
*/ |
- LibraryElement loadCoreLibrary(LibraryDependencyHandler handler) { |
- if (compiler.coreLibrary == null) { |
- Uri coreUri = new Uri(scheme: 'dart', path: 'core'); |
- compiler.coreLibrary |
- = createLibrary(handler, null, coreUri, null, coreUri); |
+ Future<LibraryElement> loadCoreLibrary(LibraryDependencyHandler handler) { |
+ if (compiler.coreLibrary != null) { |
+ return new Future.value(compiler.coreLibrary); |
} |
- return compiler.coreLibrary; |
+ |
+ Uri coreUri = new Uri(scheme: 'dart', path: 'core'); |
+ return createLibrary(handler, null, coreUri, null, coreUri).then((library) { |
+ compiler.coreLibrary = library; |
+ return library; |
+ }); |
} |
- void patchDartLibrary(LibraryDependencyHandler handler, |
+ Future patchDartLibrary(LibraryDependencyHandler handler, |
LibraryElement library, String dartLibraryPath) { |
- if (library.isPatched) return; |
+ if (library.isPatched) return new Future.value(); |
Uri patchUri = compiler.resolvePatchUri(dartLibraryPath); |
- if (patchUri != null) { |
- compiler.patchParser.patchLibrary(handler, patchUri, library); |
- } |
+ 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. |
*/ |
- void scanPart(Part part, Uri resolvedUri, LibraryElement library) { |
+ Future scanPart(Part part, Uri resolvedUri, LibraryElement library) { |
if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri); |
Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part); |
- Script sourceScript = compiler.readScript(readableUri, part); |
- CompilationUnitElement unit = |
- new CompilationUnitElementX(sourceScript, library); |
- compiler.withCurrentElement(unit, () { |
- compiler.scanner.scan(unit); |
- if (unit.partTag == null) { |
- bool wasDiagnosticEmitted = false; |
- compiler.withCurrentElement(library, () { |
- wasDiagnosticEmitted = |
- compiler.onDeprecatedFeature(part, 'missing part-of tag'); |
- }); |
- if (wasDiagnosticEmitted) { |
- compiler.reportMessage( |
- compiler.spanFromElement(unit), |
- MessageKind.MISSING_PART_OF_TAG.error(), |
- api.Diagnostic.INFO); |
+ return compiler.readScript(readableUri, part).then((sourceScript) { |
+ CompilationUnitElement unit = |
+ new CompilationUnitElementX(sourceScript, library); |
+ compiler.withCurrentElement(unit, () { |
+ compiler.scanner.scan(unit); |
+ if (unit.partTag == null) { |
+ bool wasDiagnosticEmitted = false; |
+ compiler.withCurrentElement(library, () { |
+ wasDiagnosticEmitted = |
+ compiler.onDeprecatedFeature(part, 'missing part-of tag'); |
+ }); |
+ if (wasDiagnosticEmitted) { |
+ compiler.reportMessage( |
+ compiler.spanFromElement(unit), |
+ MessageKind.MISSING_PART_OF_TAG.error(), |
+ api.Diagnostic.INFO); |
+ } |
} |
- } |
+ }); |
}); |
} |
@@ -386,21 +394,21 @@ class LibraryLoaderTask extends LibraryLoader { |
* registering its dependency in [handler] for the computation of the import/ |
* export scope. |
*/ |
- void registerLibraryFromTag(LibraryDependencyHandler handler, |
+ Future registerLibraryFromTag(LibraryDependencyHandler handler, |
LibraryElement library, |
LibraryDependency tag) { |
Uri base = library.entryCompilationUnit.script.uri; |
Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); |
- LibraryElement loadedLibrary = |
- createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); |
- handler.registerDependency(library, tag, loadedLibrary); |
- |
- if (!loadedLibrary.hasLibraryName()) { |
- compiler.withCurrentElement(library, () { |
- compiler.reportError(tag == null ? null : tag.uri, |
- 'no library name found in ${loadedLibrary.canonicalUri}'); |
- }); |
- } |
+ return createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri) |
+ .then((loadedLibrary) { |
+ handler.registerDependency(library, tag, loadedLibrary); |
+ if (!loadedLibrary.hasLibraryName()) { |
+ compiler.withCurrentElement(library, () { |
+ compiler.reportError(tag == null ? null : tag.uri, |
+ 'no library name found in ${loadedLibrary.canonicalUri}'); |
+ }); |
+ } |
+ }); |
} |
/** |
@@ -411,37 +419,36 @@ class LibraryLoaderTask extends LibraryLoader { |
*/ |
// TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the |
// canonical uri when [Compiler.scanBuiltinLibrary] is removed. |
- LibraryElement createLibrary(LibraryDependencyHandler handler, |
+ Future<LibraryElement> createLibrary(LibraryDependencyHandler handler, |
LibraryElement importingLibrary, |
Uri resolvedUri, Node node, Uri canonicalUri) { |
- bool newLibrary = false; |
Uri readableUri = |
compiler.translateResolvedUri(importingLibrary, resolvedUri, node); |
if (readableUri == null) return null; |
- LibraryElement createLibrary() { |
- newLibrary = true; |
- Script script = compiler.readScript(readableUri, node); |
+ |
+ if (canonicalUri != null) { |
+ LibraryElement library = compiler.libraries[canonicalUri.toString()]; |
+ if (library != null) { |
+ return new Future.value(library); |
+ } |
+ } |
+ |
+ return compiler.readScript(readableUri, node).then((script) { |
LibraryElement element = new LibraryElementX(script, canonicalUri); |
handler.registerNewLibrary(element); |
native.maybeEnableNative(compiler, element); |
- return element; |
- } |
- LibraryElement library; |
- if (canonicalUri == null) { |
- library = createLibrary(); |
- } else { |
- library = compiler.libraries.putIfAbsent(canonicalUri.toString(), |
- createLibrary); |
- } |
- if (newLibrary) { |
- compiler.withCurrentElement(library, () { |
- compiler.scanner.scanLibrary(library); |
- processLibraryTags(handler, library); |
- handler.registerLibraryExports(library); |
- compiler.onLibraryScanned(library, resolvedUri); |
+ compiler.libraries[canonicalUri.toString()] = element; |
+ return compiler.withCurrentElement(element, () { |
+ compiler.scanner.scanLibrary(element); |
+ return processLibraryTags(handler, element); |
+ }).then((_) { |
+ compiler.withCurrentElement(element, () { |
+ handler.registerLibraryExports(element); |
+ compiler.onLibraryScanned(element, resolvedUri); |
+ }); |
+ return element; |
}); |
- } |
- return library; |
+ }); |
} |
// TODO(johnniwinther): Remove this method when 'js_helper' is handled by |