From 51b8e400d9f77afd52741c42c71a872735b66580 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Tue, 9 May 2023 13:18:23 +0300 Subject: [PATCH] [FIR] Sort KtSourceFiles analogously to KtFiles The `IncrementalJsFirKlibCompilerWithScopeExpansionRunnerTestGenerate .testSerializedSubClassAndChangedInterfaces` test fail because the checksums of the `manifest` files don't match after the full recompilation. It happens, because the `b.kt` file may be passed to the compiler before `a.kt`, in which case while generating the data class members the compiler will generate a call to `Any::hashCode` when accessing the hashcode of the `a` property instead of generating a call to the fake override `A::hashCode`. When working with PSI, the compiler sorts the input files to at `KotlinCoreEnvironment.kt:200`. This change removes the flaky behavior by sorting the input files. --- .../jetbrains/kotlin/cli/common/GroupedKtSources.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/GroupedKtSources.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/GroupedKtSources.kt index 2c4c028f3d2..6d5028ec7ba 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/GroupedKtSources.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/GroupedKtSources.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.forAllFiles import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.idea.KotlinFileType +import java.util.TreeSet private const val kotlinFileExtensionWithDot = ".${KotlinFileType.EXTENSION}" private const val javaFileExtensionWithDot = ".${JavaFileType.DEFAULT_EXTENSION}" @@ -35,13 +36,19 @@ fun collectSources( return collectSources(compilerConfiguration, projectEnvironment.project, messageCollector) } +private val ktSourceFileComparator = Comparator { o1, o2 -> + val path1 = o1.path ?: error("Expected a file with a well-defined path") + val path2 = o2.path ?: error("Expected a file with a well-defined path") + path1.compareTo(path2) +} + fun collectSources( compilerConfiguration: CompilerConfiguration, project: Project, messageCollector: MessageCollector ): GroupedKtSources { - val platformSources = linkedSetOf() - val commonSources = linkedSetOf() + val platformSources = TreeSet(ktSourceFileComparator) + val commonSources = TreeSet(ktSourceFileComparator) val sourcesByModuleName = mutableMapOf>() // TODO: the scripts checking should be part of the scripting plugin functionality, as it is implemented now in ScriptingProcessSourcesBeforeCompilingExtension