[IR, JS] Refactoring: Introduce JsUnlinkedDeclarationsSupport

^KT-50775
This commit is contained in:
Dmitriy Dolovov
2022-01-13 17:26:17 +03:00
parent 0b1a7d05a9
commit 319125607e
7 changed files with 106 additions and 58 deletions
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSerializer
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.*
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
@@ -364,18 +361,18 @@ fun getIrModuleInfoForKlib(
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val unlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(allowUnboundSymbols)
val irLinker =
JsIrLinker(
null,
messageLogger,
irBuiltIns,
symbolTable,
null,
null,
friendModules,
allowUnboundSymbols
)
val irLinker = JsIrLinker(
currentModule = null,
messageLogger = messageLogger,
builtIns = irBuiltIns,
symbolTable = symbolTable,
translationPluginContext = null,
icData = null,
friendModules = friendModules,
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport
)
val deserializedModuleFragmentsToLib = deserializeDependencies(sortedDependencies, irLinker, mainModuleLib, filesToLoad, mapping)
val deserializedModuleFragments = deserializedModuleFragmentsToLib.keys.toList()
@@ -416,18 +413,18 @@ fun getIrModuleInfoForSourceFiles(
}
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
val unlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(allowUnboundSymbols)
val irLinker =
JsIrLinker(
psi2IrContext.moduleDescriptor,
messageLogger,
irBuiltIns,
symbolTable,
feContext,
null,
friendModules,
allowUnboundSymbols
)
val irLinker = JsIrLinker(
currentModule = psi2IrContext.moduleDescriptor,
messageLogger = messageLogger,
builtIns = irBuiltIns,
symbolTable = symbolTable,
translationPluginContext = feContext,
icData = null,
friendModules = friendModules,
unlinkedDeclarationsSupport = unlinkedDeclarationsSupport
)
val deserializedModuleFragmentsToLib = deserializeDependencies(allSortedDependencies, irLinker, null,null, mapping)
val deserializedModuleFragments = deserializedModuleFragmentsToLib.keys.toList()
(irBuiltIns as IrBuiltInsOverDescriptors).functionFactory =
@@ -7,6 +7,7 @@ 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.unlinked.UnlinkedDeclarationsSupport
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
@@ -23,14 +24,13 @@ class JsIrLinker(
override val translationPluginContext: TranslationPluginContext?,
private val icData: ICData? = null,
friendModules: Map<String, Collection<String>> = emptyMap(),
allowUnboundSymbols: Boolean = false
override val unlinkedDeclarationsSupport: UnlinkedDeclarationsSupport = JsUnlinkedDeclarationsSupport(allowUnboundSymbols = false)
) : KotlinIrLinker(
currentModule,
messageLogger,
builtIns,
symbolTable,
emptyList(),
allowUnboundSymbols,
currentModule = currentModule,
messageLogger = messageLogger,
builtIns = builtIns,
symbolTable = symbolTable,
exportedDependencies = emptyList(),
symbolProcessor = { symbol, idSig ->
if (idSig.isLocal) {
symbol.privateSignature = IdSignature.CompositeSignature(IdSignature.FileSignature(fileSymbol), idSig)
@@ -0,0 +1,23 @@
/*
* 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.UnlinkedDeclarationsSupport
import org.jetbrains.kotlin.backend.common.serialization.unlinked.UnlinkedDeclarationsSupport.UnlinkedMarkerTypeHandler
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 allowUnboundSymbols: Boolean) : UnlinkedDeclarationsSupport {
private val handler = object : UnlinkedMarkerTypeHandler {
override val unlinkedMarkerType = IrErrorTypeImpl(null, emptyList(), Variance.INVARIANT)
override fun IrType.isUnlinkedMarkerType() = this is IrErrorType
}
override fun <T : Any> whenUnboundSymbolsAllowed(action: (UnlinkedMarkerTypeHandler) -> T): T? =
if (allowUnboundSymbols) action(handler) else null
}