[IR] Partial linkage: unify UnlinkedDeclarationsSupport for JS and Native backends
This commit is contained in:
committed by
Space Team
parent
7b9aed25da
commit
a0fdf08b56
+17
-4
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.common.serialization.unlinked
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport.UnlinkedMarkerTypeHandler
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UsedClassifierSymbolStatus.*
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
@@ -20,19 +21,31 @@ import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
|
||||
abstract class BasicUnlinkedDeclarationsSupport : UnlinkedDeclarationsSupport {
|
||||
protected abstract val handler: UnlinkedDeclarationsSupport.UnlinkedMarkerTypeHandler
|
||||
protected abstract val builtIns: IrBuiltIns
|
||||
class UnlinkedDeclarationsSupportImpl(
|
||||
private val builtIns: IrBuiltIns,
|
||||
override val allowUnboundSymbols: Boolean
|
||||
) : UnlinkedDeclarationsSupport {
|
||||
private val handler = object : UnlinkedMarkerTypeHandler {
|
||||
override val unlinkedMarkerType = IrSimpleTypeImpl(
|
||||
classifier = builtIns.anyClass,
|
||||
hasQuestionMark = true,
|
||||
arguments = emptyList(),
|
||||
annotations = emptyList()
|
||||
)
|
||||
|
||||
override fun IrType.isUnlinkedMarkerType(): Boolean = this === unlinkedMarkerType
|
||||
}
|
||||
|
||||
private val usedClassifierSymbols = UsedClassifierSymbols()
|
||||
|
||||
final override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) {
|
||||
override fun markUsedClassifiersExcludingUnlinkedFromFakeOverrideBuilding(fakeOverrideBuilder: FakeOverrideBuilder) {
|
||||
if (!allowUnboundSymbols) return
|
||||
|
||||
val entries = fakeOverrideBuilder.fakeOverrideCandidates
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.backend.common.serialization.metadata.DynamicTypeDes
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataIncrementalSerializer
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -376,7 +377,7 @@ fun getIrModuleInfoForKlib(
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
|
||||
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
|
||||
val unlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(irBuiltIns, allowUnboundSymbols)
|
||||
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(irBuiltIns, allowUnboundSymbols)
|
||||
|
||||
val irLinker = JsIrLinker(
|
||||
currentModule = null,
|
||||
@@ -435,7 +436,7 @@ fun getIrModuleInfoForSourceFiles(
|
||||
}
|
||||
|
||||
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
|
||||
val unlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(irBuiltIns, allowUnboundSymbols)
|
||||
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(irBuiltIns, allowUnboundSymbols)
|
||||
|
||||
val irLinker = JsIrLinker(
|
||||
currentModule = psi2IrContext.moduleDescriptor,
|
||||
|
||||
+3
-8
@@ -7,17 +7,12 @@ package org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder
|
||||
import org.jetbrains.kotlin.backend.common.serialization.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.library.IrLibrary
|
||||
@@ -30,7 +25,7 @@ class JsIrLinker(
|
||||
override val translationPluginContext: TranslationPluginContext?,
|
||||
private val icData: ICData? = null,
|
||||
friendModules: Map<String, Collection<String>> = emptyMap(),
|
||||
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(
|
||||
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(
|
||||
builtIns,
|
||||
allowUnboundSymbols = false
|
||||
),
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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.ir.backend.js.lower.serialization.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.BasicUnlinkedDeclarationsSupport
|
||||
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.IrErrorTypeImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
class JsUnlinkedDeclarationsSupport(
|
||||
override val builtIns: IrBuiltIns,
|
||||
override val allowUnboundSymbols: Boolean
|
||||
) : BasicUnlinkedDeclarationsSupport() {
|
||||
override val handler = object : UnlinkedMarkerTypeHandler {
|
||||
override val unlinkedMarkerType = IrErrorTypeImpl(null, emptyList(), Variance.INVARIANT)
|
||||
override fun IrType.isUnlinkedMarkerType() = this is IrErrorType
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.backend.common.serialization.DescriptorByIdSignature
|
||||
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker
|
||||
import org.jetbrains.kotlin.backend.common.serialization.mangle.descriptor.Ir2DescriptorManglerAdapter
|
||||
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupportImpl
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isForwardDeclarationModule
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isFromInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||
@@ -122,7 +123,7 @@ internal fun Context.psiToIr(
|
||||
config.resolve.includedLibraries.map { it.uniqueName }
|
||||
).associateWith { friendModules }
|
||||
|
||||
val unlinkedDeclarationsSupport = KonanUnlinkedDeclarationsSupport(generatorContext.irBuiltIns, allowUnboundSymbols)
|
||||
val unlinkedDeclarationsSupport = UnlinkedDeclarationsSupportImpl(generatorContext.irBuiltIns, allowUnboundSymbols)
|
||||
|
||||
KonanIrLinker(
|
||||
currentModule = moduleDescriptor,
|
||||
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.BasicUnlinkedDeclarationsSupport
|
||||
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(
|
||||
override val builtIns: IrBuiltIns,
|
||||
override val allowUnboundSymbols: Boolean
|
||||
) : BasicUnlinkedDeclarationsSupport() {
|
||||
override val handler = object : UnlinkedMarkerTypeHandler {
|
||||
override val unlinkedMarkerType = IrSimpleTypeImpl(
|
||||
classifier = builtIns.anyClass,
|
||||
hasQuestionMark = true,
|
||||
arguments = emptyList(),
|
||||
annotations = emptyList()
|
||||
)
|
||||
|
||||
override fun IrType.isUnlinkedMarkerType(): Boolean = this === unlinkedMarkerType
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user