From c922484758ac73f1552124ed2dbe7c593c15bf4c Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Wed, 25 Nov 2020 14:36:40 +0100 Subject: [PATCH] [JVM_IR] Use direct field access to backing fields on current class. The current backend uses direct field access to the backing field instead of calling the companion object accessor, which calls an accessibility bridge, which then gets the field for code such as: ``` class A { companion object { val s: String = "OK" } // f uses direct access to the A.s backing field. fun f() = s } ``` This change does the same for the IR backend. --- .../ir/FirBlackBoxCodegenTestGenerated.java | 23 ++++ .../ir/FirBytecodeTextTestGenerated.java | 20 ++++ .../jvm/JvmLoweredDeclarationOrigin.kt | 2 +- .../jvm/lower/JvmPropertiesLowering.kt | 28 ++++- .../companion/delegatedPropertyOnCompanion.kt | 46 ++++++++ .../inlineFunctionCompanionPropertyAccess.kt | 19 ++++ .../companion/directAccessToBackingField.kt | 38 +++++++ .../inlineFunctionCompanionPropertyAccess.kt | 29 +++++ ...neFunctionObjectCompanionPropertyAccess.kt | 101 ++++++++++++++++++ .../companion/nonDefaultAccessors.kt | 23 ++++ .../codegen/BlackBoxCodegenTestGenerated.java | 23 ++++ .../codegen/BytecodeTextTestGenerated.java | 20 ++++ .../LightAnalysisModeTestGenerated.java | 23 ++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 23 ++++ .../ir/IrBytecodeTextTestGenerated.java | 20 ++++ .../IrJsCodegenBoxES6TestGenerated.java | 23 ++++ .../IrJsCodegenBoxTestGenerated.java | 23 ++++ .../semantics/JsCodegenBoxTestGenerated.java | 23 ++++ .../IrCodegenBoxWasmTestGenerated.java | 23 ++++ 19 files changed, 524 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt create mode 100644 compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt create mode 100644 compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt create mode 100644 compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt create mode 100644 compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt create mode 100644 compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 9a67a955b38..8ec5662af6a 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -5161,6 +5161,29 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java index 33848c6fe9a..f5a766d10f8 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBytecodeTextTestGenerated.java @@ -966,11 +966,26 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("directAccessToBackingField.kt") + public void testDirectAccessToBackingField() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt"); + } + @TestMetadata("floatingPointCompanionAccess.kt") public void testFloatingPointCompanionAccess() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt"); } + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + + @TestMetadata("inlineFunctionObjectCompanionPropertyAccess.kt") + public void testInlineFunctionObjectCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt"); + } + @TestMetadata("kt14258_1.kt") public void testKt14258_1() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_1.kt"); @@ -996,6 +1011,11 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt"); } + @TestMetadata("nonDefaultAccessors.kt") + public void testNonDefaultAccessors() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt"); + } + @TestMetadata("privateCompanionObjectAccessors_after.kt") public void testPrivateCompanionObjectAccessors_after() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt index 2df04199b2f..d1e7d1e1558 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLoweredDeclarationOrigin.kt @@ -43,7 +43,7 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin { object FOR_INLINE_STATE_MACHINE_TEMPLATE : IrDeclarationOriginImpl("FOR_INLINE_TEMPLATE") object FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE : IrDeclarationOriginImpl("FOR_INLINE_TEMPLATE_CROSSINLINE") object CONTINUATION_CLASS_RESULT_FIELD: IrDeclarationOriginImpl("CONTINUATION_CLASS_RESULT_FIELD", isSynthetic = true) - object COMPANION_PROPERTY_BACKING_FIELD : IrDeclarationOriginImpl("COMPANION_MOVED_PROPERTY_BACKING_FIELD") + object COMPANION_PROPERTY_BACKING_FIELD : IrDeclarationOriginImpl("COMPANION_PROPERTY_BACKING_FIELD") object FIELD_FOR_STATIC_CALLABLE_REFERENCE_INSTANCE : IrDeclarationOriginImpl("FIELD_FOR_STATIC_CALLABLE_REFERENCE_INSTANCE") object ABSTRACT_BRIDGE_STUB : IrDeclarationOriginImpl("ABSTRACT_BRIDGE_STUB") } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt index c0b8141e2f7..e0f1795f86e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmPropertiesLowering.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.requiresMangling import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.* @@ -28,10 +29,7 @@ import org.jetbrains.kotlin.ir.expressions.IrFieldAccessExpression import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection -import org.jetbrains.kotlin.ir.util.coerceToUnit -import org.jetbrains.kotlin.ir.util.render -import org.jetbrains.kotlin.ir.util.resolveFakeOverride -import org.jetbrains.kotlin.ir.util.transformDeclarationsFlat +import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.name.Name @@ -54,7 +52,9 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE val property = simpleFunction.correspondingPropertySymbol?.owner ?: return super.visitCall(expression) expression.transformChildrenVoid() - if (shouldSubstituteAccessorWithField(property, simpleFunction)) { + if (shouldSubstituteAccessorWithField(property, simpleFunction) || + isDefaultAccessorForCompanionPropertyBackingFieldOnCurrentClass(property, simpleFunction) + ) { backendContext.createIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset).apply { return when (simpleFunction) { property.getter -> substituteGetter(property, expression) @@ -67,6 +67,24 @@ class JvmPropertiesLowering(private val backendContext: JvmBackendContext) : IrE return expression } + private fun isDefaultAccessorForCompanionPropertyBackingFieldOnCurrentClass( + property: IrProperty, + function: IrSimpleFunction + ): Boolean { + if (function.origin != IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR) return false + if (property.isLateinit) return false + // If this code could end up inlined in another class (either an inline function or an + // inlined lambda in an inline function) use the companion object accessor. Otherwise, + // we could break binary compatibility if we only recompile the class with the companion + // object and change to non-default field accessors. The inlined code would still attempt + // to get the backing field which would no longer exist. + val inInlineFunctionScope = allScopes.any { scope -> (scope.irElement as? IrFunction)?.isInline ?: false } + if (inInlineFunctionScope) return false + val backingField = property.resolveFakeOverride()!!.backingField + return backingField?.parent == currentClass?.irElement && + backingField?.origin == JvmLoweredDeclarationOrigin.COMPANION_PROPERTY_BACKING_FIELD + } + private fun IrBuilderWithScope.substituteSetter(irProperty: IrProperty, expression: IrCall): IrExpression = patchReceiver( irSetField( diff --git a/compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt b/compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt new file mode 100644 index 00000000000..e49cb028f6e --- /dev/null +++ b/compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt @@ -0,0 +1,46 @@ +import kotlin.reflect.KProperty + +class Delegate { + operator fun getValue(t: Any?, p: KProperty<*>): String = "OK" +} + +class Delegate2 { + var value: String = "NOT OK" + + operator fun getValue(t: Any?, p: KProperty<*>): String = value + + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) { + this.value = value + } +} + +class A { + companion object { + val s: String by Delegate() + var s2: String by Delegate2() + var s3: String by Delegate2() + } + + fun f() = s + inline fun g() = s + + fun set2() { + s2 = "OK" + } + fun get2() = s2 + + inline fun set3() { + s3 = "OK" + } + inline fun get3() = s3 +} + +fun box(): String { + val a = A() + if (a.f() != "OK") return "FAIL0" + if (a.g() != "OK") return "FAIL0" + a.set2() + if (a.get2() != "OK") return "FAIL0" + a.set3() + return a.get3() +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt b/compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt new file mode 100644 index 00000000000..3e456abac3a --- /dev/null +++ b/compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt @@ -0,0 +1,19 @@ +class A { + companion object { + val s = "OK" + var v = "NOT OK" + } + + inline fun f(): String = s + + inline fun g() { + v = "OK" + } +} + +fun box(): String { + val a = A() + if (a.f() != "OK") return "FAIL0" + a.g() + return A.v +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt b/compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt new file mode 100644 index 00000000000..9f5a468dd0b --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt @@ -0,0 +1,38 @@ +class A { + companion object { + val s = "OK" + var v = "NOT OK" + } + + fun f(): String = s + + fun g() { + v = "OK" + } + + inline fun i(j: () -> Unit) { + j() + } + + fun h() { + i { + s + v = "OK" + } + } +} + +// One direct `A.s` access in `f`. +// One direct `A.s` access in the accessibility bridge `access$getS$cp`. +// One direct `A.s` access in `h`. +// 3 GETSTATIC A.s + +// One direct `A.v` set in `g`. +// One direct `A.v` set in the accessibility bridge `access$setV$cp`. +// One direct `A.v` set in `A.` +// One direct `A.v` set in `h`. +// 4 PUTSTATIC A.v + +// No calls to the getter/setter on the companion object. +// 0 INVOKEVIRTUAL A\$Companion.getS +// 0 INVOKEVIRTUAL A\$Companion.setV \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt b/compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt new file mode 100644 index 00000000000..e416dca3517 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt @@ -0,0 +1,29 @@ +class A { + companion object { + val s = "OK" + var v = "NOT OK" + } + + inline fun f(): String = s + + inline fun g() { + v = "OK" + } +} + +// One direct `A.s` access in the accessibility bridge `access$getS$cp`. +// 1 GETSTATIC A.s + +// One direct `A.v` set in the accessibility bridge `access$setV$cp`. +// One direct `A.v` set in `A.` +// 2 PUTSTATIC A.v + +// One call to the getter/setter on the companion object from f and one from g. +// 1 INVOKEVIRTUAL A\$Companion.getS +// 1 INVOKEVIRTUAL A\$Companion.setV + +// One call to the accessibility bridge `access$setV$cp` from Companion.setV. +// 1 INVOKESTATIC A.access\$setV\$cp + +// One call to the accessibility bridge `access$getS$cp` from Companion.getS. +// 1 INVOKESTATIC A.access\$getS\$cp diff --git a/compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt b/compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt new file mode 100644 index 00000000000..f571772dc6c --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt @@ -0,0 +1,101 @@ +class A { + companion object { + val s = "OK" + var v = "NOT OK" + } + + inline fun g(crossinline f: () -> Unit) { + { + f() + s + v = "OK" + } () + } + + inline fun g2(crossinline f: () -> Unit) { + object { + fun run() { + f() + s + v = "OK" + } + }.run () + } + + inline fun use() { + g { + s + g2 { s } + } + g { + v = "OK" + g2 { + v = "OK" + } + } + } + + fun useNonInline() { + g { + s + g2 { s } + } + g { + v = "OK" + g2 { + v = "OK" + } + } + } +} + +// One direct `A.s` access in the accessibility bridge `access$getS$cp`. +// 1 GETSTATIC A.s + +// One direct `A.v` set in the accessibility bridge `access$setV$cp`. +// One direct `A.v` set in `A.` +// 2 PUTSTATIC A.v + +// JVM_IR_TEMPLATES + +// Two accesses from the inline function code for `g` and `g2`. +// Four accesses from the code for `g` and `g2` inlined in `useInline`. +// Two accesses from the lambdas inlined in `useInline`. +// Four accesses from the code for `g` and `g2` inlined in `useNonInline`. +// 12 INVOKEVIRTUAL A\$Companion.getS + +// Two accesses from the inline function code for `g` and `g2`. +// Four accesses from the code for `g` and `g2` inlined in `useInline`. +// Two accesses from the lambdas inlined in `useInline`. +// Four accesses from the code for `g` and `g2` inlined in `useNonInline`. +// 12 INVOKEVIRTUAL A\$Companion.setV + +// One call to the accessibility bridge `access$setV$cp` from Companion.setV. +// Two uses of the direct accessor from the lambdas inlined in useNonInline. +// 3 INVOKESTATIC A.access\$setV\$cp + +// One call to the accessibility bridge `access$getS$cp` from Companion.getS. +// Two uses of the direct accessor from the lambdas inlined in useNonInline. +// 3 INVOKESTATIC A.access\$getS\$cp + +// JVM_TEMPLATES + +// Two accesses from the inline function code for `g` and `g2`. +// Four accesses from the code for `g` and `g2` inlined in `useInline`. +// Two accesses from the lambdas inlined in `useInline`. +// Four accesses from the code for `g` and `g2` inlined in `useNonInline`. +// Two accesses from the lambdas inlined in `useNonInline`. +// 14 INVOKEVIRTUAL A\$Companion.getS + +// Two accesses from the inline function code for `g` and `g2`. +// Four accesses from the code for `g` and `g2` inlined in `useInline`. +// Two accesses from the lambdas inlined in `useInline`. +// Four accesses from the code for `g` and `g2` inlined in `useNonInline`. +// Two accesses from the lambdas inlined in `useNonInline`. +// 14 INVOKEVIRTUAL A\$Companion.setV + +// One call to the accessibility bridge `access$setV$cp` from Companion.setV. +// 1 INVOKESTATIC A.access\$setV\$cp + +// One call to the accessibility bridge `access$getS$cp` from Companion.getS. +// 1 INVOKESTATIC A.access\$getS\$cp \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt b/compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt new file mode 100644 index 00000000000..b4a2862d91d --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt @@ -0,0 +1,23 @@ +class A { + companion object { + val s: String + get() = "Ok" + var v : String + get() = "NOT OK" + set(value) {} + } + + inline fun f(): String = s + + inline fun g() { + v = "OK" + } +} + +// No backing field on A and all accesses call the getter/setter. +// 0 GETSTATIC A.s +// 0 PUTSTATIC A.v + +// One `getS` call in `f` and one `setV` call in `g` +// 1 INVOKEVIRTUAL A\$Companion.getS +// 1 INVOKEVIRTUAL A\$Companion.setV \ No newline at end of file diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index ac17b7bb56b..e361660eab9 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5161,6 +5161,29 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 59439ce3d61..7659e7ae60e 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -966,11 +966,26 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("directAccessToBackingField.kt") + public void testDirectAccessToBackingField() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt"); + } + @TestMetadata("floatingPointCompanionAccess.kt") public void testFloatingPointCompanionAccess() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt"); } + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + + @TestMetadata("inlineFunctionObjectCompanionPropertyAccess.kt") + public void testInlineFunctionObjectCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt"); + } + @TestMetadata("kt14258_1.kt") public void testKt14258_1() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_1.kt"); @@ -996,6 +1011,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt"); } + @TestMetadata("nonDefaultAccessors.kt") + public void testNonDefaultAccessors() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt"); + } + @TestMetadata("privateCompanionObjectAccessors_after.kt") public void testPrivateCompanionObjectAccessors_after() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9cbfe8a2ff2..093a5c84f9b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5161,6 +5161,29 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 06fabd766a5..bbe47f50399 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -5161,6 +5161,29 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index b68ce967cf4..15c07b925df 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -966,11 +966,26 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeText/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("directAccessToBackingField.kt") + public void testDirectAccessToBackingField() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/directAccessToBackingField.kt"); + } + @TestMetadata("floatingPointCompanionAccess.kt") public void testFloatingPointCompanionAccess() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/floatingPointCompanionAccess.kt"); } + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + + @TestMetadata("inlineFunctionObjectCompanionPropertyAccess.kt") + public void testInlineFunctionObjectCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/inlineFunctionObjectCompanionPropertyAccess.kt"); + } + @TestMetadata("kt14258_1.kt") public void testKt14258_1() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_1.kt"); @@ -996,6 +1011,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt"); } + @TestMetadata("nonDefaultAccessors.kt") + public void testNonDefaultAccessors() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/companion/nonDefaultAccessors.kt"); + } + @TestMetadata("privateCompanionObjectAccessors_after.kt") public void testPrivateCompanionObjectAccessors_after() throws Exception { runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index e3bbbe9f8fc..56bb4193eab 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -4131,6 +4131,29 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractIrJsCodegenBoxES6Test { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 3ab7141df36..2134843916e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -4131,6 +4131,29 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index dac1e1b5e89..a2a4634fad4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -4131,6 +4131,29 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 0cb5cf7cafa..fc0ab4a5e1d 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -2982,6 +2982,29 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } + @TestMetadata("compiler/testData/codegen/box/companion") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Companion extends AbstractIrCodegenBoxWasmTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); + } + + public void testAllFilesPresentInCompanion() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/companion"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + + @TestMetadata("delegatedPropertyOnCompanion.kt") + public void testDelegatedPropertyOnCompanion() throws Exception { + runTest("compiler/testData/codegen/box/companion/delegatedPropertyOnCompanion.kt"); + } + + @TestMetadata("inlineFunctionCompanionPropertyAccess.kt") + public void testInlineFunctionCompanionPropertyAccess() throws Exception { + runTest("compiler/testData/codegen/box/companion/inlineFunctionCompanionPropertyAccess.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/compatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)