From 8ca62ad656b3ea69a62e1de7ceee4de5fb9faf6a Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Thu, 5 Oct 2023 12:25:09 +0200 Subject: [PATCH] [KLIB tool] Fail with an adequate error message on IR-less KLIBs ^KT-62341 --- .../kotlin/org/jetbrains/kotlin/cli/klib/main.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt index 824b5d7923e..51f49a985fd 100644 --- a/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt +++ b/kotlin-native/klib/src/main/kotlin/org/jetbrains/kotlin/cli/klib/main.kt @@ -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)