From f9e62f8ffa7976d7f3efeb7f6cfb97ee004eb056 Mon Sep 17 00:00:00 2001 From: Anton Bannykh Date: Fri, 12 Nov 2021 13:53:22 +0300 Subject: [PATCH] [JS IR] expose currentStage via the stageController Otherwise the signatures for the declarations, created in lowerings, will be miscalculated. --- .../kotlin/ir/backend/js/JsLoweringPhases.kt | 2 +- .../kotlin/ir/backend/js/compilerWithIC.kt | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 35284c919b2..73a4e7e968a 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 @@ -804,7 +804,7 @@ private val jsSuspendArityStorePhase = makeDeclarationTransformerPhase( description = "Store arity for suspend functions to not remove it during DCE" ) -private val loweringList = listOf( +val loweringList = listOf( scriptRemoveReceiverLowering, validateIrBeforeLowering, annotationInstantiationLowering, diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt index e1a5c8765ab..5f3ebdcd669 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/compilerWithIC.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.ir.backend.js +import org.jetbrains.kotlin.backend.common.lower import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig +import org.jetbrains.kotlin.backend.common.phaser.PhaserState import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI @@ -87,7 +89,7 @@ fun compileWithIC( generateJsTests(context, mainModule) - jsPhases.invokeToplevel(PhaseConfig(jsPhases), context, allModules) + lowerPreservingTags(allModules, context, PhaseConfig(jsPhases), symbolTable.irFactory.stageController as WholeWorldStageController) val transformer = IrModuleToJsTransformerTmp( context, @@ -107,6 +109,20 @@ fun compileWithIC( ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) } } +fun lowerPreservingTags(modules: Iterable, context: JsIrBackendContext, phaseConfig: PhaseConfig, controller: WholeWorldStageController) { + // Lower all the things + controller.currentStage = 0 + + val phaserState = PhaserState>() + + loweringList.forEachIndexed { i, lowering -> + controller.currentStage = i + 1 + lowering.modulePhase.invoke(phaseConfig, phaserState, context, modules) + } + + controller.currentStage = pirLowerings.size + 1 +} + @Suppress("UNUSED_PARAMETER") fun generateJsFromAst(