IR: do not use AnyNamedPhase where there is Context parameter

This commit is contained in:
Alexander Udalov
2020-07-01 01:56:05 +02:00
parent ef58f1e72e
commit 7997d4afd3
6 changed files with 23 additions and 23 deletions
@@ -28,7 +28,7 @@ inline fun <R, D> PhaserState<D>.downlevel(nlevels: Int, block: () -> R): R {
interface CompilerPhase<in Context : CommonBackendContext, Input, Output> { interface CompilerPhase<in Context : CommonBackendContext, Input, Output> {
fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState<Input>, context: Context, input: 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`. // In phase trees, `stickyPostconditions` is inherited along the right edge to be used in `then`.
val stickyPostconditions: Set<Checker<Output>> get() = emptySet() 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>( class NamedCompilerPhase<in Context : CommonBackendContext, Data>(
val name: String, val name: String,
val description: String, val description: String,
val prerequisite: Set<AnyNamedPhase>, val prerequisite: Set<NamedCompilerPhase<Context, *>>,
private val lower: CompilerPhase<Context, Data, Data>, private val lower: CompilerPhase<Context, Data, Data>,
val preconditions: Set<Checker<Data>> = emptySet(), val preconditions: Set<Checker<Data>> = emptySet(),
val postconditions: Set<Checker<Data>> = emptySet(), val postconditions: Set<Checker<Data>> = emptySet(),
@@ -136,7 +136,7 @@ class NamedCompilerPhase<in Context : CommonBackendContext, Data>(
return result!! 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) listOf(startDepth to this) + lower.getNamedSubphases(startDepth + nlevels)
override fun toString() = "Compiler Phase @$name" override fun toString() = "Compiler Phase @$name"
@@ -33,7 +33,7 @@ private class CompositePhase<Context : CommonBackendContext, Input, Output>(
return result as 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) } phases.flatMap { it.getNamedSubphases(startDepth) }
override val stickyPostconditions get() = phases.last().stickyPostconditions override val stickyPostconditions get() = phases.last().stickyPostconditions
@@ -51,7 +51,7 @@ infix fun <Context : CommonBackendContext, Input, Mid, Output> CompilerPhase<Con
fun <Context : CommonBackendContext> namedIrModulePhase( fun <Context : CommonBackendContext> namedIrModulePhase(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
lower: CompilerPhase<Context, IrModuleFragment, IrModuleFragment>, lower: CompilerPhase<Context, IrModuleFragment, IrModuleFragment>,
preconditions: Set<Checker<IrModuleFragment>> = emptySet(), preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
postconditions: Set<Checker<IrModuleFragment>> = emptySet(), postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
@@ -73,7 +73,7 @@ fun <Context : CommonBackendContext> namedIrModulePhase(
fun <Context : CommonBackendContext> namedIrFilePhase( fun <Context : CommonBackendContext> namedIrFilePhase(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
lower: CompilerPhase<Context, IrFile, IrFile>, lower: CompilerPhase<Context, IrFile, IrFile>,
preconditions: Set<Checker<IrFile>> = emptySet(), preconditions: Set<Checker<IrFile>> = emptySet(),
postconditions: Set<Checker<IrFile>> = emptySet(), postconditions: Set<Checker<IrFile>> = emptySet(),
@@ -96,7 +96,7 @@ fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
op: (Context, Element) -> Unit, op: (Context, Element) -> Unit,
description: String, description: String,
name: String, name: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
preconditions: Set<Checker<Element>> = emptySet(), preconditions: Set<Checker<Element>> = emptySet(),
postconditions: Set<Checker<Element>> = emptySet(), postconditions: Set<Checker<Element>> = emptySet(),
stickyPostconditions: Set<Checker<Element>> = emptySet(), stickyPostconditions: Set<Checker<Element>> = emptySet(),
@@ -127,7 +127,7 @@ fun <Context : CommonBackendContext, Element : IrElement> makeCustomPhase(
fun <Context : CommonBackendContext> namedUnitPhase( fun <Context : CommonBackendContext> namedUnitPhase(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
nlevels: Int = 1, nlevels: Int = 1,
lower: CompilerPhase<Context, Unit, Unit> lower: CompilerPhase<Context, Unit, Unit>
) = NamedCompilerPhase( ) = NamedCompilerPhase(
@@ -140,7 +140,7 @@ fun <Context : CommonBackendContext> namedUnitPhase(
fun <Context : CommonBackendContext> namedOpUnitPhase( fun <Context : CommonBackendContext> namedOpUnitPhase(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase>, prerequisite: Set<NamedCompilerPhase<Context, *>>,
op: Context.() -> Unit op: Context.() -> Unit
) = namedUnitPhase( ) = namedUnitPhase(
name, description, prerequisite, name, description, prerequisite,
@@ -155,7 +155,7 @@ fun <Context : CommonBackendContext> namedOpUnitPhase(
fun <Context : CommonBackendContext> performByIrFile( fun <Context : CommonBackendContext> performByIrFile(
name: String = "PerformByIrFile", name: String = "PerformByIrFile",
description: String = "Perform phases by IrFile", description: String = "Perform phases by IrFile",
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
preconditions: Set<Checker<IrModuleFragment>> = emptySet(), preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
postconditions: Set<Checker<IrModuleFragment>> = emptySet(), postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(), stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
@@ -195,7 +195,7 @@ fun <Context : CommonBackendContext> makeIrFilePhase(
lowering: (Context) -> FileLoweringPass, lowering: (Context) -> FileLoweringPass,
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
preconditions: Set<Checker<IrFile>> = emptySet(), preconditions: Set<Checker<IrFile>> = emptySet(),
postconditions: Set<Checker<IrFile>> = emptySet(), postconditions: Set<Checker<IrFile>> = emptySet(),
stickyPostconditions: Set<Checker<IrFile>> = emptySet(), stickyPostconditions: Set<Checker<IrFile>> = emptySet(),
@@ -219,7 +219,7 @@ fun <Context : CommonBackendContext> makeIrModulePhase(
lowering: (Context) -> FileLoweringPass, lowering: (Context) -> FileLoweringPass,
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<Context, *>> = emptySet(),
preconditions: Set<Checker<IrModuleFragment>> = emptySet(), preconditions: Set<Checker<IrModuleFragment>> = emptySet(),
postconditions: Set<Checker<IrModuleFragment>> = emptySet(), postconditions: Set<Checker<IrModuleFragment>> = emptySet(),
stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(), stickyPostconditions: Set<Checker<IrModuleFragment>> = emptySet(),
@@ -33,7 +33,7 @@ private fun makeJsModulePhase(
lowering: (JsIrBackendContext) -> FileLoweringPass, lowering: (JsIrBackendContext) -> FileLoweringPass,
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet() prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet()
) = makeCustomJsModulePhase( ) = makeCustomJsModulePhase(
op = { context, modules -> lowering(context).lower(modules) }, op = { context, modules -> lowering(context).lower(modules) },
name = name, name = name,
@@ -45,7 +45,7 @@ private fun makeCustomJsModulePhase(
op: (JsIrBackendContext, IrModuleFragment) -> Unit, op: (JsIrBackendContext, IrModuleFragment) -> Unit,
description: String, description: String,
name: String, name: String,
prerequisite: Set<AnyNamedPhase> = emptySet() prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet()
) = NamedCompilerPhase( ) = NamedCompilerPhase(
name = name, name = name,
description = description, description = description,
@@ -85,7 +85,7 @@ sealed class Lowering(val name: String) {
class DeclarationLowering( class DeclarationLowering(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet(),
private val factory: (JsIrBackendContext) -> DeclarationTransformer private val factory: (JsIrBackendContext) -> DeclarationTransformer
) : Lowering(name) { ) : Lowering(name) {
fun declarationTransformer(context: JsIrBackendContext): DeclarationTransformer { fun declarationTransformer(context: JsIrBackendContext): DeclarationTransformer {
@@ -98,7 +98,7 @@ class DeclarationLowering(
class BodyLowering( class BodyLowering(
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet(), prerequisite: Set<NamedCompilerPhase<JsIrBackendContext, *>> = emptySet(),
private val factory: (JsIrBackendContext) -> BodyLoweringPass private val factory: (JsIrBackendContext) -> BodyLoweringPass
) : Lowering(name) { ) : Lowering(name) {
fun bodyLowering(context: JsIrBackendContext): BodyLoweringPass { fun bodyLowering(context: JsIrBackendContext): BodyLoweringPass {
@@ -108,7 +108,7 @@ internal val propertiesPhase = makeIrFilePhase(
stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties) stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties)
) )
internal val localDeclarationsPhase = makeIrFilePhase<CommonBackendContext>( internal val localDeclarationsPhase = makeIrFilePhase(
{ context -> { context ->
LocalDeclarationsLowering( LocalDeclarationsLowering(
context, 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" 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, ::InitializersLowering,
name = "Initializers", name = "Initializers",
description = "Merge init blocks and field initializers into constructors", description = "Merge init blocks and field initializers into constructors",
@@ -222,7 +222,7 @@ private val initializersPhase = makeIrFilePhase<JvmBackendContext>(
prerequisite = setOf(jvmLocalClassExtractionPhase) prerequisite = setOf(jvmLocalClassExtractionPhase)
) )
private val initializersCleanupPhase = makeIrFilePhase<JvmBackendContext>( private val initializersCleanupPhase = makeIrFilePhase(
{ context -> { context ->
InitializersCleanupLowering(context) { InitializersCleanupLowering(context) {
it.constantValue(context) == null && (!it.isStatic || it.correspondingPropertySymbol?.owner?.isConst != true) it.constantValue(context) == null && (!it.isStatic || it.correspondingPropertySymbol?.owner?.isConst != true)
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.name.NameUtils
import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.Type
val inventNamesForLocalClassesPhase = makeIrFilePhase<JvmBackendContext>( val inventNamesForLocalClassesPhase = makeIrFilePhase(
{ context -> InventNamesForLocalClasses(context) }, { context -> InventNamesForLocalClasses(context) },
name = "InventNamesForLocalClasses", name = "InventNamesForLocalClasses",
description = "Invent names for local classes and anonymous objects", description = "Invent names for local classes and anonymous objects",
@@ -26,14 +26,14 @@ private fun makeWasmModulePhase(
lowering: (WasmBackendContext) -> FileLoweringPass, lowering: (WasmBackendContext) -> FileLoweringPass,
name: String, name: String,
description: String, description: String,
prerequisite: Set<AnyNamedPhase> = emptySet() prerequisite: Set<NamedCompilerPhase<WasmBackendContext, *>> = emptySet()
) = makeIrModulePhase<WasmBackendContext>(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper)) ) = makeIrModulePhase(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper))
private fun makeCustomWasmModulePhase( private fun makeCustomWasmModulePhase(
op: (WasmBackendContext, IrModuleFragment) -> Unit, op: (WasmBackendContext, IrModuleFragment) -> Unit,
description: String, description: String,
name: String, name: String,
prerequisite: Set<AnyNamedPhase> = emptySet() prerequisite: Set<NamedCompilerPhase<WasmBackendContext, *>> = emptySet()
) = namedIrModulePhase( ) = namedIrModulePhase(
name, name,
description, description,