From b28120111d98cc9ce70f31266cc81a9ae85015f9 Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Tue, 24 Oct 2023 18:12:46 +0300 Subject: Make using of the compiler single-thread (#3202) --- .../src/main/kotlin/generation/SingleModuleGeneration.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt index 602173f4..0ae6c265 100644 --- a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt +++ b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt @@ -4,7 +4,9 @@ package org.jetbrains.dokka.base.generation +import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.runBlocking import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.DokkaConfiguration @@ -61,11 +63,18 @@ public class SingleModuleGeneration(private val context: DokkaContext) : Generat override val generationName: String = "documentation for ${context.configuration.moduleName}" - public fun createDocumentationModels(): List = runBlocking(Dispatchers.Default) { - context.configuration.sourceSets.parallelMap { sourceSet -> translateSources(sourceSet, context) }.flatten() - .also { modules -> if (modules.isEmpty()) exitGenerationGracefully("Nothing to document") } + /** + * Implementation note: it runs in a separated single thread due to existing support of coroutines (see #2936) + */ + @OptIn(DelicateCoroutinesApi::class) + public fun createDocumentationModels(): List = newSingleThreadContext("Generating documentable model").use { coroutineContext -> // see https://github.com/Kotlin/dokka/issues/3151 + runBlocking(coroutineContext) { + context.configuration.sourceSets.parallelMap { sourceSet -> translateSources(sourceSet, context) }.flatten() + .also { modules -> if (modules.isEmpty()) exitGenerationGracefully("Nothing to document") } + } } + public fun transformDocumentationModelBeforeMerge(modulesFromPlatforms: List): List { return context.plugin() .query { preMergeDocumentableTransformer } -- cgit