From d16f33cf5b7d7fd5eb8edd46e39e6bc7b6ebc584 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 4 Sep 2023 15:55:53 +0200 Subject: [PATCH] JVM IR: do not collect all dependency modules in IDE Collecting all modules takes a lot of time in Evaluate Expression in IDE, and it's useless because we then invoke JvmIrLinker to load module headers, but that linker is discarded in the IDE (see `val irProviders` below). #IDEA-329915 --- .../kotlin/analyzer/ModuleInfoUtils.kt | 6 ------ .../kotlin/backend/jvm/JvmIrCodegenFactory.kt | 20 ++++++------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ModuleInfoUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ModuleInfoUtils.kt index bd316e16640..c5031a94500 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ModuleInfoUtils.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/analyzer/ModuleInfoUtils.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.analyzer -import org.jetbrains.kotlin.descriptors.ModuleCapability import org.jetbrains.kotlin.descriptors.ModuleDescriptor val ModuleDescriptor.moduleInfo: ModuleInfo? @@ -24,8 +23,3 @@ internal fun collectAllExpectedByModules(entryModule: ModuleInfo): Set("IsJdk") - -val ModuleDescriptor.hasJdkCapability: Boolean - get() = getCapability(JDK_CAPABILITY) == true diff --git a/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt b/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt index 69bc84f3d83..80d13170961 100644 --- a/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt +++ b/compiler/ir/backend.jvm/entrypoint/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.backend.jvm -import org.jetbrains.kotlin.analyzer.hasJdkCapability import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext @@ -231,20 +230,13 @@ open class JvmIrCodegenFactory( } } - val dependencies = psi2irContext.moduleDescriptor.collectAllDependencyModulesTransitively().map { - val kotlinLibrary = (it.getCapability(KlibModuleOrigin.CAPABILITY) as? DeserializedKlibModuleOrigin)?.library - if (it.hasJdkCapability) { - // For IDE environment only, i.e. when compiling for debugger - // Deserializer for built-ins module should exist because built-in types returned from SDK belong to that module, - // but JDK's built-ins module might not be in current module's dependencies - // We have to ensure that deserializer for built-ins module is created - irLinker.deserializeIrModuleHeader( - it.builtIns.builtInsModule, - null, - _moduleName = it.builtIns.builtInsModule.name.asString() - ) + val dependencies = if (ideCodegenSettings.shouldStubAndNotLinkUnboundSymbols) { + emptyList() + } else { + psi2irContext.moduleDescriptor.collectAllDependencyModulesTransitively().map { + val kotlinLibrary = (it.getCapability(KlibModuleOrigin.CAPABILITY) as? DeserializedKlibModuleOrigin)?.library + irLinker.deserializeIrModuleHeader(it, kotlinLibrary, _moduleName = it.name.asString()) } - irLinker.deserializeIrModuleHeader(it, kotlinLibrary, _moduleName = it.name.asString()) } val irProviders = if (ideCodegenSettings.shouldStubAndNotLinkUnboundSymbols) {