Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 41d13f0

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Cleanup unused parts in uriToSource
Change-Id: Ie26fb25a0394999df1c681296ef96a90d51d8c13 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/120789 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent f09edd1 commit 41d13f0

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

pkg/front_end/lib/src/fasta/incremental_compiler.dart

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
249249

250250
bool removedDillBuilders = false;
251251
for (LibraryBuilder builder in notReusedLibraries) {
252-
// TODO(jensj): What about parts in uriToSource?
253-
CompilerContext.current.uriToSource.remove(builder.fileUri);
252+
cleanupSourcesForBuilder(
253+
builder, uriTranslator, CompilerContext.current.uriToSource);
254254
incrementalSerializer?.invalidate(builder.fileUri);
255255

256256
LibraryBuilder dillBuilder =
@@ -446,6 +446,19 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
446446
});
447447
}
448448

449+
void cleanupSourcesForBuilder(LibraryBuilder builder,
450+
UriTranslator uriTranslator, Map<Uri, Source> uriToSource,
451+
[Map<Uri, Source> uriToSourceExtra]) {
452+
uriToSource.remove(builder.fileUri);
453+
uriToSourceExtra?.remove(builder.fileUri);
454+
Library lib = builder.library;
455+
for (LibraryPart part in lib.parts) {
456+
Uri partFileUri = getPartFileUri(lib.fileUri, part, uriTranslator);
457+
uriToSource.remove(partFileUri);
458+
uriToSourceExtra?.remove(partFileUri);
459+
}
460+
}
461+
449462
@override
450463
CoreTypes getCoreTypes() => userCode?.loader?.coreTypes;
451464

@@ -710,8 +723,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
710723
Library lib = builder.library;
711724
removedLibraries.add(lib);
712725
dillLoadedData.loader.builders.remove(uri);
713-
CompilerContext.current.uriToSource.remove(uri);
714-
uriToSource.remove(uri);
726+
cleanupSourcesForBuilder(builder, uriTranslator,
727+
CompilerContext.current.uriToSource, uriToSource);
715728
userBuilders?.remove(uri);
716729
removeLibraryFromRemainingComponentProblems(lib, uriTranslator);
717730

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright (c) 2019, 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.md file.
4+
5+
# Compile an application with no packages and two libraries. Update the world
6+
# to now only include one library. The now no longer referenced library should
7+
# also have been removed from the uri to sources.
8+
9+
type: newworld
10+
worlds:
11+
- entry: main.dart
12+
sources:
13+
main.dart: |
14+
import "b.dart";
15+
main() { b(); }
16+
b.dart: |
17+
part 'c.dart';
18+
b() {
19+
c();
20+
}
21+
c.dart: |
22+
part of 'b.dart';
23+
c() {}
24+
expectedLibraryCount: 2
25+
- entry: main.dart
26+
worldType: updated
27+
invalidate:
28+
- b.dart
29+
expectInitializeFromDill: false
30+
sources:
31+
b.dart: |
32+
b() {}
33+
expectedLibraryCount: 2
34+
uriToSourcesDoesntInclude:
35+
- c.dart

pkg/front_end/testcases/incremental_initialize_from_dill/cleans_up_uritosource_non_package_unreferenced_libraries.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ worlds:
1414
import "b.dart";
1515
main() { b(); }
1616
b.dart: |
17-
b() {}
17+
part 'c.dart';
18+
b() {
19+
c();
20+
}
21+
c.dart: |
22+
part of 'b.dart';
23+
c() {}
1824
expectedLibraryCount: 2
1925
- entry: main.dart
2026
worldType: updated
@@ -27,6 +33,7 @@ worlds:
2733
expectedLibraryCount: 1
2834
uriToSourcesDoesntInclude:
2935
- b.dart
36+
- c.dart
3037
- entry: main.dart
3138
worldType: updated
3239
invalidate:
@@ -38,3 +45,4 @@ worlds:
3845
expectedLibraryCount: 1
3946
uriToSourcesDoesntInclude:
4047
- b.dart
48+
- c.dart

0 commit comments

Comments
 (0)