[K/N] deserialize inline functions for header klibs

For header klibs the indices in the cache for the function bodies
are wrong so we instead deserialize the inline functions up-front.
^KT-65443
This commit is contained in:
Johan Bay
2024-01-09 15:43:28 +01:00
committed by Space Cloud
parent 59f0c0464b
commit a481f35450
2 changed files with 6 additions and 3 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.ir.objcinterop.IrObjCOverridabilityCondition
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.library.isHeader
import org.jetbrains.kotlin.library.metadata.DeserializedKlibModuleOrigin
import org.jetbrains.kotlin.library.metadata.KlibModuleOrigin
import org.jetbrains.kotlin.library.metadata.isFromInteropLibrary
@@ -180,7 +181,9 @@ internal fun PsiToIrContext.psiToIr(
val kotlinLibrary = (dependency.getCapability(KlibModuleOrigin.CAPABILITY) as? DeserializedKlibModuleOrigin)?.library
val isFullyCachedLibrary = kotlinLibrary != null &&
config.cachedLibraries.isLibraryCached(kotlinLibrary) && kotlinLibrary != config.libraryToCache?.klib
if (isProducingLibrary || isFullyCachedLibrary)
if (isFullyCachedLibrary && kotlinLibrary?.isHeader == true)
linker.deserializeHeadersWithInlineBodies(dependency, kotlinLibrary)
else if (isProducingLibrary || isFullyCachedLibrary)
linker.deserializeOnlyHeaderModule(dependency, kotlinLibrary)
else
linker.deserializeIrModuleHeader(dependency, kotlinLibrary, dependency.name.asString())
@@ -38,7 +38,8 @@ internal class NativeInlineFunctionResolver(override val context: Context, val g
val packageFragment = function.getPackageFragment()
val moduleDeserializer = context.irLinker.getCachedDeclarationModuleDeserializer(function)
val irFile: IrFile
val (possiblyLoweredFunction, shouldLower) = if (moduleDeserializer != null) {
val functionIsCached = moduleDeserializer != null && function.body == null
val (possiblyLoweredFunction, shouldLower) = if (functionIsCached) {
// The function is cached, get its body from the IR linker.
val (firstAccess, deserializedInlineFunction) = moduleDeserializer.deserializeInlineFunction(function)
generationState.inlineFunctionOrigins[function] = deserializedInlineFunction
@@ -57,7 +58,6 @@ internal class NativeInlineFunctionResolver(override val context: Context, val g
}
if (shouldLower) {
val functionIsCached = moduleDeserializer != null
lower(possiblyLoweredFunction, irFile, functionIsCached)
if (!functionIsCached) {
generationState.inlineFunctionOrigins[function] =