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