[IR, Native] Refactoring: Introduce KonanUnlinkedDeclarationsSupport
^KT-50775
This commit is contained in:
+4
-2
@@ -106,6 +106,8 @@ internal fun Context.psiToIr(
|
||||
config.resolve.includedLibraries.map { it.uniqueName }
|
||||
).associateWith { friendModules }
|
||||
|
||||
val unlinkedDeclarationsSupport = KonanUnlinkedDeclarationsSupport(generatorContext.irBuiltIns, allowUnboundSymbols)
|
||||
|
||||
KonanIrLinker(
|
||||
currentModule = moduleDescriptor,
|
||||
translationPluginContext = translationContext,
|
||||
@@ -119,8 +121,8 @@ internal fun Context.psiToIr(
|
||||
exportedDependencies = exportedDependencies,
|
||||
cachedLibraries = config.cachedLibraries,
|
||||
lazyIrForCaches = config.lazyIrForCaches,
|
||||
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport,
|
||||
allowUnboundSymbols = allowUnboundSymbols
|
||||
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport,
|
||||
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport
|
||||
).also { linker ->
|
||||
|
||||
// context.config.librariesWithDependencies could change at each iteration.
|
||||
|
||||
+3
-2
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.backend.common.serialization.encodings.BinaryNameAnd
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.FunctionFlags
|
||||
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.UserVisibleIrModulesSupport
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.ClassLayoutBuilder
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
|
||||
@@ -321,8 +322,8 @@ internal class KonanIrLinker(
|
||||
exportedDependencies: List<ModuleDescriptor>,
|
||||
private val cachedLibraries: CachedLibraries,
|
||||
private val lazyIrForCaches: Boolean,
|
||||
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport,
|
||||
allowUnboundSymbols: Boolean // TODO
|
||||
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport,
|
||||
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport
|
||||
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
|
||||
|
||||
companion object {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport.UnlinkedMarkerTypeHandler
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
|
||||
/**
|
||||
* Kotlin/Native backend does not support [IrErrorType].
|
||||
* So, let's use a special instance of nullable [kotlin.Any] as a marker-type instead.
|
||||
*/
|
||||
class KonanUnlinkedDeclarationsSupport(irBuiltIns: IrBuiltIns, override val allowUnboundSymbols: Boolean) : UnlinkedDeclarationsSupport {
|
||||
private val handler = object : UnlinkedMarkerTypeHandler {
|
||||
override val unlinkedMarkerType = IrSimpleTypeImpl(
|
||||
classifier = irBuiltIns.anyClass,
|
||||
hasQuestionMark = true,
|
||||
arguments = emptyList(),
|
||||
annotations = emptyList()
|
||||
)
|
||||
|
||||
override fun IrType.isUnlinkedMarkerType(): Boolean = this === unlinkedMarkerType
|
||||
}
|
||||
|
||||
override fun <T : Any> whenUnboundSymbolsAllowed(action: (UnlinkedMarkerTypeHandler) -> T): T? =
|
||||
if (allowUnboundSymbols) action(handler) else null
|
||||
}
|
||||
Reference in New Issue
Block a user