Skip to content

Commit 1d1cc3c

Browse files
Ensure library dependencies are seen by SourceLoader
Change-Id: I3fa2cbc386446172fbbb1150d351ff9282678b7a Reviewed-on: https://dart-review.googlesource.com/35181 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Peter von der Ahé <[email protected]>
1 parent 69dfe14 commit 1d1cc3c

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

pkg/front_end/lib/src/external_state_snapshot.dart

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

55
// TODO(ahe): Remove this file.
66

7-
import 'package:kernel/kernel.dart' show Library, LibraryDependency, Program;
7+
import 'package:kernel/kernel.dart' show Library, Program;
88

99
/// Helper class to work around modifications in [kernel_generator_impl.dart].
1010
class ExternalStateSnapshot {
1111
final List<ExternalState> snapshots;
1212

1313
ExternalStateSnapshot(Program program)
14-
: snapshots = new List<ExternalState>.from(program.libraries.map((l) =>
15-
new ExternalState(l, l.dependencies.toList(), l.isExternal)));
14+
: snapshots = new List<ExternalState>.from(
15+
program.libraries.map((l) => new ExternalState(l, l.isExternal)));
1616

1717
void restore() {
1818
for (ExternalState state in snapshots) {
@@ -23,15 +23,11 @@ class ExternalStateSnapshot {
2323

2424
class ExternalState {
2525
final Library library;
26-
final List<LibraryDependency> dependencies;
2726
final bool isExternal;
2827

29-
ExternalState(this.library, this.dependencies, this.isExternal);
28+
ExternalState(this.library, this.isExternal);
3029

3130
void restore() {
3231
library.isExternal = isExternal;
33-
library.dependencies
34-
..clear()
35-
..addAll(dependencies);
3632
}
3733
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import 'dart:typed_data' show Uint8List;
1111
import 'package:front_end/src/fasta/type_inference/interface_resolver.dart'
1212
show InterfaceResolver;
1313

14-
import 'package:kernel/ast.dart' show Arguments, Expression, Library, Program;
14+
import 'package:kernel/ast.dart'
15+
show Arguments, Expression, Library, LibraryDependency, Program;
1516

1617
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
1718

@@ -541,17 +542,28 @@ class SourceLoader<L> extends Loader<L> {
541542
}
542543

543544
Program computeFullProgram() {
544-
List<Library> libraries = <Library>[];
545+
Set<Library> libraries = new Set<Library>();
546+
List<Library> workList = <Library>[];
545547
builders.forEach((Uri uri, LibraryBuilder library) {
546548
if (!library.isPart && !library.isPatch) {
547-
libraries.add(library.target);
549+
if (libraries.add(library.target)) {
550+
workList.add(library.target);
551+
}
548552
}
549553
});
554+
while (workList.isNotEmpty) {
555+
Library library = workList.removeLast();
556+
for (LibraryDependency dependency in library.dependencies) {
557+
if (libraries.add(dependency.targetLibrary)) {
558+
workList.add(dependency.targetLibrary);
559+
}
560+
}
561+
}
550562
return new Program()..libraries.addAll(libraries);
551563
}
552564

553565
void computeHierarchy() {
554-
hierarchy = new ClassHierarchy.deprecated_incremental(computeFullProgram());
566+
hierarchy = new ClassHierarchy(computeFullProgram());
555567
ticker.logMs("Computed class hierarchy");
556568
}
557569

@@ -634,8 +646,8 @@ class SourceLoader<L> extends Loader<L> {
634646
// target those forwarding stubs.
635647
// TODO(paulberry): could we make this unnecessary by not clearing class
636648
// inference info?
637-
typeInferenceEngine.classHierarchy = hierarchy =
638-
new ClassHierarchy.deprecated_incremental(computeFullProgram());
649+
typeInferenceEngine.classHierarchy =
650+
hierarchy = new ClassHierarchy(computeFullProgram());
639651
ticker.logMs("Performed top level inference");
640652
}
641653

pkg/front_end/lib/src/kernel_generator_impl.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ Future<CompilerResult> generateKernelInternal(
8080
dillTarget.loader.libraries.forEach((lib) {
8181
// TODO(ahe): Don't do this, and remove [external_state_snapshot.dart].
8282
lib.isExternal = true;
83-
lib.dependencies.clear();
8483
});
8584

8685
// Linked dependencies are meant to be part of the program so they are not

pkg/kernel/lib/binary/ast_from_binary.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,6 @@ class BinaryBuilder {
656656

657657
void _readLibraryDependencies(Library library) {
658658
int length = readUInt();
659-
if (library.isExternal) {
660-
assert(length == 0);
661-
return;
662-
}
663659
library.dependencies.length = length;
664660
for (int i = 0; i < length; ++i) {
665661
library.dependencies[i] = readLibraryDependency(library);

0 commit comments

Comments
 (0)