diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ConstEvaluationLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ConstEvaluationLowering.kt index e6d320db6a3..ef8ba2be431 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ConstEvaluationLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/ConstEvaluationLowering.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreter import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration import org.jetbrains.kotlin.ir.interpreter.IrInterpreterEnvironment import org.jetbrains.kotlin.ir.interpreter.checker.EvaluationMode -import org.jetbrains.kotlin.ir.interpreter.transformer.preprocessForConstTransformer import org.jetbrains.kotlin.ir.interpreter.transformer.runConstOptimizations class ConstEvaluationLowering( @@ -27,11 +26,7 @@ class ConstEvaluationLowering( private val mode = EvaluationMode.ONLY_INTRINSIC_CONST override fun lower(irFile: IrFile) { - val useFir = context.configuration[CommonConfigurationKeys.USE_FIR] == true - val preprocessedFile = if (useFir) irFile else irFile.preprocessForConstTransformer(interpreter, mode) - preprocessedFile.runConstOptimizations( - interpreter, mode, evaluatedConstTracker, inlineConstTracker, suppressErrors - ) + irFile.runConstOptimizations(interpreter, mode, evaluatedConstTracker, inlineConstTracker, suppressErrors) } } diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstTransformer.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstTransformer.kt index 76def66f26f..113e978f097 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstTransformer.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/transformer/IrConstTransformer.kt @@ -40,23 +40,21 @@ fun IrFile.transformConst( onError: (IrFile, IrElement, IrErrorExpression) -> Unit = { _, _, _ -> }, suppressExceptions: Boolean = false, ) { - val preprocessedFile = this.preprocessForConstTransformer(interpreter, mode) - val checker = IrInterpreterCommonChecker() val irConstExpressionTransformer = IrConstOnlyNecessaryTransformer( - interpreter, preprocessedFile, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions + interpreter, this, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions ) - preprocessedFile.transform(irConstExpressionTransformer, IrConstTransformer.Data()) + this.transform(irConstExpressionTransformer, IrConstTransformer.Data()) val irConstDeclarationAnnotationTransformer = IrConstDeclarationAnnotationTransformer( - interpreter, preprocessedFile, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions + interpreter, this, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions ) - preprocessedFile.transform(irConstDeclarationAnnotationTransformer, IrConstTransformer.Data()) + this.transform(irConstDeclarationAnnotationTransformer, IrConstTransformer.Data()) val irConstTypeAnnotationTransformer = IrConstTypeAnnotationTransformer( - interpreter, preprocessedFile, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions + interpreter, this, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions ) - preprocessedFile.transform(irConstTypeAnnotationTransformer, IrConstTransformer.Data()) + this.transform(irConstTypeAnnotationTransformer, IrConstTransformer.Data()) } fun IrFile.runConstOptimizations( @@ -66,14 +64,18 @@ fun IrFile.runConstOptimizations( inlineConstTracker: InlineConstTracker? = null, suppressExceptions: Boolean = false, ) { + val preprocessedFile = this.preprocessForConstTransformer(interpreter, mode) + val checker = IrInterpreterCommonChecker() val irConstExpressionTransformer = IrConstAllTransformer( - interpreter, this, mode, checker, evaluatedConstTracker, inlineConstTracker, { _, _, _ -> }, { _, _, _ -> }, suppressExceptions + interpreter, preprocessedFile, mode, checker, evaluatedConstTracker, inlineConstTracker, + { _, _, _ -> }, { _, _, _ -> }, + suppressExceptions ) - this.transform(irConstExpressionTransformer, IrConstTransformer.Data()) + preprocessedFile.transform(irConstExpressionTransformer, IrConstTransformer.Data()) } -fun IrFile.preprocessForConstTransformer( +private fun IrFile.preprocessForConstTransformer( interpreter: IrInterpreter, mode: EvaluationMode, ): IrFile { diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/library/a.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/library/a.kt new file mode 100644 index 00000000000..0a03116a2f9 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/library/a.kt @@ -0,0 +1,10 @@ +package lib + +public class Plot { + public val layout: Int = 0 +} + +public fun plotFun(plot: Plot): String { + val mustBeOptimizedByCompiler = plot::layout.name + return mustBeOptimizedByCompiler +} diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/output.txt new file mode 100644 index 00000000000..538bb7afbb1 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/output.txt @@ -0,0 +1,4 @@ +info: produce executable: $TMP_DIR$/usage.js +info: cache directory: null +info: executable production duration: [time] +OK diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/src/empty.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/constEvaluationWithDifferentLV/src/empty.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt index 32f99044f65..0e9dd7a6de3 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractCompileKotlinAgainstCustomBinariesTest.kt @@ -712,6 +712,14 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo output.lines().filterNot { "argument -Xexpect-actual-linker is deprecated" in it }.joinToString("\n") } + fun testConstEvaluationWithDifferentLV() { + val library = compileJsLibrary("library", additionalOptions = listOf("-language-version", "1.9")) + compileKotlin( + "src", File(tmpdir, "usage.js"), emptyList(), K2JSCompiler(), + additionalOptions = listOf("-Xinclude=${library.absolutePath}", "-Xir-produce-js"), + ) + } + private fun doTestAnonymousObjectTypeMetadata( extraCommandLineArguments: List = emptyList(), filterOutput: (String) -> String = { output -> output }