[Commonizer] Fix: Keep fwd declarations under real names in CirForwardDeclarations cache

This commit is contained in:
Dmitriy Dolovov
2021-02-17 18:13:18 +03:00
parent bc9a791809
commit 79e3ce022f
4 changed files with 5 additions and 9 deletions
@@ -23,7 +23,6 @@ interface ModulesProvider {
)
class CInteropModuleAttributes(
val mainPackageFqName: String,
val exportForwardDeclarations: Collection<String>
)
@@ -45,11 +45,7 @@ internal abstract class NativeDistributionModulesProvider(libraries: Collection<
val dependencies = manifestData.dependencies.toSet()
val cInteropAttributes = if (manifestData.isInterop) {
val packageFqName = manifestData.packageFqName
?: manifestData.shortName?.let { "platform.$it" }
?: manifestData.uniqueName.substringAfter("platform.").let { "platform.$it" }
CInteropModuleAttributes(packageFqName, manifestData.exportForwardDeclarations)
CInteropModuleAttributes(manifestData.exportForwardDeclarations)
} else null
libraryMap.put(name, library)?.let { error("Duplicated libraries: $name") }
@@ -253,12 +253,13 @@ class CirTreeMerger(
private fun processCInteropModuleAttributes(moduleInfo: ModuleInfo) {
val cInteropAttributes = moduleInfo.cInteropAttributes ?: return
val exportForwardDeclarations = cInteropAttributes.exportForwardDeclarations.takeIf { it.isNotEmpty() } ?: return
val mainPackageFqName = CirPackageName.create(cInteropAttributes.mainPackageFqName)
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(mainPackageFqName, className))
classifiers.forwardDeclarations.addExportedForwardDeclaration(CirEntityId.create(packageName, className))
}
}
}
@@ -72,7 +72,7 @@ interface CirForwardDeclarations {
override fun isExportedForwardDeclaration(classId: CirEntityId) = classId in exportedForwardDeclarations
override fun addExportedForwardDeclaration(classId: CirEntityId) {
check(!classId.packageName.isUnderKotlinNativeSyntheticPackages)
check(classId.packageName.isUnderKotlinNativeSyntheticPackages)
exportedForwardDeclarations += classId
}
}