[IR] User-friendly message about unexpected unlinked symbols
^KT-53649
This commit is contained in:
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel
|
||||
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.backend.js.codegen.JsGenerationGranularity
|
||||
@@ -21,9 +22,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.noUnboundLeft
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
import org.jetbrains.kotlin.js.config.RuntimeDiagnostic
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.File
|
||||
@@ -95,7 +94,7 @@ fun compileIr(
|
||||
moduleToName: Map<IrModuleFragment, String>,
|
||||
irBuiltIns: IrBuiltIns,
|
||||
symbolTable: SymbolTable,
|
||||
deserializer: JsIrLinker,
|
||||
irLinker: JsIrLinker,
|
||||
phaseConfig: PhaseConfig,
|
||||
exportedDeclarations: Set<FqName>,
|
||||
dceRuntimeDiagnostic: RuntimeDiagnostic?,
|
||||
@@ -114,8 +113,6 @@ fun compileIr(
|
||||
is MainModule.Klib -> dependencyModules
|
||||
}
|
||||
|
||||
val allowUnboundSymbols = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
|
||||
|
||||
val context = JsIrBackendContext(
|
||||
moduleDescriptor,
|
||||
irBuiltIns,
|
||||
@@ -133,13 +130,11 @@ fun compileIr(
|
||||
)
|
||||
|
||||
// Load declarations referenced during `context` initialization
|
||||
val irProviders = listOf(deserializer)
|
||||
val irProviders = listOf(irLinker)
|
||||
ExternalDependenciesGenerator(symbolTable, irProviders).generateUnboundSymbolsAsDependencies()
|
||||
|
||||
deserializer.postProcess()
|
||||
if (!allowUnboundSymbols) {
|
||||
symbolTable.noUnboundLeft("Unbound symbols at the end of linker")
|
||||
}
|
||||
irLinker.postProcess()
|
||||
irLinker.checkNoUnboundSymbols(symbolTable, "at the end of IR linkage process")
|
||||
|
||||
allModules.forEach { module ->
|
||||
collectNativeImplementations(context, module)
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.ir.backend.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaserState
|
||||
import org.jetbrains.kotlin.backend.common.serialization.linkerissues.checkNoUnboundSymbols
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.collectNativeImplementations
|
||||
@@ -17,7 +18,6 @@ import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.noUnboundLeft
|
||||
import org.jetbrains.kotlin.js.config.RuntimeDiagnostic
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
fun compileWithIC(
|
||||
mainModule: IrModuleFragment,
|
||||
configuration: CompilerConfiguration,
|
||||
deserializer: JsIrLinker,
|
||||
irLinker: JsIrLinker,
|
||||
allModules: Collection<IrModuleFragment>,
|
||||
filesToLower: Collection<IrFile>,
|
||||
mainArguments: List<String>? = null,
|
||||
@@ -63,11 +63,11 @@ fun compileWithIC(
|
||||
)
|
||||
|
||||
// Load declarations referenced during `context` initialization
|
||||
val irProviders = listOf(deserializer)
|
||||
val irProviders = listOf(irLinker)
|
||||
ExternalDependenciesGenerator(symbolTable, irProviders).generateUnboundSymbolsAsDependencies()
|
||||
|
||||
deserializer.postProcess()
|
||||
symbolTable.noUnboundLeft("Unbound symbols at the end of linker")
|
||||
irLinker.postProcess()
|
||||
irLinker.checkNoUnboundSymbols(symbolTable, "at the end of IR linkage process")
|
||||
|
||||
allModules.forEach {
|
||||
collectNativeImplementations(context, it)
|
||||
|
||||
@@ -26,7 +26,7 @@ fun interface CacheExecutor {
|
||||
fun execute(
|
||||
mainModule: IrModuleFragment,
|
||||
allModules: Collection<IrModuleFragment>,
|
||||
deserializer: JsIrLinker,
|
||||
irLinker: JsIrLinker,
|
||||
configuration: CompilerConfiguration,
|
||||
dirtyFiles: Collection<IrFile>,
|
||||
exportedDeclarations: Set<FqName>,
|
||||
@@ -87,7 +87,7 @@ class CacheUpdater(
|
||||
val allResolvedDependencies = jsResolveLibraries(
|
||||
allModules,
|
||||
compilerConfiguration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
|
||||
compilerConfiguration[IrMessageLogger.IR_MESSAGE_LOGGER].toResolverLogger()
|
||||
compilerConfiguration.resolverLogger
|
||||
)
|
||||
|
||||
return allResolvedDependencies.getFullList().associateBy { KotlinLibraryFile(it) }
|
||||
@@ -568,7 +568,7 @@ class CacheUpdater(
|
||||
val rebuiltFragments = executor.execute(
|
||||
mainModule = loadedIr.loadedFragments[mainLibraryFile] ?: notFoundIcError("main lib loaded fragment", mainLibraryFile),
|
||||
allModules = loadedIr.loadedFragments.values,
|
||||
deserializer = loadedIr.linker,
|
||||
irLinker = loadedIr.linker,
|
||||
configuration = compilerConfiguration,
|
||||
dirtyFiles = loadedIr.loadedFragments.flatMap { (libFile, libFragment) ->
|
||||
dirtyFileExports[libFile]?.let { libDirtyFiles ->
|
||||
@@ -617,7 +617,7 @@ fun rebuildCacheForDirtyFiles(
|
||||
return currentIrModule to buildCacheForModuleFiles(
|
||||
mainModule = currentIrModule,
|
||||
allModules = irModules.values,
|
||||
deserializer = jsIrLinker,
|
||||
irLinker = jsIrLinker,
|
||||
configuration = configuration,
|
||||
dirtyFiles = dirtyIrFiles,
|
||||
exportedDeclarations = exportedDeclarations,
|
||||
@@ -628,7 +628,7 @@ fun rebuildCacheForDirtyFiles(
|
||||
fun buildCacheForModuleFiles(
|
||||
mainModule: IrModuleFragment,
|
||||
allModules: Collection<IrModuleFragment>,
|
||||
deserializer: JsIrLinker,
|
||||
irLinker: JsIrLinker,
|
||||
configuration: CompilerConfiguration,
|
||||
dirtyFiles: Collection<IrFile>,
|
||||
exportedDeclarations: Set<FqName>,
|
||||
@@ -639,7 +639,7 @@ fun buildCacheForModuleFiles(
|
||||
allModules = allModules,
|
||||
filesToLower = dirtyFiles,
|
||||
configuration = configuration,
|
||||
deserializer = deserializer,
|
||||
irLinker = irLinker,
|
||||
mainArguments = mainArguments,
|
||||
exportedDeclarations = exportedDeclarations,
|
||||
)
|
||||
|
||||
+2
-3
@@ -19,8 +19,8 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.irMessageLogger
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||
@@ -36,13 +36,12 @@ internal class JsIrLinkerLoader(
|
||||
) {
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
private fun createLinker(loadedModules: Map<ModuleDescriptor, KotlinLibrary>): JsIrLinker {
|
||||
val logger = compilerConfiguration[IrMessageLogger.IR_MESSAGE_LOGGER] ?: IrMessageLogger.None
|
||||
val signaturer = IdSignatureDescriptor(JsManglerDesc)
|
||||
val symbolTable = SymbolTable(signaturer, irFactory)
|
||||
val moduleDescriptor = loadedModules.keys.last()
|
||||
val typeTranslator = TypeTranslatorImpl(symbolTable, compilerConfiguration.languageVersionSettings, moduleDescriptor)
|
||||
val irBuiltIns = IrBuiltInsOverDescriptors(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||
return JsIrLinker(null, logger, irBuiltIns, symbolTable, null)
|
||||
return JsIrLinker(null, compilerConfiguration.irMessageLogger, irBuiltIns, symbolTable, null)
|
||||
}
|
||||
|
||||
private fun loadModules(): Map<ModuleDescriptor, KotlinLibrary> {
|
||||
|
||||
Reference in New Issue
Block a user