[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 }
|
config.resolve.includedLibraries.map { it.uniqueName }
|
||||||
).associateWith { friendModules }
|
).associateWith { friendModules }
|
||||||
|
|
||||||
|
val unlinkedDeclarationsSupport = KonanUnlinkedDeclarationsSupport(generatorContext.irBuiltIns, allowUnboundSymbols)
|
||||||
|
|
||||||
KonanIrLinker(
|
KonanIrLinker(
|
||||||
currentModule = moduleDescriptor,
|
currentModule = moduleDescriptor,
|
||||||
translationPluginContext = translationContext,
|
translationPluginContext = translationContext,
|
||||||
@@ -119,8 +121,8 @@ internal fun Context.psiToIr(
|
|||||||
exportedDependencies = exportedDependencies,
|
exportedDependencies = exportedDependencies,
|
||||||
cachedLibraries = config.cachedLibraries,
|
cachedLibraries = config.cachedLibraries,
|
||||||
lazyIrForCaches = config.lazyIrForCaches,
|
lazyIrForCaches = config.lazyIrForCaches,
|
||||||
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport,
|
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport,
|
||||||
allowUnboundSymbols = allowUnboundSymbols
|
userVisibleIrModulesSupport = config.userVisibleIrModulesSupport
|
||||||
).also { linker ->
|
).also { linker ->
|
||||||
|
|
||||||
// context.config.librariesWithDependencies could change at each iteration.
|
// 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.BinarySymbolData
|
||||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.FunctionFlags
|
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.linkerissues.UserVisibleIrModulesSupport
|
||||||
|
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
|
||||||
import org.jetbrains.kotlin.backend.konan.*
|
import org.jetbrains.kotlin.backend.konan.*
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.ClassLayoutBuilder
|
import org.jetbrains.kotlin.backend.konan.descriptors.ClassLayoutBuilder
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
|
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
|
||||||
@@ -321,8 +322,8 @@ internal class KonanIrLinker(
|
|||||||
exportedDependencies: List<ModuleDescriptor>,
|
exportedDependencies: List<ModuleDescriptor>,
|
||||||
private val cachedLibraries: CachedLibraries,
|
private val cachedLibraries: CachedLibraries,
|
||||||
private val lazyIrForCaches: Boolean,
|
private val lazyIrForCaches: Boolean,
|
||||||
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport,
|
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport,
|
||||||
allowUnboundSymbols: Boolean // TODO
|
override val userVisibleIrModulesSupport: UserVisibleIrModulesSupport
|
||||||
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
|
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
|
||||||
|
|
||||||
companion object {
|
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