[FIR] Add isCommon property to FirModuleData

It will be used for correct OPTIONAL_DECLARATION_USAGE_IN_NON_COMMON_SOURCE reporting
This commit is contained in:
Ivan Kochurkin
2023-08-09 14:52:19 +02:00
committed by Space Team
parent b08df32cac
commit 9ec7218af6
4 changed files with 20 additions and 6 deletions
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.moduleData
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
val FirElementWithResolveState.llFirModuleData: LLFirModuleData val FirElementWithResolveState.llFirModuleData: LLFirModuleData
@@ -49,6 +50,8 @@ class LLFirModuleData(
override val platform: TargetPlatform get() = ktModule.platform override val platform: TargetPlatform get() = ktModule.platform
override val isCommon: Boolean get() = ktModule.platform.isCommon()
override val analyzerServices: PlatformDependentAnalyzerServices get() = ktModule.analyzerServices override val analyzerServices: PlatformDependentAnalyzerServices get() = ktModule.analyzerServices
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.load.kotlin.PackageAndMetadataPartProvider
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.CommonPlatforms import org.jetbrains.kotlin.platform.CommonPlatforms
import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
import org.jetbrains.kotlin.platform.konan.NativePlatforms import org.jetbrains.kotlin.platform.konan.NativePlatforms
@@ -392,7 +393,8 @@ private inline fun <F> createSessionsForLegacyMppProject(
listOf(), listOf(),
libraryList.friendsDependencies, libraryList.friendsDependencies,
targetPlatform, targetPlatform,
analyzerServices analyzerServices,
isCommon = true
) )
val platformModuleData = FirModuleDataImpl( val platformModuleData = FirModuleDataImpl(
@@ -401,7 +403,8 @@ private inline fun <F> createSessionsForLegacyMppProject(
listOf(commonModuleData), listOf(commonModuleData),
libraryList.friendsDependencies, libraryList.friendsDependencies,
targetPlatform, targetPlatform,
analyzerServices analyzerServices,
isCommon = false
) )
val commonFiles = mutableListOf<F>() val commonFiles = mutableListOf<F>()
@@ -438,7 +441,7 @@ private inline fun <F> createSessionsForHmppProject(
): List<SessionWithSources<F>> { ): List<SessionWithSources<F>> {
val moduleDataForHmppModule = LinkedHashMap<HmppCliModule, FirModuleData>() val moduleDataForHmppModule = LinkedHashMap<HmppCliModule, FirModuleData>()
for (module in hmppModuleStructure.modules) { for ((index, module) in hmppModuleStructure.modules.withIndex()) {
val dependencies = hmppModuleStructure.dependenciesMap[module] val dependencies = hmppModuleStructure.dependenciesMap[module]
?.map { moduleDataForHmppModule.getValue(it) } ?.map { moduleDataForHmppModule.getValue(it) }
.orEmpty() .orEmpty()
@@ -448,7 +451,8 @@ private inline fun <F> createSessionsForHmppProject(
dependsOnDependencies = dependencies, dependsOnDependencies = dependencies,
libraryList.friendsDependencies, libraryList.friendsDependencies,
targetPlatform, targetPlatform,
analyzerServices analyzerServices,
isCommon = index < hmppModuleStructure.modules.size - 1
) )
moduleDataForHmppModule[module] = moduleData moduleDataForHmppModule[module] = moduleData
} }
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.platform.isCommon
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
/** /**
@@ -38,6 +39,9 @@ import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
* of IO operations and false matches. To solve this problem we use single session for all dependencies with single deserialized * of IO operations and false matches. To solve this problem we use single session for all dependencies with single deserialized
* symbol provider. And during creation FIR for some declaration symbol provider chose which module this declaration will belong to * symbol provider. And during creation FIR for some declaration symbol provider chose which module this declaration will belong to
* basing on path of this declaration and passed compiler arguments * basing on path of this declaration and passed compiler arguments
*
* With MPP mode, all modules have the same platform, but some checkers need info about whether the current module is common or not.
* For this purpose the flag [isCommon] is used
*/ */
abstract class FirModuleData : FirSessionComponent { abstract class FirModuleData : FirSessionComponent {
abstract val name: Name abstract val name: Name
@@ -45,6 +49,7 @@ abstract class FirModuleData : FirSessionComponent {
abstract val dependsOnDependencies: List<FirModuleData> abstract val dependsOnDependencies: List<FirModuleData>
abstract val friendDependencies: List<FirModuleData> abstract val friendDependencies: List<FirModuleData>
abstract val platform: TargetPlatform abstract val platform: TargetPlatform
abstract val isCommon: Boolean
// TODO: analyzerServices are needed only as default imports providers // TODO: analyzerServices are needed only as default imports providers
// refactor them to make API clearer // refactor them to make API clearer
@@ -77,7 +82,8 @@ class FirModuleDataImpl(
override val friendDependencies: List<FirModuleData>, override val friendDependencies: List<FirModuleData>,
override val platform: TargetPlatform, override val platform: TargetPlatform,
override val analyzerServices: PlatformDependentAnalyzerServices, override val analyzerServices: PlatformDependentAnalyzerServices,
override val capabilities: FirModuleCapabilities = FirModuleCapabilities.Empty override val capabilities: FirModuleCapabilities = FirModuleCapabilities.Empty,
override val isCommon: Boolean = platform.isCommon(),
) : FirModuleData() ) : FirModuleData()
val FirSession.nullableModuleData: FirModuleData? by FirSession.nullableSessionComponentAccessor() val FirSession.nullableModuleData: FirModuleData? by FirSession.nullableSessionComponentAccessor()
@@ -151,7 +151,8 @@ open class FirFrontendFacade(
dependsOnModules, dependsOnModules,
friendModules, friendModules,
mainModule.targetPlatform, mainModule.targetPlatform,
mainModule.targetPlatform.getAnalyzerServices() mainModule.targetPlatform.getAnalyzerServices(),
isCommon = module.targetPlatform.isCommon(),
) )
moduleInfoProvider.registerModuleData(module, moduleData) moduleInfoProvider.registerModuleData(module, moduleData)