Shrink snapshots non-incrementally after fallback
If incremental compilation fails, we currently fall back to non-incremental compilation. When that happens, it would be incorrect to shrink classpath snapshot incrementally, so this commit makes sure we'll shrink classpath snapshot non-incrementally in that case. ^KT-53231 In progress
This commit is contained in:
+7
-6
@@ -116,7 +116,7 @@ abstract class IncrementalCompilerRunner<
|
||||
classpathAbiSnapshot = classpathAbiSnapshot
|
||||
).also {
|
||||
if (it == ExitCode.OK) {
|
||||
performWorkAfterSuccessfulCompilation(caches)
|
||||
performWorkAfterSuccessfulCompilation(caches, wasIncremental = false)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -179,7 +179,7 @@ abstract class IncrementalCompilerRunner<
|
||||
compileIncrementally(args, caches, allSourceFiles, compilationMode, messageCollector, withAbiSnapshot)
|
||||
}
|
||||
if (exitCode == ExitCode.OK) {
|
||||
performWorkAfterSuccessfulCompilation(caches)
|
||||
performWorkAfterSuccessfulCompilation(caches, wasIncremental = true)
|
||||
}
|
||||
return exitCode
|
||||
} catch (e: Throwable) {
|
||||
@@ -516,11 +516,13 @@ abstract class IncrementalCompilerRunner<
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs some work after a compilation if the compilation completed successfully.
|
||||
* Performs some work after a compilation if the compilation completed successfully (no exceptions were thrown AND exit code == 0).
|
||||
*
|
||||
* This method MUST NOT be called when the compilation failed because the results produced by the work here would be incorrect.
|
||||
* This method MUST NOT be called when the compilation failed because the results produced by the work here would be invalid.
|
||||
*
|
||||
* @wasIncremental whether the compilation was incremental or non-incremental
|
||||
*/
|
||||
protected open fun performWorkAfterSuccessfulCompilation(caches: CacheManager) {}
|
||||
protected open fun performWorkAfterSuccessfulCompilation(caches: CacheManager, wasIncremental: Boolean) {}
|
||||
|
||||
companion object {
|
||||
const val DIRTY_SOURCES_FILE_NAME = "dirty-sources.txt"
|
||||
@@ -543,4 +545,3 @@ abstract class IncrementalCompilerRunner<
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -478,12 +478,12 @@ open class IncrementalJvmCompilerRunner(
|
||||
return exitCode to sourcesToCompile
|
||||
}
|
||||
|
||||
override fun performWorkAfterSuccessfulCompilation(caches: IncrementalJvmCachesManager) {
|
||||
override fun performWorkAfterSuccessfulCompilation(caches: IncrementalJvmCachesManager, wasIncremental: Boolean) {
|
||||
if (classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled) {
|
||||
reporter.measure(BuildTime.SHRINK_AND_SAVE_CURRENT_CLASSPATH_SNAPSHOT_AFTER_COMPILATION) {
|
||||
shrinkAndSaveClasspathSnapshot(
|
||||
classpathChanges, caches.lookupCache, currentClasspathSnapshot, shrunkCurrentClasspathAgainstPreviousLookups,
|
||||
ClasspathSnapshotBuildReporter(reporter)
|
||||
wasIncremental, classpathChanges, caches.lookupCache, currentClasspathSnapshot,
|
||||
shrunkCurrentClasspathAgainstPreviousLookups, ClasspathSnapshotBuildReporter(reporter)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -200,6 +200,7 @@ private sealed class ShrinkMode {
|
||||
}
|
||||
|
||||
internal fun shrinkAndSaveClasspathSnapshot(
|
||||
compilationWasIncremental: Boolean,
|
||||
classpathChanges: ClasspathChanges.ClasspathSnapshotEnabled,
|
||||
lookupStorage: LookupStorage,
|
||||
currentClasspathSnapshot: List<AccessibleClassSnapshot>?, // Not null iff classpathChanges is ToBeComputedByIncrementalCompiler
|
||||
@@ -210,7 +211,9 @@ internal fun shrinkAndSaveClasspathSnapshot(
|
||||
// For incremental shrinking, we currently use only lookupStorage.addedLookupSymbols, not lookupStorage.removedLookupSymbols. It is
|
||||
// because updating the shrunk classpath snapshot for removedLookupSymbols is expensive. Therefore, the shrunk classpath snapshot may be
|
||||
// larger than necessary (and non-deterministic), but it is okay for it to be an over-approximation.
|
||||
val shrinkMode = when (classpathChanges) {
|
||||
val shrinkMode = if (!compilationWasIncremental) {
|
||||
ShrinkMode.NonIncremental
|
||||
} else when (classpathChanges) {
|
||||
is NoChanges -> {
|
||||
val addedLookupSymbols = lookupStorage.addedLookupSymbols
|
||||
if (addedLookupSymbols.isEmpty()) {
|
||||
@@ -234,7 +237,8 @@ internal fun shrinkAndSaveClasspathSnapshot(
|
||||
)
|
||||
}
|
||||
}
|
||||
is NotAvailableDueToMissingClasspathSnapshot, is NotAvailableForNonIncrementalRun -> ShrinkMode.NonIncremental
|
||||
is NotAvailableDueToMissingClasspathSnapshot -> ShrinkMode.NonIncremental
|
||||
is NotAvailableForNonIncrementalRun -> error("NotAvailableForNonIncrementalRun is not expected as compilationWasIncremental==true")
|
||||
}
|
||||
|
||||
// Shrink current classpath against current lookups
|
||||
|
||||
Reference in New Issue
Block a user