diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt new file mode 100644 index 00000000000..740cd70bb2c --- /dev/null +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/createPhaseConfig.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.cli.common + +import org.jetbrains.kotlin.backend.common.phaser.AnyNamedPhase +import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase +import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig +import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap +import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.CompilerConfigurationKey + +fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig { + val phases = compoundPhase.toPhaseMap() + val enabled = computeEnabled(phases, config).toMutableSet() + val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES) + + val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE) + val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER) + val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE) + val toDumpStateBefore = beforeDumpSet + bothDumpSet + val toDumpStateAfter = afterDumpSet + bothDumpSet + val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE) + val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER) + val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE) + val toValidateStateBefore = beforeValidateSet + bothValidateSet + val toValidateStateAfter = afterValidateSet + bothValidateSet + + val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES) + val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS) + val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS) + + return PhaseConfig( + compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, + needProfiling, checkConditions, checkStickyConditions + ) +} + +private fun computeEnabled( + phases: MutableMap, + config: CompilerConfiguration +): Set { + val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES) + return phases.values.toSet() - disabledPhases +} + +private fun phaseSetFromConfiguration( + phases: MutableMap, + config: CompilerConfiguration, + key: CompilerConfigurationKey> +): Set { + val phaseNames = config.get(key) ?: emptySet() + if ("ALL" in phaseNames) return phases.values.toSet() + return phaseNames.map { phases[it]!! }.toSet() +} diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index 223fb8caae3..f10a473e020 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -16,28 +16,25 @@ package org.jetbrains.kotlin.cli.jvm.compiler -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiJavaModule -import com.intellij.psi.PsiManager -import com.intellij.psi.impl.PsiModificationTrackerImpl import com.intellij.psi.search.DelegatingGlobalSearchScope import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics import org.jetbrains.kotlin.backend.common.output.OutputFileCollection import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection -import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.backend.jvm.jvmPhases import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot +import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING @@ -67,7 +64,6 @@ import org.jetbrains.kotlin.utils.newLinkedHashMapWithExpectedSize import java.io.File import java.lang.reflect.InvocationTargetException import java.net.URLClassLoader -import javax.swing.SwingUtilities object KotlinToJVMBytecodeCompiler { private fun writeOutput( diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt index e0612419a3c..e4be04ab1f4 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseConfig.kt @@ -5,33 +5,6 @@ package org.jetbrains.kotlin.backend.common.phaser -import org.jetbrains.kotlin.config.CommonConfigurationKeys -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.config.CompilerConfigurationKey - -fun createPhaseConfig(compoundPhase: CompilerPhase<*, *, *>, config: CompilerConfiguration): PhaseConfig { - val phases = compoundPhase.toPhaseMap() - val enabled = computeEnabled(phases, config).toMutableSet() - val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES) - - val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE) - val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER) - val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE) - val toDumpStateBefore = beforeDumpSet + bothDumpSet - val toDumpStateAfter = afterDumpSet + bothDumpSet - val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE) - val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER) - val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE) - val toValidateStateBefore = beforeValidateSet + bothValidateSet - val toValidateStateAfter = afterValidateSet + bothValidateSet - - val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES) - val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS) - val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS) - - return PhaseConfig(compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, needProfiling, checkConditions, checkStickyConditions) -} - fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig { val phases = compoundPhase.toPhaseMap() val enabled = phases.values.toMutableSet() @@ -44,31 +17,13 @@ fun createDefaultPhaseConfig(compoundPhase: CompilerPhase<*, *, *>): PhaseConfig ) } -private fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap = +fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap = getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) -> check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"} acc[phase.name] = phase acc } -private fun computeEnabled( - phases: MutableMap, - config: CompilerConfiguration -): Set { - val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES) - return phases.values.toSet() - disabledPhases -} - -private fun phaseSetFromConfiguration( - phases: MutableMap, - config: CompilerConfiguration, - key: CompilerConfigurationKey> -): Set { - val phaseNames = config.get(key) ?: emptySet() - if ("ALL" in phaseNames) return phases.values.toSet() - return phaseNames.map { phases[it]!! }.toSet() -} - class PhaseConfig( private val compoundPhase: CompilerPhase<*, *, *>, private val phases: MutableMap, diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt index afe5bbd9e18..ec2ef77132d 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/GenerationUtils.kt @@ -18,9 +18,9 @@ package org.jetbrains.kotlin.codegen import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.TestsCompiletimeError -import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.backend.jvm.jvmPhases +import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.cli.common.output.writeAllTo import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace diff --git a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateIrRuntime.kt b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateIrRuntime.kt index 71d3b83a9eb..0dc978014ef 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateIrRuntime.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateIrRuntime.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.Disposable import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiManager -import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig +import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.* diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 03466c13e6c..db4b88934bc 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.js.test -import org.jetbrains.kotlin.backend.common.phaser.createPhaseConfig +import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.ir.backend.js.* import org.jetbrains.kotlin.js.config.JSConfigurationKeys