[KLIB] Add a reliable mechanism to check if KLIB has IR inside

^KT-62341
This commit is contained in:
Dmitriy Dolovov
2023-10-05 12:21:51 +02:00
committed by Space Team
parent 4b2776e126
commit f276fe6506
3 changed files with 8 additions and 0 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.library.impl.*
class ICData(val icData: List<SerializedIrFile>, val containsErrorCode: Boolean)
class ICKotlinLibrary(private val icData: List<SerializedIrFile>) : IrLibrary {
override val hasIr get() = true
override val dataFlowGraph: ByteArray? = null
private inline fun <K, R : IrTableReader<K>> Array<R?>.itemBytes(fileIndex: Int, key: K, factory: () -> R): ByteArray {
@@ -75,6 +75,7 @@ interface MetadataLibrary {
}
interface IrLibrary {
val hasIr: Boolean
val dataFlowGraph: ByteArray?
fun irDeclaration(index: Int, fileIndex: Int): ByteArray
fun type(index: Int, fileIndex: Int): ByteArray
@@ -89,6 +89,12 @@ class MetadataLibraryImpl(
abstract class IrLibraryImpl(
val access: IrLibraryAccess<IrKotlinLibraryLayout>
) : IrLibrary {
override val hasIr by lazy {
access.inPlace { it: IrKotlinLibraryLayout ->
it.irDir.exists
}
}
override val dataFlowGraph by lazy {
access.inPlace { it: IrKotlinLibraryLayout ->
it.dataFlowGraphFile.let { if (it.exists) it.readBytes() else null }