[K/N] Consolidate forward declarations handling
This is refactoring in preparation for KT-59764. Names and layout of forward declarations related classes was copy-pasted many times over compiler code. Implementing KT-59764 would require copy-pasting it two more times. So instead of doing this it was put in single place. No behaviour changes intended in this commit.
This commit is contained in:
committed by
Space Team
parent
0179b45840
commit
ef9413108b
@@ -157,6 +157,7 @@ dependencies {
|
||||
compilerImplementation project(":kotlin-compiler")
|
||||
compilerApi project(":native:kotlin-native-utils")
|
||||
compilerApi project(":core:descriptors")
|
||||
compilerApi project(":core:compiler.common.native")
|
||||
compilerApi project(":compiler:ir.tree")
|
||||
compilerApi project(":compiler:ir.backend.common")
|
||||
compilerApi project(":compiler:util")
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataFactories
|
||||
import org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.name.*
|
||||
|
||||
internal val KlibFactories = KlibMetadataFactories(::KonanBuiltIns, DynamicTypeDeserializer, PlatformDependentTypeTransformer.None)
|
||||
|
||||
@@ -111,7 +111,7 @@ internal fun PhaseContext.fir2Ir(
|
||||
}
|
||||
// This packages exists in all platform libraries, but can contain only synthetic declarations.
|
||||
// These declarations are not really located in klib, so we don't need to depend on klib to use them.
|
||||
removeAll(ForwardDeclarationKind.values().map { it.packageFqName })
|
||||
removeAll(NativeForwardDeclarationKind.entries.map { it.packageFqName })
|
||||
}.toList()
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBasedClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||
@@ -37,7 +38,6 @@ internal val objCDirectFqName = interopPackageName.child(Name.identifier("ObjCDi
|
||||
internal val objCMethodFqName = interopPackageName.child(Name.identifier("ObjCMethod"))
|
||||
internal val objCConstructorFqName = FqName("kotlinx.cinterop.ObjCConstructor")
|
||||
internal val objCFactoryFqName = interopPackageName.child(Name.identifier("ObjCFactory"))
|
||||
private val objcnamesForwardDeclarationsPackageName = Name.identifier("objcnames")
|
||||
|
||||
fun ClassDescriptor.isObjCClass(): Boolean =
|
||||
this.containingDeclaration.fqNameSafe != interopPackageName &&
|
||||
@@ -64,8 +64,10 @@ fun IrClass.isExternalObjCClass(): Boolean = this.isObjCClass() &&
|
||||
it.annotations.hasAnnotation(externalObjCClassFqName)
|
||||
}
|
||||
|
||||
fun ClassDescriptor.isObjCForwardDeclaration(): Boolean =
|
||||
this.findPackage().fqName.startsWith(objcnamesForwardDeclarationsPackageName)
|
||||
fun ClassDescriptor.isObjCForwardDeclaration(): Boolean = when (NativeForwardDeclarationKind.packageFqNameToKind[findPackage().fqName]) {
|
||||
null, NativeForwardDeclarationKind.Struct -> false
|
||||
NativeForwardDeclarationKind.ObjCProtocol, NativeForwardDeclarationKind.ObjCClass -> true
|
||||
}
|
||||
|
||||
fun IrClass.isObjCForwardDeclaration(): Boolean =
|
||||
getPackageFragment().packageFqName.startsWith(objcnamesForwardDeclarationsPackageName)
|
||||
|
||||
+2
-9
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isFromInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
||||
import org.jetbrains.kotlin.backend.konan.ir.konanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isFromInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isFromInteropLibraryByDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.konan.isNativeStdlib
|
||||
@@ -58,6 +57,7 @@ import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.metadata.DeserializedKlibModuleOrigin
|
||||
import org.jetbrains.kotlin.library.metadata.klibModuleOrigin
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -472,12 +472,7 @@ internal class KonanIrLinker(
|
||||
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
|
||||
|
||||
companion object {
|
||||
private val C_NAMES_NAME = Name.identifier("cnames")
|
||||
private val OBJC_NAMES_NAME = Name.identifier("objcnames")
|
||||
|
||||
val FORWARD_DECLARATION_ORIGIN = object : IrDeclarationOriginImpl("FORWARD_DECLARATION_ORIGIN") {}
|
||||
|
||||
const val offset = SYNTHETIC_OFFSET
|
||||
}
|
||||
|
||||
override fun isBuiltInModule(moduleDescriptor: ModuleDescriptor): Boolean = moduleDescriptor.isNativeStdlib()
|
||||
@@ -1111,9 +1106,7 @@ internal class KonanIrLinker(
|
||||
|
||||
private fun IdSignature.isForwardDeclarationSignature(): Boolean {
|
||||
if (isPubliclyVisible) {
|
||||
return packageFqName().run {
|
||||
startsWith(C_NAMES_NAME) || startsWith(OBJC_NAMES_NAME)
|
||||
}
|
||||
return packageFqName() in NativeForwardDeclarationKind.packageFqNameToKind
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user