[K/N] Disable scope initialization on constant access
^KT-57098
This commit is contained in:
committed by
Space Team
parent
e6297f92fa
commit
62fb3df7f0
+6
@@ -8355,6 +8355,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -8355,6 +8355,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+3
-1
@@ -33,7 +33,9 @@ abstract class InlineConstTransformer : IrElementTransformerVoid() {
|
|||||||
|
|
||||||
abstract fun reportInlineConst(field: IrField, value: IrConst<*>)
|
abstract fun reportInlineConst(field: IrField, value: IrConst<*>)
|
||||||
|
|
||||||
abstract fun IrExpression.shouldDropConstReceiver(): Boolean
|
fun IrExpression.shouldDropConstReceiver(): Boolean {
|
||||||
|
return this is IrConst<*> || this is IrGetValue || this is IrGetObjectValue
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitCall(expression: IrCall): IrExpression {
|
override fun visitCall(expression: IrCall): IrExpression {
|
||||||
val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression)
|
val function = (expression.symbol.owner as? IrSimpleFunction) ?: return super.visitCall(expression)
|
||||||
|
|||||||
-2
@@ -50,6 +50,4 @@ private class JvmInlineConstTransformer(val irFile: IrFile, val inlineConstTrack
|
|||||||
|
|
||||||
inlineConstTracker.report(path, owner, name, constType)
|
inlineConstTracker.report(path, owner, name, constType)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun IrExpression.shouldDropConstReceiver() = this is IrConst<*> || this is IrGetValue || this is IrGetObjectValue
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// IGNORE_BACKEND: WASM
|
||||||
|
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6
|
||||||
|
var initialized = 0
|
||||||
|
|
||||||
|
object O {
|
||||||
|
init {
|
||||||
|
initialized += 1
|
||||||
|
}
|
||||||
|
const val x = 1
|
||||||
|
val y = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
if (O.x != 1) return "FAIL 1"
|
||||||
|
if (initialized != 0) return "FAIL 2"
|
||||||
|
if (O.y != 2) return "FAIL 3"
|
||||||
|
if (initialized != 1) return "FAIL 4"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -8151,6 +8151,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -8355,6 +8355,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+5
@@ -6224,6 +6224,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/constants/float.kt");
|
runTest("compiler/testData/codegen/box/constants/float.kt");
|
||||||
|
|||||||
+6
@@ -5369,6 +5369,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -5429,6 +5429,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -5429,6 +5429,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -5429,6 +5429,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+1
-1
@@ -552,8 +552,8 @@ private fun PhaseEngine<NativeGenerationState>.getAllLowerings() = listOfNotNull
|
|||||||
coroutinesPhase,
|
coroutinesPhase,
|
||||||
typeOperatorPhase,
|
typeOperatorPhase,
|
||||||
expressionBodyTransformPhase,
|
expressionBodyTransformPhase,
|
||||||
objectClassesPhase,
|
|
||||||
constantInliningPhase,
|
constantInliningPhase,
|
||||||
|
objectClassesPhase,
|
||||||
staticInitializersPhase,
|
staticInitializersPhase,
|
||||||
builtinOperatorPhase,
|
builtinOperatorPhase,
|
||||||
bridgesPhase,
|
bridgesPhase,
|
||||||
|
|||||||
-3
@@ -32,7 +32,4 @@ private class NativeInlineConstTransformer : InlineConstTransformer() {
|
|||||||
?.takeUnless { it.kind == IrConstKind.Float && IrConstKind.Float.valueOf(it).isNaN() }
|
?.takeUnless { it.kind == IrConstKind.Float && IrConstKind.Float.valueOf(it).isNaN() }
|
||||||
|
|
||||||
override fun reportInlineConst(field: IrField, value: IrConst<*>) {}
|
override fun reportInlineConst(field: IrField, value: IrConst<*>) {}
|
||||||
// on jvm IrGetObjectValue is also dropped. This would be breaking change for native.
|
|
||||||
// Some design work is required to decide what is correct, let just keep current behaviour for now
|
|
||||||
override fun IrExpression.shouldDropConstReceiver() = this is IrConst<*> || this is IrGetValue
|
|
||||||
}
|
}
|
||||||
@@ -57,8 +57,12 @@ object ClassWithConstructor {
|
|||||||
@Test fun checkConstructor() {
|
@Test fun checkConstructor() {
|
||||||
assertEquals(0, ClassWithConstructorInitialized)
|
assertEquals(0, ClassWithConstructorInitialized)
|
||||||
assertEquals(1, ClassWithConstructor.A)
|
assertEquals(1, ClassWithConstructor.A)
|
||||||
|
assertEquals(0, ClassWithConstructorInitialized)
|
||||||
|
val unused1 = ClassWithConstructor
|
||||||
|
assertEquals(1, unused1.A)
|
||||||
assertEquals(1, ClassWithConstructorInitialized)
|
assertEquals(1, ClassWithConstructorInitialized)
|
||||||
assertEquals(1, ClassWithConstructor.A)
|
val unused2 = ClassWithConstructor
|
||||||
|
assertEquals(1, unused2.A)
|
||||||
assertEquals(1, ClassWithConstructorInitialized)
|
assertEquals(1, ClassWithConstructorInitialized)
|
||||||
assertFalse(ClassWithConstructor.isPermanent())
|
assertFalse(ClassWithConstructor.isPermanent())
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -6338,6 +6338,12 @@ public class K2NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
+6
@@ -6265,6 +6265,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
|
|||||||
Generated
+5
@@ -4784,6 +4784,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
runTest("compiler/testData/codegen/box/constants/divisionByZero.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("doNotTriggerInit.kt")
|
||||||
|
public void testDoNotTriggerInit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/doNotTriggerInit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("float.kt")
|
@TestMetadata("float.kt")
|
||||||
public void testFloat() throws Exception {
|
public void testFloat() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/constants/float.kt");
|
runTest("compiler/testData/codegen/box/constants/float.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user