JVM_IR: call serializeIr from a phase
This circumvents the need to run expect/actual resolution on deserialized IR.
This commit is contained in:
committed by
TeamCityServer
parent
0d5fe0b029
commit
50068607b9
-12
@@ -23,10 +23,8 @@ import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrLinker
|
||||
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrFunctionFactory
|
||||
@@ -188,16 +186,6 @@ open class JvmIrCodegenFactory(
|
||||
/* JvmBackendContext creates new unbound symbols, have to resolve them. */
|
||||
ExternalDependenciesGenerator(symbolTable, irProviders).generateUnboundSymbolsAsDependencies()
|
||||
|
||||
if (state.configuration.getBoolean(JVMConfigurationKeys.SERIALIZE_IR)) {
|
||||
for (irFile in irModuleFragment.files) {
|
||||
(irFile.metadata as? MetadataSource.File)?.serializedIr = serializeIrFile(context, irFile)
|
||||
|
||||
for (irClass in irFile.declarations.filterIsInstance<IrClass>()) {
|
||||
(irClass.metadata as? MetadataSource.Class)?.serializedIr = serializeTopLevelIrClass(context, irClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.state.factory.registerSourceFiles(irModuleFragment.files.map(IrFile::getKtFile))
|
||||
|
||||
jvmPhases.invokeToplevel(phaseConfig, context, irModuleFragment)
|
||||
|
||||
@@ -72,7 +72,7 @@ private val arrayConstructorPhase = makeIrFilePhase(
|
||||
description = "Transform `Array(size) { index -> value }` into a loop"
|
||||
)
|
||||
|
||||
private val expectDeclarationsRemovingPhase = makeIrModulePhase(
|
||||
internal val expectDeclarationsRemovingPhase = makeIrModulePhase(
|
||||
::ExpectDeclarationsRemoveLowering,
|
||||
name = "ExpectDeclarationsRemoving",
|
||||
description = "Remove expect declaration from module fragment"
|
||||
@@ -428,6 +428,7 @@ private val jvmLoweringPhases = NamedCompilerPhase(
|
||||
lower = validateIrBeforeLowering then
|
||||
processOptionalAnnotationsPhase then
|
||||
expectDeclarationsRemovingPhase then
|
||||
serializeIrPhase then
|
||||
scriptsToClassesPhase then
|
||||
fileClassPhase then
|
||||
jvmStaticInObjectPhase then
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeCustomPhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.expectDeclarationsRemovingPhase
|
||||
import org.jetbrains.kotlin.backend.jvm.serializeIrFile
|
||||
import org.jetbrains.kotlin.backend.jvm.serializeTopLevelIrClass
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
|
||||
internal val serializeIrPhase = makeCustomPhase<JvmBackendContext, IrModuleFragment>(
|
||||
{ context, irModule -> SerializeIrPhase(context).lower(irModule) },
|
||||
name = "SerializeIr",
|
||||
description = "If specified by compiler options, save serialized IR in class annotations",
|
||||
prerequisite = setOf(expectDeclarationsRemovingPhase),
|
||||
)
|
||||
|
||||
class SerializeIrPhase(val context: JvmBackendContext) : FileLoweringPass {
|
||||
override fun lower(irFile: IrFile) {
|
||||
if (context.state.configuration.getBoolean(JVMConfigurationKeys.SERIALIZE_IR)) {
|
||||
(irFile.metadata as? MetadataSource.File)?.serializedIr = serializeIrFile(context, irFile)
|
||||
|
||||
for (irClass in irFile.declarations.filterIsInstance<IrClass>()) {
|
||||
(irClass.metadata as? MetadataSource.Class)?.serializedIr = serializeTopLevelIrClass(context, irClass)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user