[K/N] Normalize lowering names

This commit is contained in:
Sergey Bogolepov
2023-01-24 15:50:46 +02:00
committed by Space Team
parent 5d44f01a88
commit 4c11f6ff30
2 changed files with 19 additions and 36 deletions
@@ -62,7 +62,7 @@ internal val modulePhaseActions: Set<Action<IrModuleFragment, NativeGenerationSt
nativeStateIrValidator.takeIf { validateAll } nativeStateIrValidator.takeIf { validateAll }
) )
internal val FunctionsWithoutBoundCheck = createSimpleNamedCompilerPhase<Context, Unit>( internal val functionsWithoutBoundCheck = createSimpleNamedCompilerPhase<Context, Unit>(
name = "FunctionsWithoutBoundCheckGenerator", name = "FunctionsWithoutBoundCheckGenerator",
description = "Functions without bounds check generation", description = "Functions without bounds check generation",
op = { context, _ -> FunctionsWithoutBoundCheckGenerator(context).generate() } op = { context, _ -> FunctionsWithoutBoundCheckGenerator(context).generate() }
@@ -256,7 +256,7 @@ private val forLoopsPhase = createFileLoweringPhase(
}, },
name = "ForLoops", name = "ForLoops",
description = "For loops lowering", description = "For loops lowering",
prerequisite = setOf(FunctionsWithoutBoundCheck) prerequisite = setOf(functionsWithoutBoundCheck)
) )
private val dataClassesPhase = createFileLoweringPhase( private val dataClassesPhase = createFileLoweringPhase(
@@ -420,7 +420,7 @@ internal val UnboxInlinePhase = createFileLoweringPhase(
lowering = ::UnboxInlineLowering, lowering = ::UnboxInlineLowering,
) )
private val InlinePhase = createFileLoweringPhase( private val inlinePhase = createFileLoweringPhase(
lowering = { context: NativeGenerationState -> lowering = { context: NativeGenerationState ->
object : FileLoweringPass { object : FileLoweringPass {
override fun lower(irFile: IrFile) { override fun lower(irFile: IrFile) {
@@ -433,27 +433,27 @@ private val InlinePhase = createFileLoweringPhase(
// prerequisite = setOf(lowerBeforeInlinePhase, arrayConstructorPhase, extractLocalClassesFromInlineBodies) // prerequisite = setOf(lowerBeforeInlinePhase, arrayConstructorPhase, extractLocalClassesFromInlineBodies)
) )
private val DelegationPhase = createFileLoweringPhase( private val delegationPhase = createFileLoweringPhase(
lowering = ::PropertyDelegationLowering, lowering = ::PropertyDelegationLowering,
name = "Delegation", name = "Delegation",
description = "Delegation lowering" description = "Delegation lowering"
// prerequisite = setOf(volatilePhase) // prerequisite = setOf(volatilePhase)
) )
private val FunctionReferencePhase = createFileLoweringPhase( private val functionReferencePhase = createFileLoweringPhase(
lowering = ::FunctionReferenceLowering, lowering = ::FunctionReferenceLowering,
name = "FunctionReference", name = "FunctionReference",
description = "Function references lowering", description = "Function references lowering",
// prerequisite = setOf(delegationPhase, localFunctionsPhase) // TODO: make weak dependency on `testProcessorPhase` // prerequisite = setOf(delegationPhase, localFunctionsPhase) // TODO: make weak dependency on `testProcessorPhase`
) )
private val InventNamesForLocalClasses = createFileLoweringPhase( private val inventNamesForLocalClasses = createFileLoweringPhase(
lowering = ::NativeInventNamesForLocalClasses, lowering = ::NativeInventNamesForLocalClasses,
name = "InventNamesForLocalClasses", name = "InventNamesForLocalClasses",
description = "Invent names for local classes and anonymous objects", description = "Invent names for local classes and anonymous objects",
) )
private val UseInternalAbiPhase = createSimpleNamedCompilerPhase<NativeGenerationState, IrFile, IrFile>( private val useInternalAbiPhase = createSimpleNamedCompilerPhase<NativeGenerationState, IrFile, IrFile>(
name = "UseInternalAbi", name = "UseInternalAbi",
description = "Use internal ABI functions to access private entities", description = "Use internal ABI functions to access private entities",
outputIfNotEnabled = { _, _, _, irFile -> irFile }, outputIfNotEnabled = { _, _, _, irFile -> irFile },
@@ -463,13 +463,13 @@ private val UseInternalAbiPhase = createSimpleNamedCompilerPhase<NativeGeneratio
} }
private val ObjectClassesPhase = createFileLoweringPhase( private val objectClassesPhase = createFileLoweringPhase(
lowering = ::ObjectClassLowering, lowering = ::ObjectClassLowering,
name = "ObjectClasses", name = "ObjectClasses",
description = "Object classes lowering" description = "Object classes lowering"
) )
private val CoroutinesPhase = createFileLoweringPhase( private val coroutinesPhase = createFileLoweringPhase(
lowering = { context: NativeGenerationState -> lowering = { context: NativeGenerationState ->
object : FileLoweringPass { object : FileLoweringPass {
override fun lower(irFile: IrFile) { override fun lower(irFile: IrFile) {
@@ -485,7 +485,7 @@ private val CoroutinesPhase = createFileLoweringPhase(
// prerequisite = setOf(localFunctionsPhase, finallyBlocksPhase, kotlinNothingValueExceptionPhase) // prerequisite = setOf(localFunctionsPhase, finallyBlocksPhase, kotlinNothingValueExceptionPhase)
) )
private val InteropPhase = createFileLoweringPhase( private val interopPhase = createFileLoweringPhase(
lowering = ::InteropLowering, lowering = ::InteropLowering,
name = "Interop", name = "Interop",
description = "Interop lowering", description = "Interop lowering",
@@ -499,10 +499,10 @@ private fun PhaseEngine<NativeGenerationState>.getAllLowerings() = listOfNotNull
arrayConstructorPhase, arrayConstructorPhase,
lateinitPhase, lateinitPhase,
sharedVariablesPhase, sharedVariablesPhase,
InventNamesForLocalClasses, inventNamesForLocalClasses,
extractLocalClassesFromInlineBodies, extractLocalClassesFromInlineBodies,
wrapInlineDeclarationsWithReifiedTypeParametersLowering, wrapInlineDeclarationsWithReifiedTypeParametersLowering,
InlinePhase, inlinePhase,
provisionalFunctionExpressionPhase, provisionalFunctionExpressionPhase,
postInlinePhase, postInlinePhase,
contractsDslRemovePhase, contractsDslRemovePhase,
@@ -524,45 +524,29 @@ private fun PhaseEngine<NativeGenerationState>.getAllLowerings() = listOfNotNull
dataClassesPhase, dataClassesPhase,
ifNullExpressionsFusionPhase, ifNullExpressionsFusionPhase,
testProcessorPhase.takeIf { context.config.configuration.getNotNull(KonanConfigKeys.GENERATE_TEST_RUNNER) != TestRunnerKind.NONE }, testProcessorPhase.takeIf { context.config.configuration.getNotNull(KonanConfigKeys.GENERATE_TEST_RUNNER) != TestRunnerKind.NONE },
DelegationPhase, delegationPhase,
FunctionReferencePhase, functionReferencePhase,
singleAbstractMethodPhase, singleAbstractMethodPhase,
enumWhenPhase, enumWhenPhase,
builtinOperatorPhase, builtinOperatorPhase,
finallyBlocksPhase, finallyBlocksPhase,
enumClassPhase, enumClassPhase,
enumUsagePhase, enumUsagePhase,
InteropPhase, interopPhase,
varargPhase, varargPhase,
kotlinNothingValueExceptionPhase, kotlinNothingValueExceptionPhase,
CoroutinesPhase, coroutinesPhase,
typeOperatorPhase, typeOperatorPhase,
expressionBodyTransformPhase, expressionBodyTransformPhase,
ObjectClassesPhase, objectClassesPhase,
constantInliningPhase, constantInliningPhase,
staticInitializersPhase, staticInitializersPhase,
bridgesPhase, bridgesPhase,
exportInternalAbiPhase.takeIf { context.config.produce.isCache }, exportInternalAbiPhase.takeIf { context.config.produce.isCache },
UseInternalAbiPhase, useInternalAbiPhase,
autoboxPhase, autoboxPhase,
) )
/**
* Simplify porting of lowerings from static driver (where lowerings were executed in one big Context)
* to dynamic with NativeGenerationState. It can be done manual rewriting, but it is an enormous work.
*/
private fun PhaseEngine<NativeGenerationState>.convertToNativeGeneration(
phase: SameTypeNamedCompilerPhase<Context, IrFile>,
): SimpleNamedCompilerPhase<NativeGenerationState, IrFile, IrFile> {
return createSimpleNamedCompilerPhase(
phase.name,
phase.description,
postactions = fileLoweringActions,
outputIfNotEnabled = { _, _, _, irFile -> irFile },
op = { context, irFile -> phase.phaseBody(phaseConfig, phaserState.changePhaserStateType(), context.context, irFile) }
)
}
private fun createFileLoweringPhase( private fun createFileLoweringPhase(
name: String, name: String,
description: String, description: String,
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
@@ -51,7 +50,7 @@ internal fun <T> PhaseEngine<PhaseContext>.runPsiToIr(
internal fun <C : PhaseContext> PhaseEngine<C>.runBackend(backendContext: Context, irModule: IrModuleFragment) { internal fun <C : PhaseContext> PhaseEngine<C>.runBackend(backendContext: Context, irModule: IrModuleFragment) {
useContext(backendContext) { backendEngine -> useContext(backendContext) { backendEngine ->
backendEngine.runPhase(FunctionsWithoutBoundCheck) backendEngine.runPhase(functionsWithoutBoundCheck)
val fragments = backendEngine.splitIntoFragments(irModule) val fragments = backendEngine.splitIntoFragments(irModule)
fragments.forEach { (generationState, fragment) -> fragments.forEach { (generationState, fragment) ->
backendEngine.useContext(generationState) { generationStateEngine -> backendEngine.useContext(generationState) { generationStateEngine ->