Skip to content

Commit 4bbc4cf

Browse files
ivandev0Space Team
authored and
Space Team
committed
[CLI] Notify JS IR perf manager when analysis is started and finished
#KT-67473 (cherry picked from commit 5bf27f0)
1 parent 3b5b98a commit 4bbc4cf

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt

+28-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
2929
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
3030
import org.jetbrains.kotlin.cli.common.messages.MessageUtil
3131
import org.jetbrains.kotlin.cli.js.klib.*
32-
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.K2JVMCompilerPerformanceManager
3332
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
3433
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
3534
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
@@ -275,15 +274,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
275274
val outputKlibPath =
276275
if (arguments.irProduceKlibFile) outputDir.resolve("$outputName.klib").normalize().absolutePath
277276
else outputDirPath
278-
if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) {
279-
sourceModule = processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
280-
} else {
281-
sourceModule = processSourceModule(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
282-
283-
if (!sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode)
284-
return OK
285-
}
277+
sourceModule = produceSourceModule(configuration, environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
286278

279+
if (configuration.get(CommonConfigurationKeys.USE_FIR) != true && !sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode)
280+
return OK
287281
}
288282

289283
if (!arguments.irProduceJs) return OK
@@ -419,13 +413,34 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
419413
return OK
420414
}
421415

422-
private fun processSourceModule(
416+
private fun produceSourceModule(
417+
configuration: CompilerConfiguration,
418+
environmentForJS: KotlinCoreEnvironment,
419+
libraries: List<String>,
420+
friendLibraries: List<String>,
421+
arguments: K2JSCompilerArguments,
422+
outputKlibPath: String,
423+
): ModulesStructure {
424+
val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER)
425+
performanceManager?.notifyAnalysisStarted()
426+
427+
val sourceModule = if (configuration.get(CommonConfigurationKeys.USE_FIR) == true) {
428+
processSourceModuleWithK2(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
429+
} else {
430+
processSourceModuleWithK1(environmentForJS, libraries, friendLibraries, arguments, outputKlibPath)
431+
}
432+
433+
return sourceModule
434+
}
435+
436+
private fun processSourceModuleWithK1(
423437
environmentForJS: KotlinCoreEnvironment,
424438
libraries: List<String>,
425439
friendLibraries: List<String>,
426440
arguments: K2JSCompilerArguments,
427441
outputKlibPath: String
428442
): ModulesStructure {
443+
val performanceManager = environmentForJS.configuration.get(CLIConfigurationKeys.PERF_MANAGER)
429444
lateinit var sourceModule: ModulesStructure
430445
do {
431446
val analyzerFacade = when (arguments.wasm) {
@@ -446,6 +461,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
446461
environmentForJS.addKotlinSourceRoots(result.additionalKotlinRoots)
447462
}
448463
} while (result is JsAnalysisResult.RetryWithAdditionalRoots)
464+
performanceManager?.notifyAnalysisFinished()
449465

450466
if (sourceModule.jsFrontEndResult.jsAnalysisResult.shouldGenerateCode && (arguments.irProduceKlibDir || arguments.irProduceKlibFile)) {
451467
val moduleSourceFiles = (sourceModule.mainModule as MainModule.SourceFiles).files
@@ -497,6 +513,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
497513
outputKlibPath: String
498514
): ModulesStructure {
499515
val configuration = environmentForJS.configuration
516+
val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER)
500517
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
501518
val diagnosticsReporter = DiagnosticReporterFactory.createPendingReporter()
502519

@@ -537,6 +554,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
537554
)
538555
}
539556

557+
performanceManager?.notifyAnalysisFinished()
540558
if (analyzedOutput.reportCompilationErrors(moduleStructure, diagnosticsReporter, messageCollector)) {
541559
throw CompilationErrorException()
542560
}

0 commit comments

Comments
 (0)