[IR] Visit file annotations in IR interpreter
#KT-55866 Fixed
This commit is contained in:
+7
-2
@@ -162,8 +162,13 @@ private fun getGeneratedClassName(file: File, text: String, newPackagePrefix: St
|
|||||||
for (annotation in FILE_NAME_ANNOTATIONS) {
|
for (annotation in FILE_NAME_ANNOTATIONS) {
|
||||||
if (text.contains(annotation)) {
|
if (text.contains(annotation)) {
|
||||||
val indexOf = text.indexOf(annotation)
|
val indexOf = text.indexOf(annotation)
|
||||||
val annotationParameter = text.substring(text.indexOf("(\"", indexOf) + 2, text.indexOf("\")", indexOf))
|
val startIndex = text.indexOf("(\"", indexOf)
|
||||||
return packageFqName.child(Name.identifier(annotationParameter))
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -28345,6 +28345,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
|||||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt55912.kt")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
|
|||||||
+6
@@ -28345,6 +28345,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt55912.kt")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
|
|||||||
+5
@@ -22,6 +22,11 @@ internal class IrConstDeclarationAnnotationTransformer(
|
|||||||
onError: (IrFile, IrElement, IrErrorExpression) -> Unit,
|
onError: (IrFile, IrElement, IrErrorExpression) -> Unit,
|
||||||
suppressExceptions: Boolean,
|
suppressExceptions: Boolean,
|
||||||
) : IrConstAnnotationTransformer(interpreter, irFile, mode, evaluatedConstTracker, onWarning, onError, suppressExceptions) {
|
) : 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 {
|
override fun visitDeclaration(declaration: IrDeclarationBase, data: Nothing?): IrStatement {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
return super.visitDeclaration(declaration, data)
|
return super.visitDeclaration(declaration, data)
|
||||||
|
|||||||
+2
-3
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.constant.ErrorValue
|
|||||||
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
|
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
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.IrConst
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrErrorExpression
|
import org.jetbrains.kotlin.ir.expressions.IrErrorExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
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.interpreter.toConstantValue
|
||||||
import org.jetbrains.kotlin.ir.util.dump
|
import org.jetbrains.kotlin.ir.util.dump
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
fun IrFile.transformConst(
|
fun IrFile.transformConst(
|
||||||
interpreter: IrInterpreter,
|
interpreter: IrInterpreter,
|
||||||
@@ -99,7 +98,7 @@ internal abstract class IrConstTransformer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
evaluatedConstTracker?.save(
|
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)
|
constant = if (result is IrErrorExpression) ErrorValue.create(result.description)
|
||||||
else (result as IrConst<*>).toConstantValue()
|
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.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
fun <D : IrAttributeContainer> D.copyAttributes(other: IrAttributeContainer?): D = apply {
|
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.path: String get() = fileEntry.name
|
||||||
val IrFile.name: String get() = File(path).name
|
val IrFile.name: String get() = File(path).name
|
||||||
|
val IrFile.nameWithPackage: String get() = fqName.child(Name.identifier(name)).asString()
|
||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
fun IrFunction.getIrValueParameter(parameter: ValueParameterDescriptor): IrValueParameter =
|
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"
|
||||||
+6
@@ -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);
|
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
|
@Test
|
||||||
@TestMetadata("kt55912.kt")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
|
|||||||
+6
@@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt55912.kt")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
|
|||||||
+6
@@ -28345,6 +28345,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
|||||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55108.kt");
|
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
|
@Test
|
||||||
@TestMetadata("kt55912.kt")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
|
|||||||
+2
-2
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.constant.ErrorValue
|
import org.jetbrains.kotlin.constant.ErrorValue
|
||||||
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
|
import org.jetbrains.kotlin.constant.EvaluatedConstTracker
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
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.TargetBackend
|
||||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_K2
|
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_BACKEND_K2
|
||||||
import org.jetbrains.kotlin.test.model.*
|
import org.jetbrains.kotlin.test.model.*
|
||||||
@@ -51,7 +51,7 @@ interface IrInterpreterDumpHandler {
|
|||||||
|
|
||||||
private fun EvaluatedConstTracker.processFile(testFile: TestFile, irFile: IrFile) {
|
private fun EvaluatedConstTracker.processFile(testFile: TestFile, irFile: IrFile) {
|
||||||
val rangesThatAreNotSupposedToBeRendered = testFile.extractRangesWithoutRender()
|
val rangesThatAreNotSupposedToBeRendered = testFile.extractRangesWithoutRender()
|
||||||
this.load(irFile.name)?.forEach { (pair, constantValue) ->
|
this.load(irFile.nameWithPackage)?.forEach { (pair, constantValue) ->
|
||||||
val (start, end) = pair
|
val (start, end) = pair
|
||||||
if (rangesThatAreNotSupposedToBeRendered.any { start >= it.first && start <= it.second }) return@forEach
|
if (rangesThatAreNotSupposedToBeRendered.any { start >= it.first && start <= it.second }) return@forEach
|
||||||
|
|
||||||
|
|||||||
+5
@@ -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);
|
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")
|
@TestMetadata("kt55912.kt")
|
||||||
public void testKt55912() throws Exception {
|
public void testKt55912() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
runTest("compiler/testData/codegen/box/involvesIrInterpreter/kt55912.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user