diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt index 17468d0c0c8..a427e7a2055 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalCompilerRunner.kt @@ -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< } } } - diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt index 44db152438f..8531832bf35 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunner.kt @@ -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) ) } } diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotShrinker.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotShrinker.kt index 4a22ff39361..799800383b6 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotShrinker.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotShrinker.kt @@ -200,6 +200,7 @@ private sealed class ShrinkMode { } internal fun shrinkAndSaveClasspathSnapshot( + compilationWasIncremental: Boolean, classpathChanges: ClasspathChanges.ClasspathSnapshotEnabled, lookupStorage: LookupStorage, currentClasspathSnapshot: List?, // 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