Kapt: add flag kapt.use.jvm.ir for enabling JVM IR support

#KT-49682
This commit is contained in:
Alexander Udalov
2022-05-31 14:39:44 +02:00
parent 65c7a7f939
commit 7e9d7c895a
13 changed files with 133 additions and 44 deletions
@@ -85,11 +85,6 @@ public class JVMConfigurationKeys {
public static final CompilerConfigurationKey<Boolean> IR =
CompilerConfigurationKey.create("IR");
// Temporary option to make it possible to test kapt with JVM IR. As soon as all tests start to pass, it can be removed,
// and the backend (old or IR) will be deduced from the compiler arguments provided by the user.
public static final CompilerConfigurationKey<Boolean> USE_KAPT_WITH_JVM_IR =
CompilerConfigurationKey.create("Enable JVM IR for kapt");
public static final CompilerConfigurationKey<Boolean> USE_PSI_CLASS_FILES_READING =
CompilerConfigurationKey.create("use a slower (PSI-based) class files reading implementation");
@@ -203,10 +203,7 @@ open class JvmIrCodegenFactory(
// We need to compile all files we reference in Klibs
irModuleFragment.files.addAll(dependencies.flatMap { it.files })
if (!input.configuration.getBoolean(JVMConfigurationKeys.DO_NOT_CLEAR_BINDING_CONTEXT) && !input.configuration.getBoolean(
JVMConfigurationKeys.USE_KAPT_WITH_JVM_IR
)
) {
if (!input.configuration.getBoolean(JVMConfigurationKeys.DO_NOT_CLEAR_BINDING_CONTEXT)) {
val originalBindingContext = input.bindingContext as? CleanableBindingContext
?: error("BindingContext should be cleanable in JVM IR to avoid leaking memory: ${input.bindingContext}")
originalBindingContext.clear()
@@ -187,8 +187,7 @@ object GenerationUtils {
configureGenerationState: GenerationState.Builder.() -> Unit = {},
): GenerationState {
val isIrBackend =
(classBuilderFactory.classBuilderMode == ClassBuilderMode.FULL && configuration.getBoolean(JVMConfigurationKeys.IR)) ||
configuration.getBoolean(JVMConfigurationKeys.USE_KAPT_WITH_JVM_IR)
configuration.getBoolean(JVMConfigurationKeys.IR)
val generationState = GenerationState.Builder(
project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext,
configuration