[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:
committed by
Space Team
parent
b08df32cac
commit
9ec7218af6
+3
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.moduleData
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||
|
||||
val FirElementWithResolveState.llFirModuleData: LLFirModuleData
|
||||
@@ -49,6 +50,8 @@ class LLFirModuleData(
|
||||
|
||||
override val platform: TargetPlatform get() = ktModule.platform
|
||||
|
||||
override val isCommon: Boolean get() = ktModule.platform.isCommon()
|
||||
|
||||
override val analyzerServices: PlatformDependentAnalyzerServices get() = ktModule.analyzerServices
|
||||
|
||||
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.platform.CommonPlatforms
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||
@@ -392,7 +393,8 @@ private inline fun <F> createSessionsForLegacyMppProject(
|
||||
listOf(),
|
||||
libraryList.friendsDependencies,
|
||||
targetPlatform,
|
||||
analyzerServices
|
||||
analyzerServices,
|
||||
isCommon = true
|
||||
)
|
||||
|
||||
val platformModuleData = FirModuleDataImpl(
|
||||
@@ -401,7 +403,8 @@ private inline fun <F> createSessionsForLegacyMppProject(
|
||||
listOf(commonModuleData),
|
||||
libraryList.friendsDependencies,
|
||||
targetPlatform,
|
||||
analyzerServices
|
||||
analyzerServices,
|
||||
isCommon = false
|
||||
)
|
||||
|
||||
val commonFiles = mutableListOf<F>()
|
||||
@@ -438,7 +441,7 @@ private inline fun <F> createSessionsForHmppProject(
|
||||
): List<SessionWithSources<F>> {
|
||||
val moduleDataForHmppModule = LinkedHashMap<HmppCliModule, FirModuleData>()
|
||||
|
||||
for (module in hmppModuleStructure.modules) {
|
||||
for ((index, module) in hmppModuleStructure.modules.withIndex()) {
|
||||
val dependencies = hmppModuleStructure.dependenciesMap[module]
|
||||
?.map { moduleDataForHmppModule.getValue(it) }
|
||||
.orEmpty()
|
||||
@@ -448,7 +451,8 @@ private inline fun <F> createSessionsForHmppProject(
|
||||
dependsOnDependencies = dependencies,
|
||||
libraryList.friendsDependencies,
|
||||
targetPlatform,
|
||||
analyzerServices
|
||||
analyzerServices,
|
||||
isCommon = index < hmppModuleStructure.modules.size - 1
|
||||
)
|
||||
moduleDataForHmppModule[module] = moduleData
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
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
|
||||
* 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
|
||||
*
|
||||
* 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 val name: Name
|
||||
@@ -45,6 +49,7 @@ abstract class FirModuleData : FirSessionComponent {
|
||||
abstract val dependsOnDependencies: List<FirModuleData>
|
||||
abstract val friendDependencies: List<FirModuleData>
|
||||
abstract val platform: TargetPlatform
|
||||
abstract val isCommon: Boolean
|
||||
|
||||
// TODO: analyzerServices are needed only as default imports providers
|
||||
// refactor them to make API clearer
|
||||
@@ -77,7 +82,8 @@ class FirModuleDataImpl(
|
||||
override val friendDependencies: List<FirModuleData>,
|
||||
override val platform: TargetPlatform,
|
||||
override val analyzerServices: PlatformDependentAnalyzerServices,
|
||||
override val capabilities: FirModuleCapabilities = FirModuleCapabilities.Empty
|
||||
override val capabilities: FirModuleCapabilities = FirModuleCapabilities.Empty,
|
||||
override val isCommon: Boolean = platform.isCommon(),
|
||||
) : FirModuleData()
|
||||
|
||||
val FirSession.nullableModuleData: FirModuleData? by FirSession.nullableSessionComponentAccessor()
|
||||
|
||||
+2
-1
@@ -151,7 +151,8 @@ open class FirFrontendFacade(
|
||||
dependsOnModules,
|
||||
friendModules,
|
||||
mainModule.targetPlatform,
|
||||
mainModule.targetPlatform.getAnalyzerServices()
|
||||
mainModule.targetPlatform.getAnalyzerServices(),
|
||||
isCommon = module.targetPlatform.isCommon(),
|
||||
)
|
||||
|
||||
moduleInfoProvider.registerModuleData(module, moduleData)
|
||||
|
||||
Reference in New Issue
Block a user