From 7997d4afd310c4a389d51a070c20d8ac68743d6e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 1 Jul 2020 01:56:05 +0200 Subject: [PATCH] IR: do not use AnyNamedPhase where there is Context parameter --- .../backend/common/phaser/CompilerPhase.kt | 6 +++--- .../backend/common/phaser/PhaseBuilders.kt | 18 +++++++++--------- .../kotlin/ir/backend/js/JsLoweringPhases.kt | 8 ++++---- .../jetbrains/kotlin/backend/jvm/JvmLower.kt | 6 +++--- .../jvm/lower/InventNamesForLocalClasses.kt | 2 +- .../kotlin/backend/wasm/WasmLoweringPhases.kt | 6 +++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt index 213d58ee145..c0e6bfd977d 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/CompilerPhase.kt @@ -28,7 +28,7 @@ inline fun PhaserState.downlevel(nlevels: Int, block: () -> R): R { interface CompilerPhase { fun invoke(phaseConfig: PhaseConfig, phaserState: PhaserState, context: Context, input: Input): Output - fun getNamedSubphases(startDepth: Int = 0): List> = emptyList() + fun getNamedSubphases(startDepth: Int = 0): List>> = emptyList() // In phase trees, `stickyPostconditions` is inherited along the right edge to be used in `then`. val stickyPostconditions: Set> get() = emptySet() @@ -67,7 +67,7 @@ infix operator fun Action.plus(other: Action( val name: String, val description: String, - val prerequisite: Set, + val prerequisite: Set>, private val lower: CompilerPhase, val preconditions: Set> = emptySet(), val postconditions: Set> = emptySet(), @@ -136,7 +136,7 @@ class NamedCompilerPhase( return result!! } - override fun getNamedSubphases(startDepth: Int): List>> = + override fun getNamedSubphases(startDepth: Int): List>> = listOf(startDepth to this) + lower.getNamedSubphases(startDepth + nlevels) override fun toString() = "Compiler Phase @$name" diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt index 0fbf52eae56..365881896a3 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/phaser/PhaseBuilders.kt @@ -33,7 +33,7 @@ private class CompositePhase( return result as Output } - override fun getNamedSubphases(startDepth: Int): List> = + override fun getNamedSubphases(startDepth: Int): List>> = phases.flatMap { it.getNamedSubphases(startDepth) } override val stickyPostconditions get() = phases.last().stickyPostconditions @@ -51,7 +51,7 @@ infix fun CompilerPhase namedIrModulePhase( name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), lower: CompilerPhase, preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), @@ -73,7 +73,7 @@ fun namedIrModulePhase( fun namedIrFilePhase( name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), lower: CompilerPhase, preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), @@ -96,7 +96,7 @@ fun makeCustomPhase( op: (Context, Element) -> Unit, description: String, name: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), stickyPostconditions: Set> = emptySet(), @@ -127,7 +127,7 @@ fun makeCustomPhase( fun namedUnitPhase( name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), nlevels: Int = 1, lower: CompilerPhase ) = NamedCompilerPhase( @@ -140,7 +140,7 @@ fun namedUnitPhase( fun namedOpUnitPhase( name: String, description: String, - prerequisite: Set, + prerequisite: Set>, op: Context.() -> Unit ) = namedUnitPhase( name, description, prerequisite, @@ -155,7 +155,7 @@ fun namedOpUnitPhase( fun performByIrFile( name: String = "PerformByIrFile", description: String = "Perform phases by IrFile", - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), stickyPostconditions: Set> = emptySet(), @@ -195,7 +195,7 @@ fun makeIrFilePhase( lowering: (Context) -> FileLoweringPass, name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), stickyPostconditions: Set> = emptySet(), @@ -219,7 +219,7 @@ fun makeIrModulePhase( lowering: (Context) -> FileLoweringPass, name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = emptySet(), preconditions: Set> = emptySet(), postconditions: Set> = emptySet(), stickyPostconditions: Set> = emptySet(), diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index 7da43d3d09a..be00891644e 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -33,7 +33,7 @@ private fun makeJsModulePhase( lowering: (JsIrBackendContext) -> FileLoweringPass, name: String, description: String, - prerequisite: Set = emptySet() + prerequisite: Set> = 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 = emptySet() + prerequisite: Set> = emptySet() ) = NamedCompilerPhase( name = name, description = description, @@ -85,7 +85,7 @@ sealed class Lowering(val name: String) { class DeclarationLowering( name: String, description: String, - prerequisite: Set = emptySet(), + prerequisite: Set> = 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 = emptySet(), + prerequisite: Set> = emptySet(), private val factory: (JsIrBackendContext) -> BodyLoweringPass ) : Lowering(name) { fun bodyLowering(context: JsIrBackendContext): BodyLoweringPass { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index b81b0921d36..32fd2644ce2 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -108,7 +108,7 @@ internal val propertiesPhase = makeIrFilePhase( stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties) ) -internal val localDeclarationsPhase = makeIrFilePhase( +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 function" ) -private val initializersPhase = makeIrFilePhase( +private val initializersPhase = makeIrFilePhase( ::InitializersLowering, name = "Initializers", description = "Merge init blocks and field initializers into constructors", @@ -222,7 +222,7 @@ private val initializersPhase = makeIrFilePhase( prerequisite = setOf(jvmLocalClassExtractionPhase) ) -private val initializersCleanupPhase = makeIrFilePhase( +private val initializersCleanupPhase = makeIrFilePhase( { context -> InitializersCleanupLowering(context) { it.constantValue(context) == null && (!it.isStatic || it.correspondingPropertySymbol?.owner?.isConst != true) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt index 8cdf951d7a5..ffb9d86f3af 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt @@ -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( +val inventNamesForLocalClassesPhase = makeIrFilePhase( { context -> InventNamesForLocalClasses(context) }, name = "InventNamesForLocalClasses", description = "Invent names for local classes and anonymous objects", diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt index 10fbf975875..07464d23a7a 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmLoweringPhases.kt @@ -26,14 +26,14 @@ private fun makeWasmModulePhase( lowering: (WasmBackendContext) -> FileLoweringPass, name: String, description: String, - prerequisite: Set = emptySet() -) = makeIrModulePhase(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper)) + prerequisite: Set> = emptySet() +) = makeIrModulePhase(lowering, name, description, prerequisite, actions = setOf(validationAction, defaultDumper)) private fun makeCustomWasmModulePhase( op: (WasmBackendContext, IrModuleFragment) -> Unit, description: String, name: String, - prerequisite: Set = emptySet() + prerequisite: Set> = emptySet() ) = namedIrModulePhase( name, description,