[KLIB tool] Fail with an adequate error message on IR-less KLIBs

^KT-62341
This commit is contained in:
Dmitriy Dolovov
2023-10-05 12:25:09 +02:00
committed by Space Team
parent f276fe6506
commit 8ca62ad656
@@ -255,20 +255,24 @@ class Library(val libraryNameOrPath: String, val requestedRepository: String?) {
@OptIn(ObsoleteDescriptorBasedAPI::class)
fun ir(output: Appendable, printSignatures: Boolean) {
val module = loadModule()
if (module.kotlinLibrary.isInterop) error("Deserializing IR from IR-less libraries is not supported yet")
val library = module.kotlinLibrary
checkLibraryHasIr(library)
val versionSpec = LanguageVersionSettingsImpl(currentLanguageVersion, currentApiVersion)
val idSignaturer = KonanIdSignaturer(KonanManglerDesc)
val symbolTable = SymbolTable(idSignaturer, IrFactoryImpl)
val typeTranslator = TypeTranslatorImpl(symbolTable, versionSpec, module)
val irBuiltIns = IrBuiltInsOverDescriptors(module.builtIns, typeTranslator, symbolTable)
val linker = KlibToolLinker(module, irBuiltIns, symbolTable)
module.allDependencyModules.forEach {
linker.deserializeOnlyHeaderModule(it, it.kotlinLibrary)
linker.resolveModuleDeserializer(it, null).init()
}
val irFragment = linker.deserializeFullModule(module, module.kotlinLibrary)
val irFragment = linker.deserializeFullModule(module, library)
linker.resolveModuleDeserializer(module, null).init()
linker.modulesWithReachableTopLevels.forEach(IrModuleDeserializer::deserializeReachableDeclarations)
output.append(irFragment.dump(DumpIrTreeOptions(printSignatures = printSignatures)))
}
@@ -291,12 +295,17 @@ class Library(val libraryNameOrPath: String, val requestedRepository: String?) {
fun dumpIrSignatures(output: Appendable, signatureVersion: KotlinIrSignatureVersion?) {
val library = libraryInCurrentDir(libraryNameOrPath)
checkLibraryHasIr(library)
signatureVersion?.checkSupportedInLibrary(library)
val signatures = IrSignaturesExtractor(library).extract()
IrSignaturesRenderer(output, signatureVersion).render(signatures)
}
private fun checkLibraryHasIr(library: KotlinLibrary) {
if (!library.hasIr) error("Library ${library.libraryFile} is an IR-less library.")
}
private fun KotlinIrSignatureVersion.checkSupportedInLibrary(library: KotlinLibrary) {
val supportedSignatureVersions = library.versions.irSignatureVersions
if (this !in supportedSignatureVersions)