Redesign LibraryPart
Before, the part-URI was serialized as a file-URI and conflated with
source location information. The part-URI is the URI in the following
declaration in a Dart source file:
part "URI";
This is different from what we normally call a file-URI. A file URI
is used to point to the source location of the part declaration, not
the URI in the part declaration.
Furthermore, the field was serialized using writeUriReference which
only works for URIs that are in the uriToSource map on a Component.
Although this might seem like a safe optimization, it doesn't work
if the uriToSource map is omitted or if a part declaration refers to
a missing file.
Finally, due to the confusing use of fileUri, LibraryPart was
mistakenly implementing FileUriNode and annotations were stripped
of source locations if the source for the part were omitted from
uriToSource.
The partUri field is now an unresolved string that can be resolved
against either the parent library's import- or file-URI to obtain
either version as needed.
Change-Id: I255cb4eeaf89928292ab32a2f6be9ead6cc8cee1
Reviewed-on: https://dart-review.googlesource.com/49500
Commit-Queue: Peter von der Ahé <ahe@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart b/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
index 9340caf..ba59397 100644
--- a/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
@@ -272,7 +272,7 @@
addFileResult(library.fileUri);
for (var part in library.parts) {
- addFileResult(part.fileUri);
+ addFileResult(library.fileUri.resolve(part.partUri));
}
var libraryResult = new LibraryCompilationResult(
@@ -328,7 +328,7 @@
// Remember libraries for parts.
for (var part in library.parts) {
- _partToLibrary[part.fileUri] = library.fileUri;
+ _partToLibrary[library.fileUri.resolve(part.partUri)] = library.fileUri;
}
// Record reverse dependencies.
diff --git a/pkg/analyzer/lib/src/kernel/resynthesize.dart b/pkg/analyzer/lib/src/kernel/resynthesize.dart
index 5586c26..a66763e 100644
--- a/pkg/analyzer/lib/src/kernel/resynthesize.dart
+++ b/pkg/analyzer/lib/src/kernel/resynthesize.dart
@@ -201,7 +201,7 @@
// Build units for parts.
var parts = new List<CompilationUnitElementImpl>(kernel.parts.length);
for (int i = 0; i < kernel.parts.length; i++) {
- var fileUri = kernel.parts[i].fileUri;
+ var fileUri = kernel.fileUri.resolve(kernel.parts[i].partUri);
var unitContext = libraryContext._buildUnit("$fileUri");
parts[i] = unitContext.unit;
}
@@ -974,7 +974,8 @@
List<kernel.Expression> get annotations {
if (_annotations == null) {
for (var part in context.libraryContext.library.parts) {
- if ("${part.fileUri}" == context.fileUri) {
+ if ("${context.libraryContext.library.fileUri.resolve(part.partUri)}" ==
+ context.fileUri) {
return _annotations = part.annotations;
}
}
diff --git a/pkg/front_end/lib/src/fasta/builder_graph.dart b/pkg/front_end/lib/src/fasta/builder_graph.dart
index b4350b1..7f54bc2 100644
--- a/pkg/front_end/lib/src/fasta/builder_graph.dart
+++ b/pkg/front_end/lib/src/fasta/builder_graph.dart
@@ -60,7 +60,7 @@
// Parts
for (LibraryPart part in library.library.parts) {
- Uri uri = part.fileUri;
+ Uri uri = library.uri.resolve(part.partUri);
if (builders.containsKey(uri)) {
yield uri;
}
diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
index 4a00f0a..3693a7d 100644
--- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart
+++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
@@ -348,7 +348,8 @@
}
} else if (library is DillLibraryBuilder) {
for (LibraryPart part in library.library.parts) {
- addBuilderAndInvalidateUris(part.fileUri, library, false);
+ Uri partUri = library.uri.resolve(part.partUri);
+ addBuilderAndInvalidateUris(partUri, library, false);
}
}
}
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart
index 4cbda32..5bd9437 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart
@@ -810,12 +810,20 @@
}
for (KernelLibraryBuilder part in parts) {
- library.addPart(new LibraryPart(<Expression>[], part.fileUri));
part.addDependencies(library, seen);
}
}
@override
+ void addPart(List<MetadataBuilder> metadata, String uri, int charOffset) {
+ super.addPart(metadata, uri, charOffset);
+ // TODO(ahe): [metadata] should be stored, evaluated, and added to [part].
+ LibraryPart part = new LibraryPart(<Expression>[], uri)
+ ..fileOffset = charOffset;
+ library.addPart(part);
+ }
+
+ @override
Library build(LibraryBuilder coreLibrary) {
super.build(coreLibrary);
diff --git a/pkg/kernel/binary.md b/pkg/kernel/binary.md
index 6a577c3..2806388 100644
--- a/pkg/kernel/binary.md
+++ b/pkg/kernel/binary.md
@@ -238,8 +238,8 @@
}
type LibraryPart {
- UriReference fileUri;
List<Expression> annotations;
+ StringReference partUri;
}
type Typedef {
diff --git a/pkg/kernel/lib/ast.dart b/pkg/kernel/lib/ast.dart
index c2fa92f..dcb6c66 100644
--- a/pkg/kernel/lib/ast.dart
+++ b/pkg/kernel/lib/ast.dart
@@ -523,14 +523,11 @@
/// part <url>;
///
/// optionally with metadata.
-class LibraryPart extends TreeNode implements FileUriNode {
+class LibraryPart extends TreeNode {
final List<Expression> annotations;
- final Uri fileUri;
+ final String partUri;
- LibraryPart(List<Expression> annotations, Uri fileUri)
- : this.byReference(annotations, fileUri);
-
- LibraryPart.byReference(this.annotations, this.fileUri) {
+ LibraryPart(this.annotations, this.partUri) {
setParents(annotations, this);
}
diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart
index 951aedd..97fd9dd 100644
--- a/pkg/kernel/lib/binary/ast_from_binary.dart
+++ b/pkg/kernel/lib/binary/ast_from_binary.dart
@@ -715,9 +715,9 @@
}
LibraryPart readLibraryPart(Library library) {
- var fileUri = readUriReference();
- var annotations = readExpressionList();
- return new LibraryPart(annotations, fileUri)..parent = library;
+ List<Expression> annotations = readExpressionList();
+ String partUri = readStringReference();
+ return new LibraryPart(annotations, partUri)..parent = library;
}
Typedef readTypedef() {
diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart
index a050b72..ec68922 100644
--- a/pkg/kernel/lib/binary/ast_to_binary.dart
+++ b/pkg/kernel/lib/binary/ast_to_binary.dart
@@ -665,10 +665,8 @@
if (_metadataSubsections != null) {
_recordNodeOffsetForMetadataMapping(node);
}
- final Uri activeFileUriSaved = _activeFileUri;
- _activeFileUri = writeUriReference(node.fileUri);
writeNodeList(node.annotations);
- _activeFileUri = activeFileUriSaved;
+ writeStringReference(node.partUri);
}
void visitTypedef(Typedef node) {
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index d39e205..e598e3e 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -5987,8 +5987,8 @@
}
void StreamingFlowGraphBuilder::SkipLibraryPart() {
- ReadUInt(); // Read source_uri_index.
SkipListOfExpressions(); // Read annotations.
+ SkipStringReference(); // Read part URI index.
}
void StreamingFlowGraphBuilder::SkipLibraryTypedef() {