From bb7625c5b0c318aa8ea4e2cd3cb9fd7635419923 Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Tue, 9 May 2023 12:58:49 +0200 Subject: [PATCH] [LL FIR] KT-58325 Fix test library discoverability for combined Kotlin symbol providers - An LL FIR test failed after merging stub-based deserialized symbol providers into combined Kotlin symbol providers: `DiagnosticCompilerTestFE10TestdataTestGenerated.TestsWithStdLib.Multiplatform.testJvmOverloads` - Cause: The combined Kotlin symbol provider was able to find a class for `JvmOverloads`. However, the `KtModule` of `JvmOverloads` was `LibraryByRoots` with just the stdlib, while the registered stub-based deserialized symbol provider was known to the combined symbol provider with a `LibraryByRoots` containing 6 different paths. Hence, the single-root module wasn't found in the provider map. - The fix creates a `LibraryByRoot` for each root, which leads to a separate deserialized symbol provider for each of the six roots, solving the discoverability problem. --- .../KtSourceModuleByCompilerConfiguration.kt | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtSourceModuleByCompilerConfiguration.kt b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtSourceModuleByCompilerConfiguration.kt index 7dd67a13008..d69ec9d0147 100644 --- a/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtSourceModuleByCompilerConfiguration.kt +++ b/analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/project/structure/KtSourceModuleByCompilerConfiguration.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.test.getAnalyzerServices import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.compilerConfigurationProvider -import org.jetbrains.kotlin.utils.addIfNotNull import java.io.File import java.nio.file.Path import java.nio.file.Paths @@ -44,8 +43,8 @@ abstract class KtModuleByCompilerConfiguration( val directRegularDependencies: List by lazy(LazyThreadSafetyMode.PUBLICATION) { buildList { testModule.allDependencies.mapTo(this) { moduleProvider.getModule(it.moduleName) } - addIfNotNull( - libraryByRoots( + addAll( + librariesByRoots( (configuration.jvmModularRoots + configuration.jvmClasspathRoots).map(File::toPath) ) ) @@ -62,22 +61,15 @@ abstract class KtModuleByCompilerConfiguration( val directFriendDependencies: List by lazy(LazyThreadSafetyMode.PUBLICATION) { buildList { testModule.friendDependencies.mapTo(this) { moduleProvider.getModule(it.moduleName) } - addIfNotNull( - libraryByRoots(configuration[JVMConfigurationKeys.FRIEND_PATHS].orEmpty().map(Paths::get)) + addAll( + librariesByRoots(configuration[JVMConfigurationKeys.FRIEND_PATHS].orEmpty().map(Paths::get)) ) } } protected abstract val ktModule: KtModule - private fun libraryByRoots(roots: List): LibraryByRoots? { - if (roots.isEmpty()) return null - return LibraryByRoots( - roots, - ktModule, - project, - ) - } + private fun librariesByRoots(roots: List): List = roots.map { LibraryByRoot(it, ktModule, project) } val languageVersionSettings: LanguageVersionSettings get() = testModule.languageVersionSettings @@ -131,33 +123,33 @@ class KtLibrarySourceModuleByCompilerConfiguration( override val libraryName: String get() = testModule.name } -private class LibraryByRoots( - private val roots: List, - private val module: KtModule, +private class LibraryByRoot( + private val root: Path, + private val parentModule: KtModule, override val project: Project, ) : KtLibraryModule { - override val libraryName: String get() = "Test Library" + override val libraryName: String get() = "Test Library $root" override val directRegularDependencies: List get() = emptyList() override val directDependsOnDependencies: List get() = emptyList() override val transitiveDependsOnDependencies: List get() = emptyList() override val directFriendDependencies: List get() = emptyList() override val contentScope: GlobalSearchScope get() = ProjectScope.getLibrariesScope(project) - override val platform: TargetPlatform get() = module.platform - override val analyzerServices: PlatformDependentAnalyzerServices get() = module.analyzerServices - override fun getBinaryRoots(): Collection = roots + override val platform: TargetPlatform get() = parentModule.platform + override val analyzerServices: PlatformDependentAnalyzerServices get() = parentModule.analyzerServices + override fun getBinaryRoots(): Collection = listOf(root) + override fun equals(other: Any?): Boolean { if (this === other) return true if (javaClass != other?.javaClass) return false - other as LibraryByRoots + other as LibraryByRoot - return roots == other.roots + return root == other.root } override fun hashCode(): Int { - return roots.hashCode() + return root.hashCode() } override val librarySources: KtLibrarySourceModule? get() = null } -