Skip to content

Commit aff5d76

Browse files
Serialize exports scopes.
[email protected] Review-Url: https://codereview.chromium.org/3009573002 .
1 parent 984382b commit aff5d76

13 files changed

+141
-4
lines changed

pkg/front_end/lib/src/fasta/builder/invalid_type_builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
library fasta.invalid_type_builder;
66

7+
import '../fasta_codes.dart' show Message;
8+
79
import 'builder.dart' show TypeBuilder, TypeDeclarationBuilder;
810

911
abstract class InvalidTypeBuilder<T extends TypeBuilder, R>
1012
extends TypeDeclarationBuilder<T, R> {
1113
InvalidTypeBuilder(String name, int charOffset, [Uri fileUri])
1214
: super(null, 0, name, null, charOffset, fileUri);
1315

16+
Message get message;
17+
1418
String get debugName => "InvalidTypeBuilder";
1519
}

pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44

55
library fasta.dill_library_builder;
66

7+
import 'dart:convert' show JSON;
8+
79
import 'package:kernel/ast.dart'
8-
show Class, Field, Library, ListLiteral, Member, StaticGet, Typedef;
10+
show
11+
Class,
12+
Field,
13+
Library,
14+
ListLiteral,
15+
Member,
16+
StaticGet,
17+
StringLiteral,
18+
Typedef;
19+
20+
import '../fasta_codes.dart' show templateUnspecified;
921

1022
import '../problems.dart' show unimplemented;
1123

@@ -35,6 +47,19 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
3547

3648
Library library;
3749

50+
/// Exports in addition to the members declared in this library.
51+
///
52+
/// Each entry in the list is either two or three elements long.
53+
///
54+
/// The first element is the library URI, if it is null, this is an ambiguous
55+
/// export and the list has three elements. Otherwise the list has two
56+
/// elements.
57+
///
58+
/// The second element is the name of the exported element.
59+
///
60+
/// The third element (if present) is an error message.
61+
List<List<String>> additionalExports;
62+
3863
DillLibraryBuilder(this.uri, this.loader)
3964
: super(uri, new Scope.top(), new Scope.top());
4065

@@ -64,9 +89,9 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
6489
void addMember(Member member) {
6590
String name = member.name.name;
6691
if (name == "_exports#") {
67-
// TODO(ahe): Add this to exportScope.
68-
// This is a hack / work around for storing exports in dill files. See
69-
// [compile_platform_dartk.dart](../analyzer/compile_platform_dartk.dart).
92+
Field field = member;
93+
StringLiteral string = field.initializer;
94+
additionalExports = JSON.decode(string.value);
7095
} else {
7196
addBuilder(name, new DillMemberBuilder(member, this), member.fileOffset);
7297
}
@@ -118,4 +143,28 @@ class DillLibraryBuilder extends LibraryBuilder<KernelTypeBuilder, Library> {
118143
String get fullNameForErrors {
119144
return library.name ?? "<library '${library.fileUri}'>";
120145
}
146+
147+
void finalizeExports() {
148+
if (additionalExports != null) {
149+
for (List<String> additionalExport in additionalExports) {
150+
Uri originUri = Uri.parse(additionalExport[0]);
151+
String name = additionalExport[1];
152+
Builder builder;
153+
if (originUri == null) {
154+
builder = new KernelInvalidTypeBuilder(name, -1, null,
155+
templateUnspecified.withArguments(additionalExport[2]));
156+
} else {
157+
DillLibraryBuilder library = loader.read(originUri, -1);
158+
builder = library.exportScopeBuilder[name];
159+
if (library != null) {
160+
builder = library.exportScopeBuilder[name];
161+
}
162+
if (builder == null) {
163+
builder = new KernelInvalidTypeBuilder(name, -1, null);
164+
}
165+
}
166+
exportScopeBuilder.addMember(name, builder);
167+
}
168+
}
169+
}
121170
}

pkg/front_end/lib/src/fasta/dill/dill_loader.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'dart:async' show Future;
88

99
import 'package:kernel/ast.dart' show Library, Program, Source;
1010

11+
import '../kernel/kernel_builder.dart' show LibraryBuilder;
12+
1113
import '../loader.dart' show Loader;
1214

1315
import '../problems.dart' show unhandled;
@@ -55,4 +57,11 @@ class DillLoader extends Loader<Library> {
5557
Future<Null> buildBody(DillLibraryBuilder builder) {
5658
return buildOutline(builder);
5759
}
60+
61+
void finalizeExports() {
62+
builders.forEach((Uri uri, LibraryBuilder builder) {
63+
DillLibraryBuilder library = builder;
64+
library.finalizeExports();
65+
});
66+
}
5867
}

pkg/front_end/lib/src/fasta/dill/dill_target.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class DillTarget extends TargetImplementation {
5151
Future<Null> buildOutlines() async {
5252
if (loader.libraries.isNotEmpty) {
5353
await loader.buildOutlines();
54+
loader.finalizeExports();
5455
}
5556
isLoaded = true;
5657
}

pkg/front_end/lib/src/fasta/kernel/kernel_invalid_type_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'kernel_builder.dart'
1313

1414
class KernelInvalidTypeBuilder
1515
extends InvalidTypeBuilder<KernelTypeBuilder, DartType> {
16+
@override
1617
final Message message;
1718

1819
KernelInvalidTypeBuilder(String name, int charOffset, Uri fileUri,

pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
library fasta.kernel_library_builder;
66

7+
import 'dart:convert' show JSON;
8+
79
import 'package:front_end/src/fasta/combinator.dart' as fasta;
810
import 'package:front_end/src/fasta/export.dart';
911
import 'package:front_end/src/fasta/import.dart';
@@ -780,6 +782,14 @@ class KernelLibraryBuilder
780782

781783
library.name = name;
782784
library.procedures.sort(compareProcedures);
785+
786+
if (additionalExports != null) {
787+
library.addMember(new Field(new Name("_exports#", library),
788+
initializer: new StringLiteral(JSON.encode(additionalExports)),
789+
isStatic: true,
790+
isConst: true));
791+
}
792+
783793
return library;
784794
}
785795

pkg/front_end/lib/src/fasta/source/source_library_builder.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../builder/builder.dart'
1717
ConstructorReferenceBuilder,
1818
FormalParameterBuilder,
1919
FunctionTypeBuilder,
20+
InvalidTypeBuilder,
2021
LibraryBuilder,
2122
MemberBuilder,
2223
MetadataBuilder,
@@ -96,6 +97,12 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
9697

9798
bool canAddImplementationBuilders = false;
9899

100+
/// Exports in addition to the members declared in this library.
101+
///
102+
/// See [../dill/dill_library_builder.dart] for additional details on the
103+
/// format used.
104+
List<List<String>> additionalExports;
105+
99106
SourceLibraryBuilder(SourceLoader loader, Uri fileUri)
100107
: this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(),
101108
new Scope.top());
@@ -512,6 +519,19 @@ abstract class SourceLibraryBuilder<T extends TypeBuilder, R>
512519
addToScope(name, member, -1, true);
513520
});
514521
}
522+
exportScope.forEach((String name, Builder member) {
523+
if (member.parent != this) {
524+
additionalExports ??= <List<String>>[];
525+
Builder parent = member.parent;
526+
if (parent is LibraryBuilder) {
527+
additionalExports.add(<String>["${parent.uri}", name]);
528+
} else {
529+
InvalidTypeBuilder invalidType = member;
530+
String message = invalidType.message.message;
531+
additionalExports.add(<String>[null, name, message]);
532+
}
533+
}
534+
});
515535
}
516536

517537
@override

pkg/front_end/messages.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,3 +913,4 @@ InvalidPackageUri:
913913
IntegerLiteralIsOutOfRange:
914914
template: "The integer literal #lexeme can't be represented in 64 bits."
915915
tip: "Try using BigInt (from 'dart:typed_data' library) if you need an integer larger than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808."
916+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Test that exports are serialized in platform.dill.
6+
7+
// Note: "dart:profiler" exports UserTag from "dart:developer". This is
8+
// somewhat brittle and we should extend this test framework to be able to deal
9+
// with multiple .dill files.
10+
import 'dart:profiler' show UserTag;
11+
12+
export 'dart:core' show print;
13+
14+
main() {
15+
print(UserTag);
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:developer" as dev;
5+
6+
static const field dynamic _exports# = "[[\"dart:core\",\"print\"]]" /* from null */;
7+
static method main() → dynamic {
8+
core::print(dev::UserTag);
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library;
2+
import self as self;
3+
4+
static const field dynamic _exports# = "[[\"dart:core\",\"print\"]]" /* from null */;
5+
static method main() → dynamic
6+
;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
import "dart:developer" as dev;
5+
6+
static const field dynamic _exports# = "[[\"dart:core\",\"print\"]]" /* from null */;
7+
static method main() → dynamic {
8+
core::print(dev::UserTag);
9+
}

pkg/front_end/testcases/outline.status

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,5 @@ rasta/type_with_parse_error: Fail
278278
regress/issue_29977: Crash # Issue 29977.
279279
regress/issue_29985: Crash # Issue 29985.
280280
regress/issue_29987: Crash # Issue 29987.
281+
282+
rasta/export: Fail # TODO(ahe): Remove absolute URI.

0 commit comments

Comments
 (0)