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

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

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove withCurrentElementAsync Created 7 years, 5 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/apiimpl.dart
diff --git a/sdk/lib/_internal/compiler/implementation/apiimpl.dart b/sdk/lib/_internal/compiler/implementation/apiimpl.dart
index 9f24fc63d2d6ff54a701a543e3dd905a5e346d73..2fda52d22a028bee2278fbbd7118b2ea070f3fb5 100644
--- a/sdk/lib/_internal/compiler/implementation/apiimpl.dart
+++ b/sdk/lib/_internal/compiler/implementation/apiimpl.dart
@@ -137,12 +137,10 @@ class Compiler extends leg.Compiler {
return "lib/$path";
}
- elements.LibraryElement scanBuiltinLibrary(String path) {
+ Future<elements.LibraryElement> scanBuiltinLibrary(String path) {
Uri uri = libraryRoot.resolve(lookupLibraryPath(path));
Uri canonicalUri = new Uri(scheme: "dart", path: path);
- elements.LibraryElement library =
- libraryLoader.loadLibrary(uri, null, canonicalUri);
- return library;
+ return libraryLoader.loadLibrary(uri, null, canonicalUri);
}
void log(message) {
@@ -161,35 +159,39 @@ class Compiler extends leg.Compiler {
/**
* Reads the script designated by [readableUri].
*/
- leg.Script readScript(Uri readableUri, [tree.Node node]) {
+ Future<leg.Script> readScript(Uri readableUri,
+ [elements.Element element, tree.Node node]) {
if (!readableUri.isAbsolute) {
internalError('Relative uri $readableUri provided to readScript(Uri)',
node: node);
}
- return fileReadingTask.measure(() {
- Uri resourceUri = translateUri(readableUri, node);
- String text = "";
- try {
- // TODO(ahe): We expect the future to be complete and call value
- // directly. In effect, we don't support truly asynchronous API.
- text = deprecatedFutureValue(provider(resourceUri));
- } catch (exception) {
- if (node != null) {
- cancel("$exception", node: node);
- } else {
- reportError(
- null,
- leg.MessageKind.GENERIC, {'text': 'Error: $exception'});
- throw new leg.CompilerCancelledException("$exception");
- }
- }
- SourceFile sourceFile = new SourceFile(resourceUri.toString(), text);
- // We use [readableUri] as the URI for the script since need to preserve
- // the scheme in the script because [Script.uri] is used for resolving
- // relative URIs mentioned in the script. See the comment on
- // [LibraryLoader] for more details.
- return new leg.Script(readableUri, sourceFile);
- });
+
+ void reportError(String error) {
+ withCurrentElement(element, () {
+ reportFatalError(
+ node,
+ leg.MessageKind.GENERIC, {'text': 'Error: $error'});
+ });
+ }
+
+ Uri resourceUri = translateUri(readableUri, node);
+ // TODO(johnniwinther): Wrap the result from [provider] in a specialized
+ // [Future] to ensure that we exexute an asynchronous action without setting
ahe 2013/08/06 16:29:17 "we exexute" -> "we never execute"
Johnni Winther 2013/08/27 11:05:00 Done.
+ // up the current element of the compiler.
+ try {
+ return provider(resourceUri).then((String text) {
+ SourceFile sourceFile = new SourceFile(resourceUri.toString(), text);
+ // We use [readableUri] as the URI for the script since need to preserve
+ // the scheme in the script because [Script.uri] is used for resolving
+ // relative URIs mentioned in the script. See the comment on
+ // [LibraryLoader] for more details.
+ return new leg.Script(readableUri, sourceFile);
+ }).catchError((error) {
+ reportError(error);
+ });
+ } catch (error) {
+ reportError(error);
+ }
}
/**
@@ -273,18 +275,19 @@ class Compiler extends leg.Compiler {
return packageRoot.resolve(uri.path);
}
- bool run(Uri uri) {
+ Future<bool> run(Uri uri) {
log('Allowed library categories: $allowedLibraryCategories');
- bool success = super.run(uri);
- int cumulated = 0;
- for (final task in tasks) {
- cumulated += task.timing;
- log('${task.name} took ${task.timing}msec');
- }
- int total = totalCompileTime.elapsedMilliseconds;
- log('Total compile-time ${total}msec;'
- ' unaccounted ${total - cumulated}msec');
- return success;
+ return super.run(uri).then((bool success) {
+ int cumulated = 0;
+ for (final task in tasks) {
+ cumulated += task.timing;
+ log('${task.name} took ${task.timing}msec');
+ }
+ int total = totalCompileTime.elapsedMilliseconds;
+ log('Total compile-time ${total}msec;'
+ ' unaccounted ${total - cumulated}msec');
+ return success;
+ });
}
void reportDiagnostic(leg.SourceSpan span, String message,

Powered by Google App Engine
This is Rietveld 408576698