Use CLI compiler arguments directly in PhaseConfig creation

This commit is contained in:
Georgy Bronnikov
2019-03-21 17:18:07 +03:00
parent 40079f7cae
commit fae003866b
16 changed files with 105 additions and 112 deletions
@@ -232,6 +232,30 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
) )
var phasesToDump: Array<String>? by FreezableVar(null) var phasesToDump: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xexclude-from-dumping",
description = "Names of elements that should not be dumped"
)
var namesExcludedFromDumping: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xphases-to-validate-before",
description = "Validate backend state before these phases"
)
var phasesToValidateBefore: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xphases-to-validate-after",
description = "Validate backend state after these phases"
)
var phasesToValidateAfter: Array<String>? by FreezableVar(null)
@Argument(
value = "-Xphases-to-validate",
description = "Validate backend state both before and after these phases"
)
var phasesToValidate: Array<String>? by FreezableVar(null)
@Argument( @Argument(
value = "-Xprofile-phases", value = "-Xprofile-phases",
description = "Profile backend phases" description = "Profile backend phases"
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.cli.common; package org.jetbrains.kotlin.cli.common;
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig;
import org.jetbrains.kotlin.cli.common.config.ContentRoot; import org.jetbrains.kotlin.cli.common.config.ContentRoot;
import org.jetbrains.kotlin.cli.common.messages.MessageCollector; import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
import org.jetbrains.kotlin.config.CompilerConfigurationKey; import org.jetbrains.kotlin.config.CompilerConfigurationKey;
@@ -44,6 +45,9 @@ public class CLIConfigurationKeys {
public static final CompilerConfigurationKey<File> METADATA_DESTINATION_DIRECTORY = public static final CompilerConfigurationKey<File> METADATA_DESTINATION_DIRECTORY =
CompilerConfigurationKey.create("metadata destination directory"); CompilerConfigurationKey.create("metadata destination directory");
public static final CompilerConfigurationKey<PhaseConfig> PHASE_CONFIG =
CompilerConfigurationKey.create("phase configuration");
private CLIConfigurationKeys() { private CLIConfigurationKeys() {
} }
} }
@@ -39,22 +39,6 @@ fun <A : CommonCompilerArguments> CompilerConfiguration.setupCommonArguments(
} }
setupLanguageVersionSettings(arguments) setupLanguageVersionSettings(arguments)
put(CommonConfigurationKeys.LIST_PHASES, arguments.listPhases)
listOf(
CommonConfigurationKeys.DISABLED_PHASES to arguments.disablePhases,
CommonConfigurationKeys.VERBOSE_PHASES to arguments.verbosePhases,
CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE to arguments.phasesToDumpBefore,
CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER to arguments.phasesToDumpAfter,
CommonConfigurationKeys.PHASES_TO_DUMP_STATE to arguments.phasesToDump
).forEach { (k, v) ->
if (v != null) put(k, setOf(*v))
}
put(CommonConfigurationKeys.PROFILE_PHASES, arguments.profilePhases)
put(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS, arguments.checkPhaseConditions or arguments.checkStickyPhaseConditions)
put(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS, arguments.checkStickyPhaseConditions)
} }
fun <A : CommonCompilerArguments> CompilerConfiguration.setupLanguageVersionSettings(arguments: A) { fun <A : CommonCompilerArguments> CompilerConfiguration.setupLanguageVersionSettings(arguments: A) {
@@ -9,62 +9,69 @@ import org.jetbrains.kotlin.backend.common.phaser.AnyNamedPhase
import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap import org.jetbrains.kotlin.backend.common.phaser.toPhaseMap
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
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 { fun createPhaseConfig(
compoundPhase: CompilerPhase<*, *, *>,
arguments: CommonCompilerArguments,
messageCollector: MessageCollector
): PhaseConfig {
fun warn(message: String) = messageCollector.report(CompilerMessageSeverity.WARNING, message)
val phases = compoundPhase.toPhaseMap() val phases = compoundPhase.toPhaseMap()
val enabled = computeEnabled(phases, config).toMutableSet() val enabled = computeEnabled(phases, arguments.disablePhases, ::warn).toMutableSet()
val verbose = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.VERBOSE_PHASES) val verbose = phaseSetFromArguments(phases, arguments.verbosePhases, ::warn)
val beforeDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_BEFORE) val beforeDumpSet = phaseSetFromArguments(phases, arguments.phasesToDumpBefore, ::warn)
val afterDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE_AFTER) val afterDumpSet = phaseSetFromArguments(phases, arguments.phasesToDumpAfter, ::warn)
val bothDumpSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_DUMP_STATE) val bothDumpSet = phaseSetFromArguments(phases, arguments.phasesToDump, ::warn)
val toDumpStateBefore = beforeDumpSet + bothDumpSet val toDumpStateBefore = beforeDumpSet + bothDumpSet
val toDumpStateAfter = afterDumpSet + bothDumpSet val toDumpStateAfter = afterDumpSet + bothDumpSet
val beforeValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_BEFORE) val beforeValidateSet = phaseSetFromArguments(phases, arguments.phasesToValidateBefore, ::warn)
val afterValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE_AFTER) val afterValidateSet = phaseSetFromArguments(phases, arguments.phasesToValidateAfter, ::warn)
val bothValidateSet = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.PHASES_TO_VALIDATE) val bothValidateSet = phaseSetFromArguments(phases, arguments.phasesToValidate, ::warn)
val toValidateStateBefore = beforeValidateSet + bothValidateSet val toValidateStateBefore = beforeValidateSet + bothValidateSet
val toValidateStateAfter = afterValidateSet + bothValidateSet val toValidateStateAfter = afterValidateSet + bothValidateSet
val needProfiling = config.getBoolean(CommonConfigurationKeys.PROFILE_PHASES) val namesOfElementsExcludedFromDumping = arguments.namesExcludedFromDumping?.toSet() ?: emptySet()
val checkConditions = config.getBoolean(CommonConfigurationKeys.CHECK_PHASE_CONDITIONS)
val checkStickyConditions = config.getBoolean(CommonConfigurationKeys.CHECK_STICKY_CONDITIONS) val needProfiling = arguments.profilePhases
val checkConditions = arguments.checkPhaseConditions
val checkStickyConditions = arguments.checkStickyPhaseConditions
return PhaseConfig( return PhaseConfig(
compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter, compoundPhase, phases, enabled, verbose, toDumpStateBefore, toDumpStateAfter, toValidateStateBefore, toValidateStateAfter,
namesOfElementsExcludedFromDumping,
needProfiling, checkConditions, checkStickyConditions needProfiling, checkConditions, checkStickyConditions
) ).also {
if (arguments.listPhases) {
it.list()
}
}
} }
private fun computeEnabled( private fun computeEnabled(
phases: MutableMap<String, AnyNamedPhase>, phases: MutableMap<String, AnyNamedPhase>,
config: CompilerConfiguration namesOfDisabled: Array<String>?,
warn: (String) -> Unit
): Set<AnyNamedPhase> { ): Set<AnyNamedPhase> {
val disabledPhases = phaseSetFromConfiguration(phases, config, CommonConfigurationKeys.DISABLED_PHASES) val disabledPhases = phaseSetFromArguments(phases, namesOfDisabled, warn)
return phases.values.toSet() - disabledPhases return phases.values.toSet() - disabledPhases
} }
private fun phaseSetFromConfiguration( private fun phaseSetFromArguments(
phases: MutableMap<String, AnyNamedPhase>, phases: MutableMap<String, AnyNamedPhase>,
config: CompilerConfiguration, names: Array<String>?,
key: CompilerConfigurationKey<Set<String>> warn: (String) -> Unit
): Set<AnyNamedPhase> { ): Set<AnyNamedPhase> {
val phaseNames = config.get(key) ?: emptySet() if (names == null) return emptySet()
if ("ALL" in phaseNames) return phases.values.toSet() if ("ALL" in names) return phases.values.toSet()
return phaseNames.mapNotNull { return names.mapNotNull {
phases[it] ?: run { phases[it] ?: run {
warn(config, "no phase named $it, ignoring") warn("no phase named $it, ignoring")
null null
} }
}.toSet() }.toSet()
} }
private fun warn(config: CompilerConfiguration, message: String) {
val messageCollector = config.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) ?: MessageCollector.NONE
messageCollector.report(CompilerMessageSeverity.WARNING, message)
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.cli.jvm
import com.intellij.ide.highlighter.JavaFileType import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.Disposable import com.intellij.openapi.Disposable
import org.jetbrains.kotlin.backend.jvm.jvmPhases
import org.jetbrains.kotlin.cli.common.* import org.jetbrains.kotlin.cli.common.*
import org.jetbrains.kotlin.cli.common.ExitCode.* import org.jetbrains.kotlin.cli.common.ExitCode.*
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
@@ -62,6 +63,8 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
): ExitCode { ): ExitCode {
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
configuration.put(CLIConfigurationKeys.PHASE_CONFIG, createPhaseConfig(jvmPhases, arguments, messageCollector))
if (!configuration.configureJdkHome(arguments)) return COMPILATION_ERROR if (!configuration.configureJdkHome(arguments)) return COMPILATION_ERROR
configuration.put(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION, arguments.disableStandardScript) configuration.put(JVMConfigurationKeys.DISABLE_STANDARD_SCRIPT_DEFINITION, arguments.disableStandardScript)
@@ -28,13 +28,13 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.backend.jvm.jvmPhases import org.jetbrains.kotlin.backend.jvm.jvmPhases
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot 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.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.WARNING
@@ -441,7 +441,11 @@ object KotlinToJVMBytecodeCompiler {
sourceFiles, sourceFiles,
configuration configuration
) )
.codegenFactory(if (isIR) JvmIrCodegenFactory(createPhaseConfig(jvmPhases, configuration)) else DefaultCodegenFactory) .codegenFactory(
if (isIR) JvmIrCodegenFactory(
configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases)
) else DefaultCodegenFactory
)
.withModule(module) .withModule(module)
.onIndependentPartCompilationEnd(createOutputFilesFlushingCallbackIfPossible(configuration)) .onIndependentPartCompilationEnd(createOutputFilesFlushingCallbackIfPossible(configuration))
.build() .build()
@@ -41,45 +41,6 @@ object CommonConfigurationKeys {
@JvmField @JvmField
val METADATA_VERSION = CompilerConfigurationKey.create<BinaryVersion>("metadata version") val METADATA_VERSION = CompilerConfigurationKey.create<BinaryVersion>("metadata version")
@JvmField
val LIST_PHASES = CompilerConfigurationKey.create<Boolean>("list names of backend phases")
@JvmField
val DISABLED_PHASES = CompilerConfigurationKey.create<Set<String>>("disable backend phases")
@JvmField
val PHASES_TO_DUMP_STATE_BEFORE = CompilerConfigurationKey.create<Set<String>>("backend phases where we dump compiler state before the phase")
@JvmField
val PHASES_TO_DUMP_STATE_AFTER = CompilerConfigurationKey.create<Set<String>>("backend phases where we dump compiler state after the phase")
@JvmField
val PHASES_TO_DUMP_STATE = CompilerConfigurationKey.create<Set<String>>("backend phases where we dump compiler state both before and after the phase")
@JvmField
val PHASES_TO_VALIDATE_BEFORE = CompilerConfigurationKey.create<Set<String>>("backend phases where we validate Ir before the phase")
@JvmField
val PHASES_TO_VALIDATE_AFTER = CompilerConfigurationKey.create<Set<String>>("backend phases where we validate Ir after the phase")
@JvmField
val PHASES_TO_VALIDATE = CompilerConfigurationKey.create<Set<String>>("backend phases where we validate Ir both before and after the phase")
@JvmField
val VERBOSE_PHASES = CompilerConfigurationKey.create<Set<String>>("verbose backend phases")
@JvmField
val PROFILE_PHASES = CompilerConfigurationKey.create<Boolean>("profile backend phase execution")
@JvmField
val CHECK_PHASE_CONDITIONS = CompilerConfigurationKey.create<Boolean>("run pre- and postcondition checkers for phases")
@JvmField
val CHECK_STICKY_CONDITIONS = CompilerConfigurationKey.create<Boolean>("run sticky postcondition checkers on subsequent phases as well")
@JvmField
val EXCLUDED_ELEMENTS_FROM_DUMPING = CompilerConfigurationKey.create<Set<String>>("lowering elements which shouldn't be dumped at all")
} }
var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings
@@ -57,7 +57,7 @@ typealias AnyNamedPhase = NamedCompilerPhase<*, *, *>
enum class BeforeOrAfter { BEFORE, AFTER } enum class BeforeOrAfter { BEFORE, AFTER }
interface PhaseDumperVerifier<in Context : CommonBackendContext, Data> { interface PhaseDumperVerifier<in Context : CommonBackendContext, Data> {
fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter) fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter)
fun verify(context: Context, data: Data) fun verify(context: Context, data: Data)
} }
@@ -97,7 +97,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
} }
private fun runBefore(phaseConfig: PhaseConfig, context: Context, input: Input) { private fun runBefore(phaseConfig: PhaseConfig, context: Context, input: Input) {
checkAndRun(phaseConfig.toDumpStateBefore) { inputDumperVerifier.dump(this, context, input, BeforeOrAfter.BEFORE) } checkAndRun(phaseConfig.toDumpStateBefore) { inputDumperVerifier.dump(this, phaseConfig, input, BeforeOrAfter.BEFORE) }
checkAndRun(phaseConfig.toValidateStateBefore) { inputDumperVerifier.verify(context, input) } checkAndRun(phaseConfig.toValidateStateBefore) { inputDumperVerifier.verify(context, input) }
if (phaseConfig.checkConditions) { if (phaseConfig.checkConditions) {
for (pre in preconditions) pre(input) for (pre in preconditions) pre(input)
@@ -115,7 +115,7 @@ abstract class AbstractNamedPhaseWrapper<in Context : CommonBackendContext, Inpu
} }
private fun runAfter(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, output: Output) { private fun runAfter(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, output: Output) {
checkAndRun(phaseConfig.toDumpStateAfter) { outputDumperVerifier.dump(this, context, output, BeforeOrAfter.AFTER) } checkAndRun(phaseConfig.toDumpStateAfter) { outputDumperVerifier.dump(this, phaseConfig, output, BeforeOrAfter.AFTER) }
checkAndRun(phaseConfig.toValidateStateAfter) { outputDumperVerifier.verify(context, output) } checkAndRun(phaseConfig.toValidateStateAfter) { outputDumperVerifier.verify(context, output) }
if (phaseConfig.checkConditions) { if (phaseConfig.checkConditions) {
for (post in postconditions) post(output) for (post in postconditions) post(output)
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.backend.common.phaser package org.jetbrains.kotlin.backend.common.phaser
import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.CommonBackendContext
import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
@@ -14,15 +13,15 @@ import org.jetbrains.kotlin.ir.declarations.name
import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.util.dump
abstract class IrPhaseDumperVerifier<in Context : CommonBackendContext, Data : IrElement>( abstract class IrPhaseDumperVerifier<in Context : CommonBackendContext, Data : IrElement>(
val verifier: (Context, Data) -> Unit val verifier: (Context, Data) -> Unit
) : PhaseDumperVerifier<Context, Data> { ) : PhaseDumperVerifier<Context, Data> {
abstract fun Data.getElementName(): String abstract fun Data.getElementName(): String
// TODO: use a proper logger. // TODO: use a proper logger.
override fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter) { override fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter) {
fun separator(title: String) = println("\n\n--- $title ----------------------\n") fun separator(title: String) = println("\n\n--- $title ----------------------\n")
if (!shouldBeDumped(context, data)) return if (!shouldBeDumped(phaseConfig, data)) return
val beforeOrAfterStr = beforeOrAfter.name.toLowerCase() val beforeOrAfterStr = beforeOrAfter.name.toLowerCase()
val title = "IR for ${data.getElementName()} $beforeOrAfterStr ${phase.description}" val title = "IR for ${data.getElementName()} $beforeOrAfterStr ${phase.description}"
@@ -32,22 +31,22 @@ abstract class IrPhaseDumperVerifier<in Context : CommonBackendContext, Data : I
override fun verify(context: Context, data: Data) = verifier(context, data) override fun verify(context: Context, data: Data) = verifier(context, data)
private fun shouldBeDumped(context: Context, input: Data) = private fun shouldBeDumped(phaseConfig: PhaseConfig, input: Data) =
input.getElementName() !in context.configuration.get(CommonConfigurationKeys.EXCLUDED_ELEMENTS_FROM_DUMPING, emptySet()) input.getElementName() !in phaseConfig.namesOfElementsExcludedFromDumping
} }
class IrFileDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrFile) -> Unit) : class IrFileDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrFile) -> Unit) :
IrPhaseDumperVerifier<Context, IrFile>(verifier) { IrPhaseDumperVerifier<Context, IrFile>(verifier) {
override fun IrFile.getElementName() = name override fun IrFile.getElementName() = name
} }
class IrModuleDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrModuleFragment) -> Unit) : class IrModuleDumperVerifier<in Context : CommonBackendContext>(verifier: (Context, IrModuleFragment) -> Unit) :
IrPhaseDumperVerifier<Context, IrModuleFragment>(verifier) { IrPhaseDumperVerifier<Context, IrModuleFragment>(verifier) {
override fun IrModuleFragment.getElementName() = name.asString() override fun IrModuleFragment.getElementName() = name.asString()
} }
class EmptyDumperVerifier<in Context : CommonBackendContext, Data> : PhaseDumperVerifier<Context, Data> { class EmptyDumperVerifier<in Context : CommonBackendContext, Data> : PhaseDumperVerifier<Context, Data> {
override fun dump(phase: AnyNamedPhase, context: Context, data: Data, beforeOrAfter: BeforeOrAfter) {} override fun dump(phase: AnyNamedPhase, phaseConfig: PhaseConfig, data: Data, beforeOrAfter: BeforeOrAfter) {}
override fun verify(context: Context, data: Data) {} override fun verify(context: Context, data: Data) {}
} }
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.backend.common.phaser
fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> = fun CompilerPhase<*, *, *>.toPhaseMap(): MutableMap<String, AnyNamedPhase> =
getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) -> getNamedSubphases().fold(mutableMapOf()) { acc, (_, phase) ->
check(phase.name !in acc) { "Duplicate phase name '${phase.name}'"} check(phase.name !in acc) { "Duplicate phase name '${phase.name}'" }
acc[phase.name] = phase acc[phase.name] = phase
acc acc
} }
@@ -21,6 +21,7 @@ class PhaseConfig(
val toDumpStateAfter: Set<AnyNamedPhase> = emptySet(), val toDumpStateAfter: Set<AnyNamedPhase> = emptySet(),
val toValidateStateBefore: Set<AnyNamedPhase> = emptySet(), val toValidateStateBefore: Set<AnyNamedPhase> = emptySet(),
val toValidateStateAfter: Set<AnyNamedPhase> = emptySet(), val toValidateStateAfter: Set<AnyNamedPhase> = emptySet(),
val namesOfElementsExcludedFromDumping: Set<String> = emptySet(),
val needProfiling: Boolean = false, val needProfiling: Boolean = false,
val checkConditions: Boolean = false, val checkConditions: Boolean = false,
val checkStickyConditions: Boolean = false val checkStickyConditions: Boolean = false
@@ -44,12 +44,6 @@ class JvmBackendContext(
override val configuration get() = state.configuration override val configuration get() = state.configuration
init {
if (state.configuration.get(CommonConfigurationKeys.LIST_PHASES) == true) {
phaseConfig.list()
}
}
private fun getJvmInternalClass(name: String): ClassDescriptor { private fun getJvmInternalClass(name: String): ClassDescriptor {
return getClass(FqName("kotlin.jvm.internal").child(Name.identifier(name))) return getClass(FqName("kotlin.jvm.internal").child(Name.identifier(name)))
} }
+4
View File
@@ -21,12 +21,16 @@ where advanced options include:
-Xlist-phases List backend phases -Xlist-phases List backend phases
-Xmetadata-version Change metadata version of the generated binary files -Xmetadata-version Change metadata version of the generated binary files
-Xmulti-platform Enable experimental language support for multi-platform projects -Xmulti-platform Enable experimental language support for multi-platform projects
-Xexclude-from-dumping Names of elements that should not be dumped
-Xnew-inference Enable new experimental generic type inference algorithm -Xnew-inference Enable new experimental generic type inference algorithm
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects -Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
-Xno-inline Disable method inlining -Xno-inline Disable method inlining
-Xphases-to-dump Dump backend state both before and after these phases -Xphases-to-dump Dump backend state both before and after these phases
-Xphases-to-dump-after Dump backend state after these phases -Xphases-to-dump-after Dump backend state after these phases
-Xphases-to-dump-before Dump backend state before these phases -Xphases-to-dump-before Dump backend state before these phases
-Xphases-to-validate Validate backend state both before and after these phases
-Xphases-to-validate-after Validate backend state after these phases
-Xphases-to-validate-before Validate backend state before these phases
-Xplugin=<path> Load plugins from the given classpath -Xplugin=<path> Load plugins from the given classpath
-Xprofile-phases Profile backend phases -Xprofile-phases Profile backend phases
-Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types -Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types
+4
View File
@@ -85,12 +85,16 @@ where advanced options include:
-Xlist-phases List backend phases -Xlist-phases List backend phases
-Xmetadata-version Change metadata version of the generated binary files -Xmetadata-version Change metadata version of the generated binary files
-Xmulti-platform Enable experimental language support for multi-platform projects -Xmulti-platform Enable experimental language support for multi-platform projects
-Xexclude-from-dumping Names of elements that should not be dumped
-Xnew-inference Enable new experimental generic type inference algorithm -Xnew-inference Enable new experimental generic type inference algorithm
-Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects -Xno-check-actual Do not check presence of 'actual' modifier in multi-platform projects
-Xno-inline Disable method inlining -Xno-inline Disable method inlining
-Xphases-to-dump Dump backend state both before and after these phases -Xphases-to-dump Dump backend state both before and after these phases
-Xphases-to-dump-after Dump backend state after these phases -Xphases-to-dump-after Dump backend state after these phases
-Xphases-to-dump-before Dump backend state before these phases -Xphases-to-dump-before Dump backend state before these phases
-Xphases-to-validate Validate backend state both before and after these phases
-Xphases-to-validate-after Validate backend state after these phases
-Xphases-to-validate-before Validate backend state before these phases
-Xplugin=<path> Load plugins from the given classpath -Xplugin=<path> Load plugins from the given classpath
-Xprofile-phases Profile backend phases -Xprofile-phases Profile backend phases
-Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types -Xproper-ieee754-comparisons Generate proper IEEE 754 comparisons in all cases if values are statically known to be of primitive numeric types
@@ -18,9 +18,10 @@ package org.jetbrains.kotlin.codegen
import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.TestsCompiletimeError import org.jetbrains.kotlin.TestsCompiletimeError
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.backend.jvm.jvmPhases import org.jetbrains.kotlin.backend.jvm.jvmPhases
import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.output.writeAllTo import org.jetbrains.kotlin.cli.common.output.writeAllTo
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace
@@ -76,7 +77,8 @@ object GenerationUtils {
files.first().project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext, files.first().project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext,
files, configuration files, configuration
).codegenFactory( ).codegenFactory(
if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory(createPhaseConfig(jvmPhases, configuration)) if (configuration.getBoolean(JVMConfigurationKeys.IR))
JvmIrCodegenFactory(configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases))
else DefaultCodegenFactory else DefaultCodegenFactory
).build() ).build()
if (analysisResult.shouldGenerateCode) { if (analysisResult.shouldGenerateCode) {
@@ -9,7 +9,8 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.StandardFileSystems
import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.PsiManager import com.intellij.psi.PsiManager
import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.config.*
@@ -64,7 +65,7 @@ fun main() {
project = environment.project, project = environment.project,
files = sources.map(::createPsiFile), files = sources.map(::createPsiFile),
configuration = configuration, configuration = configuration,
phaseConfig = createPhaseConfig(jsPhases, configuration), phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jsPhases),
compileMode = CompilationMode.KLIB, compileMode = CompilationMode.KLIB,
immediateDependencies = emptyList(), immediateDependencies = emptyList(),
allDependencies = emptyList(), allDependencies = emptyList(),
@@ -5,7 +5,8 @@
package org.jetbrains.kotlin.js.test package org.jetbrains.kotlin.js.test
import org.jetbrains.kotlin.cli.common.createPhaseConfig import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.ir.backend.js.* import org.jetbrains.kotlin.ir.backend.js.*
import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.config.JSConfigurationKeys
@@ -110,7 +111,7 @@ abstract class BasicIrBoxTest(
project = config.project, project = config.project,
files = filesToCompile, files = filesToCompile,
configuration = config.configuration, configuration = config.configuration,
phaseConfig = createPhaseConfig(jsPhases, config.configuration), phaseConfig = config.configuration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jsPhases),
compileMode = if (isMainModule) CompilationMode.JS else CompilationMode.KLIB, compileMode = if (isMainModule) CompilationMode.JS else CompilationMode.KLIB,
immediateDependencies = dependencies, immediateDependencies = dependencies,
allDependencies = allDependencies, allDependencies = allDependencies,