From ee8db2f7607e3ba2df6433f8d21c5a9f7e026edf Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Tue, 3 Nov 2020 15:57:48 +0300 Subject: [PATCH] Escape resolving same library several times in K/N (#3880) --- .../kotlin/library/SearchPathResolver.kt | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt b/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt index 244afda4296..55ba0a44ee3 100644 --- a/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt +++ b/compiler/util-klib/src/org/jetbrains/kotlin/library/SearchPathResolver.kt @@ -132,22 +132,28 @@ abstract class KotlinLibrarySearchPathResolver( } } - override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L { - val givenPath = unresolved.path - try { - val fileSequence = resolutionSequence(givenPath) - val matching = fileSequence - .filterOutPre_1_4_libraries() - .flatMap { libraryComponentBuilder(it, isDefaultLink).asSequence() } - .map { it.takeIf { libraryMatch(it, unresolved) } } - .filterNotNull() + // Default libraries could be resolved several times during findLibraries and resolveDependencies. + // Store already resolved libraries. + private val resolvedLibraries = HashMap() - return matching.firstOrNull() ?: run { - logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.") + override fun resolve(unresolved: UnresolvedLibrary, isDefaultLink: Boolean): L { + return resolvedLibraries.getOrPut(unresolved) { + val givenPath = unresolved.path + try { + val fileSequence = resolutionSequence(givenPath) + val matching = fileSequence + .filterOutPre_1_4_libraries() + .flatMap { libraryComponentBuilder(it, isDefaultLink).asSequence() } + .map { it.takeIf { libraryMatch(it, unresolved) } } + .filterNotNull() + + matching.firstOrNull() ?: run { + logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.") + } + } catch (e: Throwable) { + logger.error("Failed to resolve Kotlin library: $givenPath") + throw e } - } catch (e: Throwable) { - logger.error("Failed to resolve Kotlin library: $givenPath") - throw e } }