[Commonizer] Drop no more necessary logic for forward declarations
This commit is contained in:
@@ -18,11 +18,7 @@ interface ModulesProvider {
|
||||
open class ModuleInfo(
|
||||
val name: String,
|
||||
val originalLocation: File,
|
||||
val cInteropAttributes: CInteropModuleAttributes?
|
||||
)
|
||||
|
||||
class CInteropModuleAttributes(
|
||||
val exportForwardDeclarations: Collection<String>
|
||||
val isCInterop: Boolean
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
+2
-4
@@ -202,10 +202,8 @@ private fun commonizeClass(classId: CirEntityId, classifiers: CirKnownClassifier
|
||||
|
||||
return when (val node = classifiers.commonizedNodes.classNode(classId)) {
|
||||
null -> {
|
||||
// No node means that the class was not subject for commonization.
|
||||
// - Either it is missing in certain targets at all => not commonized.
|
||||
// - Or it is a known forward declaration => consider it as commonized.
|
||||
classifiers.forwardDeclarations.isExportedForwardDeclaration(classId)
|
||||
// No node means that the type alias was not subject for commonization. It is missing in some target(s) => not commonized.
|
||||
false
|
||||
}
|
||||
else -> {
|
||||
// Common declaration in node is not null -> successfully commonized.
|
||||
|
||||
@@ -40,7 +40,6 @@ private fun mergeAndCommonize(storageManager: StorageManager, parameters: Common
|
||||
// build merged tree:
|
||||
val classifiers = CirKnownClassifiers(
|
||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||
forwardDeclarations = CirForwardDeclarations.default(),
|
||||
commonDependencies = CirProvidedClassifiers.of(
|
||||
CirFictitiousFunctionClassifiers,
|
||||
CirProvidedClassifiers.by(parameters.dependencyModulesProvider)
|
||||
|
||||
+3
-8
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.konan
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.CInteropModuleAttributes
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.ModulesProvider.ModuleInfo
|
||||
import org.jetbrains.kotlin.konan.library.KONAN_STDLIB_NAME
|
||||
import org.jetbrains.kotlin.library.SerializedMetadata
|
||||
@@ -18,8 +17,8 @@ internal class NativeDistributionModulesProvider(libraries: Collection<NativeLib
|
||||
name: String,
|
||||
originalLocation: File,
|
||||
val dependencies: Set<String>,
|
||||
cInteropAttributes: CInteropModuleAttributes?
|
||||
) : ModuleInfo(name, originalLocation, cInteropAttributes)
|
||||
isCInterop: Boolean
|
||||
) : ModuleInfo(name, originalLocation, isCInterop)
|
||||
|
||||
private val libraryMap: Map<String, NativeLibrary>
|
||||
private val moduleInfoMap: Map<String, NativeModuleInfo>
|
||||
@@ -35,12 +34,8 @@ internal class NativeDistributionModulesProvider(libraries: Collection<NativeLib
|
||||
val location = File(library.library.libraryFile.path)
|
||||
val dependencies = manifestData.dependencies.toSet()
|
||||
|
||||
val cInteropAttributes = if (manifestData.isInterop) {
|
||||
CInteropModuleAttributes(manifestData.exportForwardDeclarations)
|
||||
} else null
|
||||
|
||||
libraryMap.put(name, library)?.let { error("Duplicated libraries: $name") }
|
||||
moduleInfoMap[name] = NativeModuleInfo(name, location, dependencies, cInteropAttributes)
|
||||
moduleInfoMap[name] = NativeModuleInfo(name, location, dependencies, manifestData.isInterop)
|
||||
}
|
||||
|
||||
this.libraryMap = libraryMap
|
||||
|
||||
-25
@@ -6,13 +6,10 @@
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import gnu.trove.THashSet
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirEntityId
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderKotlinNativeSyntheticPackages
|
||||
|
||||
class CirKnownClassifiers(
|
||||
val commonizedNodes: CirCommonizedClassifierNodes,
|
||||
val forwardDeclarations: CirForwardDeclarations,
|
||||
val commonDependencies: CirProvidedClassifiers
|
||||
)
|
||||
|
||||
@@ -46,25 +43,3 @@ interface CirCommonizedClassifierNodes {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A set of all exported forward declaration classes/objects/structs. */
|
||||
interface CirForwardDeclarations {
|
||||
/* Accessors */
|
||||
fun isExportedForwardDeclaration(classId: CirEntityId): Boolean
|
||||
|
||||
/* Mutators */
|
||||
fun addExportedForwardDeclaration(classId: CirEntityId)
|
||||
|
||||
companion object {
|
||||
fun default() = object : CirForwardDeclarations {
|
||||
private val exportedForwardDeclarations = THashSet<CirEntityId>()
|
||||
|
||||
override fun isExportedForwardDeclaration(classId: CirEntityId) = classId in exportedForwardDeclarations
|
||||
|
||||
override fun addExportedForwardDeclaration(classId: CirEntityId) {
|
||||
check(classId.packageName.isUnderKotlinNativeSyntheticPackages)
|
||||
exportedForwardDeclarations += classId
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -47,7 +47,7 @@ internal class CirProvidedClassifiersByModules private constructor(
|
||||
var hasForwardDeclarations = false
|
||||
|
||||
modulesProvider.loadModuleInfos().forEach { moduleInfo ->
|
||||
if (moduleInfo.cInteropAttributes != null) {
|
||||
if (moduleInfo.isCInterop) {
|
||||
// this is a C-interop module
|
||||
hasForwardDeclarations = true
|
||||
}
|
||||
|
||||
+1
-20
@@ -88,9 +88,6 @@ class CirTreeMerger(
|
||||
private fun processRoot(): CirTreeMergeResult {
|
||||
val rootNode: CirRootNode = buildRootNode(storageManager, leafTargetsSize)
|
||||
|
||||
// remember any exported forward declarations from common fragments of dependee modules
|
||||
parameters.dependencyModulesProvider?.loadModuleInfos()?.forEach(::processCInteropModuleAttributes)
|
||||
|
||||
val commonModuleNames = parameters.getCommonModuleNames()
|
||||
val missingModuleInfosByTargets = mutableMapOf<LeafCommonizerTarget, Collection<ModuleInfo>>()
|
||||
|
||||
@@ -138,18 +135,15 @@ class CirTreeMerger(
|
||||
commonModuleInfos.forEach { moduleInfo ->
|
||||
val metadata = targetProvider.modulesProvider.loadModuleMetadata(moduleInfo.name)
|
||||
val module = KlibModuleMetadata.read(SerializedMetadataLibraryProvider(metadata))
|
||||
processModule(context, rootNode, moduleInfo, module)
|
||||
processModule(context, rootNode, module)
|
||||
}
|
||||
}
|
||||
|
||||
private fun processModule(
|
||||
context: CirTreeMergingContext,
|
||||
rootNode: CirRootNode,
|
||||
moduleInfo: ModuleInfo,
|
||||
module: KlibModuleMetadata
|
||||
) {
|
||||
processCInteropModuleAttributes(moduleInfo)
|
||||
|
||||
val moduleName: CirName = CirName.create(module.name)
|
||||
val moduleNode: CirModuleNode = rootNode.modules.getOrPut(moduleName) {
|
||||
buildModuleNode(storageManager, leafTargetsSize)
|
||||
@@ -345,19 +339,6 @@ class CirTreeMerger(
|
||||
typeResolver = context.typeResolver
|
||||
)
|
||||
}
|
||||
|
||||
private fun processCInteropModuleAttributes(moduleInfo: ModuleInfo) {
|
||||
val cInteropAttributes = moduleInfo.cInteropAttributes ?: return
|
||||
val exportForwardDeclarations = cInteropAttributes.exportForwardDeclarations.takeIf { it.isNotEmpty() } ?: return
|
||||
|
||||
exportForwardDeclarations.forEach { classFqName ->
|
||||
// Class has synthetic package FQ name (cnames/objcnames). Need to transfer it to the main package.
|
||||
val packageName = CirPackageName.create(classFqName.substringBeforeLast('.', missingDelimiterValue = ""))
|
||||
val className = CirName.create(classFqName.substringAfterLast('.'))
|
||||
|
||||
classifiers.forwardDeclarations.addExportedForwardDeclaration(CirEntityId.create(packageName, className))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ClassesToProcess {
|
||||
|
||||
-1
@@ -28,7 +28,6 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
|
||||
// reset cache
|
||||
classifiers = CirKnownClassifiers(
|
||||
commonizedNodes = CirCommonizedClassifierNodes.default(),
|
||||
forwardDeclarations = CirForwardDeclarations.default(),
|
||||
commonDependencies = object : CirProvidedClassifiers {
|
||||
override fun hasClassifier(classifierId: CirEntityId) = classifierId.packageName.isUnderStandardKotlinPackages
|
||||
override fun classifier(classifierId: CirEntityId) = error("This method should not be called")
|
||||
|
||||
@@ -78,10 +78,6 @@ internal val MOCK_CLASSIFIERS = CirKnownClassifiers(
|
||||
override fun addClassNode(classId: CirEntityId, node: CirClassNode) = error("This method should not be called")
|
||||
override fun addTypeAliasNode(typeAliasId: CirEntityId, node: CirTypeAliasNode) = error("This method should not be called")
|
||||
},
|
||||
forwardDeclarations = object : CirForwardDeclarations {
|
||||
override fun isExportedForwardDeclaration(classId: CirEntityId) = false
|
||||
override fun addExportedForwardDeclaration(classId: CirEntityId) = error("This method should not be called")
|
||||
},
|
||||
commonDependencies = CirProvidedClassifiers.EMPTY
|
||||
)
|
||||
|
||||
@@ -97,7 +93,7 @@ internal class MockModulesProvider private constructor(
|
||||
return SERIALIZER.serializeModule(module)
|
||||
}
|
||||
|
||||
private fun fakeModuleInfo(name: String) = ModuleInfo(name, File("/tmp/commonizer/mocks/$name"), null)
|
||||
private fun fakeModuleInfo(name: String) = ModuleInfo(name, File("/tmp/commonizer/mocks/$name"), false)
|
||||
|
||||
companion object {
|
||||
@JvmName("createByModuleNames")
|
||||
|
||||
Reference in New Issue
Block a user