[LL FIR] KT-55329 Support transitive dependsOn dependencies in LL FIR

- In contrast to other kinds of dependencies, `dependsOn` dependencies
  must be followed transitively.
- Add `transitiveDependsOnDependencies` to `KtModule`. These
  dependencies are calculated lazily with a topological sort. They are
  added to the dependency provider when it's built in
  `LLFirSessionFactory`.

^KT-55329 fixed
This commit is contained in:
Marco Pennekamp
2022-12-20 18:41:23 +01:00
committed by teamcity
parent 1803bd36cc
commit d6cb75ca91
15 changed files with 126 additions and 36 deletions
@@ -9,10 +9,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.ProjectScope
import org.jetbrains.kotlin.analysis.project.structure.KtLibraryModule
import org.jetbrains.kotlin.analysis.project.structure.KtLibrarySourceModule
import org.jetbrains.kotlin.analysis.project.structure.KtModule
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
import org.jetbrains.kotlin.analysis.project.structure.*
import org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots
@@ -60,6 +57,8 @@ abstract class KtModuleByCompilerConfiguration(
.map { moduleProvider.getModule(it.moduleName) }
}
val transitiveDependsOnDependencies: List<KtModule> by lazy { computeTransitiveDependsOnDependencies(directDependsOnDependencies) }
val directFriendDependencies: List<KtModule> by lazy(LazyThreadSafetyMode.PUBLICATION) {
buildList {
testModule.friendDependencies.mapTo(this) { moduleProvider.getModule(it.moduleName) }
@@ -140,6 +139,7 @@ private class LibraryByRoots(
override val libraryName: String get() = "Test Library"
override val directRegularDependencies: List<KtModule> get() = emptyList()
override val directDependsOnDependencies: List<KtModule> get() = emptyList()
override val transitiveDependsOnDependencies: List<KtModule> get() = emptyList()
override val directFriendDependencies: List<KtModule> get() = emptyList()
override val contentScope: GlobalSearchScope get() = ProjectScope.getLibrariesScope(project)
override val platform: TargetPlatform get() = module.platform
@@ -14,10 +14,17 @@ import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
import org.jetbrains.kotlin.test.getAnalyzerServices
import java.nio.file.Path
interface KtModuleWithModifiableDependencies {
val directRegularDependencies: MutableList<KtModule>
val directDependsOnDependencies: MutableList<KtModule>
val directFriendDependencies: MutableList<KtModule>
abstract class KtModuleWithModifiableDependencies {
abstract val directRegularDependencies: MutableList<KtModule>
abstract val directDependsOnDependencies: MutableList<KtModule>
abstract val directFriendDependencies: MutableList<KtModule>
/**
* When dependencies are modifiable, transitive `dependsOn` dependencies must be recomputed each time as [directDependsOnDependencies]
* may have been mutated.
*/
val transitiveDependsOnDependencies: List<KtModule>
get() = computeTransitiveDependsOnDependencies(directDependsOnDependencies)
}
class KtSourceModuleImpl(
@@ -26,7 +33,7 @@ class KtSourceModuleImpl(
override val languageVersionSettings: LanguageVersionSettings,
override val project: Project,
override val contentScope: GlobalSearchScope,
) : KtSourceModule, KtModuleWithModifiableDependencies {
) : KtModuleWithModifiableDependencies(), KtSourceModule {
override val analyzerServices: PlatformDependentAnalyzerServices get() = platform.getAnalyzerServices()
override val directRegularDependencies: MutableList<KtModule> = mutableListOf()
@@ -40,7 +47,7 @@ class KtJdkModuleImpl(
override val contentScope: GlobalSearchScope,
override val project: Project,
private val binaryRoots: Collection<Path>,
) : KtSdkModule, KtModuleWithModifiableDependencies {
) : KtModuleWithModifiableDependencies(), KtSdkModule {
override val analyzerServices: PlatformDependentAnalyzerServices
get() = platform.getAnalyzerServices()
@@ -58,7 +65,7 @@ class KtLibraryModuleImpl(
override val project: Project,
private val binaryRoots: Collection<Path>,
override var librarySources: KtLibrarySourceModule?,
) : KtLibraryModule, KtModuleWithModifiableDependencies {
) : KtModuleWithModifiableDependencies(), KtLibraryModule {
override val analyzerServices: PlatformDependentAnalyzerServices get() = platform.getAnalyzerServices()
override fun getBinaryRoots(): Collection<Path> = binaryRoots
@@ -73,7 +80,7 @@ class KtLibrarySourceModuleImpl(
override val contentScope: GlobalSearchScope,
override val project: Project,
override val binaryLibrary: KtLibraryModule,
) : KtLibrarySourceModule, KtModuleWithModifiableDependencies {
) : KtModuleWithModifiableDependencies(), KtLibrarySourceModule {
override val analyzerServices: PlatformDependentAnalyzerServices get() = platform.getAnalyzerServices()
override val directRegularDependencies: MutableList<KtModule> = mutableListOf()