Don't use global state for keeping incremental compilation state

Previously IC state was stored in System properties. As result parallel
compilation might cause incorrect state of IC, what led to corruption
of kotlin_module files. Now IC state is stored via CompilerArguments
and CompilerConfiguration
#KT-46038 Fixed
diff --git a/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt b/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt
index b9f905d..87d45ab 100644
--- a/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt
+++ b/build-common/src/org/jetbrains/kotlin/incremental/buildUtil.kt
@@ -47,7 +47,8 @@
     commonSources: Iterable<File>,
     javaSourceRoots: Iterable<JvmSourceRoot>,
     classpath: Iterable<File>,
-    friendDirs: Iterable<File>
+    friendDirs: Iterable<File>,
+    isIncrementalMode: Boolean = true
 ): File {
     val builder = KotlinModuleXmlBuilder()
     builder.addModule(
@@ -65,7 +66,8 @@
         isTest,
         // this excludes the output directories from the class path, to be removed for true incremental compilation
         setOf(outputDir),
-        friendDirs
+        friendDirs,
+        isIncrementalMode
     )
 
     val scriptFile = Files.createTempFile("kjps", sanitizeJavaIdentifier(name) + ".script.xml").toFile()
diff --git a/build-common/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.kt b/build-common/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.kt
index 3c49984..62c08b5 100644
--- a/build-common/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.kt
+++ b/build-common/src/org/jetbrains/kotlin/modules/KotlinModuleXmlBuilder.kt
@@ -31,6 +31,7 @@
         openTag(p, MODULES)
     }
 
+    @Deprecated(message = "State of IC should be set explicitly")
     fun addModule(
         moduleName: String,
         outputDir: String,
@@ -43,6 +44,34 @@
         isTests: Boolean,
         directoriesToFilterOut: Set<File>,
         friendDirs: Iterable<File>
+    ) = addModule(
+        moduleName,
+        outputDir,
+        sourceFiles,
+        javaSourceRoots,
+        classpathRoots,
+        commonSourceFiles,
+        modularJdkRoot,
+        targetTypeId,
+        isTests,
+        directoriesToFilterOut,
+        friendDirs,
+        IncrementalCompilation.isEnabledForJvm()
+    )
+
+    fun addModule(
+        moduleName: String,
+        outputDir: String,
+        sourceFiles: Iterable<File>,
+        javaSourceRoots: Iterable<JvmSourceRoot>,
+        classpathRoots: Iterable<File>,
+        commonSourceFiles: Iterable<File>,
+        modularJdkRoot: File?,
+        targetTypeId: String,
+        isTests: Boolean,
+        directoriesToFilterOut: Set<File>,
+        friendDirs: Iterable<File>,
+        isIncrementalCompilation: Boolean
     ): KotlinModuleXmlBuilder {
         assert(!done) { "Already done" }
 
@@ -67,7 +96,7 @@
         }
 
         processJavaSourceRoots(javaSourceRoots)
-        processClasspath(classpathRoots, directoriesToFilterOut)
+        processClasspath(classpathRoots, directoriesToFilterOut, isIncrementalCompilation)
 
         if (modularJdkRoot != null) {
             p.println("<", MODULAR_JDK_ROOT, " ", PATH, "=\"", getEscapedPath(modularJdkRoot), "\"/>")
@@ -79,10 +108,11 @@
 
     private fun processClasspath(
             files: Iterable<File>,
-            directoriesToFilterOut: Set<File>) {
+            directoriesToFilterOut: Set<File>,
+            isIncrementalCompilation: Boolean) {
         p.println("<!-- Classpath -->")
         for (file in files) {
-            val isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.isEnabledForJvm()
+            val isOutput = directoriesToFilterOut.contains(file) && !isIncrementalCompilation
             if (isOutput) {
                 // For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
                 // appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt
index 0338f88..cabe595 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MultifileClassCodegen.kt
@@ -372,7 +372,7 @@
         private fun getCompiledPackageFragment(
             facadeFqName: FqName, state: GenerationState
         ): IncrementalPackageFragmentProvider.IncrementalMultifileClassPackageFragment? {
-            if (!IncrementalCompilation.isEnabledForJvm()) return null
+            if (!state.isIncrementalCompilation) return null
 
             val packageFqName = facadeFqName.parent()
 
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
index cbe504a..b6ff18a 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt
@@ -72,6 +72,7 @@
     val isIrBackend: Boolean,
     val ignoreErrors: Boolean,
     val diagnosticReporter: DiagnosticReporter,
+    val isIncrementalCompilation: Boolean
 ) {
     class Builder(
         private val project: Project,
@@ -129,13 +130,16 @@
         fun diagnosticReporter(v: DiagnosticReporter) =
             apply { diagnosticReporter = v }
 
+        val isIncrementalCompilation: Boolean = configuration.getBoolean(CommonConfigurationKeys.INCREMENTAL_COMPILATION)
+
         fun build() =
             GenerationState(
                 project, builderFactory, module, bindingContext, files, configuration,
                 generateDeclaredClassFilter, codegenFactory, targetId,
                 moduleName, outDirectory, onIndependentPartCompilationEnd, wantsDiagnostics,
                 jvmBackendClassResolver, isIrBackend, ignoreErrors,
-                diagnosticReporter ?: DiagnosticReporterFactory.createReporter()
+                diagnosticReporter ?: DiagnosticReporterFactory.createReporter(),
+                isIncrementalCompilation
             )
     }
 
diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
index 7589ee2..48e507e 100644
--- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
+++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt
@@ -394,6 +394,9 @@
     )
     var normalizeAbsolutePath: Boolean by FreezableVar(false)
 
+    @Argument(value = "-Xenable-incremental-compilation", description = "Enable incremental compilation")
+    var incrementalCompilation: Boolean? by FreezableVar(null)
+
     open fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
         return HashMap<AnalysisFlag<*>, Any>().apply {
             put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck)
diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java
index 47db4ae..a30d48a 100644
--- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java
+++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java
@@ -181,7 +181,7 @@
             return exitCode;
         }
 
-        if (arguments.getFreeArgs().isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
+        if (arguments.getFreeArgs().isEmpty() && (!Boolean.TRUE.equals(arguments.getIncrementalCompilation()))) {
             if (arguments.getVersion()) {
                 return OK;
             }
@@ -219,7 +219,7 @@
             return ExitCode.COMPILATION_ERROR;
         }
 
-        if (sourcesFiles.isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
+        if (sourcesFiles.isEmpty() && !Boolean.TRUE.equals(arguments.getIncrementalCompilation())) {
             messageCollector.report(ERROR, "No source files", null);
             return COMPILATION_ERROR;
         }
diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt
index 0fae5c9..2018134 100644
--- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt
+++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt
@@ -114,7 +114,7 @@
             return scriptingEvaluator.eval(arguments, configuration, projectEnv)
         }
 
-        if (arguments.freeArgs.isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
+        if (arguments.freeArgs.isEmpty() && !(true == arguments.incrementalCompilation)) {
             if (arguments.version) {
                 return OK
             }
@@ -166,7 +166,7 @@
             return ExitCode.COMPILATION_ERROR
         }
 
-        if (sourcesFiles.isEmpty() && !IncrementalCompilation.isEnabledForJs() && arguments.includes.isNullOrEmpty()) {
+        if (sourcesFiles.isEmpty() && (true != arguments.incrementalCompilation) && arguments.includes.isNullOrEmpty()) {
             messageCollector.report(ERROR, "No source files", null)
             return COMPILATION_ERROR
         }
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
index 7bc1c2c..2d05f96 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt
@@ -27,6 +27,7 @@
     put(CommonConfigurationKeys.EXPECT_ACTUAL_LINKER, arguments.expectActualLinker)
     putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)
     put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles)
+    put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, arguments.incrementalCompilation ?: false)
 
     val metadataVersionString = arguments.metadataVersion
     if (metadataVersionString != null) {
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt
index 057d7d76..d4f4e0d 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt
@@ -240,7 +240,7 @@
         configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services
     ) {
         with(configuration) {
-            if (IncrementalCompilation.isEnabledForJvm()) {
+            if (true == arguments.incrementalCompilation) {
                 putIfNotNull(CommonConfigurationKeys.LOOKUP_TRACKER, services[LookupTracker::class.java])
 
                 putIfNotNull(CommonConfigurationKeys.EXPECT_ACTUAL_TRACKER, services[ExpectActualTracker::class.java])
diff --git a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
index ed151b8..7213245 100644
--- a/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
+++ b/compiler/config/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt
@@ -66,6 +66,10 @@
     @JvmField
     val KLIB_NORMALIZE_ABSOLUTE_PATH =
         CompilerConfigurationKey.create<Boolean>("Normalize absolute paths in klib (replace file separator with '/')")
+
+    @JvmField
+    val INCREMENTAL_COMPILATION =
+        CompilerConfigurationKey.create<Boolean>("Enable incremental compilation")
 }
 
 var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings
diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt
index e94b4cb..fc481fa 100644
--- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt
+++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt
@@ -319,7 +319,7 @@
             CompilerMode.JPS_COMPILER -> {
                 @Suppress("UNCHECKED_CAST")
                 servicesFacade as JpsServicesFacadeT
-                withIC(enabled = servicesFacade.hasIncrementalCaches()) {
+                withIC(k2PlatformArgs, enabled = servicesFacade.hasIncrementalCaches()) {
                     doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
                         val services = createServices(servicesFacade, eventManger, profiler)
                         compiler.exec(messageCollector, services, k2PlatformArgs)
@@ -346,7 +346,7 @@
                 val gradleIncrementalServicesFacade = servicesFacade
 
                 when (targetPlatform) {
-                    CompileService.TargetPlatform.JVM -> withIC {
+                    CompileService.TargetPlatform.JVM -> withIC(k2PlatformArgs) {
                         doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
                             execIncrementalCompiler(
                                 k2PlatformArgs as K2JVMCompilerArguments,
@@ -360,7 +360,7 @@
                             )
                         }
                     }
-                    CompileService.TargetPlatform.JS -> withJsIC {
+                    CompileService.TargetPlatform.JS -> withJsIC(k2PlatformArgs) {
                         doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
                             execJsIncrementalCompiler(
                                 k2PlatformArgs as K2JSCompilerArguments,
diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt
index c7c827c..25b33b8 100644
--- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt
+++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/AbstractFullPipelineModularizedTest.kt
@@ -159,7 +159,8 @@
             "java-production",
             isTests = false,
             emptySet(),
-            friendDirs = moduleData.friendDirs
+            friendDirs = moduleData.friendDirs,
+            isIncrementalCompilation = true
         )
         val modulesFile = tmp.toFile().resolve("modules.xml")
         modulesFile.writeText(builder.asText().toString())
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 5d61da8..6f591ca 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
@@ -61,7 +61,6 @@
     //TODO(valtman) temporal measure to ensure quick disable, should be deleted after successful release
     protected val withSnapshot: Boolean = CompilerSystemProperties.COMPILE_INCREMENTAL_WITH_CLASSPATH_SNAPSHOTS.value.toBooleanLenient() ?: false
 
-    protected abstract fun isICEnabled(): Boolean
     protected abstract fun createCacheManager(args: Args, projectDir: File?): CacheManager
     protected abstract fun destinationDir(args: Args): File
 
@@ -84,7 +83,6 @@
         providedChangedFiles: ChangedFiles?,
         projectDir: File? = null
     ): ExitCode {
-        assert(isICEnabled()) { "Incremental compilation is not enabled" }
         var caches = createCacheManager(args, projectDir)
 
         if (withSnapshot) {
diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt
index 1a40a2e..2319178 100644
--- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt
+++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/IncrementalJsCompilerRunner.kt
@@ -22,6 +22,7 @@
 import org.jetbrains.kotlin.build.report.metrics.BuildAttribute
 import org.jetbrains.kotlin.build.report.metrics.DoNothingBuildMetricsReporter
 import org.jetbrains.kotlin.cli.common.ExitCode
+import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
 import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
 import org.jetbrains.kotlin.cli.common.arguments.isIrBackendEnabled
 import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -52,7 +53,7 @@
         .filter { it.isFile && it.extension.equals("kt", ignoreCase = true) }.toList()
 
     val buildReporter = BuildReporter(icReporter = reporter, buildMetricsReporter = DoNothingBuildMetricsReporter)
-    withJsIC {
+    withJsIC(args) {
         val compiler = IncrementalJsCompilerRunner(
             cachesDir, buildReporter,
             buildHistoryFile = buildHistoryFile,
@@ -63,11 +64,15 @@
     }
 }
 
-inline fun <R> withJsIC(fn: () -> R): R {
+@Suppress("DEPRECATION")
+inline fun <R> withJsIC(args: CommonCompilerArguments, enabled: Boolean = true, fn: () -> R): R {
     val isJsEnabledBackup = IncrementalCompilation.isEnabledForJs()
     IncrementalCompilation.setIsEnabledForJs(true)
 
     try {
+        if (args.incrementalCompilation == null) {
+            args.incrementalCompilation = enabled
+        }
         return fn()
     } finally {
         IncrementalCompilation.setIsEnabledForJs(isJsEnabledBackup)
@@ -86,8 +91,6 @@
     reporter,
     buildHistoryFile = buildHistoryFile
 ) {
-    override fun isICEnabled(): Boolean =
-        IncrementalCompilation.isEnabledForJs()
 
     override fun createCacheManager(args: K2JSCompilerArguments, projectDir: File?): IncrementalJsCachesManager {
         val serializerProtocol = if (!args.isIrBackendEnabled()) JsSerializerProtocol else KlibMetadataSerializerProtocol
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 be8481b..d464d0d 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
@@ -35,6 +35,7 @@
 import org.jetbrains.kotlin.build.report.metrics.measure
 import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
 import org.jetbrains.kotlin.cli.common.ExitCode
+import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
 import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
 import org.jetbrains.kotlin.cli.common.messages.FilteringMessageCollector
 import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@@ -83,7 +84,7 @@
     args.javaSourceRoots = sourceRoots.map { it.absolutePath }.toTypedArray()
     val buildReporter = BuildReporter(icReporter = reporter, buildMetricsReporter = DoNothingBuildMetricsReporter)
 
-    withIC {
+    withIC(args) {
         val compiler = IncrementalJvmCompilerRunner(
             cachesDir,
             buildReporter,
@@ -109,11 +110,15 @@
     override fun reportMarkDirty(affectedFiles: Iterable<File>, reason: String) {}
 }
 
-inline fun <R> withIC(enabled: Boolean = true, fn: () -> R): R {
+@Suppress("DEPRECATION")
+inline fun <R> withIC(args: CommonCompilerArguments, enabled: Boolean = true, fn: () -> R): R {
     val isEnabledBackup = IncrementalCompilation.isEnabledForJvm()
     IncrementalCompilation.setIsEnabledForJvm(enabled)
 
     try {
+        if (args.incrementalCompilation == null) {
+            args.incrementalCompilation = enabled
+        }
         return fn()
     } finally {
         IncrementalCompilation.setIsEnabledForJvm(isEnabledBackup)
@@ -136,9 +141,6 @@
     additionalOutputFiles = outputFiles,
     buildHistoryFile = buildHistoryFile
 ) {
-    override fun isICEnabled(): Boolean =
-        IncrementalCompilation.isEnabledForJvm()
-
     override fun createCacheManager(args: K2JVMCompilerArguments, projectDir: File?): IncrementalJvmCachesManager =
         IncrementalJvmCachesManager(
             cacheDirectory,
diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt
index 6038420..3e1abbc 100644
--- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt
+++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt
@@ -618,7 +618,7 @@
         ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
 
         val analysisResult = analyzer.analysisResult
-        if (IncrementalCompilation.isEnabledForJs()) {
+        if (compilerConfiguration.getBoolean(CommonConfigurationKeys.INCREMENTAL_COMPILATION)) {
             /** can throw [IncrementalNextRoundException] */
             compareMetadataAndGoToNextICRoundIfNeeded(analysisResult, compilerConfiguration, project, files, errorPolicy.allowErrors)
         }
diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out
index 4abf26e..2ee2a09 100644
--- a/compiler/testData/cli/js/jsExtraHelp.out
+++ b/compiler/testData/cli/js/jsExtraHelp.out
@@ -65,6 +65,8 @@
                              Use 'warning' level to issue warnings instead of errors.
   -Xextended-compiler-checks Enable additional compiler checks that might provide verbose diagnostic information for certain errors.
                              Warning: this mode is not backward-compatible and might cause compilation errors in previously compiled code.
+  -Xenable-incremental-compilation
+                             Enable incremental compilation
   -Xinference-compatibility  Enable compatibility changes for generic type inference algorithm
   -Xinline-classes           Enable experimental inline classes
   -Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out
index 00b4e90..908312a 100644
--- a/compiler/testData/cli/jvm/extraHelp.out
+++ b/compiler/testData/cli/jvm/extraHelp.out
@@ -170,6 +170,8 @@
                              Use 'warning' level to issue warnings instead of errors.
   -Xextended-compiler-checks Enable additional compiler checks that might provide verbose diagnostic information for certain errors.
                              Warning: this mode is not backward-compatible and might cause compilation errors in previously compiled code.
+  -Xenable-incremental-compilation
+                             Enable incremental compilation
   -Xinference-compatibility  Enable compatibility changes for generic type inference algorithm
   -Xinline-classes           Enable experimental inline classes
   -Xintellij-plugin-root=<path> Path to the kotlin-compiler.jar or directory where IntelliJ configuration files can be found
diff --git a/compiler/util/src/org/jetbrains/kotlin/config/IncrementalCompilation.java b/compiler/util/src/org/jetbrains/kotlin/config/IncrementalCompilation.java
index 348871a..ea7ecf9 100644
--- a/compiler/util/src/org/jetbrains/kotlin/config/IncrementalCompilation.java
+++ b/compiler/util/src/org/jetbrains/kotlin/config/IncrementalCompilation.java
@@ -25,23 +25,26 @@
     public static final String INCREMENTAL_COMPILATION_JS_PROPERTY = "kotlin.incremental.compilation.js";
 
     public static boolean isEnabledForJvm() {
-        return "true".equals(System.getProperty(INCREMENTAL_COMPILATION_JVM_PROPERTY));
+        return Boolean.valueOf(System.getProperty(INCREMENTAL_COMPILATION_JVM_PROPERTY));
     }
 
     public static boolean isEnabledForJs() {
-        return "true".equals(System.getProperty(INCREMENTAL_COMPILATION_JS_PROPERTY));
+        return Boolean.valueOf(System.getProperty(INCREMENTAL_COMPILATION_JS_PROPERTY));
     }
 
+    @Deprecated
     @TestOnly
     public static void setIsEnabledForJvm(boolean value) {
         System.setProperty(INCREMENTAL_COMPILATION_JVM_PROPERTY, String.valueOf(value));
     }
 
+    @Deprecated
     @TestOnly
     public static void setIsEnabledForJs(boolean value) {
         System.setProperty(INCREMENTAL_COMPILATION_JS_PROPERTY, String.valueOf(value));
     }
 
+    @Deprecated
     public static void toJvmArgs(List<String> jvmArgs) {
         if (isEnabledForJvm()) addJvmSystemFlag(jvmArgs, INCREMENTAL_COMPILATION_JVM_PROPERTY);
         if (isEnabledForJs()) addJvmSystemFlag(jvmArgs, INCREMENTAL_COMPILATION_JS_PROPERTY);
diff --git a/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt b/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt
index 7e77f28..ad45291 100644
--- a/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt
+++ b/js/js.tests/test/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt
@@ -319,7 +319,7 @@
 
         val cleanBuildStart = System.nanoTime()
 
-        withJsIC {
+        withJsIC(args) {
             val buildHistoryFile = File(cachesDir, "build-history.bin")
             val compiler = IncrementalJsCompilerRunner(
                 cachesDir, BuildReporter(EmptyICReporter, DoNothingBuildMetricsReporter),
@@ -363,7 +363,7 @@
             done,
             update
         ) {
-            withJsIC {
+            withJsIC(args) {
                 val buildHistoryFile = File(cachesDir, "build-history.bin")
                 val compiler = IncrementalJsCompilerRunner(
                     cachesDir, BuildReporter(EmptyICReporter, DoNothingBuildMetricsReporter),