diff --git a/SKIE/.run/1.9.20_Tests_Acceptance_All.run.xml b/SKIE/.run/1.9.20_Tests_Acceptance_All.run.xml new file mode 100644 index 000000000..f64750cb5 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Acceptance_All.run.xml @@ -0,0 +1,24 @@ + + + + + + + false + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Acceptance_Failed.run.xml b/SKIE/.run/1.9.20_Tests_Acceptance_Failed.run.xml new file mode 100644 index 000000000..718e70a66 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Acceptance_Failed.run.xml @@ -0,0 +1,29 @@ + + + + + + + + false + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Acceptance_Selected.run.xml b/SKIE/.run/1.9.20_Tests_Acceptance_Selected.run.xml new file mode 100644 index 000000000..ce990be8b --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Acceptance_Selected.run.xml @@ -0,0 +1,29 @@ + + + + + + + + false + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Libraries_All.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_All.run.xml new file mode 100644 index 000000000..f56abe79f --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_All.run.xml @@ -0,0 +1,24 @@ + + + + + + + true + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Libraries_Compare.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_Compare.run.xml new file mode 100644 index 000000000..145422565 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_Compare.run.xml @@ -0,0 +1,26 @@ + + + + + + + false + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Libraries_Failed.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_Failed.run.xml new file mode 100644 index 000000000..de915bcb0 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_Failed.run.xml @@ -0,0 +1,29 @@ + + + + + + + + true + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Libraries_Selected Library.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_Selected Library.run.xml new file mode 100644 index 000000000..dedfa743c --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_Selected Library.run.xml @@ -0,0 +1,30 @@ + + + + + + + + true + true + false + false + + + \ No newline at end of file diff --git a/SKIE/.run/1.9.20_Tests_Libraries_Stdlib.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_Stdlib.run.xml new file mode 100644 index 000000000..160eaa3c5 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_Stdlib.run.xml @@ -0,0 +1,24 @@ + + + + + + + true + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Libraries_Without SKIE.run.xml b/SKIE/.run/1.9.20_Tests_Libraries_Without SKIE.run.xml new file mode 100644 index 000000000..84d8d4559 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Libraries_Without SKIE.run.xml @@ -0,0 +1,24 @@ + + + + + + + true + true + false + false + + + diff --git a/SKIE/.run/1.9.20_Tests_Types_All.run.xml b/SKIE/.run/1.9.20_Tests_Types_All.run.xml new file mode 100644 index 000000000..20de19313 --- /dev/null +++ b/SKIE/.run/1.9.20_Tests_Types_All.run.xml @@ -0,0 +1,24 @@ + + + + + + + false + true + false + false + + + diff --git a/SKIE/acceptance-tests b/SKIE/acceptance-tests index 84e534c10..c6926eb88 160000 --- a/SKIE/acceptance-tests +++ b/SKIE/acceptance-tests @@ -1 +1 @@ -Subproject commit 84e534c106bb18e7d7eb0f8e3ac5d8796afb8582 +Subproject commit c6926eb882e590382785e0a13737c4578a011019 diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0..1.9.0/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0..1.9.0/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.0.kt new file mode 100644 index 000000000..c39c41d5e --- /dev/null +++ b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0..1.9.0/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.0.kt @@ -0,0 +1,36 @@ +package co.touchlab.skie.kir.util + +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable +import org.jetbrains.kotlin.ir.util.referenceFunction + +@OptIn(ObsoleteDescriptorBasedAPI::class) +actual class SymbolTableDescriptorExtensionShim actual constructor( + private val symbolTable: ReferenceSymbolTable +) { + + actual fun referenceFunction(callable: CallableDescriptor): IrFunctionSymbol = + symbolTable.referenceFunction(callable) + + actual fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol = + symbolTable.referenceProperty(descriptor) + + actual fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol = + symbolTable.referenceSimpleFunction(descriptor) + + actual fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol = + symbolTable.referenceConstructor(descriptor) + + actual fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol = + symbolTable.referenceClass(descriptor) +} diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.0.kt index a6f7cb8b5..a01a0a421 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.0.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.0.kt @@ -1,5 +1,17 @@ package co.touchlab.skie.phases.analytics.compiler.specific +import co.touchlab.skie.phases.analytics.util.toPrettyJson +import kotlinx.serialization.Serializable import org.jetbrains.kotlin.backend.konan.KonanConfig +import org.jetbrains.kotlin.backend.konan.KonanConfigKeys + +actual fun KonanConfig.getSpecificCompilerConfigurationAnalytics(): String = + AnalyticsData( + garbageCollector = configuration.get(KonanConfigKeys.GARBAGE_COLLECTOR)?.toString(), + ).toPrettyJson() + +@Serializable +private data class AnalyticsData( + val garbageCollector: String?, +) -actual fun KonanConfig.getSpecificCompilerConfigurationAnalytics(): String = "{}" diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.9.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.20.kt similarity index 77% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.9.0.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.20.kt index b1ddb17eb..66dd94f14 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.9.0.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.20.kt @@ -4,13 +4,16 @@ import co.touchlab.skie.phases.analytics.util.toPrettyJson import kotlinx.serialization.Serializable import org.jetbrains.kotlin.backend.konan.BinaryOptions import org.jetbrains.kotlin.backend.konan.KonanConfig +import org.jetbrains.kotlin.backend.konan.KonanConfigKeys actual fun KonanConfig.getSpecificCompilerConfigurationAnalytics(): String = AnalyticsData( objcExportDisableSwiftMemberNameMangling = configuration.get(BinaryOptions.objcExportDisableSwiftMemberNameMangling), + garbageCollector = configuration.get(KonanConfigKeys.GARBAGE_COLLECTOR)?.toString(), ).toPrettyJson() @Serializable private data class AnalyticsData( val objcExportDisableSwiftMemberNameMangling: Boolean?, + val garbageCollector: String?, ) diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/co/touchlab/skie/entrypoint/ProduceObjCExportInterfacePhaseInterceptor.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.20/kotlin/co/touchlab/skie/entrypoint/ProduceObjCExportInterfacePhaseInterceptor.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/co/touchlab/skie/entrypoint/ProduceObjCExportInterfacePhaseInterceptor.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.20/kotlin/co/touchlab/skie/entrypoint/ProduceObjCExportInterfacePhaseInterceptor.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/org/jetbrains/kotlin/backend/konan/objcexport/ObjCNoneExportScope.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.20/kotlin/org/jetbrains/kotlin/backend/konan/objcexport/ObjCNoneExportScope.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.0/kotlin/org/jetbrains/kotlin/backend/konan/objcexport/ObjCNoneExportScope.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.8.20..1.9.20/kotlin/org/jetbrains/kotlin/backend/konan/objcexport/ObjCNoneExportScope.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/SameTypeNamedPhaseInterceptorConfigurer.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/SameTypeNamedPhaseInterceptorConfigurer.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/SameTypeNamedPhaseInterceptorConfigurer.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/SameTypeNamedPhaseInterceptorConfigurer.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/SimpleNamedPhaseInterceptorConfigurer.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/SimpleNamedPhaseInterceptorConfigurer.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/SimpleNamedPhaseInterceptorConfigurer.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/SimpleNamedPhaseInterceptorConfigurer.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/phaseInterceptorConfigurers.kgp_1.9.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/phaseInterceptorConfigurers.kgp_1.9.0.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/interceptor/phaseInterceptorConfigurers.kgp_1.9.0.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/interceptor/phaseInterceptorConfigurers.kgp_1.9.0.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/UserVisibleIrModulesSupportReflector.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/UserVisibleIrModulesSupportReflector.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/UserVisibleIrModulesSupportReflector.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/UserVisibleIrModulesSupportReflector.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/entrypoint/CreateObjCExportCodeSpecPhaseInterceptor.kgp_1.9.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/entrypoint/CreateObjCExportCodeSpecPhaseInterceptor.kgp_1.9.0.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/entrypoint/CreateObjCExportCodeSpecPhaseInterceptor.kgp_1.9.0.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/entrypoint/CreateObjCExportCodeSpecPhaseInterceptor.kgp_1.9.0.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/entrypoint/LinkerPhaseInterceptor.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/entrypoint/LinkerPhaseInterceptor.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/entrypoint/LinkerPhaseInterceptor.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/entrypoint/LinkerPhaseInterceptor.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/kir/irbuilder/impl/symboltable/DummyIrSimpleFunction.kgp_1.9.0.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/kir/irbuilder/impl/symboltable/DummyIrSimpleFunction.kgp_1.9.0.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/kotlin/co/touchlab/skie/kir/irbuilder/impl/symboltable/DummyIrSimpleFunction.kgp_1.9.0.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/kotlin/co/touchlab/skie/kir/irbuilder/impl/symboltable/DummyIrSimpleFunction.kgp_1.9.0.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/resources/META-INF/services/co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/resources/META-INF/services/co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.9.0/resources/META-INF/services/co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.0..1.9.20/resources/META-INF/services/co.touchlab.skie.compilerinject.interceptor.PhaseInterceptor diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.9.20/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.20.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.20/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.20.kt new file mode 100644 index 000000000..bd572f65b --- /dev/null +++ b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.20/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kgp_1.9.20.kt @@ -0,0 +1,36 @@ +package co.touchlab.skie.kir.util + +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable +import org.jetbrains.kotlin.ir.util.referenceFunction + +@OptIn(ObsoleteDescriptorBasedAPI::class) +actual class SymbolTableDescriptorExtensionShim actual constructor( + private val symbolTable: ReferenceSymbolTable +) { + + actual fun referenceFunction(callable: CallableDescriptor): IrFunctionSymbol = + symbolTable.referenceFunction(callable) + + actual fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol = + symbolTable.descriptorExtension.referenceProperty(descriptor) + + actual fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol = + symbolTable.descriptorExtension.referenceSimpleFunction(descriptor) + + actual fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol = + symbolTable.descriptorExtension.referenceConstructor(descriptor) + + actual fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol = + symbolTable.descriptorExtension.referenceClass(descriptor) +} diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_1.8.20/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.20.kt b/SKIE/compiler/kotlin-plugin/src/kgp_1.9.20/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.9.20.kt similarity index 100% rename from SKIE/compiler/kotlin-plugin/src/kgp_1.8.20/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.8.20.kt rename to SKIE/compiler/kotlin-plugin/src/kgp_1.9.20/kotlin/co/touchlab/skie/phases/analytics/compiler/specific/SpecificCompilerConfigurationAnalytics.kgp_1.9.20.kt diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/ObjCExportReflector.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/ObjCExportReflector.kt index 60d7487b3..5545b0fd1 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/ObjCExportReflector.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/compilerinject/reflection/reflectors/ObjCExportReflector.kt @@ -3,12 +3,9 @@ package co.touchlab.skie.compilerinject.reflection.reflectors import co.touchlab.skie.compilerinject.reflection.Reflector import co.touchlab.skie.compilerinject.reflection.reflectedBy import org.jetbrains.kotlin.backend.common.CommonBackendContext -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.backend.konan.serialization.KonanIdSignaturer +import org.jetbrains.kotlin.backend.konan.serialization.KonanManglerDesc import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl -import org.jetbrains.kotlin.ir.util.IdSignature -import org.jetbrains.kotlin.ir.util.IdSignatureComposer import org.jetbrains.kotlin.ir.util.SymbolTable class ObjCExportReflector( @@ -30,21 +27,6 @@ class ObjCExportReflector( } private fun createSymbolTable(): SymbolTable = - SymbolTable(DummySignaturer(), IrFactoryImpl) - - class DummySignaturer : IdSignatureComposer { - - override fun composeAnonInitSignature(descriptor: ClassDescriptor): IdSignature? = null - - override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? = null - - override fun composeFieldSignature(descriptor: PropertyDescriptor): IdSignature? = null - - override fun composeSignature(descriptor: DeclarationDescriptor): IdSignature? = null - - override fun withFileSignature(fileSignature: IdSignature.FileSignature, body: () -> Unit) { - body() - } - } + SymbolTable(KonanIdSignaturer(KonanManglerDesc), IrFactoryImpl) } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/KotlinIrPhaseContext.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/KotlinIrPhaseContext.kt index e3d1b6b45..b13067622 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/KotlinIrPhaseContext.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/KotlinIrPhaseContext.kt @@ -3,12 +3,14 @@ package co.touchlab.skie.context import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl +import co.touchlab.skie.kir.util.SkieSymbolTable import co.touchlab.skie.phases.KotlinIrPhase import co.touchlab.skie.phases.SkiePhase import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.extensions.IrPluginContextImpl import org.jetbrains.kotlin.backend.konan.serialization.KonanIrLinker import org.jetbrains.kotlin.ir.declarations.IrModuleFragment +import org.jetbrains.kotlin.ir.util.SymbolTable class KotlinIrPhaseContext( mainSkieContext: MainSkieContext, @@ -23,4 +25,6 @@ class KotlinIrPhaseContext( override val allModules: Map = linker.modules override val declarationBuilder: DeclarationBuilderImpl = mainSkieContext.declarationBuilder + + override val skieSymbolTable: SkieSymbolTable = SkieSymbolTable(pluginContext.symbolTable as SymbolTable) } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/SymbolTablePhaseContext.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/SymbolTablePhaseContext.kt index 483cc0648..0bff57a46 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/SymbolTablePhaseContext.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/context/SymbolTablePhaseContext.kt @@ -1,16 +1,19 @@ package co.touchlab.skie.context import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl +import co.touchlab.skie.kir.util.SkieSymbolTable import co.touchlab.skie.phases.SkiePhase import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.ir.util.SymbolTable class SymbolTablePhaseContext( mainSkieContext: MainSkieContext, - override val symbolTable: SymbolTable, + symbolTable: SymbolTable, ) : SymbolTablePhase.Context, SkiePhase.Context by mainSkieContext { override val context: SymbolTablePhaseContext = this override val declarationBuilder: DeclarationBuilderImpl = mainSkieContext.declarationBuilder + + override val skieSymbolTable: SkieSymbolTable = SkieSymbolTable(symbolTable) } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/DeclarationTemplate.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/DeclarationTemplate.kt index a07f5b398..669961218 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/DeclarationTemplate.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/DeclarationTemplate.kt @@ -1,18 +1,21 @@ package co.touchlab.skie.kir.irbuilder -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase +import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer -import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext interface DeclarationTemplate { val descriptor: D - fun declareSymbol(symbolTable: SymbolTable) + context(SymbolTablePhase.Context) + fun declareSymbol() + context(KotlinIrPhase.Context) fun generateIrDeclaration(parent: IrDeclarationContainer, generatorContext: GeneratorContext) - fun generateIrBody(irPluginContext: IrPluginContext) + context(KotlinIrPhase.Context) + fun generateIrBody() } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/FunctionBuilder.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/FunctionBuilder.kt index 8376c38d4..8a82e48d8 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/FunctionBuilder.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/FunctionBuilder.kt @@ -1,5 +1,6 @@ package co.touchlab.skie.kir.irbuilder +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.DescriptorVisibilities @@ -36,6 +37,6 @@ class FunctionBuilder(val descriptor: SimpleFunctionDescriptor) { var isSuspend: Boolean = false - // TODO Change to context(IrPluginContext, DeclarationIrBuilder) once are context implemented properly - var body: (context(IrPluginContext) DeclarationIrBuilder.(IrSimpleFunction) -> IrBody)? = null + // TODO Change to context(KotlinIrPhase.Context, DeclarationIrBuilder) once are context implemented properly + var body: (context(KotlinIrPhase.Context) DeclarationIrBuilder.(IrSimpleFunction) -> IrBody)? = null } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/Namespace.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/Namespace.kt index 968a2632b..7f3c74f1e 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/Namespace.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/Namespace.kt @@ -1,10 +1,12 @@ package co.touchlab.skie.kir.irbuilder import co.touchlab.skie.kir.DescriptorRegistrationScope +import co.touchlab.skie.kir.util.SkieSymbolTable +import co.touchlab.skie.phases.KotlinIrPhase +import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.SourceElement -import org.jetbrains.kotlin.ir.util.SymbolTable interface Namespace { @@ -15,9 +17,12 @@ interface Namespace { context(DescriptorRegistrationScope) fun addTemplate(declarationTemplate: DeclarationTemplate<*>) - fun registerSymbols(symbolTable: SymbolTable) + context(SymbolTablePhase.Context) + fun registerSymbols() - fun generateIrDeclarations(pluginContext: IrPluginContext, symbolTable: SymbolTable) + context(KotlinIrPhase.Context) + fun generateIrDeclarations() - fun generateIrBodies(pluginContext: IrPluginContext) + context(KotlinIrPhase.Context) + fun generateIrBodies() } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/SecondaryConstructorBuilder.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/SecondaryConstructorBuilder.kt index d51f82942..0ce94235f 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/SecondaryConstructorBuilder.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/SecondaryConstructorBuilder.kt @@ -1,5 +1,6 @@ package co.touchlab.skie.kir.irbuilder +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor @@ -15,6 +16,6 @@ class SecondaryConstructorBuilder(val descriptor: ClassConstructorDescriptor) { var visibility: DescriptorVisibility = DescriptorVisibilities.PUBLIC - // TODO Change to context(IrPluginContext, DeclarationIrBuilder) once are context implemented properly - var body: (context(IrPluginContext) DeclarationIrBuilder.(IrConstructor) -> IrBody)? = null + // TODO Change to context(KotlinIrPhase.Context, DeclarationIrBuilder) once are context implemented properly + var body: (context(KotlinIrPhase.Context) DeclarationIrBuilder.(IrConstructor) -> IrBody)? = null } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/DeclarationBuilderImpl.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/DeclarationBuilderImpl.kt index 9b75adc39..11533947c 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/DeclarationBuilderImpl.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/DeclarationBuilderImpl.kt @@ -16,10 +16,14 @@ import co.touchlab.skie.kir.irbuilder.impl.symboltable.DummyIrConstructor import co.touchlab.skie.kir.irbuilder.impl.symboltable.DummyIrSimpleFunction import co.touchlab.skie.kir.irbuilder.impl.template.FunctionTemplate import co.touchlab.skie.kir.irbuilder.impl.template.SecondaryConstructorTemplate -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.kir.util.SkieSymbolTable +import co.touchlab.skie.phases.KotlinIrPhase +import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.backend.common.serialization.findPackage import org.jetbrains.kotlin.backend.common.serialization.findSourceFile import org.jetbrains.kotlin.backend.common.serialization.signature.PublicIdSignatureComputer +import org.jetbrains.kotlin.backend.konan.serialization.KonanIdSignaturer +import org.jetbrains.kotlin.backend.konan.serialization.KonanManglerDesc import org.jetbrains.kotlin.backend.konan.serialization.KonanManglerIr import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor @@ -36,8 +40,6 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterPublicSymbolImpl -import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.ir.util.referenceFunction import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor @@ -88,7 +90,7 @@ class DeclarationBuilderImpl( val sourceFile = existingMember.findSourceFileOrNull() val hasOriginalPackage = existingMember.findPackage() is DeserializedPackageFragment && - sourceFile in originalExposedFiles + sourceFile in originalExposedFiles return when { sourceFile == null -> getCustomNamespace(existingMember.findPackage().name.asStringStripSpecialMarkers()) @@ -134,23 +136,25 @@ class DeclarationBuilderImpl( return declarationTemplate.descriptor } - fun declareSymbols(symbolTable: SymbolTable) { + context(SymbolTablePhase.Context) + fun declareSymbols() { allNamespaces.forEach { - it.registerSymbols(symbolTable) + it.registerSymbols() } } - fun generateIr(mairIrModuleFragment: IrModuleFragment, pluginContext: IrPluginContext, symbolTable: SymbolTable) { - this.mainIrModuleFragment = mairIrModuleFragment + context(KotlinIrPhase.Context) + fun generateIr() { + this.mainIrModuleFragment = moduleFragment - fixPrivateTypeParametersSymbolsFromOldKLibs(symbolTable) + fixPrivateTypeParametersSymbolsFromOldKLibs(skieSymbolTable) allNamespaces.forEach { - it.generateIrDeclarations(pluginContext, symbolTable) + it.generateIrDeclarations() } allNamespaces.forEach { - it.generateIrBodies(pluginContext) + it.generateIrBodies() } } @@ -162,21 +166,21 @@ class DeclarationBuilderImpl( * This then probably confuses the deserializer which in return declares the TypeParameters with non-public symbol (because it does not see that symbol as being declared in public declaration). * This fix registers these missing symbols manually. */ - private fun fixPrivateTypeParametersSymbolsFromOldKLibs(symbolTable: SymbolTable) { - symbolTable.allExposedTypeParameters(mutableDescriptorProvider) + private fun fixPrivateTypeParametersSymbolsFromOldKLibs(skieSymbolTable: SkieSymbolTable) { + skieSymbolTable.allExposedTypeParameters(mutableDescriptorProvider) .filter { it.symbol !is IrTypeParameterPublicSymbolImpl } .forEach { - symbolTable.declarePrivateTypeParameterAsPublic(it) + skieSymbolTable.declarePrivateTypeParameterAsPublic(it) } } } -private fun SymbolTable.allExposedTypeParameters(descriptorProvider: DescriptorProvider): List = +private fun SkieSymbolTable.allExposedTypeParameters(descriptorProvider: DescriptorProvider): List = (descriptorProvider.allExposedMembers.flatMap { referenceBoundTypeParameterContainer(it) } + - descriptorProvider.exposedClasses.flatMap { referenceBoundTypeParameterContainer(it) }) + descriptorProvider.exposedClasses.flatMap { referenceBoundTypeParameterContainer(it) }) .flatMap { it.typeParameters } -private fun SymbolTable.referenceBoundTypeParameterContainer( +private fun SkieSymbolTable.referenceBoundTypeParameterContainer( callableMemberDescriptor: CallableMemberDescriptor, ): List = when (callableMemberDescriptor) { @@ -185,33 +189,30 @@ private fun SymbolTable.referenceBoundTypeParameterContainer( else -> error("Unsupported type $callableMemberDescriptor.") } -@OptIn(ObsoleteDescriptorBasedAPI::class) -private fun SymbolTable.referenceBoundTypeParameterContainer(functionDescriptor: FunctionDescriptor): List = +private fun SkieSymbolTable.referenceBoundTypeParameterContainer(functionDescriptor: FunctionDescriptor): List = listOfNotNull( - referenceFunction(functionDescriptor).takeIf { + descriptorExtension.referenceFunction(functionDescriptor).takeIf { it.isBound && it.owner !is DummyIrSimpleFunction && it.owner !is DummyIrConstructor }?.owner, ) -@OptIn(ObsoleteDescriptorBasedAPI::class) -private fun SymbolTable.referenceBoundTypeParameterContainer(propertyDescriptor: PropertyDescriptor): List { - val property = referenceProperty(propertyDescriptor).takeIf { it.isBound }?.owner +private fun SkieSymbolTable.referenceBoundTypeParameterContainer(propertyDescriptor: PropertyDescriptor): List { + val property = descriptorExtension.referenceProperty(propertyDescriptor).takeIf { it.isBound }?.owner return listOfNotNull(property?.getter, property?.setter) } -@OptIn(ObsoleteDescriptorBasedAPI::class) -private fun SymbolTable.referenceBoundTypeParameterContainer(classDescriptor: ClassDescriptor): List = +private fun SkieSymbolTable.referenceBoundTypeParameterContainer(classDescriptor: ClassDescriptor): List = listOfNotNull( - referenceClass(classDescriptor).takeIf { it.isBound }?.owner, + descriptorExtension.referenceClass(classDescriptor).takeIf { it.isBound }?.owner, ) @OptIn(ObsoleteDescriptorBasedAPI::class) -private fun SymbolTable.declarePrivateTypeParameterAsPublic(typeParameter: IrTypeParameter) { +private fun SkieSymbolTable.declarePrivateTypeParameterAsPublic(typeParameter: IrTypeParameter) { val signature = PublicIdSignatureComputer(KonanManglerIr).computeSignature(typeParameter) val publicSymbol = IrTypeParameterPublicSymbolImpl(signature, typeParameter.descriptor) publicSymbol.bind(typeParameter) - declareGlobalTypeParameter(signature, { publicSymbol }, { typeParameter }) + kotlinSymbolTable.declareGlobalTypeParameter(signature, { publicSymbol }, { typeParameter }) } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/GenerateIrPhase.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/GenerateIrPhase.kt index eb4d263d0..a6ec56ae9 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/GenerateIrPhase.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/GenerateIrPhase.kt @@ -1,12 +1,11 @@ package co.touchlab.skie.kir.irbuilder.impl import co.touchlab.skie.phases.KotlinIrPhase -import org.jetbrains.kotlin.ir.util.SymbolTable object GenerateIrPhase : KotlinIrPhase { context(KotlinIrPhase.Context) override fun execute() { - declarationBuilder.generateIr(moduleFragment, pluginContext, pluginContext.symbolTable as SymbolTable) + declarationBuilder.generateIr() } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/BaseNamespace.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/BaseNamespace.kt index 21f873304..1f758191c 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/BaseNamespace.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/BaseNamespace.kt @@ -3,10 +3,10 @@ package co.touchlab.skie.kir.irbuilder.impl.namespace import co.touchlab.skie.kir.DescriptorRegistrationScope import co.touchlab.skie.kir.irbuilder.DeclarationTemplate import co.touchlab.skie.kir.irbuilder.Namespace -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase +import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer -import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions @@ -23,9 +23,10 @@ abstract class BaseNamespace : Namespace { registerDescriptorProvider(declarationTemplate.descriptor) } - override fun registerSymbols(symbolTable: SymbolTable) { + context(SymbolTablePhase.Context) + override fun registerSymbols() { templates.forEach { - it.declareSymbol(symbolTable) + it.declareSymbol() } } @@ -40,33 +41,36 @@ abstract class BaseNamespace : Namespace { registerExposedDescriptor(declarationDescriptor) } - override fun generateIrDeclarations(pluginContext: IrPluginContext, symbolTable: SymbolTable) { + context(KotlinIrPhase.Context) + override fun generateIrDeclarations() { val generatorContext = GeneratorContext( Psi2IrConfiguration(), descriptor.module, pluginContext.bindingContext, pluginContext.languageVersionSettings, - symbolTable, + skieSymbolTable.kotlinSymbolTable, GeneratorExtensions(), pluginContext.typeTranslator, pluginContext.irBuiltIns, null, ) - val namespaceIr = generateNamespaceIr(generatorContext) + val namespaceIr = generateNamespaceIr() templates.forEach { it.generateIrDeclaration(namespaceIr, generatorContext) } } - override fun generateIrBodies(pluginContext: IrPluginContext) { + context(KotlinIrPhase.Context) + override fun generateIrBodies() { templates.forEach { - it.generateIrBody(pluginContext) + it.generateIrBody() } } protected abstract fun addDescriptorIntoDescriptorHierarchy(declarationDescriptor: DeclarationDescriptor) - protected abstract fun generateNamespaceIr(generatorContext: GeneratorContext): IrDeclarationContainer + context(KotlinIrPhase.Context) + protected abstract fun generateNamespaceIr(): IrDeclarationContainer } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedClassNamespace.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedClassNamespace.kt index 09f170de0..981044ef8 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedClassNamespace.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedClassNamespace.kt @@ -4,14 +4,13 @@ import co.touchlab.skie.compilerinject.reflection.reflectedBy import co.touchlab.skie.compilerinject.reflection.reflectors.DeserializedClassMemberScopeReflector import co.touchlab.skie.kir.irbuilder.UnsupportedDeclarationDescriptorException import co.touchlab.skie.kir.irbuilder.util.findSourceFile +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SourceElement -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer -import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor class DeserializedClassNamespace( @@ -48,7 +47,7 @@ class DeserializedClassNamespace( (descriptor.constructors as MutableCollection).add(constructorDescriptor) } - @OptIn(ObsoleteDescriptorBasedAPI::class) - override fun generateNamespaceIr(generatorContext: GeneratorContext): IrDeclarationContainer = - generatorContext.symbolTable.referenceClass(descriptor).owner + context(KotlinIrPhase.Context) + override fun generateNamespaceIr(): IrDeclarationContainer = + skieSymbolTable.descriptorExtension.referenceClass(descriptor).owner } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedPackageNamespace.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedPackageNamespace.kt index 9e5672a84..c6d099ee2 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedPackageNamespace.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/DeserializedPackageNamespace.kt @@ -1,6 +1,7 @@ package co.touchlab.skie.kir.irbuilder.impl.namespace import co.touchlab.skie.kir.irbuilder.UnsupportedDeclarationDescriptorException +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.serialization.findPackage import org.jetbrains.kotlin.backend.common.serialization.findSourceFile import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -8,11 +9,8 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.SourceElement -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer import org.jetbrains.kotlin.ir.util.getPackageFragment -import org.jetbrains.kotlin.ir.util.referenceFunction -import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment class DeserializedPackageNamespace( @@ -35,7 +33,7 @@ class DeserializedPackageNamespace( descriptor.getMemberScope().addFunctionDescriptorToImpl(functionDescriptor) } - @OptIn(ObsoleteDescriptorBasedAPI::class) - override fun generateNamespaceIr(generatorContext: GeneratorContext): IrDeclarationContainer = - generatorContext.symbolTable.referenceFunction(existingMember).owner.getPackageFragment() + context(KotlinIrPhase.Context) + override fun generateNamespaceIr(): IrDeclarationContainer = + skieSymbolTable.descriptorExtension.referenceFunction(existingMember).owner.getPackageFragment() } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/NewFileNamespace.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/NewFileNamespace.kt index 9a4bca5bf..7e80453b3 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/NewFileNamespace.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/namespace/NewFileNamespace.kt @@ -3,6 +3,7 @@ package co.touchlab.skie.kir.irbuilder.impl.namespace import co.touchlab.skie.compilerinject.reflection.reflectedBy import co.touchlab.skie.compilerinject.reflection.reflectors.CompositePackageFragmentProviderReflector import co.touchlab.skie.compilerinject.reflection.reflectors.ModuleDescriptorImplReflector +import co.touchlab.skie.phases.KotlinIrPhase import co.touchlab.skie.util.swift.toValidSwiftIdentifier import org.jetbrains.kotlin.backend.common.SimpleMemberScope import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -21,7 +22,6 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.resolve.scopes.MemberScope import org.jetbrains.kotlin.resolve.source.PsiSourceFile @@ -53,7 +53,8 @@ class NewFileNamespace private constructor( packageContent.add(declarationDescriptor) } - override fun generateNamespaceIr(generatorContext: GeneratorContext): IrDeclarationContainer { + context(KotlinIrPhase.Context) + override fun generateNamespaceIr(): IrDeclarationContainer { val fileEntry = DummyIrFileEntry(sourceFile.nameOrError) val file = IrFileImpl(fileEntry, descriptor, context.mainIrModuleFragment) diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/BaseDeclarationTemplate.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/BaseDeclarationTemplate.kt index e37afe80f..2956876d5 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/BaseDeclarationTemplate.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/BaseDeclarationTemplate.kt @@ -3,13 +3,12 @@ package co.touchlab.skie.kir.irbuilder.impl.template import co.touchlab.skie.kir.irbuilder.DeclarationTemplate -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclaration import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer import org.jetbrains.kotlin.ir.symbols.IrBindableSymbol -import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable import org.jetbrains.kotlin.ir.util.patchDeclarationParents import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.psi2ir.generators.SyntheticDeclarationsGenerator @@ -17,6 +16,7 @@ import org.jetbrains.kotlin.psi2ir.generators.SyntheticDeclarationsGenerator abstract class BaseDeclarationTemplate> : DeclarationTemplate { + context(KotlinIrPhase.Context) override fun generateIrDeclaration(parent: IrDeclarationContainer, generatorContext: GeneratorContext) { createDeclarationStubsIfIrLazyClass(parent) @@ -24,7 +24,7 @@ abstract class BaseDeclarationTemplate IrBody + // TODO Change to context(KotlinIrPhase.Context, DeclarationIrBuilder) once are context implemented properly + private val irBodyBuilder: context(KotlinIrPhase.Context) DeclarationIrBuilder.(IrSimpleFunction) -> IrBody init { functionBuilder.config() @@ -58,8 +56,9 @@ class FunctionTemplate( descriptor.isSuspend = functionBuilder.isSuspend } - override fun declareSymbol(symbolTable: SymbolTable) { - val signature = symbolTable.signaturer.composeSignature(descriptor) + context(SymbolTablePhase.Context) + override fun declareSymbol() { + val signature = skieSymbolTable.kotlinSymbolTable.signaturer.composeSignature(descriptor) ?: throw IllegalArgumentException("Only exported declarations are currently supported. Check declaration visibility.") // IrRebindableSimpleFunctionPublicSymbol is used so that we can later bind it to the correct declaration which cannot be created before the symbol table is validated to not contain any unbound symbols. @@ -74,20 +73,17 @@ class FunctionTemplate( } } - val declaration = symbolTable.declareSimpleFunction(signature, symbolFactory, functionFactory) + val declaration = skieSymbolTable.kotlinSymbolTable.declareSimpleFunction(signature, symbolFactory, functionFactory) // But the symbol cannot be bounded otherwise DeclarationBuilder will not to generate the declaration (because it thinks it already exists). (declaration.symbol as? IrRebindableSimpleFunctionPublicSymbol)?.unbind() } - @OptIn(ObsoleteDescriptorBasedAPI::class) - override fun getSymbol(symbolTable: ReferenceSymbolTable): IrSimpleFunctionSymbol = - symbolTable.referenceSimpleFunction(descriptor) + context(KotlinIrPhase.Context) + override fun getSymbol(): IrSimpleFunctionSymbol = + skieSymbolTable.descriptorExtension.referenceSimpleFunction(descriptor) - override fun initializeBody( - declaration: IrSimpleFunction, - irPluginContext: IrPluginContext, - declarationIrBuilder: DeclarationIrBuilder, - ) { - declaration.body = irBodyBuilder(irPluginContext, declarationIrBuilder, declaration) + context(KotlinIrPhase.Context) + override fun initializeBody(declaration: IrSimpleFunction, declarationIrBuilder: DeclarationIrBuilder) { + declaration.body = irBodyBuilder(this@Context, declarationIrBuilder, declaration) } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/SecondaryConstructorTemplate.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/SecondaryConstructorTemplate.kt index b149cd2fb..1fcbdd503 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/SecondaryConstructorTemplate.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/irbuilder/impl/template/SecondaryConstructorTemplate.kt @@ -6,18 +6,16 @@ import co.touchlab.skie.kir.irbuilder.Namespace import co.touchlab.skie.kir.irbuilder.SecondaryConstructorBuilder import co.touchlab.skie.kir.irbuilder.impl.symboltable.DummyIrConstructor import co.touchlab.skie.kir.irbuilder.impl.symboltable.IrRebindableConstructorPublicSymbol -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase +import co.touchlab.skie.phases.SymbolTablePhase import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol -import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable -import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.name.Name class SecondaryConstructorTemplate( @@ -36,8 +34,8 @@ class SecondaryConstructorTemplate( private val constructorBuilder = SecondaryConstructorBuilder(descriptor) - // TODO Change to context(IrPluginContext, DeclarationIrBuilder) once are context implemented properly - private val irBodyBuilder: context(IrPluginContext) DeclarationIrBuilder.(IrConstructor) -> IrBody + // TODO Change to context(KotlinIrPhase.Context, DeclarationIrBuilder) once are context implemented properly + private val irBodyBuilder: context(KotlinIrPhase.Context) DeclarationIrBuilder.(IrConstructor) -> IrBody init { descriptor.reflectedBy().name = name @@ -54,8 +52,9 @@ class SecondaryConstructorTemplate( descriptor.returnType = namespace.descriptor.defaultType } - override fun declareSymbol(symbolTable: SymbolTable) { - val signature = symbolTable.signaturer.composeSignature(descriptor) + context(SymbolTablePhase.Context) + override fun declareSymbol() { + val signature = skieSymbolTable.kotlinSymbolTable.signaturer.composeSignature(descriptor) ?: throw IllegalArgumentException("Only exported declarations are currently supported. Check declaration visibility.") // IrRebindableConstructorPublicSymbol is used so that we can later bind it to the correct declaration which cannot be created before the symbol table is validated to not contain any unbound symbols. @@ -70,20 +69,17 @@ class SecondaryConstructorTemplate( } } - val declaration = symbolTable.declareConstructor(signature, symbolFactory, functionFactory) + val declaration = skieSymbolTable.kotlinSymbolTable.declareConstructor(signature, symbolFactory, functionFactory) // But the symbol cannot be bounded otherwise DeclarationBuilder will not to generate the declaration (because it thinks it already exists). (declaration.symbol as? IrRebindableConstructorPublicSymbol)?.unbind() } - @OptIn(ObsoleteDescriptorBasedAPI::class) - override fun getSymbol(symbolTable: ReferenceSymbolTable): IrConstructorSymbol = - symbolTable.referenceConstructor(descriptor) + context(KotlinIrPhase.Context) + override fun getSymbol(): IrConstructorSymbol = + skieSymbolTable.descriptorExtension.referenceConstructor(descriptor) - override fun initializeBody( - declaration: IrConstructor, - irPluginContext: IrPluginContext, - declarationIrBuilder: DeclarationIrBuilder, - ) { - declaration.body = irBodyBuilder(irPluginContext, declarationIrBuilder, declaration) + context(KotlinIrPhase.Context) + override fun initializeBody(declaration: IrConstructor, declarationIrBuilder: DeclarationIrBuilder) { + declaration.body = irBodyBuilder(this@Context, declarationIrBuilder, declaration) } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SkieSymbolTable.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SkieSymbolTable.kt new file mode 100644 index 000000000..0609f5807 --- /dev/null +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SkieSymbolTable.kt @@ -0,0 +1,10 @@ +package co.touchlab.skie.kir.util + +import org.jetbrains.kotlin.ir.util.SymbolTable + +class SkieSymbolTable( + val kotlinSymbolTable: SymbolTable, +) { + + val descriptorExtension: SymbolTableDescriptorExtensionShim = SymbolTableDescriptorExtensionShim(kotlinSymbolTable) +} diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kt new file mode 100644 index 000000000..c8044a6bc --- /dev/null +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/util/SymbolTableDescriptorExtensionShim.kt @@ -0,0 +1,26 @@ +package co.touchlab.skie.kir.util + +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable + +expect class SymbolTableDescriptorExtensionShim(symbolTable: ReferenceSymbolTable) { + + fun referenceFunction(callable: CallableDescriptor): IrFunctionSymbol + + fun referenceProperty(descriptor: PropertyDescriptor): IrPropertySymbol + + fun referenceSimpleFunction(descriptor: FunctionDescriptor): IrSimpleFunctionSymbol + + fun referenceConstructor(descriptor: ClassConstructorDescriptor): IrConstructorSymbol + + fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol +} diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/KotlinIrPhase.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/KotlinIrPhase.kt index 78378902f..514dc7d41 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/KotlinIrPhase.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/KotlinIrPhase.kt @@ -1,7 +1,9 @@ package co.touchlab.skie.phases import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl +import co.touchlab.skie.kir.util.SkieSymbolTable import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.ir.IrBuiltIns import org.jetbrains.kotlin.ir.declarations.IrModuleFragment interface KotlinIrPhase : SkiePhase { @@ -16,6 +18,11 @@ interface KotlinIrPhase : SkiePhase { val pluginContext: IrPluginContext + val skieSymbolTable: SkieSymbolTable + val allModules: Map + + val irBuiltIns: IrBuiltIns + get() = pluginContext.irBuiltIns } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/SymbolTablePhase.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/SymbolTablePhase.kt index 9215bb417..eee2dcba6 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/SymbolTablePhase.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/SymbolTablePhase.kt @@ -1,7 +1,7 @@ package co.touchlab.skie.phases import co.touchlab.skie.kir.irbuilder.impl.DeclarationBuilderImpl -import org.jetbrains.kotlin.ir.util.SymbolTable +import co.touchlab.skie.kir.util.SkieSymbolTable interface SymbolTablePhase : SkiePhase { @@ -11,6 +11,6 @@ interface SymbolTablePhase : SkiePhase { val declarationBuilder: DeclarationBuilderImpl - val symbolTable: SymbolTable + val skieSymbolTable: SkieSymbolTable } } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/compiler/common/CommonCompilerConfigurationAnalytics.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/compiler/common/CommonCompilerConfigurationAnalytics.kt index 69ea3805a..0dfa3f1d9 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/compiler/common/CommonCompilerConfigurationAnalytics.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/compiler/common/CommonCompilerConfigurationAnalytics.kt @@ -26,7 +26,6 @@ data class CommonCompilerConfigurationAnalytics( val objcGenerics: Boolean?, val memoryModel: String?, val allocationMode: String?, - val garbageCollector: String?, val unitSuspendFunctionObjCExport: String?, val objcExportSuspendFunctionLaunchThreadRestriction: String?, ) { @@ -52,7 +51,6 @@ data class CommonCompilerConfigurationAnalytics( objcGenerics = config.configuration.get(KonanConfigKeys.OBJC_GENERICS), memoryModel = config.configuration.get(BinaryOptions.memoryModel)?.toString(), allocationMode = config.configuration.get(KonanConfigKeys.ALLOCATION_MODE)?.toString(), - garbageCollector = config.configuration.get(KonanConfigKeys.GARBAGE_COLLECTOR)?.toString(), unitSuspendFunctionObjCExport = config.configuration.get(BinaryOptions.unitSuspendFunctionObjCExport)?.toString(), objcExportSuspendFunctionLaunchThreadRestriction = config.configuration.get(BinaryOptions.objcExportSuspendFunctionLaunchThreadRestriction) ?.toString(), diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/environment/CompilerEnvironmentAnalytics.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/environment/CompilerEnvironmentAnalytics.kt index d0f9e5f97..d016347f5 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/environment/CompilerEnvironmentAnalytics.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/analytics/environment/CompilerEnvironmentAnalytics.kt @@ -24,11 +24,13 @@ data class CompilerEnvironmentAnalytics( override val configurationFlag: SkieConfigurationFlag = SkieConfigurationFlag.Analytics_CompilerEnvironment + // Xcode.findCurrent().version.toString() is not redundant because from 1.9.20 the version is not a String + @Suppress("RemoveRedundantCallsOfConversionMethods") override fun produce(): String = CompilerEnvironmentAnalytics( jvmVersion = Runtime.version().toString(), compilerVersion = konanConfig.distribution.compilerVersion, - xcodeVersion = Xcode.findCurrent().version, + xcodeVersion = Xcode.findCurrent().version.toString(), availableProcessors = Runtime.getRuntime().availableProcessors(), maxJvmMemory = Runtime.getRuntime().maxMemory(), ).toPrettyJson() diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/BaseFunctionDefaultArgumentGeneratorDelegate.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/BaseFunctionDefaultArgumentGeneratorDelegate.kt index 7fe043243..2e044e05e 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/BaseFunctionDefaultArgumentGeneratorDelegate.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/BaseFunctionDefaultArgumentGeneratorDelegate.kt @@ -6,18 +6,17 @@ import co.touchlab.skie.kir.irbuilder.getNamespace import co.touchlab.skie.kir.irbuilder.util.copyIndexing import co.touchlab.skie.kir.irbuilder.util.copyWithoutDefaultValue import co.touchlab.skie.phases.DescriptorModificationPhase +import co.touchlab.skie.phases.KotlinIrPhase import co.touchlab.skie.phases.SkiePhase import co.touchlab.skie.phases.features.defaultarguments.DefaultArgumentGenerator import co.touchlab.skie.phases.util.doInPhase import co.touchlab.skie.swiftmodel.callable.KotlinDirectlyCallableMemberSwiftModel.CollisionResolutionStrategy import co.touchlab.skie.util.SharedCounter -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.irGet @@ -104,12 +103,11 @@ abstract class BaseFunctionDefaultArgumentGeneratorDelegate( } } - context(IrPluginContext, DeclarationIrBuilder) - @OptIn(ObsoleteDescriptorBasedAPI::class) + context(KotlinIrPhase.Context, DeclarationIrBuilder) private fun getOverloadBody( originalFunction: FunctionDescriptor, overloadIr: IrFunction, ): IrBody { - val originalFunctionSymbol = symbolTable.referenceSimpleFunction(originalFunction) + val originalFunctionSymbol = skieSymbolTable.descriptorExtension.referenceSimpleFunction(originalFunction) return irBlockBody { +irReturn( diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/ConstructorsDefaultArgumentGeneratorDelegate.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/ConstructorsDefaultArgumentGeneratorDelegate.kt index 2572edc89..1c979ab67 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/ConstructorsDefaultArgumentGeneratorDelegate.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/defaultarguments/delegate/ConstructorsDefaultArgumentGeneratorDelegate.kt @@ -5,19 +5,18 @@ import co.touchlab.skie.kir.irbuilder.createSecondaryConstructor import co.touchlab.skie.kir.irbuilder.getNamespace import co.touchlab.skie.kir.irbuilder.util.copyWithoutDefaultValue import co.touchlab.skie.phases.DescriptorModificationPhase +import co.touchlab.skie.phases.KotlinIrPhase import co.touchlab.skie.phases.SkiePhase import co.touchlab.skie.phases.features.defaultarguments.DefaultArgumentGenerator import co.touchlab.skie.phases.util.doInPhase import co.touchlab.skie.swiftmodel.callable.KotlinDirectlyCallableMemberSwiftModel.CollisionResolutionStrategy import co.touchlab.skie.util.SharedCounter -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irDelegatingConstructorCall @@ -118,12 +117,11 @@ class ConstructorsDefaultArgumentGeneratorDelegate( private fun String.dropUniqueParameterMangling(): String = this.split(uniqueNameSubstring).first() - context(IrPluginContext, DeclarationIrBuilder) - @OptIn(ObsoleteDescriptorBasedAPI::class) + context(KotlinIrPhase.Context, DeclarationIrBuilder) private fun getOverloadBody( originalConstructor: ClassConstructorDescriptor, overloadIr: IrConstructor, ): IrBody { - val originalConstructorSymbol = symbolTable.referenceConstructor(originalConstructor) + val originalConstructorSymbol = skieSymbolTable.descriptorExtension.referenceConstructor(originalConstructor) return irBlockBody { +irDelegatingConstructorCall(originalConstructorSymbol.owner).apply { diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeBodyGenerator.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeBodyGenerator.kt index d681db447..6f8d3f0e1 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeBodyGenerator.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeBodyGenerator.kt @@ -1,10 +1,9 @@ package co.touchlab.skie.phases.features.suspend.kotlin -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.irGet @@ -19,7 +18,7 @@ class SuspendKotlinBridgeBodyGenerator( private val exceptionFieldGenerator = SuspendKotlinBridgeCheckedExceptionsGenerator() private val lambdaGenerator = SuspendKotlinBridgeHandlerLambdaGenerator() - context(IrPluginContext, DeclarationIrBuilder) + context(KotlinIrPhase.Context, DeclarationIrBuilder) fun createBody( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, @@ -43,10 +42,10 @@ class SuspendKotlinBridgeBodyGenerator( ) } - @OptIn(ObsoleteDescriptorBasedAPI::class) - private val IrPluginContext.suspendHandlerLaunchMethod: IrSimpleFunction + context(KotlinIrPhase.Context) + private val suspendHandlerLaunchMethod: IrSimpleFunction get() { - val suspendHandlerClass = symbolTable.referenceClass(suspendHandlerDescriptor).owner + val suspendHandlerClass = skieSymbolTable.descriptorExtension.referenceClass(suspendHandlerDescriptor).owner return suspendHandlerClass.declarations .filterIsInstance() diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeCheckedExceptionsGenerator.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeCheckedExceptionsGenerator.kt index b23ca153c..d7690fee9 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeCheckedExceptionsGenerator.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeCheckedExceptionsGenerator.kt @@ -2,12 +2,11 @@ package co.touchlab.skie.phases.features.suspend.kotlin import co.touchlab.skie.kir.irbuilder.util.SUSPEND_WRAPPER_CHECKED_EXCEPTIONS import co.touchlab.skie.kir.irbuilder.util.addChild -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI -import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler.fqnString import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.irExprBody import org.jetbrains.kotlin.ir.builders.irGetField @@ -33,7 +32,7 @@ import org.jetbrains.kotlin.types.KotlinType class SuspendKotlinBridgeCheckedExceptionsGenerator { - context(IrPluginContext, DeclarationIrBuilder) + context(KotlinIrPhase.Context, DeclarationIrBuilder) fun createGetCheckedExceptions( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, @@ -43,7 +42,8 @@ class SuspendKotlinBridgeCheckedExceptionsGenerator { return irGetField(null, field) } - private fun IrPluginContext.createCheckedExceptionsField( + context(KotlinIrPhase.Context) + private fun createCheckedExceptionsField( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, ): IrFieldImpl { @@ -69,17 +69,19 @@ class SuspendKotlinBridgeCheckedExceptionsGenerator { return field } + @Suppress("RecursivePropertyAccessor") private val IrDeclaration.parentPackageFragment: IrPackageFragment get() = parent as? IrPackageFragment ?: (parent as IrDeclaration).parentPackageFragment private val IrSimpleFunction.nameForCheckedExceptionsField: String - get() = this.fqnString(false) + "_checkedExceptions" + get() = this.name.identifier + "__checkedExceptions" - private fun IrPluginContext.createCheckExceptionsFieldInitializer( + context(KotlinIrPhase.Context) + private fun createCheckExceptionsFieldInitializer( fieldSymbol: IrFieldSymbolImpl, originalFunctionDescriptor: FunctionDescriptor, ): IrExpressionBody = - DeclarationIrBuilder(this, fieldSymbol, 0, 0).run { + DeclarationIrBuilder(pluginContext, fieldSymbol, 0, 0).run { irExprBody( irCall(irBuiltIns.arrayOf).apply { val checkedExceptionClassReferences = createCheckedExceptionClassReferences(originalFunctionDescriptor) @@ -93,14 +95,14 @@ class SuspendKotlinBridgeCheckedExceptionsGenerator { ) } - context(IrPluginContext) + context(KotlinIrPhase.Context) @OptIn(ObsoleteDescriptorBasedAPI::class) private fun createCheckedExceptionClassReferences( originalFunctionDescriptor: FunctionDescriptor, ): List = originalFunctionDescriptor.declaredThrownExceptions .map { exceptionType -> - val exceptionTypeSymbol = symbolTable.referenceClassifier(exceptionType.constructor.declarationDescriptor!!) + val exceptionTypeSymbol = skieSymbolTable.kotlinSymbolTable.referenceClassifier(exceptionType.constructor.declarationDescriptor!!) IrClassReferenceImpl( startOffset = 0, diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeHandlerLambdaGenerator.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeHandlerLambdaGenerator.kt index 8142a652c..ad8586696 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeHandlerLambdaGenerator.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/features/suspend/kotlin/SuspendKotlinBridgeHandlerLambdaGenerator.kt @@ -2,11 +2,10 @@ package co.touchlab.skie.phases.features.suspend.kotlin import co.touchlab.skie.kir.irbuilder.util.irFunctionExpression import co.touchlab.skie.kir.irbuilder.util.irSimpleFunction -import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import co.touchlab.skie.phases.KotlinIrPhase import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.builders.IrBlockBodyBuilder import org.jetbrains.kotlin.ir.builders.irBlockBody import org.jetbrains.kotlin.ir.builders.irCall @@ -26,7 +25,7 @@ import org.jetbrains.kotlin.name.SpecialNames class SuspendKotlinBridgeHandlerLambdaGenerator { - context(IrPluginContext, IrBlockBodyBuilder) + context(KotlinIrPhase.Context, IrBlockBodyBuilder) fun createOriginalFunctionCallLambda( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, @@ -38,7 +37,7 @@ class SuspendKotlinBridgeHandlerLambdaGenerator { function = createOriginalFunctionCallLambdaFunction(bridgingFunction, originalFunctionDescriptor), ) - context(IrPluginContext, IrBlockBodyBuilder) + context(KotlinIrPhase.Context, IrBlockBodyBuilder) private fun createOriginalFunctionCallLambdaFunction( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, @@ -52,14 +51,13 @@ class SuspendKotlinBridgeHandlerLambdaGenerator { body = { createOriginalFunctionCallLambdaFunctionBody(bridgingFunction, originalFunctionDescriptor) }, ) - context(IrPluginContext, DeclarationIrBuilder) - @OptIn(ObsoleteDescriptorBasedAPI::class) + context(KotlinIrPhase.Context, DeclarationIrBuilder) private fun createOriginalFunctionCallLambdaFunctionBody( bridgingFunction: IrSimpleFunction, originalFunctionDescriptor: FunctionDescriptor, ): IrBlockBody = irBlockBody { - val originalFunctionSymbol = symbolTable.referenceSimpleFunction(originalFunctionDescriptor) + val originalFunctionSymbol = skieSymbolTable.descriptorExtension.referenceSimpleFunction(originalFunctionDescriptor) +irReturn( irCall(originalFunctionSymbol).apply { diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/DeclareMissingSymbolsPhase.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/DeclareMissingSymbolsPhase.kt index de1ba7170..32eb620a5 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/DeclareMissingSymbolsPhase.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/other/DeclareMissingSymbolsPhase.kt @@ -6,6 +6,6 @@ object DeclareMissingSymbolsPhase : SymbolTablePhase { context(SymbolTablePhase.Context) override fun execute() { - declarationBuilder.declareSymbols(symbolTable) + declarationBuilder.declareSymbols() } } diff --git a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/ConfigureMinOsVersionTask.kt b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/ConfigureMinOsVersionTask.kt index 0c35d6de6..c784e22c8 100644 --- a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/ConfigureMinOsVersionTask.kt +++ b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/coroutines/ConfigureMinOsVersionTask.kt @@ -1,5 +1,6 @@ package co.touchlab.skie.plugin.coroutines +import co.touchlab.skie.plugin.util.getKonanHome import co.touchlab.skie.util.version.getMinRequiredOsVersionForSwiftAsync import co.touchlab.skie.util.version.isLowerVersionThan import org.gradle.api.DefaultTask @@ -10,7 +11,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBinary import org.jetbrains.kotlin.konan.properties.resolvablePropertyString import org.jetbrains.kotlin.konan.target.Distribution import org.jetbrains.kotlin.konan.target.KonanTarget -import org.jetbrains.kotlin.konan.util.DependencyDirectories import java.util.Properties internal abstract class ConfigureMinOsVersionTask : DefaultTask() { @@ -47,7 +47,7 @@ private val NativeBinary.distribution: Distribution get() { val overrideKonanProperties = parseOverrideKonanProperties(freeCompilerArgs) - return Distribution(konanHome = DependencyDirectories.localKonanDir.absolutePath, propertyOverrides = overrideKonanProperties) + return Distribution(konanHome = project.getKonanHome().absolutePath, propertyOverrides = overrideKonanProperties) } private fun parseOverrideKonanProperties( diff --git a/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/KonanHome.kt b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/KonanHome.kt new file mode 100644 index 000000000..fe4ff32d7 --- /dev/null +++ b/SKIE/skie-gradle/plugin/src/kgp_common/gradle_common/kotlin/co/touchlab/skie/plugin/util/KonanHome.kt @@ -0,0 +1,8 @@ +package co.touchlab.skie.plugin.util + +import org.gradle.api.Project +import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader +import java.io.File + +internal fun Project.getKonanHome(): File = + NativeCompilerDownloader(this).compilerDirectory diff --git a/common-gradle/gradle.properties b/common-gradle/gradle.properties index 147910dff..c590d3625 100644 --- a/common-gradle/gradle.properties +++ b/common-gradle/gradle.properties @@ -8,7 +8,8 @@ kotlin.mpp.import.enableKgpDependencyResolution=true pluginId=co.touchlab.skie -versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10) +# WIP remove RC +versionSupport.kotlinTooling=1.8.0(1.8.10), 1.8.20(1.8.21, 1.8.22), 1.9.0(1.9.10), 1.9.20[1.9.20-RC] versionSupport.gradleApi=7.3, 8.0, 8.1 touchlab.key=ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/dev-support/build.gradle.kts b/dev-support/build.gradle.kts index cd80e6236..4ae5509fd 100644 --- a/dev-support/build.gradle.kts +++ b/dev-support/build.gradle.kts @@ -1,6 +1,6 @@ plugins { id("dev.root") - kotlin("multiplatform") version "1.9.0" apply false + kotlin("multiplatform") version "1.9.20-RC" apply false } buildscript {