Skip to content

Commit

Permalink
[CLI] Notify JS IR perf manager when analysis is started and finished
Browse files Browse the repository at this point in the history
#KT-67473

(cherry picked from commit 5bf27f0)
  • Loading branch information
ivandev0 authored and qodana-bot committed Apr 30, 2024
1 parent 3b5b98a commit 4bbc4cf
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -275,15 +274,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
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
Expand Down Expand Up @@ -419,13 +413,34 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
return OK
}

private fun processSourceModule(
private fun produceSourceModule(
configuration: CompilerConfiguration,
environmentForJS: KotlinCoreEnvironment,
libraries: List<String>,
friendLibraries: List<String>,
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<String>,
friendLibraries: List<String>,
arguments: K2JSCompilerArguments,
outputKlibPath: String
): ModulesStructure {
val performanceManager = environmentForJS.configuration.get(CLIConfigurationKeys.PERF_MANAGER)
lateinit var sourceModule: ModulesStructure
do {
val analyzerFacade = when (arguments.wasm) {
Expand All @@ -446,6 +461,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
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
Expand Down Expand Up @@ -497,6 +513,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
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()

Expand Down Expand Up @@ -537,6 +554,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
)
}

performanceManager?.notifyAnalysisFinished()
if (analyzedOutput.reportCompilationErrors(moduleStructure, diagnosticsReporter, messageCollector)) {
throw CompilationErrorException()
}
Expand Down

0 comments on commit 4bbc4cf

Please sign in to comment.