[IR][Serialization] Allow backends to skip files
This change is required for Native interop libraries. For enums and structs we generate full-blown IR classes that should not be serialized because they will be generated anew.
This commit is contained in:
committed by
Sergey Bogolepov
parent
bcf6ee0c0b
commit
208c06516b
+13
-1
@@ -15,12 +15,24 @@ import org.jetbrains.kotlin.library.SerializedIrModule
|
||||
abstract class IrModuleSerializer<F : IrFileSerializer>(protected val logger: LoggingContext) {
|
||||
abstract fun createSerializerForFile(file: IrFile): F
|
||||
|
||||
/**
|
||||
* Allows to skip [file] during serialization.
|
||||
*
|
||||
* For example, some files should be generated anew instead of deserialization.
|
||||
*/
|
||||
protected open fun backendSpecificFileFilter(file: IrFile): Boolean =
|
||||
true
|
||||
|
||||
private fun serializeIrFile(file: IrFile): SerializedIrFile {
|
||||
val fileSerializer = createSerializerForFile(file)
|
||||
return fileSerializer.serializeIrFile(file)
|
||||
}
|
||||
|
||||
fun serializedIrModule(module: IrModuleFragment): SerializedIrModule {
|
||||
return SerializedIrModule(module.files.filter { it.packageFragmentDescriptor !is FunctionInterfacePackageFragment }.map { serializeIrFile(it) })
|
||||
val serializedFiles = module.files
|
||||
.filter { it.packageFragmentDescriptor !is FunctionInterfacePackageFragment }
|
||||
.filter(this::backendSpecificFileFilter)
|
||||
.map(this::serializeIrFile)
|
||||
return SerializedIrModule(serializedFiles)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user