[LL] Set `isMetadataCompilation` correctly for metadata LL FIR sessions - Some of the compiler functionality relies on the relatively new `isMetadataCompilation`, which indicates whether the compiler is performing metadata compilation. In the Analysis API, the property has a slightly different meaning: Instead of a sort of "global mode" of metadata compilation, it should determine whether the specific FIR session is a metadata session. When analyzing common modules, it then signals to the compiler that *this specific module* has to be analyzed as if we were performing metadata compilation. - The commit fixes the LL FIR divergence in the `jvmRecordCommon` metadata diagnostic test. The fix in KT-85626 relies on `isMetadataCompilation` to determine `Vector`'s superclass. ^KT-82220
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirBuiltinsSessionFactory.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirBuiltinsSessionFactory.kt index 77dc212..53651c4 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirBuiltinsSessionFactory.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirBuiltinsSessionFactory.kt
@@ -98,7 +98,7 @@ val languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT registerIdeComponents(project, languageVersionSettings, builtinsModule.contentScope) register(FirLazyDeclarationResolver::class, FirDummyCompilerLazyDeclarationResolver) - registerCommonComponents(languageVersionSettings, isMetadataCompilation = false) + registerCommonComponents(languageVersionSettings, isMetadataCompilation = session.isMetadataSession) registerCommonComponentsAfterExtensionsAreConfigured() registerModuleData(moduleData)
diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirSessionFactory.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirSessionFactory.kt index d8a9b2b..9913f2e 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirSessionFactory.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/factory/LLFirSessionFactory.kt
@@ -303,7 +303,7 @@ registerModuleData(moduleData) registerIdeComponents(project, languageVersionSettings, contentScope) register(FirLazyDeclarationResolver::class, FirDummyCompilerLazyDeclarationResolver) - registerCommonComponents(languageVersionSettings, isMetadataCompilation = false) + registerCommonComponents(languageVersionSettings, isMetadataCompilation = session.isMetadataSession) registerCommonComponentsAfterExtensionsAreConfigured() registerKdocDeserializer() @@ -745,7 +745,7 @@ annotationSearchScope: GlobalSearchScope, ) { registerIdeComponents(project, languageVersionSettings, annotationSearchScope) - registerCommonComponents(languageVersionSettings, isMetadataCompilation = false) + registerCommonComponents(languageVersionSettings, isMetadataCompilation = isMetadataSession) registerResolveComponents(KtRegisteredDiagnosticFactoriesStorage()) }
diff --git a/compiler/fir/analysis-tests/testData/metadataDiagnostic/jvmRecordCommon.ll.kt b/compiler/fir/analysis-tests/testData/metadataDiagnostic/jvmRecordCommon.ll.kt deleted file mode 100644 index e38bf54..0000000 --- a/compiler/fir/analysis-tests/testData/metadataDiagnostic/jvmRecordCommon.ll.kt +++ /dev/null
@@ -1,16 +0,0 @@ -// LL_FIR_DIVERGENCE -// This test was recently introduced in the scope of KT-85626. Unfortunately, the fix doesn't work in the Analysis API out of the box -// because it checks `isMetadataCompilation` for the session, which is only set in compiler mode. -// LL_FIR_DIVERGENCE - -// METADATA_TARGET_PLATFORMS: JVM, JS -// LANGUAGE: +MultiPlatformProjects -// ISSUE: KT-85626 -// WITH_STDLIB -// JVM_TARGET: 17 - -@kotlin.jvm.JvmRecord -data <!MISSING_DEPENDENCY_SUPERCLASS!>class Vector<!>( - <!MISSING_DEPENDENCY_SUPERCLASS!>val x: Float<!>, - <!MISSING_DEPENDENCY_SUPERCLASS!>val y: Float<!>, -)
diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLanguageSettingsComponent.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLanguageSettingsComponent.kt index 8aef532..df704f8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLanguageSettingsComponent.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirLanguageSettingsComponent.kt
@@ -18,5 +18,14 @@ val FirSession.languageVersionSettings: LanguageVersionSettings get() = languageSettingsComponent.languageVersionSettings +/** + * Whether the [FirSession] is used for metadata compilation, as opposed to compilation on a specific platform. + * + * In the compiler mode, the property is effectively global, since only one module is compiled at a time. + * + * In the Analysis API mode, [isMetadataCompilation] indicates whether the [FirSession] is a metadata session. Because the Analysis API can + * analyze multiple modules at the same time, the property does not determine any "global mode" of metadata compilation. Rather, it signals + * to the compiler that *this specific module* has to be analyzed as if we were performing metadata compilation. + */ val FirSession.isMetadataCompilation: Boolean get() = languageSettingsComponent.isMetadataCompilation