IR: do not use AnyNamedPhase where there is Context parameter
This commit is contained in:
+3
-3
@@ -28,7 +28,7 @@ inline fun <R, D> PhaserState<D>.downlevel(nlevels: Int, block: () -> R): R {
|
||||
interface CompilerPhase<in Context : CommonBackendContext, Input, Output> {
|
||||
fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, input: Input): Output
|
||||
|
||||
fun getNamedSubphases(startDepth: Int = 0): List<Pair<Int, AnyNamedPhase>> = emptyList()
|
||||
fun getNamedSubphases(startDepth: Int = 0): List<Pair<Int, NamedCompilerPhase<Context, *>>> = emptyList()
|
||||
|
||||
// In phase trees, `stickyPostconditions` is inherited along the right edge to be used in `then`.
|
||||
val stickyPostconditions: Set<Checker<Output>> get() = emptySet()
|
||||
@@ -67,7 +67,7 @@ infix operator fun <Data, Context> Action<Data, Context>.plus(other: Action<Data
|
||||
class NamedCompilerPhase<in Context : CommonBackendContext, Data>(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val prerequisite: Set<AnyNamedPhase>,
|
||||
val prerequisite: Set<NamedCompilerPhase<Context, *>>,
|
||||
private val lower: CompilerPhase<Context, Data, Data>,
|
||||
val preconditions: Set<Checker<Data>> = emptySet(),
|
||||
val postconditions: Set<Checker<Data>> = emptySet(),
|
||||
@@ -136,7 +136,7 @@ class NamedCompilerPhase<in Context : CommonBackendContext, Data>(
|
||||
return result!!
|
||||
}
|
||||
|
||||
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, NamedCompilerPhase<*, *>>> =
|
||||
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, NamedCompilerPhase<Context, *>>> =
|
||||
listOf(startDepth to this) + lower.getNamedSubphases(startDepth + nlevels)
|
||||
|
||||
override fun toString() = "Compiler Phase @$name"
|
||||
|
||||
+9
-9
@@ -33,7 +33,7 @@ private class CompositePhase<Context : CommonBackendContext, Input, Output>(
|
||||
return result as Output
|
||||
}
|
||||
|
||||
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, AnyNamedPhase>> =
|
||||
override fun getNamedSubphases(startDepth: Int): List<Pair<Int, NamedCompilerPhase<Context, *>>> =
|
||||
phases.flatMap { it.getNamedSubphases(startDepth) }
|
||||
|
||||
override val stickyPostconditions get() = phases.last().stickyPostconditions
|
||||
@@ -51,7 +51,7 @@ infix fun <Context : CommonBackendContext, Input, Mid, Output> CompilerPhase<Con
|
||||
fun <Context : CommonBackendContext> namedIrModulePhase(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
lower: CompilerPhase<Context, IrModuleFragment, IrModuleFragment>,
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
@@ -73,7 +73,7 @@ fun <Context : CommonBackendContext> namedIrModulePhase(
|
||||
fun <Context : CommonBackendContext> namedIrFilePhase(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
lower: CompilerPhase<Context, IrFile, IrFile>,
|
||||
preconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
postconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
@@ -96,7 +96,7 @@ fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
|
||||
op: (Context, Element) -> Unit,
|
||||
description: String,
|
||||
name: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
preconditions: Set<Checker<Element>> = emptySet(),
|
||||
postconditions: Set<Checker<Element>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<Element>> = emptySet(),
|
||||
@@ -127,7 +127,7 @@ fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
|
||||
fun <Context : CommonBackendContext> namedUnitPhase(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
nlevels: Int = 1,
|
||||
lower: CompilerPhase<Context, Unit, Unit>
|
||||
) = NamedCompilerPhase(
|
||||
@@ -140,7 +140,7 @@ fun <Context : CommonBackendContext> namedUnitPhase(
|
||||
fun <Context : CommonBackendContext> namedOpUnitPhase(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase>,
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>>,
|
||||
op: Context.() -> Unit
|
||||
) = namedUnitPhase(
|
||||
name, description, prerequisite,
|
||||
@@ -155,7 +155,7 @@ fun <Context : CommonBackendContext> namedOpUnitPhase(
|
||||
fun <Context : CommonBackendContext> performByIrFile(
|
||||
name: String = "PerformByIrFile",
|
||||
description: String = "Perform phases by IrFile",
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
@@ -195,7 +195,7 @@ fun <Context : CommonBackendContext> makeIrFilePhase(
|
||||
lowering: (Context) -> FileLoweringPass,
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
preconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
postconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrFile>> = emptySet(),
|
||||
@@ -219,7 +219,7 @@ fun <Context : CommonBackendContext> makeIrModulePhase(
|
||||
lowering: (Context) -> FileLoweringPass,
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
|
||||
preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
|
||||
|
||||
@@ -33,7 +33,7 @@ private fun makeJsModulePhase(
|
||||
lowering: (JsIrBackendContext) -> FileLoweringPass,
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet()
|
||||
prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet()
|
||||
) = makeCustomJsModulePhase(
|
||||
op = { context, modules -> lowering(context).lower(modules) },
|
||||
name = name,
|
||||
@@ -45,7 +45,7 @@ private fun makeCustomJsModulePhase(
|
||||
op: (JsIrBackendContext, IrModuleFragment) -> Unit,
|
||||
description: String,
|
||||
name: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet()
|
||||
prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet()
|
||||
) = NamedCompilerPhase(
|
||||
name = name,
|
||||
description = description,
|
||||
@@ -85,7 +85,7 @@ sealed class Lowering(val name: String) {
|
||||
class DeclarationLowering(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet(),
|
||||
private val factory: (JsIrBackendContext) -> DeclarationTransformer
|
||||
) : Lowering(name) {
|
||||
fun declarationTransformer(context: JsIrBackendContext): DeclarationTransformer {
|
||||
@@ -98,7 +98,7 @@ class DeclarationLowering(
|
||||
class BodyLowering(
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet(),
|
||||
prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet(),
|
||||
private val factory: (JsIrBackendContext) -> BodyLoweringPass
|
||||
) : Lowering(name) {
|
||||
fun bodyLowering(context: JsIrBackendContext): BodyLoweringPass {
|
||||
|
||||
@@ -108,7 +108,7 @@ internal val propertiesPhase = makeIrFilePhase(
|
||||
stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties)
|
||||
)
|
||||
|
||||
internal val localDeclarationsPhase = makeIrFilePhase<CommonBackendContext>(
|
||||
internal val localDeclarationsPhase = makeIrFilePhase(
|
||||
{ context ->
|
||||
LocalDeclarationsLowering(
|
||||
context,
|
||||
@@ -214,7 +214,7 @@ private val staticInitializersPhase = makeIrFilePhase(
|
||||
description = "Move code from object init blocks and static field initializers to a new <clinit> function"
|
||||
)
|
||||
|
||||
private val initializersPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
private val initializersPhase = makeIrFilePhase(
|
||||
::InitializersLowering,
|
||||
name = "Initializers",
|
||||
description = "Merge init blocks and field initializers into constructors",
|
||||
@@ -222,7 +222,7 @@ private val initializersPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
prerequisite = setOf(jvmLocalClassExtractionPhase)
|
||||
)
|
||||
|
||||
private val initializersCleanupPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
private val initializersCleanupPhase = makeIrFilePhase(
|
||||
{ context ->
|
||||
InitializersCleanupLowering(context) {
|
||||
it.constantValue(context) == null && (!it.isStatic || it.correspondingPropertySymbol?.owner?.isConst != true)
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.NameUtils
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
val inventNamesForLocalClassesPhase = makeIrFilePhase<JvmBackendContext>(
|
||||
val inventNamesForLocalClassesPhase = makeIrFilePhase(
|
||||
{ context -> InventNamesForLocalClasses(context) },
|
||||
name = "InventNamesForLocalClasses",
|
||||
description = "Invent names for local classes and anonymous objects",
|
||||
|
||||
+3
-3
@@ -26,14 +26,14 @@ private fun makeWasmModulePhase(
|
||||
lowering: (WasmBackendContext) -> FileLoweringPass,
|
||||
name: String,
|
||||
description: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet()
|
||||
) = makeIrModulePhase<WasmBackendContext>(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper))
|
||||
prerequisite: Set<NamedCompilerPhase<WasmBackendContext, *>> = emptySet()
|
||||
) = makeIrModulePhase(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper))
|
||||
|
||||
private fun makeCustomWasmModulePhase(
|
||||
op: (WasmBackendContext, IrModuleFragment) -> Unit,
|
||||
description: String,
|
||||
name: String,
|
||||
prerequisite: Set<AnyNamedPhase> = emptySet()
|
||||
prerequisite: Set<NamedCompilerPhase<WasmBackendContext, *>> = emptySet()
|
||||
) = namedIrModulePhase(
|
||||
name,
|
||||
description,
|
||||
|
||||
Reference in New Issue
Block a user