JVM IR: transform fake override properties in SAM adapters

Replace every property with its getter and setter. This is needed
because later on, JVM backend assumes that all properties have been
lowered (by JvmPropertiesLowering) to this state.

 #KT-64116 Fixed
This commit is contained in:
Alexander Udalov
2024-01-02 15:32:07 +01:00
committed by Space Team
parent d5b59c48c2
commit d08c9ba222
24 changed files with 167 additions and 10 deletions
@@ -50854,6 +50854,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -50854,6 +50854,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -50319,6 +50319,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -50319,6 +50319,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -50319,6 +50319,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -79,6 +79,8 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
open val inInlineFunctionScope get() = allScopes.any { scope -> (scope.irElement as? IrFunction)?.isInline ?: false }
protected open fun postprocessCreatedObjectProxy(klass: IrClass) {}
override fun lower(irFile: IrFile) {
cachedImplementations.clear()
inlineCachedImplementations.clear()
@@ -248,6 +250,8 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
ignoredParentSymbols = listOf(transformedSuperMethod.symbol)
)
postprocessCreatedObjectProxy(subclass)
return subclass
}
@@ -18,14 +18,12 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.declarations.IrFunctionBuilder
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrTypeOperatorCall
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
import org.jetbrains.kotlin.utils.filterIsInstanceAnd
internal val singleAbstractMethodPhase = makeIrFilePhase(
::JvmSingleAbstractMethodLowering,
@@ -67,4 +65,13 @@ private class JvmSingleAbstractMethodLowering(context: JvmBackendContext) : Sing
override val IrType.needEqualsHashCodeMethods
get() = isKotlinFunInterface || isJavaSamConversionWithEqualsHashCode
override fun postprocessCreatedObjectProxy(klass: IrClass) {
val fakeOverrideProperties = klass.declarations.filterIsInstanceAnd(IrProperty::isFakeOverride)
klass.declarations.removeAll(fakeOverrideProperties)
for (property in fakeOverrideProperties) {
property.getter?.let(klass.declarations::add)
property.setter?.let(klass.declarations::add)
}
}
}
@@ -1311,12 +1311,11 @@ fun IrClass.addFakeOverrides(
implementedMembers: List<IrOverridableMember> = emptyList(),
ignoredParentSymbols: List<IrSymbol> = emptyList()
) {
IrFakeOverrideBuilder(typeSystem, BindToNewEmptySymbols, emptyList())
.buildFakeOverridesForClassUsingOverriddenSymbols(this,
implementedMembers = implementedMembers,
compatibilityMode = false,
ignoredParentSymbols = ignoredParentSymbols)
.forEach { addChild(it) }
val fakeOverrides = IrFakeOverrideBuilder(typeSystem, BindToNewEmptySymbols, emptyList())
.buildFakeOverridesForClassUsingOverriddenSymbols(this, implementedMembers, compatibilityMode = false, ignoredParentSymbols)
for (fakeOverride in fakeOverrides) {
addChild(fakeOverride)
}
}
fun IrFactory.createStaticFunctionWithReceivers(
+28
View File
@@ -0,0 +1,28 @@
// MODULE: lib
// FILE: JsPrimitives.kt
package lib
interface JsObject {
val isString: Boolean
get() = false
}
fun interface JsRunnable : JsObject {
fun run()
}
// MODULE: main(lib)
// FILE: main.kt
import lib.JsRunnable
class ReactComponent {
fun forceUpdate(callback: JsRunnable) { callback.run() }
}
fun forceUpdate(myNativeComponent: ReactComponent, callback: () -> Unit) {
myNativeComponent.forceUpdate(callback)
}
fun box(): String {
return "OK"
}
@@ -49659,6 +49659,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -46725,6 +46725,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -49659,6 +49659,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -49659,6 +49659,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Test
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
@@ -39856,6 +39856,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@TestMetadata("noConversionFromSamToSam.kt")
public void testNoConversionFromSamToSam() throws Exception {
runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt");
@@ -35217,6 +35217,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -35217,6 +35217,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -34665,6 +34665,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -34665,6 +34665,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -38966,6 +38966,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -39946,6 +39946,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -37422,6 +37422,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -38391,6 +38391,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -35091,6 +35091,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")
@@ -34539,6 +34539,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
runTest("compiler/testData/codegen/box/sam/kt63564.kt");
}
@Test
@TestMetadata("kt64116.kt")
public void testKt64116() throws Exception {
runTest("compiler/testData/codegen/box/sam/kt64116.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/sam/adapters")
@TestDataPath("$PROJECT_ROOT")