[IR] Don't evaluate expressions in inner class of an annotation

This commit is contained in:
Ivan Kylchik
2023-11-14 13:06:51 +01:00
committed by Space Team
parent 9742b5af73
commit 8715bd6189
21 changed files with 129 additions and 8 deletions
@@ -29636,6 +29636,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -29636,6 +29636,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -29289,6 +29289,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -29289,6 +29289,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -29289,6 +29289,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.ir.interpreter.IrInterpreter
import org.jetbrains.kotlin.ir.interpreter.checker.EvaluationMode
import org.jetbrains.kotlin.ir.interpreter.checker.IrInterpreterChecker
import org.jetbrains.kotlin.ir.interpreter.createGetField
import org.jetbrains.kotlin.ir.util.parentClassOrNull
import kotlin.math.max
import kotlin.math.min
@@ -35,16 +36,12 @@ internal abstract class IrConstExpressionTransformer(
interpreter, irFile, mode, checker, evaluatedConstTracker, inlineConstTracker, onWarning, onError, suppressExceptions
) {
override fun visitFunction(declaration: IrFunction, data: Data): IrStatement {
// It is useless to visit default accessor and if we do that we could render excess information for `IrGetField`
// It is useless to visit default accessor, and if we do that, we could render excess information for `IrGetField`
if (declaration.origin == IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR) return declaration
return super.visitFunction(declaration, data)
}
override fun visitClass(declaration: IrClass, data: Data): IrStatement {
if (declaration.kind == ClassKind.ANNOTATION_CLASS) {
return super.visitClass(declaration, data.copy(inConstantExpression = true))
}
return super.visitClass(declaration, data)
// We want to be able to evaluate default arguments of annotation's constructor
val isAnnotationConstructor = declaration is IrConstructor && declaration.parentClassOrNull?.kind == ClassKind.ANNOTATION_CLASS
return super.visitFunction(declaration, data.copy(inConstantExpression = isAnnotationConstructor))
}
override fun visitCall(expression: IrCall, data: Data): IrElement {
@@ -0,0 +1,11 @@
val a = "OK"
annotation class Anno {
class Inner {
val shouldNotBeEvaluated = a
}
}
fun box(): String {
return Anno.Inner().shouldNotBeEvaluated
}
@@ -27987,6 +27987,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("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("kt55866.kt")
public void testKt55866() throws Exception {
@@ -29289,6 +29289,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -29289,6 +29289,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -24755,6 +24755,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/booleanOperations.kt");
@@ -21681,6 +21681,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -21681,6 +21681,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -21681,6 +21681,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -21681,6 +21681,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -24788,6 +24788,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -25276,6 +25276,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -24300,6 +24300,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -24789,6 +24789,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("booleanOperations.kt")
public void testBooleanOperations() throws Exception {
@@ -21705,6 +21705,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
@@ -21705,6 +21705,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/involvesIrInterpreter"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@Test
@TestMetadata("annotationClassWithInner.kt")
public void testAnnotationClassWithInner() throws Exception {
runTest("compiler/testData/codegen/box/involvesIrInterpreter/annotationClassWithInner.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {