From 4bbc4cf9bd72aede06b52cdcb51c1d686950f3dc Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Fri, 19 Apr 2024 14:26:27 +0200 Subject: [PATCH] [CLI] Notify JS IR perf manager when analysis is started and finished #KT-67473 (cherry picked from commit 5bf27f0a4474f17c19e9f974a2d26fcd93aef3dc) --- .../jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index f5367860a5599..2c39ad9b1f20b 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -29,7 +29,6 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageUtil import org.jetbrains.kotlin.cli.js.klib.* -import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.K2JVMCompilerPerformanceManager import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser @@ -275,15 +274,10 @@ class K2JsIrCompiler : CLICompiler() { val outputKlibPath = if (arguments.irProduceKlibFile) outputDir.resolve("$outputName.klib").normalize().absolutePath else outputDirPath - if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) { - sourceModule = processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath) - } else { - sourceModule = processSourceModule(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath) - - if (!sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode) - return OK - } + sourceModule = produceSourceModule(configuration, environmentForJS, libraries, friendLibraries, arguments, outputKlibPath) + if (configuration.get(CommonConfigurationKeys.USE_FIR) != true && !sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode) + return OK } if (!arguments.irProduceJs) return OK @@ -419,13 +413,34 @@ class K2JsIrCompiler : CLICompiler() { return OK } - private fun processSourceModule( + private fun produceSourceModule( + configuration: CompilerConfiguration, + environmentForJS: KotlinCoreEnvironment, + libraries: List, + friendLibraries: List, + arguments: K2JSCompilerArguments, + outputKlibPath: String, + ): ModulesStructure { + val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER) + performanceManager?.notifyAnalysisStarted() + + val sourceModule = if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) { + processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath) + } else { + processSourceModuleWithK1(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath) + } + + return sourceModule + } + + private fun processSourceModuleWithK1( environmentForJS: KotlinCoreEnvironment, libraries: List, friendLibraries: List, arguments: K2JSCompilerArguments, outputKlibPath: String ): ModulesStructure { + val performanceManager = environmentForJS.configuration.get(CLIConfigurationKeys.PERF_MANAGER) lateinit var sourceModule: ModulesStructure do { val analyzerFacade = when (arguments.wasm) { @@ -446,6 +461,7 @@ class K2JsIrCompiler : CLICompiler() { environmentForJS.addKotlinSourceRoots(result.additionalKotlinRoots) } } while (result is JsAnalysisResult.RetryWithAdditionalRoots) + performanceManager?.notifyAnalysisFinished() if (sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode && (arguments.irProduceKlibDir || arguments.irProduceKlibFile)) { val moduleSourceFiles = (sourceModule.mainModule as MainModule.SourceFiles).files @@ -497,6 +513,7 @@ class K2JsIrCompiler : CLICompiler() { outputKlibPath: String ): ModulesStructure { val configuration = environmentForJS.configuration + val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER) val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter() @@ -537,6 +554,7 @@ class K2JsIrCompiler : CLICompiler() { ) } + performanceManager?.notifyAnalysisFinished() if (analyzedOutput.reportCompilationErrors(moduleStructure, diagnosticsReporter, messageCollector)) { throw CompilationErrorException() }