[JVM_IR] Use createSimpleNamedCompilerPhase to create lowerings
This commit is contained in:
+46
-55
@@ -94,76 +94,67 @@ fun <Context : LoggingContext, Input> createSimpleNamedCompilerPhase(
|
|||||||
op(context, input)
|
op(context, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
|
private val defaultConditions = setOf(defaultDumper, validationAction)
|
||||||
op: (Context, Element) -> Unit,
|
|
||||||
|
fun <Context : CommonBackendContext> makeCustomPhase(
|
||||||
|
op: (Context, IrModuleFragment) -> Unit,
|
||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
||||||
preconditions: Set<Checker<Element>> = emptySet(),
|
preconditions: Set<Action<IrModuleFragment, Context>> = emptySet(),
|
||||||
postconditions: Set<Checker<Element>> = emptySet(),
|
postconditions: Set<Action<IrModuleFragment, Context>> = emptySet(),
|
||||||
stickyPostconditions: Set<Checker<Element>> = emptySet(),
|
): SimpleNamedCompilerPhase<Context, IrModuleFragment, IrModuleFragment> =
|
||||||
actions: Set<Action<Element, Context>> = setOf(defaultDumper, validationAction),
|
createSimpleNamedCompilerPhase(
|
||||||
nlevels: Int = 1
|
name = name,
|
||||||
): SameTypeNamedCompilerPhase<Context, Element> =
|
description = description,
|
||||||
SameTypeNamedCompilerPhase(
|
preactions = defaultConditions + preconditions,
|
||||||
name, description, prerequisite, CustomPhaseAdapter(op), preconditions, postconditions, stickyPostconditions, actions, nlevels,
|
postactions = defaultConditions + postconditions,
|
||||||
|
prerequisite = prerequisite,
|
||||||
|
outputIfNotEnabled = { _, _, _, irModule -> irModule },
|
||||||
|
op = { context, irModule ->
|
||||||
|
op(context, irModule)
|
||||||
|
irModule
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
private class CustomPhaseAdapter<Context : CommonBackendContext, Element>(
|
|
||||||
private val op: (Context, Element) -> Unit
|
|
||||||
) : SameTypeCompilerPhase<Context, Element> {
|
|
||||||
override fun invoke(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<Element>, context: Context, input: Element): Element {
|
|
||||||
op(context, input)
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <Context : CommonBackendContext> makeIrFilePhase(
|
fun <Context : CommonBackendContext> makeIrFilePhase(
|
||||||
lowering: (Context) -> FileLoweringPass,
|
lowering: (Context) -> FileLoweringPass,
|
||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
||||||
preconditions: Set<Checker<IrFile>> = emptySet(),
|
preconditions: Set<Action<IrFile, Context>> = emptySet(),
|
||||||
postconditions: Set<Checker<IrFile>> = emptySet(),
|
postconditions: Set<Action<IrFile, Context>> = emptySet(),
|
||||||
stickyPostconditions: Set<Checker<IrFile>> = emptySet(),
|
): SimpleNamedCompilerPhase<Context, IrFile, IrFile> =
|
||||||
actions: Set<Action<IrFile, Context>> = setOf(defaultDumper, validationAction)
|
createSimpleNamedCompilerPhase(
|
||||||
): SameTypeNamedCompilerPhase<Context, IrFile> =
|
name = name,
|
||||||
SameTypeNamedCompilerPhase(
|
description = description,
|
||||||
name, description, prerequisite, FileLoweringPhaseAdapter(lowering), preconditions, postconditions, stickyPostconditions, actions,
|
preactions = defaultConditions + preconditions,
|
||||||
nlevels = 0,
|
postactions = defaultConditions + postconditions,
|
||||||
|
prerequisite = prerequisite,
|
||||||
|
outputIfNotEnabled = { _, _, _, irFile -> irFile },
|
||||||
|
op = { context, irFile ->
|
||||||
|
lowering(context).lower(irFile)
|
||||||
|
irFile
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
private class FileLoweringPhaseAdapter<Context : CommonBackendContext>(
|
|
||||||
private val lowering: (Context) -> FileLoweringPass
|
|
||||||
) : SameTypeCompilerPhase<Context, IrFile> {
|
|
||||||
override fun invoke(phaseConfig: PhaseConfigurationService, phaserState: PhaserState<IrFile>, context: Context, input: IrFile): IrFile {
|
|
||||||
lowering(context).lower(input)
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <Context : CommonBackendContext> makeIrModulePhase(
|
fun <Context : CommonBackendContext> makeIrModulePhase(
|
||||||
lowering: (Context) -> FileLoweringPass,
|
lowering: (Context) -> FileLoweringPass,
|
||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
prerequisite: Set<AbstractNamedCompilerPhase<Context, *, *>> = emptySet(),
|
||||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
preconditions: Set<Action<IrModuleFragment, Context>> = emptySet(),
|
||||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
postconditions: Set<Action<IrModuleFragment, Context>> = emptySet(),
|
||||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
): SimpleNamedCompilerPhase<Context, IrModuleFragment, IrModuleFragment> =
|
||||||
actions: Set<Action<IrModuleFragment, Context>> = setOf(defaultDumper, validationAction)
|
createSimpleNamedCompilerPhase(
|
||||||
): SameTypeNamedCompilerPhase<Context, IrModuleFragment> =
|
name = name,
|
||||||
SameTypeNamedCompilerPhase(
|
description = description,
|
||||||
name, description, prerequisite, ModuleLoweringPhaseAdapter(lowering), preconditions, postconditions, stickyPostconditions, actions,
|
preactions = defaultConditions + preconditions,
|
||||||
nlevels = 0,
|
postactions = defaultConditions + postconditions,
|
||||||
|
prerequisite = prerequisite,
|
||||||
|
outputIfNotEnabled = { _, _, _, irModule -> irModule },
|
||||||
|
op = { context, irModule ->
|
||||||
|
lowering(context).lower(irModule)
|
||||||
|
irModule
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
private class ModuleLoweringPhaseAdapter<Context : CommonBackendContext>(
|
|
||||||
private val lowering: (Context) -> FileLoweringPass
|
|
||||||
) : SameTypeCompilerPhase<Context, IrModuleFragment> {
|
|
||||||
override fun invoke(
|
|
||||||
phaseConfig: PhaseConfigurationService, phaserState: PhaserState<IrModuleFragment>, context: Context, input: IrModuleFragment
|
|
||||||
): IrModuleFragment {
|
|
||||||
lowering(context).lower(input)
|
|
||||||
return input
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+4
-7
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.backend.jvm.ir.shouldContainSuspendMarkers
|
|||||||
import org.jetbrains.kotlin.backend.jvm.lower.*
|
import org.jetbrains.kotlin.backend.jvm.lower.*
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||||
@@ -26,8 +25,6 @@ import org.jetbrains.kotlin.ir.util.PatchDeclarationParentsVisitor
|
|||||||
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
||||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||||
import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
import org.jetbrains.kotlin.ir.util.resolveFakeOverride
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
|
||||||
import org.jetbrains.kotlin.name.NameUtils
|
import org.jetbrains.kotlin.name.NameUtils
|
||||||
@@ -35,7 +32,7 @@ import org.jetbrains.kotlin.name.NameUtils
|
|||||||
private var patchParentPhases = 0
|
private var patchParentPhases = 0
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
private fun makePatchParentsPhase(): SameTypeNamedCompilerPhase<CommonBackendContext, IrFile> {
|
private fun makePatchParentsPhase(): SimpleNamedCompilerPhase<CommonBackendContext, IrFile, IrFile> {
|
||||||
val number = patchParentPhases++
|
val number = patchParentPhases++
|
||||||
return makeIrFilePhase(
|
return makeIrFilePhase(
|
||||||
{ PatchDeclarationParents() },
|
{ PatchDeclarationParents() },
|
||||||
@@ -47,7 +44,7 @@ private fun makePatchParentsPhase(): SameTypeNamedCompilerPhase<CommonBackendCon
|
|||||||
private var checkParentPhases = 0
|
private var checkParentPhases = 0
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
private fun makeCheckParentsPhase(): SameTypeNamedCompilerPhase<CommonBackendContext, IrFile> {
|
private fun makeCheckParentsPhase(): SimpleNamedCompilerPhase<CommonBackendContext, IrFile, IrFile> {
|
||||||
val number = checkParentPhases++
|
val number = checkParentPhases++
|
||||||
return makeIrFilePhase(
|
return makeIrFilePhase(
|
||||||
{ CheckDeclarationParents() },
|
{ CheckDeclarationParents() },
|
||||||
@@ -452,7 +449,7 @@ val jvmLoweringPhases = buildJvmLoweringPhases("IrLowering", listOf("PerformByIr
|
|||||||
|
|
||||||
private fun buildJvmLoweringPhases(
|
private fun buildJvmLoweringPhases(
|
||||||
name: String,
|
name: String,
|
||||||
phases: List<Pair<String, List<SameTypeNamedCompilerPhase<JvmBackendContext, IrFile>>>>,
|
phases: List<Pair<String, List<SimpleNamedCompilerPhase<JvmBackendContext, IrFile, IrFile>>>>,
|
||||||
): SameTypeNamedCompilerPhase<JvmBackendContext, IrModuleFragment> {
|
): SameTypeNamedCompilerPhase<JvmBackendContext, IrModuleFragment> {
|
||||||
return SameTypeNamedCompilerPhase(
|
return SameTypeNamedCompilerPhase(
|
||||||
name = name,
|
name = name,
|
||||||
@@ -489,7 +486,7 @@ private fun buildJvmLoweringPhases(
|
|||||||
// Build a compiler phase from a list of lowering sequences: each subsequence is run
|
// Build a compiler phase from a list of lowering sequences: each subsequence is run
|
||||||
// in parallel per file, and each parallel composition is run in sequence.
|
// in parallel per file, and each parallel composition is run in sequence.
|
||||||
private fun buildLoweringsPhase(
|
private fun buildLoweringsPhase(
|
||||||
perModuleLowerings: List<Pair<String, List<SameTypeNamedCompilerPhase<JvmBackendContext, IrFile>>>>,
|
perModuleLowerings: List<Pair<String, List<SimpleNamedCompilerPhase<JvmBackendContext, IrFile, IrFile>>>>,
|
||||||
): CompilerPhase<JvmBackendContext, IrModuleFragment, IrModuleFragment> =
|
): CompilerPhase<JvmBackendContext, IrModuleFragment, IrModuleFragment> =
|
||||||
perModuleLowerings.map { (name, lowerings) -> performByIrFile(name, lower = lowerings) }
|
perModuleLowerings.map { (name, lowerings) -> performByIrFile(name, lower = lowerings) }
|
||||||
.reduce<
|
.reduce<
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_SYNTHETIC_ANNOTATION_FQ
|
|||||||
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
|
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors
|
||||||
|
|
||||||
internal val generateMultifileFacadesPhase = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
internal val generateMultifileFacadesPhase = makeCustomPhase(
|
||||||
name = "GenerateMultifileFacades",
|
name = "GenerateMultifileFacades",
|
||||||
description = "Generate JvmMultifileClass facades, based on the information provided by FileClassLowering",
|
description = "Generate JvmMultifileClass facades, based on the information provided by FileClassLowering",
|
||||||
prerequisite = setOf(fileClassPhase),
|
prerequisite = setOf(fileClassPhase),
|
||||||
|
|||||||
+2
-4
@@ -47,12 +47,10 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.topologicalSort
|
import org.jetbrains.kotlin.utils.topologicalSort
|
||||||
|
|
||||||
internal val scriptsToClassesPhase = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
internal val scriptsToClassesPhase = makeCustomPhase<JvmBackendContext>(
|
||||||
|
op = { context, irModule -> ScriptsToClassesLowering(context, context.innerClassesSupport).lower(irModule) },
|
||||||
name = "ScriptsToClasses",
|
name = "ScriptsToClasses",
|
||||||
description = "Put script declarations into classes",
|
description = "Put script declarations into classes",
|
||||||
op = { context, input ->
|
|
||||||
ScriptsToClassesLowering(context, context.innerClassesSupport).lower(input)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -6,17 +6,15 @@
|
|||||||
package org.jetbrains.kotlin.backend.jvm.lower
|
package org.jetbrains.kotlin.backend.jvm.lower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||||
import org.jetbrains.kotlin.backend.common.lower
|
import org.jetbrains.kotlin.backend.common.phaser.makeIrModulePhase
|
||||||
import org.jetbrains.kotlin.backend.common.phaser.makeCustomPhase
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.backend.jvm.expectDeclarationsRemovingPhase
|
import org.jetbrains.kotlin.backend.jvm.expectDeclarationsRemovingPhase
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
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.MetadataSource
|
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||||
|
|
||||||
internal val serializeIrPhase = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
internal val serializeIrPhase = makeIrModulePhase(
|
||||||
{ context, irModule -> SerializeIrPhase(context).lower(irModule) },
|
lowering = ::SerializeIrPhase,
|
||||||
name = "SerializeIr",
|
name = "SerializeIr",
|
||||||
description = "If specified by compiler options, save serialized IR in class annotations",
|
description = "If specified by compiler options, save serialized IR in class annotations",
|
||||||
prerequisite = setOf(expectDeclarationsRemovingPhase),
|
prerequisite = setOf(expectDeclarationsRemovingPhase),
|
||||||
|
|||||||
Reference in New Issue
Block a user