[IR] Visit file annotations in IR interpreter

#KT-55866 Fixed
This commit is contained in:
Ivan Kylchik
2023-04-24 10:26:50 +02:00
committed by Space Team
parent 1ba900be44
commit 3d4f3d2f57
12 changed files with 64 additions and 7 deletions
@@ -162,8 +162,13 @@ private fun getGeneratedClassName(file: File, text: String, newPackagePrefix: St
for (annotation in FILE_NAME_ANNOTATIONS) {
if (text.contains(annotation)) {
val indexOf = text.indexOf(annotation)
val annotationParameter = text.substring(text.indexOf("(\"", indexOf) + 2, text.indexOf("\")", indexOf))
return packageFqName.child(Name.identifier(annotationParameter))
val startIndex = text.indexOf("(\"", indexOf)
val endIndex = text.indexOf("\")", indexOf)
// "start", "end" can be -1 in case when we use some const val in argument place
if (startIndex != -1 && endIndex != -1) {
val annotationParameter = text.substring(startIndex + 2, endIndex)
return packageFqName.child(Name.identifier(annotationParameter))
}
}
}
@@ -28345,6 +28345,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -28345,6 +28345,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -22,6 +22,11 @@ internal class IrConstDeclarationAnnotationTransformer(
onError: (IrFile, IrElement, IrErrorExpression) -> Unit,
suppressExceptions: Boolean,
) : IrConstAnnotationTransformer(interpreter, irFile, mode, evaluatedConstTracker, onWarning, onError, suppressExceptions) {
override fun visitFile(declaration: IrFile, data: Nothing?): IrFile {
transformAnnotations(declaration)
return super.visitFile(declaration, data)
}
override fun visitDeclaration(declaration: IrDeclarationBase, data: Nothing?): IrStatement {
transformAnnotations(declaration)
return super.visitDeclaration(declaration, data)
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.constant.ErrorValue
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.name
import org.jetbrains.kotlin.ir.declarations.nameWithPackage
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrErrorExpression
import org.jetbrains.kotlin.ir.expressions.IrExpression
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreterConfiguration
import org.jetbrains.kotlin.ir.interpreter.toConstantValue
import org.jetbrains.kotlin.ir.util.dump
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.name.Name
fun IrFile.transformConst(
interpreter: IrInterpreter,
@@ -99,7 +98,7 @@ internal abstract class IrConstTransformer(
}
evaluatedConstTracker?.save(
result.startOffset, result.endOffset, irFile.fqName.child(Name.identifier(irFile.name)).asString(),
result.startOffset, result.endOffset, irFile.nameWithPackage,
constant = if (result is IrErrorExpression) ErrorValue.create(result.description)
else (result as IrConst<*>).toConstantValue()
)
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.name.Name
import java.io.File
fun <D : IrAttributeContainer> D.copyAttributes(other: IrAttributeContainer?): D = apply {
@@ -37,6 +38,7 @@ fun IrClass.addAll(members: List<IrDeclaration>) {
val IrFile.path: String get() = fileEntry.name
val IrFile.name: String get() = File(path).name
val IrFile.nameWithPackage: String get() = fqName.child(Name.identifier(name)).asString()
@ObsoleteDescriptorBasedAPI
fun IrFunction.getIrValueParameter(parameter: ValueParameterDescriptor): IrValueParameter =
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM
// WITH_STDLIB
@file:JvmName(<!EVALUATED("Tagged")!>TAG<!>)
package root
private const val TAG = <!EVALUATED("Tagged")!>"Tagged"<!>
class ConstParamFiller
fun box(): String = "OK"
@@ -27211,6 +27211,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
import org.jetbrains.kotlin.constant.ErrorValue
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.name
import org.jetbrains.kotlin.ir.declarations.nameWithPackage
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_K2
import org.jetbrains.kotlin.test.model.*
@@ -51,7 +51,7 @@ interface IrInterpreterDumpHandler {
private fun EvaluatedConstTracker.processFile(testFile: TestFile, irFile: IrFile) {
val rangesThatAreNotSupposedToBeRendered = testFile.extractRangesWithoutRender()
this.load(irFile.name)?.forEach { (pair, constantValue) ->
this.load(irFile.nameWithPackage)?.forEach { (pair, constantValue) ->
val (start, end) = pair
if (rangesThatAreNotSupposedToBeRendered.any { start >= it.first && start <= it.second }) return@forEach
@@ -22962,6 +22962,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55866.kt");
}
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");