[K2/N] KT-55598: Use InteropBuiltIns only in KonanSymbols and DescriptorsLookup
Merge-request: KT-MR-9431 Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
23c3d0c36d
commit
176325eaa7
-4
@@ -93,10 +93,6 @@ internal class Context(
|
||||
override val typeSystem: IrTypeSystemContext
|
||||
get() = IrTypeSystemContextImpl(irBuiltIns)
|
||||
|
||||
val interopBuiltIns by lazy {
|
||||
InteropBuiltIns(this.builtIns)
|
||||
}
|
||||
|
||||
var cAdapterExportedElements: CAdapterExportedElements? = null
|
||||
var objCExportedInterface: ObjCExportedInterface? = null
|
||||
var objCExportCodeSpec: ObjCExportCodeSpec? = null
|
||||
|
||||
+2
-5
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.types.isNullable
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.isTopLevel
|
||||
import org.jetbrains.kotlin.ir.util.packageFqName
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
@@ -300,7 +297,7 @@ internal object IrTypeInlineClassesSupport : InlineClassesSupport<IrClass, IrTyp
|
||||
|
||||
override fun getNativePointedSuperclass(clazz: IrClass): IrClass? {
|
||||
var superClass: IrClass? = clazz
|
||||
while (superClass != null && InteropIdSignatures.nativePointed != superClass.symbol.signature)
|
||||
while (superClass != null && InteropFqNames.nativePointed.toSafe() != superClass.fqNameWhenAvailable)
|
||||
superClass = superClass.getSuperClassNotAny()
|
||||
return superClass
|
||||
}
|
||||
|
||||
+52
-34
@@ -5,14 +5,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames.cValue
|
||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames.cValueName
|
||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames.managedTypeName
|
||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.types.getPublicSignature
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
@@ -21,36 +23,66 @@ object InteropFqNames {
|
||||
const val cPointerName = "CPointer"
|
||||
const val nativePointedName = "NativePointed"
|
||||
|
||||
const val objCObjectBaseName = "ObjCObjectBase"
|
||||
const val objCOverrideInitName = "OverrideInit"
|
||||
const val objCActionName = "ObjCAction"
|
||||
const val objCOutletName = "ObjCOutlet"
|
||||
const val objCMethodImpName = "ObjCMethodImp"
|
||||
const val exportObjCClassName = "ExportObjCClass"
|
||||
|
||||
const val cValueName = "CValue"
|
||||
const val cValuesName = "CValues"
|
||||
const val cValuesRefName = "CValuesRef"
|
||||
const val cEnumName = "CEnum"
|
||||
const val cStructVarName = "CStructVar"
|
||||
private const val cPointedName = "CPointed"
|
||||
|
||||
const val interopStubsName = "InteropStubs"
|
||||
const val managedTypeName = "ManagedType"
|
||||
|
||||
val packageName = FqName("kotlinx.cinterop")
|
||||
|
||||
val cPointer = packageName.child(Name.identifier(cPointerName)).toUnsafe()
|
||||
val nativePointed = packageName.child(Name.identifier(nativePointedName)).toUnsafe()
|
||||
val cPointer = packageName.child(cPointerName).toUnsafe()
|
||||
val nativePointed = packageName.child(nativePointedName).toUnsafe()
|
||||
|
||||
val objCObjectBase = packageName.child(objCObjectBaseName)
|
||||
val objCOverrideInit = objCObjectBase.child(objCOverrideInitName)
|
||||
val objCAction = packageName.child(objCActionName)
|
||||
val objCOutlet = packageName.child(objCOutletName)
|
||||
val objCMethodImp = packageName.child(objCMethodImpName)
|
||||
val exportObjCClass = packageName.child(exportObjCClassName)
|
||||
|
||||
val cValue = packageName.child(cValueName)
|
||||
val cValues = packageName.child(cValuesName)
|
||||
val cValuesRef = packageName.child(cValuesRefName)
|
||||
val cEnum = packageName.child(cEnumName)
|
||||
val cStructVar = packageName.child(cStructVarName)
|
||||
val cPointed = packageName.child(cPointedName)
|
||||
|
||||
val interopStubs = packageName.child(interopStubsName)
|
||||
val managedType = packageName.child(managedTypeName)
|
||||
}
|
||||
|
||||
object InteropIdSignatures {
|
||||
val nativePointed = getPublicSignature(InteropFqNames.packageName, InteropFqNames.nativePointedName)
|
||||
}
|
||||
private fun FqName.child(nameIdent: String) = child(Name.identifier(nameIdent))
|
||||
|
||||
internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
|
||||
val packageScope = builtIns.builtInsModule.getPackage(InteropFqNames.packageName).memberScope
|
||||
private val packageScope = builtIns.builtInsModule.getPackage(InteropFqNames.packageName).memberScope
|
||||
|
||||
val nativePointed = packageScope.getContributedClass(InteropFqNames.nativePointedName)
|
||||
|
||||
val cValuesRef = this.packageScope.getContributedClass("CValuesRef")
|
||||
val cValues = this.packageScope.getContributedClass("CValues")
|
||||
val cValue = this.packageScope.getContributedClass("CValue")
|
||||
val cValue = this.packageScope.getContributedClass(cValueName)
|
||||
val cOpaque = this.packageScope.getContributedClass("COpaque")
|
||||
val cValueWrite = this.packageScope.getContributedFunctions("write")
|
||||
.single { it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == cValue }
|
||||
.single { it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor?.fqNameSafe == InteropFqNames.cValue }
|
||||
val cValueRead = this.packageScope.getContributedFunctions("readValue")
|
||||
.single { it.valueParameters.size == 1 }
|
||||
|
||||
val cEnum = this.packageScope.getContributedClass("CEnum")
|
||||
val cEnumVar = this.packageScope.getContributedClass("CEnumVar")
|
||||
val cStructVar = this.packageScope.getContributedClass("CStructVar")
|
||||
val cStructVarType = cStructVar.defaultType.memberScope.getContributedClass("Type")
|
||||
val cPrimitiveVar = this.packageScope.getContributedClass("CPrimitiveVar")
|
||||
private val cPrimitiveVar = this.packageScope.getContributedClass("CPrimitiveVar")
|
||||
val cPrimitiveVarType = cPrimitiveVar.defaultType.memberScope.getContributedClass("Type")
|
||||
|
||||
val nativeMemUtils = this.packageScope.getContributedClass("nativeMemUtils")
|
||||
@@ -66,7 +98,7 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
val cPointerGetRawValue = packageScope.getContributedFunctions("getRawValue").single {
|
||||
val extensionReceiverParameter = it.extensionReceiverParameter
|
||||
extensionReceiverParameter != null &&
|
||||
TypeUtils.getClassDescriptor(extensionReceiverParameter.type) == cPointer
|
||||
TypeUtils.getClassDescriptor(extensionReceiverParameter.type)?.fqNameUnsafe == InteropFqNames.cPointer
|
||||
}
|
||||
|
||||
val cstr = packageScope.getContributedVariables("cstr").single()
|
||||
@@ -84,9 +116,6 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
|
||||
val typeOf = packageScope.getContributedFunctions("typeOf").single()
|
||||
|
||||
private fun KonanBuiltIns.getUnsignedClass(unsignedType: UnsignedType): ClassDescriptor =
|
||||
this.builtInsModule.findClassAcrossModuleDependencies(unsignedType.classId)!!
|
||||
|
||||
val objCObject = packageScope.getContributedClass("ObjCObject")
|
||||
|
||||
val objCObjectBase = packageScope.getContributedClass("ObjCObjectBase")
|
||||
@@ -113,20 +142,9 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
val objCObjectSuperInitCheck = packageScope.getContributedFunctions("superInitCheck").single()
|
||||
val objCObjectInitBy = packageScope.getContributedFunctions("initBy").single()
|
||||
|
||||
val objCAction = packageScope.getContributedClass("ObjCAction")
|
||||
|
||||
val objCOutlet = packageScope.getContributedClass("ObjCOutlet")
|
||||
|
||||
val objCOverrideInit = objCObjectBase.unsubstitutedMemberScope.getContributedClass("OverrideInit")
|
||||
|
||||
val objCMethodImp = packageScope.getContributedClass("ObjCMethodImp")
|
||||
|
||||
val exportObjCClass = packageScope.getContributedClass("ExportObjCClass")
|
||||
|
||||
val CreateNSStringFromKString = packageScope.getContributedFunctions("CreateNSStringFromKString").single()
|
||||
val objCMethodImp = packageScope.getContributedClass(InteropFqNames.objCMethodImpName)
|
||||
val nativeHeap = packageScope.getContributedClass("nativeHeap")
|
||||
val cPointed = packageScope.getContributedClass("CPointed")
|
||||
val managedType = packageScope.getContributedClass("ManagedType")
|
||||
val managedType = packageScope.getContributedClass(managedTypeName) // used in CStructVarClassGenerator.kt
|
||||
val cPlusPlusClass = packageScope.getContributedClass("CPlusPlusClass")
|
||||
val skiaRefCnt = packageScope.getContributedClass("SkiaRefCnt")
|
||||
|
||||
@@ -137,7 +155,7 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
|
||||
singleTypeParameterUpperBound != null &&
|
||||
extensionReceiverParameter != null &&
|
||||
TypeUtils.getClassDescriptor(singleTypeParameterUpperBound) == cPointed &&
|
||||
TypeUtils.getClassDescriptor(singleTypeParameterUpperBound)?.fqNameSafe == InteropFqNames.cPointed &&
|
||||
extensionReceiverParameter.type == singleTypeParameter.defaultType
|
||||
}.getter!!
|
||||
|
||||
@@ -148,8 +166,8 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns) {
|
||||
|
||||
singleTypeParameterUpperBound != null &&
|
||||
extensionReceiverParameter != null &&
|
||||
TypeUtils.getClassDescriptor(singleTypeParameterUpperBound) == cStructVar &&
|
||||
TypeUtils.getClassDescriptor(extensionReceiverParameter.type) == managedType
|
||||
TypeUtils.getClassDescriptor(singleTypeParameterUpperBound)?.fqNameSafe == InteropFqNames.cStructVar &&
|
||||
TypeUtils.getClassDescriptor(extensionReceiverParameter.type)?.fqNameSafe == InteropFqNames.managedType
|
||||
}.getter!!
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ internal fun PsiToIrContext.psiToIr(
|
||||
} else {
|
||||
val exportedDependencies = (moduleDescriptor.getExportedDependencies(config) + libraryToCacheModule?.let { listOf(it) }.orEmpty()).distinct()
|
||||
val irProviderForCEnumsAndCStructs =
|
||||
IrProviderForCEnumAndCStructStubs(generatorContext, interopBuiltIns, symbols)
|
||||
IrProviderForCEnumAndCStructStubs(generatorContext, symbols)
|
||||
|
||||
val translationContext = object : TranslationPluginContext {
|
||||
override val moduleDescriptor: ModuleDescriptor
|
||||
|
||||
+4
-6
@@ -2,14 +2,11 @@ package org.jetbrains.kotlin.backend.konan.cgen
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.at
|
||||
import org.jetbrains.kotlin.backend.common.lower.irNot
|
||||
import org.jetbrains.kotlin.backend.konan.PrimitiveBinaryType
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.backend.konan.getObjCMethodInfo
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.buildSimpleAnnotation
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getAnnotationArgumentValue
|
||||
import org.jetbrains.kotlin.backend.konan.ir.konanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.isObjCMetaClass
|
||||
import org.jetbrains.kotlin.backend.konan.lower.FunctionReferenceLowering
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
@@ -39,6 +36,7 @@ import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.getClassFqNameUnsafe
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
internal interface KotlinStubs {
|
||||
@@ -636,8 +634,8 @@ private fun KotlinToCCallBuilder.mapCalleeFunctionParameter(
|
||||
): KotlinToCArgumentPassing {
|
||||
val classifier = type.classifierOrNull
|
||||
return when {
|
||||
classifier == symbols.interopCValues || // Note: this should not be accepted, but is required for compatibility
|
||||
classifier == symbols.interopCValuesRef -> CValuesRefArgumentPassing
|
||||
classifier?.isClassWithFqName(InteropFqNames.cValues.toUnsafe()) == true || // Note: this should not be accepted, but is required for compatibility
|
||||
classifier?.isClassWithFqName(InteropFqNames.cValuesRef.toUnsafe()) == true -> CValuesRefArgumentPassing
|
||||
|
||||
classifier == symbols.string && (variadic || parameter?.isCStringParameter() == true) -> {
|
||||
require(!variadic || !isObjCMethod) { stubs.renderCompilerError(argument) }
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
package org.jetbrains.kotlin.backend.konan.cgen
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.propertyIfAccessor
|
||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames
|
||||
import org.jetbrains.kotlin.backend.konan.KonanFqNames
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.util.isUnsigned
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.getClassFqNameUnsafe
|
||||
|
||||
internal fun IrType.isCEnumType(): Boolean {
|
||||
if (isNullable()) return false
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ internal class DynamicCompilerDriver : CompilerDriver() {
|
||||
require(frontendOutput is FirOutput.Full)
|
||||
|
||||
val fir2IrOutput = engine.runFir2Ir(frontendOutput)
|
||||
// engine.runK2SpecialBackendChecks(fir2IrOutput) // TODO After fix of KT-56018 try uncommenting this line
|
||||
//engine.runK2SpecialBackendChecks(fir2IrOutput) // TODO KT-55598 try uncommenting this line after getting rid of InteropBuiltins excessive usage
|
||||
return engine.runFirSerializer(fir2IrOutput)
|
||||
}
|
||||
|
||||
|
||||
+1
-4
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.driver.phases
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.NativeGenerationState
|
||||
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
|
||||
import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.lower.ExpectToActualDefaultValueCopier
|
||||
import org.jetbrains.kotlin.backend.konan.lower.SpecialBackendChecksTraversal
|
||||
import org.jetbrains.kotlin.backend.konan.makeEntryPoint
|
||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
@@ -40,7 +38,7 @@ internal val SpecialBackendChecksPhase = createSimpleNamedCompilerPhase<PsiToIrC
|
||||
preactions = getDefaultIrActions(),
|
||||
postactions = getDefaultIrActions(),
|
||||
) { context, input ->
|
||||
SpecialBackendChecksTraversal(context, context.interopBuiltIns, input.symbols, input.irModule.irBuiltins).lower(input.irModule)
|
||||
SpecialBackendChecksTraversal(context, input.symbols, input.irModule.irBuiltins).lower(input.irModule)
|
||||
}
|
||||
|
||||
internal val K2SpecialBackendChecksPhase = createSimpleNamedCompilerPhase<PhaseContext, Fir2IrOutput>(
|
||||
@@ -50,7 +48,6 @@ internal val K2SpecialBackendChecksPhase = createSimpleNamedCompilerPhase<PhaseC
|
||||
val moduleFragment = input.irModuleFragment
|
||||
SpecialBackendChecksTraversal(
|
||||
context,
|
||||
InteropBuiltIns(input.pluginContext.moduleDescriptor.builtIns as KonanBuiltIns),
|
||||
input.symbols,
|
||||
moduleFragment.irBuiltins
|
||||
).lower(moduleFragment)
|
||||
|
||||
-7
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.driver.phases
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.KonanConfig
|
||||
import org.jetbrains.kotlin.backend.konan.KonanReflectionTypes
|
||||
import org.jetbrains.kotlin.backend.konan.driver.BasicPhaseContext
|
||||
@@ -66,8 +65,6 @@ internal interface PsiToIrContext : PhaseContext {
|
||||
|
||||
val builtIns: KonanBuiltIns
|
||||
|
||||
val interopBuiltIns: InteropBuiltIns
|
||||
|
||||
val bindingContext: BindingContext
|
||||
|
||||
val stdlibModule: ModuleDescriptor
|
||||
@@ -90,10 +87,6 @@ internal class PsiToIrContextImpl(
|
||||
moduleDescriptor.builtIns as KonanBuiltIns
|
||||
}
|
||||
|
||||
override val interopBuiltIns by lazy {
|
||||
InteropBuiltIns(this.builtIns)
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
val originalBindingContext = bindingContext as? CleanableBindingContext
|
||||
?: error("BindingContext should be cleanable in K/N IR to avoid leaking memory: $bindingContext")
|
||||
|
||||
+14
-16
@@ -14,11 +14,9 @@ import org.jetbrains.kotlin.backend.konan.llvm.findMainEntryPoint
|
||||
import org.jetbrains.kotlin.backend.konan.lower.TestProcessor
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.fir.backend.IrBuiltInsOverFir
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
@@ -32,8 +30,6 @@ import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.findDeclaration
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object KonanNameConventions {
|
||||
val setWithoutBoundCheck = Name.special("<setWithoutBoundCheck>")
|
||||
@@ -112,7 +108,6 @@ internal abstract class KonanSymbols(
|
||||
val interopWcstr = symbolTable.referenceSimpleFunction(descriptorsLookup.interopBuiltIns.wcstr.getter!!)
|
||||
val interopMemScope = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.memScope)
|
||||
val interopCValue = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.cValue)
|
||||
val interopCValues = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.cValues)
|
||||
val interopCValuesRef = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.cValuesRef)
|
||||
val interopCValueWrite = symbolTable.referenceSimpleFunction(descriptorsLookup.interopBuiltIns.cValueWrite)
|
||||
val interopCValueRead = symbolTable.referenceSimpleFunction(descriptorsLookup.interopBuiltIns.cValueRead)
|
||||
@@ -180,21 +175,10 @@ internal abstract class KonanSymbols(
|
||||
val interopInterpretCPointer =
|
||||
symbolTable.referenceSimpleFunction(descriptorsLookup.interopBuiltIns.interpretCPointer)
|
||||
|
||||
val interopCreateNSStringFromKString =
|
||||
symbolTable.referenceSimpleFunction(descriptorsLookup.interopBuiltIns.CreateNSStringFromKString)
|
||||
|
||||
val createForeignException = interopFunction("CreateForeignException")
|
||||
|
||||
val interopObjCGetSelector = interopFunction("objCGetSelector")
|
||||
|
||||
val interopCEnum = interopClass("CEnum")
|
||||
|
||||
val interopCPrimitiveVar = interopClass("CPrimitiveVar")
|
||||
|
||||
val interopCEnumVar = interopClass("CEnumVar")
|
||||
|
||||
val interopCStructVar = interopClass("CStructVar")
|
||||
|
||||
val nativeMemUtils = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.nativeMemUtils)
|
||||
|
||||
val nativeHeap = symbolTable.referenceClass(descriptorsLookup.interopBuiltIns.nativeHeap)
|
||||
@@ -415,6 +399,20 @@ internal abstract class KonanSymbols(
|
||||
|
||||
val eagerInitialization = topLevelClass(KonanFqNames.eagerInitialization)
|
||||
|
||||
val cStructVarConstructorSymbol = symbolTable.referenceConstructor(
|
||||
descriptorsLookup.interopBuiltIns.cStructVar.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
val managedTypeConstructor = symbolTable.referenceConstructor(
|
||||
descriptorsLookup.interopBuiltIns.managedType.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
val enumVarConstructorSymbol = symbolTable.referenceConstructor(
|
||||
descriptorsLookup.interopBuiltIns.cEnumVar.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
val primitiveVarPrimaryConstructor = symbolTable.referenceConstructor(
|
||||
descriptorsLookup.interopBuiltIns.cPrimitiveVarType.unsubstitutedPrimaryConstructor!!)
|
||||
val structVarPrimaryConstructor = symbolTable.referenceConstructor(
|
||||
descriptorsLookup.interopBuiltIns.cStructVarType.unsubstitutedPrimaryConstructor!!)
|
||||
|
||||
private fun topLevelClass(fqName: FqName): IrClassSymbol = irBuiltIns.findClass(fqName.shortName(), fqName.parent())!!
|
||||
|
||||
private fun internalFunction(name: String) =
|
||||
|
||||
+14
-17
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan.ir.interop
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
@@ -17,10 +17,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal inline fun <reified T: DeclarationDescriptor> ClassDescriptor.findDeclarationByName(name: String): T? =
|
||||
@@ -153,32 +150,32 @@ internal fun IrBuilder.irInstanceInitializer(classSymbol: IrClassSymbol): IrExpr
|
||||
context.irBuiltIns.unitType
|
||||
)
|
||||
|
||||
internal fun ClassDescriptor.implementsCEnum(interopBuiltIns: InteropBuiltIns): Boolean =
|
||||
interopBuiltIns.cEnum in this.getSuperInterfaces()
|
||||
internal fun ClassDescriptor.implementsCEnum(): Boolean =
|
||||
getSuperInterfaces().any { it.fqNameSafe == InteropFqNames.cEnum }
|
||||
|
||||
internal fun ClassDescriptor.inheritsFromCStructVar(interopBuiltIns: InteropBuiltIns): Boolean =
|
||||
interopBuiltIns.cStructVar == this.getSuperClassNotAny()
|
||||
internal fun ClassDescriptor.inheritsFromCStructVar(): Boolean =
|
||||
getSuperClassNotAny()?.fqNameSafe == InteropFqNames.cStructVar
|
||||
|
||||
/**
|
||||
* All enums that come from interop library implement CEnum interface.
|
||||
* This function checks that given symbol located in subtree of
|
||||
* CEnum inheritor.
|
||||
*/
|
||||
internal fun IrSymbol.findCEnumDescriptor(interopBuiltIns: InteropBuiltIns): ClassDescriptor? =
|
||||
descriptor.findCEnumDescriptor(interopBuiltIns)
|
||||
internal fun IrSymbol.findCEnumDescriptor(): ClassDescriptor? =
|
||||
descriptor.findCEnumDescriptor()
|
||||
|
||||
internal fun DeclarationDescriptor.findCEnumDescriptor(interopBuiltIns: InteropBuiltIns): ClassDescriptor? =
|
||||
parentsWithSelf.filterIsInstance<ClassDescriptor>().firstOrNull { it.implementsCEnum(interopBuiltIns) }
|
||||
internal fun DeclarationDescriptor.findCEnumDescriptor(): ClassDescriptor? =
|
||||
parentsWithSelf.filterIsInstance<ClassDescriptor>().firstOrNull { it.implementsCEnum() }
|
||||
|
||||
/**
|
||||
* All structs that come from interop library inherit from CStructVar class.
|
||||
* This function checks that given symbol located in subtree of
|
||||
* CStructVar inheritor.
|
||||
*/
|
||||
internal fun IrSymbol.findCStructDescriptor(interopBuiltIns: InteropBuiltIns): ClassDescriptor? =
|
||||
descriptor.findCStructDescriptor(interopBuiltIns)
|
||||
internal fun IrSymbol.findCStructDescriptor(): ClassDescriptor? =
|
||||
descriptor.findCStructDescriptor()
|
||||
|
||||
internal fun DeclarationDescriptor.findCStructDescriptor(interopBuiltIns: InteropBuiltIns): ClassDescriptor? =
|
||||
internal fun DeclarationDescriptor.findCStructDescriptor(): ClassDescriptor? =
|
||||
parentsWithSelf.filterIsInstance<ClassDescriptor>().firstOrNull {
|
||||
it.inheritsFromCStructVar(interopBuiltIns) || it.annotations.hasAnnotation(RuntimeNames.managedType)
|
||||
it.inheritsFromCStructVar() || it.annotations.hasAnnotation(RuntimeNames.managedType)
|
||||
}
|
||||
+7
-9
@@ -5,7 +5,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.ir.interop
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getPackageFragments
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.cenum.CEnumByValueFunctionGenerator
|
||||
@@ -34,7 +33,6 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
*/
|
||||
internal class IrProviderForCEnumAndCStructStubs(
|
||||
context: GeneratorContext,
|
||||
private val interopBuiltIns: InteropBuiltIns,
|
||||
symbols: KonanSymbols
|
||||
) {
|
||||
|
||||
@@ -48,30 +46,30 @@ internal class IrProviderForCEnumAndCStructStubs(
|
||||
private val cEnumCompanionGenerator =
|
||||
CEnumCompanionGenerator(context, cEnumByValueFunctionGenerator)
|
||||
private val cEnumVarClassGenerator =
|
||||
CEnumVarClassGenerator(context, interopBuiltIns)
|
||||
CEnumVarClassGenerator(context, symbols)
|
||||
private val cEnumClassGenerator =
|
||||
CEnumClassGenerator(context, cEnumCompanionGenerator, cEnumVarClassGenerator)
|
||||
private val cStructCompanionGenerator =
|
||||
CStructVarCompanionGenerator(context, interopBuiltIns)
|
||||
CStructVarCompanionGenerator(context, symbols)
|
||||
private val cStructClassGenerator =
|
||||
CStructVarClassGenerator(context, interopBuiltIns, cStructCompanionGenerator, symbols)
|
||||
CStructVarClassGenerator(context, cStructCompanionGenerator, symbols)
|
||||
|
||||
fun isCEnumOrCStruct(declarationDescriptor: DeclarationDescriptor): Boolean =
|
||||
declarationDescriptor.run { findCEnumDescriptor(interopBuiltIns) ?: findCStructDescriptor(interopBuiltIns) } != null
|
||||
declarationDescriptor.run { findCEnumDescriptor() ?: findCStructDescriptor() } != null
|
||||
|
||||
fun referenceAllEnumsAndStructsFrom(interopModule: ModuleDescriptor) = interopModule.getPackageFragments()
|
||||
.flatMap { it.getMemberScope().getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) }
|
||||
.filterIsInstance<ClassDescriptor>()
|
||||
.filter { it.implementsCEnum(interopBuiltIns) || it.inheritsFromCStructVar(interopBuiltIns) }
|
||||
.filter { it.implementsCEnum() || it.inheritsFromCStructVar() }
|
||||
.forEach { symbolTable.referenceClass(it) }
|
||||
|
||||
private fun generateIrIfNeeded(symbol: IrSymbol, file: IrFile) {
|
||||
// TODO: These `findOrGenerate` calls generate a whole subtree.
|
||||
// This a simple but clearly suboptimal solution.
|
||||
symbol.findCEnumDescriptor(interopBuiltIns)?.let { enumDescriptor ->
|
||||
symbol.findCEnumDescriptor()?.let { enumDescriptor ->
|
||||
cEnumClassGenerator.findOrGenerateCEnum(enumDescriptor, file)
|
||||
}
|
||||
symbol.findCStructDescriptor(interopBuiltIns)?.let { structDescriptor ->
|
||||
symbol.findCStructDescriptor()?.let { structDescriptor ->
|
||||
cStructClassGenerator.findOrGenerateCStruct(structDescriptor, file)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-8
@@ -4,8 +4,8 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan.ir.interop.cenum
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getArgumentValueOrNull
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.DescriptorToIrTranslationMixin
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.irInstanceInitializer
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
@@ -31,7 +31,7 @@ private val typeSizeAnnotation = FqName("kotlinx.cinterop.internal.CEnumVarTypeS
|
||||
|
||||
internal class CEnumVarClassGenerator(
|
||||
context: GeneratorContext,
|
||||
private val interopBuiltIns: InteropBuiltIns
|
||||
private val symbols: KonanSymbols
|
||||
) : DescriptorToIrTranslationMixin {
|
||||
|
||||
override val irBuiltIns: IrBuiltIns = context.irBuiltIns
|
||||
@@ -57,14 +57,11 @@ internal class CEnumVarClassGenerator(
|
||||
|
||||
private fun createPrimaryConstructor(enumVarClass: IrClass): IrConstructor {
|
||||
val irConstructor = createConstructor(enumVarClass.descriptor.unsubstitutedPrimaryConstructor!!)
|
||||
val enumVarConstructorSymbol = symbolTable.referenceConstructor(
|
||||
interopBuiltIns.cEnumVar.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
val classSymbol = symbolTable.referenceClass(enumVarClass.descriptor)
|
||||
postLinkageSteps.add {
|
||||
irConstructor.body = irBuilder(irBuiltIns, irConstructor.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody {
|
||||
+IrDelegatingConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset, endOffset, context.irBuiltIns.unitType, enumVarConstructorSymbol
|
||||
startOffset, endOffset, context.irBuiltIns.unitType, symbols.enumVarConstructorSymbol
|
||||
).also {
|
||||
it.putValueArgument(0, irGet(irConstructor.valueParameters[0]))
|
||||
}
|
||||
@@ -83,14 +80,13 @@ internal class CEnumVarClassGenerator(
|
||||
}
|
||||
|
||||
private fun createCompanionConstructor(companionObjectDescriptor: ClassDescriptor, typeSize: Int): IrConstructor {
|
||||
val superConstructorSymbol = symbolTable.referenceConstructor(interopBuiltIns.cPrimitiveVarType.unsubstitutedPrimaryConstructor!!)
|
||||
val classSymbol = symbolTable.referenceClass(companionObjectDescriptor)
|
||||
return createConstructor(companionObjectDescriptor.unsubstitutedPrimaryConstructor!!).also {
|
||||
postLinkageSteps.add {
|
||||
it.body = irBuilder(irBuiltIns, it.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody {
|
||||
+IrDelegatingConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset, endOffset, context.irBuiltIns.unitType,
|
||||
superConstructorSymbol
|
||||
symbols.primitiveVarPrimaryConstructor
|
||||
).also {
|
||||
it.putValueArgument(0, irInt(typeSize))
|
||||
}
|
||||
|
||||
+2
-10
@@ -4,7 +4,6 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan.ir.interop.cstruct
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.DescriptorToIrTranslationMixin
|
||||
@@ -29,7 +28,6 @@ import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
|
||||
internal class CStructVarClassGenerator(
|
||||
context: GeneratorContext,
|
||||
private val interopBuiltIns: InteropBuiltIns,
|
||||
private val companionGenerator: CStructVarCompanionGenerator,
|
||||
private val symbols: KonanSymbols
|
||||
) : DescriptorToIrTranslationMixin {
|
||||
@@ -266,15 +264,12 @@ internal class CStructVarClassGenerator(
|
||||
|
||||
private fun createPrimaryConstructor(irClass: IrClass): IrConstructor {
|
||||
if (!irClass.descriptor.annotations.hasAnnotation(RuntimeNames.managedType)) {
|
||||
val cStructVarConstructorSymbol = symbolTable.referenceConstructor(
|
||||
interopBuiltIns.cStructVar.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
return createConstructor(irClass.descriptor.unsubstitutedPrimaryConstructor!!).also { irConstructor ->
|
||||
postLinkageSteps.add {
|
||||
irConstructor.body = irBuilder(irBuiltIns, irConstructor.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody {
|
||||
+IrDelegatingConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset, endOffset,
|
||||
context.irBuiltIns.unitType, cStructVarConstructorSymbol
|
||||
context.irBuiltIns.unitType, symbols.cStructVarConstructorSymbol
|
||||
).also {
|
||||
it.putValueArgument(0, irGet(irConstructor.valueParameters[0]))
|
||||
}
|
||||
@@ -284,14 +279,11 @@ internal class CStructVarClassGenerator(
|
||||
}
|
||||
} else {
|
||||
return createConstructor(irClass.descriptor.unsubstitutedPrimaryConstructor!!).also { irConstructor ->
|
||||
val managedTypeConstructor = symbolTable.referenceConstructor(
|
||||
interopBuiltIns.managedType.unsubstitutedPrimaryConstructor!!
|
||||
)
|
||||
postLinkageSteps.add {
|
||||
irConstructor.body = irBuilder(irBuiltIns, irConstructor.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody {
|
||||
+IrDelegatingConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset, endOffset,
|
||||
context.irBuiltIns.unitType, managedTypeConstructor
|
||||
context.irBuiltIns.unitType, symbols.managedTypeConstructor
|
||||
).also {
|
||||
it.putTypeArgument(0, irConstructor.valueParameters[0].type)
|
||||
it.putValueArgument(0, irGet(irConstructor.valueParameters[0]))
|
||||
|
||||
+3
-4
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.backend.konan.ir.interop.cstruct
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.InteropBuiltIns
|
||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getArgumentValueOrNull
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.DescriptorToIrTranslationMixin
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.irInstanceInitializer
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
@@ -29,7 +29,7 @@ private val varTypeAnnotationFqName = FqName("kotlinx.cinterop.internal.CStruct.
|
||||
|
||||
internal class CStructVarCompanionGenerator(
|
||||
context: GeneratorContext,
|
||||
private val interopBuiltIns: InteropBuiltIns
|
||||
private val symbols: KonanSymbols
|
||||
) : DescriptorToIrTranslationMixin {
|
||||
|
||||
override val irBuiltIns: IrBuiltIns = context.irBuiltIns
|
||||
@@ -76,13 +76,12 @@ internal class CStructVarCompanionGenerator(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val superConstructorSymbol = symbolTable.referenceConstructor(interopBuiltIns.cStructVarType.unsubstitutedPrimaryConstructor!!)
|
||||
return createConstructor(companionObjectDescriptor.unsubstitutedPrimaryConstructor!!).also { irConstructor ->
|
||||
postLinkageSteps.add {
|
||||
irConstructor.body = irBuilder(irBuiltIns, irConstructor.symbol, SYNTHETIC_OFFSET, SYNTHETIC_OFFSET).irBlockBody {
|
||||
+IrDelegatingConstructorCallImpl.fromSymbolOwner(
|
||||
startOffset, endOffset, context.irBuiltIns.unitType,
|
||||
superConstructorSymbol
|
||||
symbols.structVarPrimaryConstructor
|
||||
).also {
|
||||
it.putValueArgument(0, irLong(size))
|
||||
it.putValueArgument(1, irInt(align))
|
||||
|
||||
+3
-2
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.uniqueName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
|
||||
internal enum class FieldStorageKind {
|
||||
GLOBAL, // In the old memory model these are only accessible from the "main" thread.
|
||||
@@ -2303,8 +2304,8 @@ internal class CodeGeneratorVisitor(
|
||||
|
||||
private fun evaluateFunctionReference(expression: IrFunctionReference): LLVMValueRef {
|
||||
// TODO: consider creating separate IR element for pointer to function.
|
||||
assert (expression.type.getClass()?.descriptor == context.interopBuiltIns.cPointer) {
|
||||
"assert: ${expression.type.getClass()?.descriptor} == ${context.interopBuiltIns.cPointer}"
|
||||
assert (expression.type.getClass()?.descriptor?.fqNameUnsafe == InteropFqNames.cPointer) {
|
||||
"assert: ${expression.type.getClass()?.descriptor?.fqNameUnsafe} == ${InteropFqNames.cPointer}"
|
||||
}
|
||||
|
||||
assert (expression.getArguments().isEmpty())
|
||||
|
||||
+2
-4
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import llvm.LLVMLinkage
|
||||
import llvm.LLVMSetLinkage
|
||||
import llvm.LLVMValueRef
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getAnnotationStringValue
|
||||
@@ -14,7 +13,6 @@ import org.jetbrains.kotlin.backend.konan.ir.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
|
||||
internal class KotlinObjCClassInfoGenerator(override val generationState: NativeGenerationState) : ContextUtils {
|
||||
fun generate(irClass: IrClass) {
|
||||
@@ -92,7 +90,7 @@ internal class KotlinObjCClassInfoGenerator(override val generationState: Native
|
||||
}
|
||||
|
||||
private fun selectExportedClassName(irClass: IrClass): String? {
|
||||
val exportObjCClassAnnotation = context.interopBuiltIns.exportObjCClass.fqNameSafe
|
||||
val exportObjCClassAnnotation = InteropFqNames.exportObjCClass
|
||||
val explicitName = irClass.getAnnotationArgumentValue<String>(exportObjCClassAnnotation, "name")
|
||||
if (explicitName != null) return explicitName
|
||||
|
||||
@@ -120,7 +118,7 @@ internal class KotlinObjCClassInfoGenerator(override val generationState: Native
|
||||
.filterIsInstance<IrSimpleFunction>()
|
||||
.mapNotNull {
|
||||
val annotation =
|
||||
it.annotations.findAnnotation(context.interopBuiltIns.objCMethodImp.fqNameSafe) ?:
|
||||
it.annotations.findAnnotation(InteropFqNames.objCMethodImp) ?:
|
||||
return@mapNotNull null
|
||||
|
||||
ObjCMethodDesc(
|
||||
|
||||
+7
-11
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.ir.inlineDeclaration
|
||||
import org.jetbrains.kotlin.backend.common.ir.inlineFunction
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.peek
|
||||
@@ -51,7 +50,7 @@ import org.jetbrains.kotlin.konan.ForeignExceptionMode
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
|
||||
internal class InteropLowering(generationState: NativeGenerationState) : FileLoweringPass {
|
||||
@@ -189,14 +188,12 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
|
||||
private fun lowerKotlinObjCClass(irClass: IrClass) {
|
||||
checkKotlinObjCClass(irClass)
|
||||
|
||||
val interop = context.interopBuiltIns
|
||||
|
||||
irClass.declarations.toList().mapNotNull {
|
||||
when {
|
||||
it is IrSimpleFunction && it.annotations.hasAnnotation(interop.objCAction.fqNameSafe) ->
|
||||
it is IrSimpleFunction && it.annotations.hasAnnotation(InteropFqNames.objCAction) ->
|
||||
generateActionImp(it)
|
||||
|
||||
it is IrProperty && it.annotations.hasAnnotation(interop.objCOutlet.fqNameSafe) ->
|
||||
it is IrProperty && it.annotations.hasAnnotation(InteropFqNames.objCOutlet) ->
|
||||
generateOutletSetterImp(it)
|
||||
|
||||
it is IrConstructor && it.isOverrideInit() ->
|
||||
@@ -206,7 +203,7 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
|
||||
}
|
||||
}.let { irClass.addChildren(it) }
|
||||
|
||||
if (irClass.annotations.hasAnnotation(interop.exportObjCClass.fqNameSafe)) {
|
||||
if (irClass.annotations.hasAnnotation(InteropFqNames.exportObjCClass)) {
|
||||
val irBuilder = context.createIrBuilder(currentFile.symbol).at(irClass)
|
||||
eagerTopLevelInitializers.add(irBuilder.getObjCClass(symbols, irClass.symbol))
|
||||
}
|
||||
@@ -220,7 +217,7 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
|
||||
return false
|
||||
}
|
||||
|
||||
return this.annotations.hasAnnotation(context.interopBuiltIns.objCOverrideInit.fqNameSafe)
|
||||
return this.annotations.hasAnnotation(InteropFqNames.objCOverrideInit)
|
||||
}
|
||||
|
||||
private fun generateOverrideInit(irClass: IrClass, constructor: IrConstructor): IrSimpleFunction {
|
||||
@@ -787,7 +784,6 @@ private class InteropTransformer(
|
||||
|
||||
val newTopLevelDeclarations = mutableListOf<IrDeclaration>()
|
||||
|
||||
val interop = context.interopBuiltIns
|
||||
val symbols = context.ir.symbols
|
||||
|
||||
override fun addTopLevel(declaration: IrDeclaration) {
|
||||
@@ -854,8 +850,8 @@ private class InteropTransformer(
|
||||
|
||||
val callee = expression.symbol.owner
|
||||
val inlinedClass = callee.returnType.getInlinedClassNative()
|
||||
require(inlinedClass?.descriptor != interop.cPointer) { renderCompilerError(expression) }
|
||||
require(inlinedClass?.descriptor != interop.nativePointed) { renderCompilerError(expression) }
|
||||
require(inlinedClass?.symbol != symbols.interopCPointer) { renderCompilerError(expression) }
|
||||
require(inlinedClass?.symbol != symbols.nativePointed) { renderCompilerError(expression) }
|
||||
|
||||
val constructedClass = callee.constructedClass
|
||||
if (!constructedClass.isObjCClass())
|
||||
|
||||
+12
-14
@@ -32,8 +32,8 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext.getClassFqNameUnsafe
|
||||
import org.jetbrains.kotlin.utils.fileUtils.descendantRelativeTo
|
||||
import java.io.File
|
||||
|
||||
@@ -43,16 +43,14 @@ import java.io.File
|
||||
*/
|
||||
internal class SpecialBackendChecksTraversal(
|
||||
private val context: PhaseContext,
|
||||
private val interop: InteropBuiltIns,
|
||||
private val symbols: KonanSymbols,
|
||||
private val irBuiltIns: IrBuiltIns,
|
||||
) : FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) = irFile.acceptChildrenVoid(BackendChecker(context, interop, symbols, irBuiltIns, irFile))
|
||||
override fun lower(irFile: IrFile) = irFile.acceptChildrenVoid(BackendChecker(context, symbols, irBuiltIns, irFile))
|
||||
}
|
||||
|
||||
private class BackendChecker(
|
||||
private val context: PhaseContext,
|
||||
val interop: InteropBuiltIns,
|
||||
val symbols: KonanSymbols,
|
||||
val irBuiltIns: IrBuiltIns,
|
||||
private val irFile: IrFile,
|
||||
@@ -109,7 +107,7 @@ private class BackendChecker(
|
||||
}
|
||||
|
||||
private fun IrConstructor.isOverrideInit() =
|
||||
this.annotations.hasAnnotation(interop.objCOverrideInit.fqNameSafe)
|
||||
this.annotations.hasAnnotation(InteropFqNames.objCOverrideInit)
|
||||
|
||||
private fun checkCanGenerateOverrideInit(irClass: IrClass, constructor: IrConstructor) {
|
||||
val superClass = irClass.getSuperClassNotAny()!!
|
||||
@@ -118,7 +116,7 @@ private class BackendChecker(
|
||||
}.toList()
|
||||
|
||||
val superConstructor = superConstructors.singleOrNull() ?: run {
|
||||
val annotation = interop.objCOverrideInit.name
|
||||
val annotation = InteropFqNames.objCOverrideInit
|
||||
if (superConstructors.isEmpty())
|
||||
reportError(constructor,
|
||||
"""
|
||||
@@ -136,7 +134,7 @@ private class BackendChecker(
|
||||
// Remove fake overrides of this init method, also check for explicit overriding:
|
||||
irClass.declarations.forEach {
|
||||
if (it is IrSimpleFunction && initMethod.symbol in it.overriddenSymbols && it.isReal) {
|
||||
val annotation = interop.objCOverrideInit.name
|
||||
val annotation = InteropFqNames.objCOverrideInit
|
||||
reportError(constructor,
|
||||
"constructor with @$annotation overrides initializer that is already overridden explicitly"
|
||||
)
|
||||
@@ -152,7 +150,7 @@ private class BackendChecker(
|
||||
}
|
||||
|
||||
private fun checkCanGenerateActionImp(function: IrSimpleFunction) {
|
||||
val action = "@${interop.objCAction.name}"
|
||||
val action = "@${InteropFqNames.objCAction}"
|
||||
|
||||
function.extensionReceiverParameter?.let {
|
||||
reportError(it, "$action method must not have extension receiver")
|
||||
@@ -176,7 +174,7 @@ private class BackendChecker(
|
||||
private fun checkCanGenerateOutletSetterImp(property: IrProperty) {
|
||||
val descriptor = property.descriptor
|
||||
|
||||
val outlet = "@${interop.objCOutlet.name}"
|
||||
val outlet = "@${InteropFqNames.objCOutlet}"
|
||||
|
||||
if (!descriptor.isVar)
|
||||
reportError(property, "$outlet property must be var")
|
||||
@@ -209,9 +207,9 @@ private class BackendChecker(
|
||||
|
||||
private fun checkKotlinObjCClass(irClass: IrClass) {
|
||||
for (declaration in irClass.declarations) {
|
||||
if (declaration is IrSimpleFunction && declaration.annotations.hasAnnotation(interop.objCAction.fqNameSafe))
|
||||
if (declaration is IrSimpleFunction && declaration.annotations.hasAnnotation(InteropFqNames.objCAction))
|
||||
checkCanGenerateActionImp(declaration)
|
||||
if (declaration is IrProperty && declaration.annotations.hasAnnotation(interop.objCOutlet.fqNameSafe))
|
||||
if (declaration is IrProperty && declaration.annotations.hasAnnotation(InteropFqNames.objCOutlet))
|
||||
checkCanGenerateOutletSetterImp(declaration)
|
||||
if (declaration is IrConstructor && declaration.isOverrideInit())
|
||||
checkCanGenerateOverrideInit(irClass, declaration)
|
||||
@@ -379,7 +377,7 @@ private class BackendChecker(
|
||||
}
|
||||
|
||||
callee.getExternalObjCMethodInfo()?.let { _ ->
|
||||
val isInteropStubsFile = irFile.annotations.hasAnnotation(FqName("kotlinx.cinterop.InteropStubs"))
|
||||
val isInteropStubsFile = irFile.annotations.hasAnnotation(InteropFqNames.interopStubs)
|
||||
|
||||
// Special case: bridge from Objective-C method implementation template to Kotlin method;
|
||||
// handled in CodeGeneratorVisitor.callVirtual.
|
||||
@@ -740,8 +738,8 @@ private fun BackendChecker.checkCanMapCalleeFunctionParameter(
|
||||
) {
|
||||
val classifier = type.classifierOrNull
|
||||
when {
|
||||
classifier == symbols.interopCValues || // Note: this should not be accepted, but is required for compatibility
|
||||
classifier == symbols.interopCValuesRef -> return
|
||||
classifier?.isClassWithFqName(InteropFqNames.cValues.toUnsafe()) == true || // Note: this should not be accepted, but is required for compatibility
|
||||
classifier?.isClassWithFqName(InteropFqNames.cValuesRef.toUnsafe()) == true -> return
|
||||
|
||||
classifier == symbols.string && (variadic || parameter?.isCStringParameter() == true) -> {
|
||||
if (variadic && isObjCMethod) {
|
||||
|
||||
Reference in New Issue
Block a user