@@ -230,7 +230,19 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
230
230
Set <Uri > invalidatedUris = this .invalidatedUris.toSet ();
231
231
invalidateNotKeptUserBuilders (invalidatedUris);
232
232
ReusageResult reusedResult =
233
- computeReusedLibraries (invalidatedUris, uriTranslator);
233
+ computeReusedLibraries (invalidatedUris, uriTranslator, entryPoints);
234
+
235
+ // Use the reused libraries to re-write entry-points.
236
+ if (reusedResult.arePartsUsedAsEntryPoints ()) {
237
+ for (int i = 0 ; i < entryPoints.length; i++ ) {
238
+ Uri entryPoint = entryPoints[i];
239
+ Uri redirect =
240
+ reusedResult.getLibraryUriForPartUsedAsEntryPoint (entryPoint);
241
+ if (redirect != null ) {
242
+ entryPoints[i] = redirect;
243
+ }
244
+ }
245
+ }
234
246
235
247
// Experimental invalidation initialization (e.g. figure out if we can).
236
248
ExperimentalInvalidation experimentalInvalidation =
@@ -1440,18 +1452,26 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1440
1452
/// any saved component problems for such builders.
1441
1453
List <Library > computeTransitiveClosure (
1442
1454
List <Library > inputLibraries,
1443
- List <Uri > entries ,
1455
+ List <Uri > entryPoints ,
1444
1456
List <LibraryBuilder > reusedLibraries,
1445
1457
ClassHierarchy hierarchy,
1446
1458
UriTranslator uriTranslator,
1447
1459
Map <Uri , Source > uriToSource,
1448
1460
[List <Library > inputLibrariesFiltered]) {
1449
1461
List <Library > result = < Library > [];
1462
+ Map <Uri , Uri > partUriToLibraryImportUri = < Uri , Uri > {};
1450
1463
Map <Uri , Library > libraryMap = < Uri , Library > {};
1451
1464
Map <Uri , Library > potentiallyReferencedLibraries = < Uri , Library > {};
1452
1465
Map <Uri , Library > potentiallyReferencedInputLibraries = < Uri , Library > {};
1453
1466
for (Library library in inputLibraries) {
1454
1467
libraryMap[library.importUri] = library;
1468
+ if (library.parts.isNotEmpty) {
1469
+ for (int partIndex = 0 ; partIndex < library.parts.length; partIndex++ ) {
1470
+ LibraryPart part = library.parts[partIndex];
1471
+ Uri partUri = getPartUri (library.importUri, part);
1472
+ partUriToLibraryImportUri[partUri] = library.importUri;
1473
+ }
1474
+ }
1455
1475
if (library.importUri.scheme == "dart" ) {
1456
1476
result.add (library);
1457
1477
inputLibrariesFiltered? .add (library);
@@ -1460,9 +1480,6 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1460
1480
potentiallyReferencedInputLibraries[library.importUri] = library;
1461
1481
}
1462
1482
}
1463
-
1464
- List <Uri > worklist = < Uri > [];
1465
- worklist.addAll (entries);
1466
1483
for (LibraryBuilder libraryBuilder in reusedLibraries) {
1467
1484
if (libraryBuilder.importUri.scheme == "dart" &&
1468
1485
! libraryBuilder.isSynthetic) {
@@ -1473,6 +1490,19 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1473
1490
libraryMap[libraryBuilder.importUri] = lib;
1474
1491
}
1475
1492
1493
+ List <Uri > worklist = < Uri > [];
1494
+ for (Uri entry in entryPoints) {
1495
+ if (libraryMap.containsKey (entry)) {
1496
+ worklist.add (entry);
1497
+ } else {
1498
+ // If the entry is a part redirect to the "main" entry.
1499
+ Uri partTranslation = partUriToLibraryImportUri[entry];
1500
+ if (partTranslation != null ) {
1501
+ worklist.add (partTranslation);
1502
+ }
1503
+ }
1504
+ }
1505
+
1476
1506
LibraryGraph graph = new LibraryGraph (libraryMap);
1477
1507
Set <Uri > partsUsed = new Set <Uri >();
1478
1508
while (worklist.isNotEmpty && potentiallyReferencedLibraries.isNotEmpty) {
@@ -1928,8 +1958,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1928
1958
}
1929
1959
1930
1960
/// Internal method.
1931
- ReusageResult computeReusedLibraries (
1932
- Set <Uri > invalidatedUris, UriTranslator uriTranslator ) {
1961
+ ReusageResult computeReusedLibraries (Set < Uri > invalidatedUris,
1962
+ UriTranslator uriTranslator, List <Uri > entryPoints ) {
1933
1963
Set <Uri > seenUris = new Set <Uri >();
1934
1964
List <LibraryBuilder > reusedLibraries = < LibraryBuilder > [];
1935
1965
for (int i = 0 ; i < platformBuilders.length; i++ ) {
@@ -1938,14 +1968,15 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1938
1968
reusedLibraries.add (builder);
1939
1969
}
1940
1970
if (userCode == null && userBuilders == null ) {
1941
- return new ReusageResult ( const {}, const {}, false , reusedLibraries);
1971
+ return new ReusageResult . reusedLibrariesOnly ( reusedLibraries);
1942
1972
}
1943
1973
bool invalidatedBecauseOfPackageUpdate = false ;
1944
1974
Set <LibraryBuilder > directlyInvalidated = new Set <LibraryBuilder >();
1945
1975
Set <LibraryBuilder > notReusedLibraries = new Set <LibraryBuilder >();
1946
1976
1947
1977
// Maps all non-platform LibraryBuilders from their import URI.
1948
1978
Map <Uri , LibraryBuilder > builders = < Uri , LibraryBuilder > {};
1979
+ Map <Uri , LibraryBuilder > partUriToParent = < Uri , LibraryBuilder > {};
1949
1980
1950
1981
// Invalidated URIs translated back to their import URI (package:, dart:,
1951
1982
// etc.).
@@ -1989,7 +2020,10 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
1989
2020
invalidatedImportUris.add (uri);
1990
2021
}
1991
2022
if (libraryBuilder is SourceLibraryBuilder ) {
2023
+ // TODO(jensj): This shouldn't be possible anymore.
1992
2024
for (LibraryBuilder part in libraryBuilder.parts) {
2025
+ partUriToParent[part.importUri] = libraryBuilder;
2026
+ partUriToParent[part.fileUri] = libraryBuilder;
1993
2027
if (isInvalidated (part.importUri, part.fileUri)) {
1994
2028
invalidatedImportUris.add (part.importUri);
1995
2029
builders[part.importUri] = part;
@@ -2000,6 +2034,8 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
2000
2034
Uri partUri = getPartUri (libraryBuilder.importUri, part);
2001
2035
Uri fileUri = getPartFileUri (
2002
2036
libraryBuilder.library.fileUri, part, uriTranslator);
2037
+ partUriToParent[partUri] = libraryBuilder;
2038
+ partUriToParent[fileUri] = libraryBuilder;
2003
2039
2004
2040
if (isInvalidated (partUri, fileUri)) {
2005
2041
invalidatedImportUris.add (partUri);
@@ -2078,8 +2114,21 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
2078
2114
reusedLibraries.add (builder);
2079
2115
}
2080
2116
2081
- return new ReusageResult (notReusedLibraries, directlyInvalidated,
2082
- invalidatedBecauseOfPackageUpdate, reusedLibraries);
2117
+ ReusageResult result = new ReusageResult (
2118
+ notReusedLibraries,
2119
+ directlyInvalidated,
2120
+ invalidatedBecauseOfPackageUpdate,
2121
+ reusedLibraries);
2122
+
2123
+ for (Uri entryPoint in entryPoints) {
2124
+ LibraryBuilder parent = partUriToParent[entryPoint];
2125
+ if (reusedLibraries.contains (parent)) {
2126
+ result.registerLibraryUriForPartUsedAsEntryPoint (
2127
+ entryPoint, parent.importUri);
2128
+ }
2129
+ }
2130
+
2131
+ return result;
2083
2132
}
2084
2133
2085
2134
@override
@@ -2153,13 +2202,32 @@ class ReusageResult {
2153
2202
final Set <LibraryBuilder > directlyInvalidated;
2154
2203
final bool invalidatedBecauseOfPackageUpdate;
2155
2204
final List <LibraryBuilder > reusedLibraries;
2205
+ final Map <Uri , Uri > _reusedLibrariesPartsToParentForEntryPoints;
2206
+
2207
+ ReusageResult .reusedLibrariesOnly (this .reusedLibraries)
2208
+ : notReusedLibraries = const {},
2209
+ directlyInvalidated = const {},
2210
+ invalidatedBecauseOfPackageUpdate = false ,
2211
+ _reusedLibrariesPartsToParentForEntryPoints = const {};
2156
2212
2157
2213
ReusageResult (this .notReusedLibraries, this .directlyInvalidated,
2158
2214
this .invalidatedBecauseOfPackageUpdate, this .reusedLibraries)
2159
- : assert (notReusedLibraries != null ),
2215
+ : _reusedLibrariesPartsToParentForEntryPoints = {},
2216
+ assert (notReusedLibraries != null ),
2160
2217
assert (directlyInvalidated != null ),
2161
2218
assert (invalidatedBecauseOfPackageUpdate != null ),
2162
2219
assert (reusedLibraries != null );
2220
+
2221
+ void registerLibraryUriForPartUsedAsEntryPoint (
2222
+ Uri entryPoint, Uri importUri) {
2223
+ _reusedLibrariesPartsToParentForEntryPoints[entryPoint] = importUri;
2224
+ }
2225
+
2226
+ bool arePartsUsedAsEntryPoints () =>
2227
+ _reusedLibrariesPartsToParentForEntryPoints.isNotEmpty;
2228
+
2229
+ Uri getLibraryUriForPartUsedAsEntryPoint (Uri entryPoint) =>
2230
+ _reusedLibrariesPartsToParentForEntryPoints[entryPoint];
2163
2231
}
2164
2232
2165
2233
class ExperimentalInvalidation {
0 commit comments