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

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

Issue 169703003: Add prefix constraints for deferred imports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/deferred_load.dart
diff --git a/sdk/lib/_internal/compiler/implementation/deferred_load.dart b/sdk/lib/_internal/compiler/implementation/deferred_load.dart
index 47ea3a1bc0c4f059188e0f53938d5992644f837a..fc1b601ba1d95725cfb581b2d55c95ba3a132527 100644
--- a/sdk/lib/_internal/compiler/implementation/deferred_load.dart
+++ b/sdk/lib/_internal/compiler/implementation/deferred_load.dart
@@ -617,21 +617,68 @@ class DeferredLoadTask extends CompilerTask {
_allDeferredImports[_fakeMainImport] = compiler.mainApp;
bool deferredUsedFromMain = false;
var lastDeferred;
+ // When detecting duplicate prefixes of deferred libraries there are 4
+ // cases of duplicate prefixes:
+ // 1.
+ // @DeferredLibrary("a") import "lib.dart" as a;
+ // @DeferredLibrary("b") import "lib2.dart" as a;
+ // 2.
+ // @DeferredLibrary("a") import "lib.dart" as a;
+ // import "lib2.dart" as a;
+ // 3.
+ // import "lib.dart" as a;
+ // @DeferredLibrary("a") import "lib2.dart" as a;
+ // 4.
+ // import "lib.dart" as a;
+ // import "lib2.dart" as a;
+ // We must be able to signal error for case 1, 2, 3, but accept case 4.
+
+ // The prefixes that have been used by any imports in this library.
+ Setlet<String> usedPrefixes = new Setlet<String>();
+ // The last deferred import we saw with a given prefix (if any).
+ Map<String, Import> prefixDeferredImport = new Map<String, Import>();
for (LibraryElement library in compiler.libraries.values) {
- // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List
- // instead of a Link.
- for (LibraryTag tag in library.tags) {
- if (tag is! Import) continue;
- Import import = tag;
- if (_isImportDeferred(import)) {
- splitProgram = true;
- _allDeferredImports[tag] = library.getLibraryFromTag(tag);
- lastDeferred = import.metadata.first;
- if (library == compiler.mainApp) {
- deferredUsedFromMain = true;
+ compiler.withCurrentElement(library, () {
+ prefixDeferredImport.clear();
+ usedPrefixes.clear();
+ // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List
+ // instead of a Link.
+ for (LibraryTag tag in library.tags) {
+ if (tag is! Import) continue;
+ Import import = tag;
+ String prefix = (import.prefix != null)
+ ? import.prefix.toString()
+ : null;
+ // The last import we saw with the same prefix.
+ Import previousDeferredImport = prefixDeferredImport[prefix];
+ bool isDeferred = _isImportDeferred(import);
+ if (isDeferred) {
+ if (prefix == null) {
+ compiler.reportError(import,
+ MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX);
+ } else {
+ prefixDeferredImport[prefix] = import;
+ }
+ splitProgram = true;
+ _allDeferredImports[tag] = library.getLibraryFromTag(tag);
+ lastDeferred = import.metadata.first;
+ if (library == compiler.mainApp) {
+ deferredUsedFromMain = true;
+ }
+ }
+ if (prefix != null) {
+ if (previousDeferredImport != null ||
+ (isDeferred && usedPrefixes.contains(prefix))) {
+ Import failingImport = (previousDeferredImport != null)
+ ? previousDeferredImport
+ : import;
+ compiler.reportError(failingImport.prefix,
+ MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX);
+ }
+ usedPrefixes.add(prefix);
}
}
- }
+ });
}
if (splitProgram && !deferredUsedFromMain) {
compiler.reportInfo(
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698