[Gradle] Add a property to control if the IC caches in-memory wrapper is enabled

#KT-56052 In Progress
This commit is contained in:
Alexander.Likhachev
2023-01-25 20:25:36 +01:00
committed by Space Team
parent e7e5a3488b
commit 3ed651a7a6
13 changed files with 56 additions and 19 deletions
@@ -35,11 +35,13 @@ class IncrementalCompilationContext(
transaction: CompilationTransaction = DummyCompilationTransaction(), transaction: CompilationTransaction = DummyCompilationTransaction(),
reporter: ICReporter = DoNothingICReporter, reporter: ICReporter = DoNothingICReporter,
trackChangesInLookupCache: Boolean = false, trackChangesInLookupCache: Boolean = false,
keepIncrementalCompilationCachesInMemory: Boolean = false,
) : this( ) : this(
createDefaultPathConverter(rootProjectDir), createDefaultPathConverter(rootProjectDir),
storeFullFqNamesInLookupCache, storeFullFqNamesInLookupCache,
transaction, transaction,
reporter, reporter,
trackChangesInLookupCache, trackChangesInLookupCache,
keepIncrementalCompilationCachesInMemory
) )
} }
@@ -73,6 +73,7 @@ class IncrementalCompilationOptions(
kotlinScriptExtensions: Array<String>? = null, kotlinScriptExtensions: Array<String>? = null,
val withAbiSnapshot: Boolean = false, val withAbiSnapshot: Boolean = false,
val preciseCompilationResultsBackup: Boolean = false, val preciseCompilationResultsBackup: Boolean = false,
val keepIncrementalCompilationCachesInMemory: Boolean = false,
) : CompilationOptions( ) : CompilationOptions(
compilerMode, compilerMode,
targetPlatform, targetPlatform,
@@ -82,7 +83,7 @@ class IncrementalCompilationOptions(
kotlinScriptExtensions kotlinScriptExtensions
) { ) {
companion object { companion object {
const val serialVersionUID: Long = 1 const val serialVersionUID: Long = 2
} }
override fun toString(): String { override fun toString(): String {
@@ -559,6 +559,7 @@ abstract class CompileServiceImplBase(
modulesApiHistory = modulesApiHistory, modulesApiHistory = modulesApiHistory,
withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot, withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot,
preciseCompilationResultsBackup = incrementalCompilationOptions.preciseCompilationResultsBackup, preciseCompilationResultsBackup = incrementalCompilationOptions.preciseCompilationResultsBackup,
keepIncrementalCompilationCachesInMemory = incrementalCompilationOptions.keepIncrementalCompilationCachesInMemory,
) )
return try { return try {
compiler.compile(allKotlinFiles, args, compilerMessageCollector, changedFiles) compiler.compile(allKotlinFiles, args, compilerMessageCollector, changedFiles)
@@ -619,6 +620,7 @@ abstract class CompileServiceImplBase(
classpathChanges = incrementalCompilationOptions.classpathChanges, classpathChanges = incrementalCompilationOptions.classpathChanges,
withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot, withAbiSnapshot = incrementalCompilationOptions.withAbiSnapshot,
preciseCompilationResultsBackup = incrementalCompilationOptions.preciseCompilationResultsBackup, preciseCompilationResultsBackup = incrementalCompilationOptions.preciseCompilationResultsBackup,
keepIncrementalCompilationCachesInMemory = incrementalCompilationOptions.keepIncrementalCompilationCachesInMemory,
) )
return try { return try {
compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, changedFiles, projectRoot) compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, changedFiles, projectRoot)
@@ -72,6 +72,7 @@ abstract class IncrementalCompilerRunner<
protected val withAbiSnapshot: Boolean = false, protected val withAbiSnapshot: Boolean = false,
private val preciseCompilationResultsBackup: Boolean = false, private val preciseCompilationResultsBackup: Boolean = false,
private val keepIncrementalCompilationCachesInMemory: Boolean = false,
) { ) {
protected val cacheDirectory = File(workingDir, cacheDirName) protected val cacheDirectory = File(workingDir, cacheDirName)
@@ -83,10 +84,21 @@ abstract class IncrementalCompilerRunner<
/** /**
* Creates an instance of [IncrementalCompilationContext] that holds common incremental compilation context mostly required for [CacheManager] * Creates an instance of [IncrementalCompilationContext] that holds common incremental compilation context mostly required for [CacheManager]
*/ */
protected abstract fun createIncrementalCompilationContext( private fun createIncrementalCompilationContext(
projectDir: File?, projectDir: File?,
transaction: CompilationTransaction transaction: CompilationTransaction
): IncrementalCompilationContext ) = IncrementalCompilationContext(
transaction = transaction,
rootProjectDir = projectDir,
reporter = reporter,
trackChangesInLookupCache = shouldTrackChangesInLookupCache,
storeFullFqNamesInLookupCache = shouldStoreFullFqNamesInLookupCache,
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory,
)
protected abstract val shouldTrackChangesInLookupCache: Boolean
protected abstract val shouldStoreFullFqNamesInLookupCache: Boolean
protected abstract fun createCacheManager(icContext: IncrementalCompilationContext, args: Args): CacheManager protected abstract fun createCacheManager(icContext: IncrementalCompilationContext, args: Args): CacheManager
protected abstract fun destinationDir(args: Args): File protected abstract fun destinationDir(args: Args): File
@@ -89,6 +89,7 @@ class IncrementalJsCompilerRunner(
private val scopeExpansion: CompileScopeExpansionMode = CompileScopeExpansionMode.NEVER, private val scopeExpansion: CompileScopeExpansionMode = CompileScopeExpansionMode.NEVER,
withAbiSnapshot: Boolean = false, withAbiSnapshot: Boolean = false,
preciseCompilationResultsBackup: Boolean = false, preciseCompilationResultsBackup: Boolean = false,
keepIncrementalCompilationCachesInMemory: Boolean = false,
) : IncrementalCompilerRunner<K2JSCompilerArguments, IncrementalJsCachesManager>( ) : IncrementalCompilerRunner<K2JSCompilerArguments, IncrementalJsCachesManager>(
workingDir, workingDir,
"caches-js", "caches-js",
@@ -97,14 +98,13 @@ class IncrementalJsCompilerRunner(
outputDirs = null, outputDirs = null,
withAbiSnapshot = withAbiSnapshot, withAbiSnapshot = withAbiSnapshot,
preciseCompilationResultsBackup = preciseCompilationResultsBackup, preciseCompilationResultsBackup = preciseCompilationResultsBackup,
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory,
) { ) {
override fun createIncrementalCompilationContext(projectDir: File?, transaction: CompilationTransaction) = override val shouldTrackChangesInLookupCache
IncrementalCompilationContext( get() = false
transaction = transaction,
rootProjectDir = projectDir, override val shouldStoreFullFqNamesInLookupCache
reporter = reporter, get() = withAbiSnapshot
storeFullFqNamesInLookupCache = withAbiSnapshot,
)
override fun createCacheManager(icContext: IncrementalCompilationContext, args: K2JSCompilerArguments) = override fun createCacheManager(icContext: IncrementalCompilationContext, args: K2JSCompilerArguments) =
IncrementalJsCachesManager(icContext, if (!args.isIrBackendEnabled()) JsSerializerProtocol else KlibMetadataSerializerProtocol, cacheDirectory) IncrementalJsCachesManager(icContext, if (!args.isIrBackendEnabled()) JsSerializerProtocol else KlibMetadataSerializerProtocol, cacheDirectory)
@@ -142,6 +142,7 @@ open class IncrementalJvmCompilerRunner(
private val classpathChanges: ClasspathChanges, private val classpathChanges: ClasspathChanges,
withAbiSnapshot: Boolean = false, withAbiSnapshot: Boolean = false,
preciseCompilationResultsBackup: Boolean = false, preciseCompilationResultsBackup: Boolean = false,
keepIncrementalCompilationCachesInMemory: Boolean = false,
) : IncrementalCompilerRunner<K2JVMCompilerArguments, IncrementalJvmCachesManager>( ) : IncrementalCompilerRunner<K2JVMCompilerArguments, IncrementalJvmCachesManager>(
workingDir, workingDir,
"caches-jvm", "caches-jvm",
@@ -150,15 +151,13 @@ open class IncrementalJvmCompilerRunner(
outputDirs = outputDirs, outputDirs = outputDirs,
withAbiSnapshot = withAbiSnapshot, withAbiSnapshot = withAbiSnapshot,
preciseCompilationResultsBackup = preciseCompilationResultsBackup, preciseCompilationResultsBackup = preciseCompilationResultsBackup,
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory,
) { ) {
override fun createIncrementalCompilationContext(projectDir: File?, transaction: CompilationTransaction) = override val shouldTrackChangesInLookupCache
IncrementalCompilationContext( get() = classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled.IncrementalRun
transaction = transaction,
rootProjectDir = projectDir, override val shouldStoreFullFqNamesInLookupCache
reporter = reporter, get() = withAbiSnapshot || classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled
trackChangesInLookupCache = classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled.IncrementalRun,
storeFullFqNamesInLookupCache = withAbiSnapshot || classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled,
)
override fun createCacheManager(icContext: IncrementalCompilationContext, args: K2JVMCompilerArguments) = override fun createCacheManager(icContext: IncrementalCompilationContext, args: K2JVMCompilerArguments) =
IncrementalJvmCachesManager(icContext, args.destination?.let { File(it) }, cacheDirectory) IncrementalJvmCachesManager(icContext, args.destination?.let { File(it) }, cacheDirectory)
@@ -298,6 +298,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
kotlinScriptExtensions = kotlinScriptExtensions, kotlinScriptExtensions = kotlinScriptExtensions,
withAbiSnapshot = icEnv.withAbiSnapshot, withAbiSnapshot = icEnv.withAbiSnapshot,
preciseCompilationResultsBackup = icEnv.preciseCompilationResultsBackup, preciseCompilationResultsBackup = icEnv.preciseCompilationResultsBackup,
keepIncrementalCompilationCachesInMemory = icEnv.keepIncrementalCompilationCachesInMemory
) )
log.info("Options for KOTLIN DAEMON: $compilationOptions") log.info("Options for KOTLIN DAEMON: $compilationOptions")
@@ -20,8 +20,9 @@ internal class IncrementalCompilationEnvironment(
val multiModuleICSettings: MultiModuleICSettings, val multiModuleICSettings: MultiModuleICSettings,
val withAbiSnapshot: Boolean = false, val withAbiSnapshot: Boolean = false,
val preciseCompilationResultsBackup: Boolean = false, val preciseCompilationResultsBackup: Boolean = false,
val keepIncrementalCompilationCachesInMemory: Boolean = false,
) : Serializable { ) : Serializable {
companion object { companion object {
const val serialVersionUID: Long = 2 const val serialVersionUID: Long = 3
} }
} }
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStream
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.Companion.jsCompilerProperty import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.Companion.jsCompilerProperty
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_STDLIB_DOM_API_INCLUDED import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_STDLIB_DOM_API_INCLUDED
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ABI_SNAPSHOT import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ABI_SNAPSHOT
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_KEEP_INCREMENTAL_COMPILATION_CACHES_IN_MEMORY
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_GRADLE_PLUGIN_COMPATIBILITY_NO_WARN import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_GRADLE_PLUGIN_COMPATIBILITY_NO_WARN
@@ -511,6 +512,12 @@ internal class PropertiesProvider private constructor(private val project: Proje
val preciseCompilationResultsBackup: Boolean val preciseCompilationResultsBackup: Boolean
get() = booleanProperty(KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP) ?: false get() = booleanProperty(KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP) ?: false
/**
* This property should be enabled together with [preciseCompilationResultsBackup]
*/
val keepIncrementalCompilationCachesInMemory: Boolean
get() = booleanProperty(KOTLIN_COMPILER_KEEP_INCREMENTAL_COMPILATION_CACHES_IN_MEMORY) ?: false
/** /**
* Retrieves a comma-separated list of browsers to use when running karma tests for [target] * Retrieves a comma-separated list of browsers to use when running karma tests for [target]
* @see KOTLIN_JS_KARMA_BROWSERS * @see KOTLIN_JS_KARMA_BROWSERS
@@ -593,6 +600,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
const val KOTLIN_OPTIONS_SUPPRESS_FREEARGS_MODIFICATION_WARNING = "kotlin.options.suppressFreeCompilerArgsModificationWarning" const val KOTLIN_OPTIONS_SUPPRESS_FREEARGS_MODIFICATION_WARNING = "kotlin.options.suppressFreeCompilerArgsModificationWarning"
const val KOTLIN_NATIVE_USE_XCODE_MESSAGE_STYLE = "kotlin.native.useXcodeMessageStyle" const val KOTLIN_NATIVE_USE_XCODE_MESSAGE_STYLE = "kotlin.native.useXcodeMessageStyle"
const val KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP = "kotlin.compiler.preciseCompilationResultsBackup" const val KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP = "kotlin.compiler.preciseCompilationResultsBackup"
const val KOTLIN_COMPILER_KEEP_INCREMENTAL_COMPILATION_CACHES_IN_MEMORY = "kotlin.compiler.keepIncrementalCompilationCachesInMemory"
} }
companion object { companion object {
@@ -191,6 +191,9 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
@get:Internal @get:Internal
internal abstract val preciseCompilationResultsBackup: Property<Boolean> internal abstract val preciseCompilationResultsBackup: Property<Boolean>
@get:Internal
internal abstract val keepIncrementalCompilationCachesInMemory: Property<Boolean>
/** Task outputs that we don't want to include in [TaskOutputsBackup] (see [TaskOutputsBackup.outputsToRestore] for more info). */ /** Task outputs that we don't want to include in [TaskOutputsBackup] (see [TaskOutputsBackup.outputsToRestore] for more info). */
@get:Internal @get:Internal
internal abstract val taskOutputsBackupExcludes: SetProperty<File> internal abstract val taskOutputsBackupExcludes: SetProperty<File>
@@ -300,6 +300,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
taskBuildCacheableOutputDirectory.get().asFile, taskBuildCacheableOutputDirectory.get().asFile,
multiModuleICSettings = multiModuleICSettings, multiModuleICSettings = multiModuleICSettings,
preciseCompilationResultsBackup = preciseCompilationResultsBackup.get(), preciseCompilationResultsBackup = preciseCompilationResultsBackup.get(),
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory.get(),
) )
} else null } else null
@@ -278,6 +278,7 @@ abstract class KotlinCompile @Inject constructor(
multiModuleICSettings = multiModuleICSettings, multiModuleICSettings = multiModuleICSettings,
withAbiSnapshot = useKotlinAbiSnapshot.get(), withAbiSnapshot = useKotlinAbiSnapshot.get(),
preciseCompilationResultsBackup = preciseCompilationResultsBackup.get(), preciseCompilationResultsBackup = preciseCompilationResultsBackup.get(),
keepIncrementalCompilationCachesInMemory = keepIncrementalCompilationCachesInMemory.get(),
) )
} else null } else null
@@ -100,6 +100,12 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
task.taskOutputsBackupExcludes.addAll(task.preciseCompilationResultsBackup.map { task.taskOutputsBackupExcludes.addAll(task.preciseCompilationResultsBackup.map {
if (it) listOf(task.destinationDirectory.get().asFile, task.taskBuildLocalStateDirectory.get().asFile) else emptyList() if (it) listOf(task.destinationDirectory.get().asFile, task.taskBuildLocalStateDirectory.get().asFile) else emptyList()
}) })
task.keepIncrementalCompilationCachesInMemory
.convention(task.preciseCompilationResultsBackup.map { it && propertiesProvider.keepIncrementalCompilationCachesInMemory })
.finalizeValueOnRead()
task.taskOutputsBackupExcludes.addAll(task.keepIncrementalCompilationCachesInMemory.map {
if (it) listOf(task.taskBuildCacheableOutputDirectory.get().asFile) else emptyList()
})
task.incremental = false task.incremental = false
task.useModuleDetection.convention(false) task.useModuleDetection.convention(false)