[K2] Move Analysis perf calculation inside corresponding fronted runner

This way it is easier to understand where `notifyAnalysis*`
methods were called. Also, in K1, we are not including
`checkKotlinPackageUsageFor*` in the analysis time.
This commit is contained in:
Ivan Kylchik
2024-03-04 18:57:52 +01:00
committed by Space Team
parent cbda22ab48
commit 8275c92cd4
3 changed files with 7 additions and 13 deletions
@@ -141,7 +141,6 @@ object FirKotlinToJvmBytecodeCompiler {
} }
private fun CompilationContext.compileModule(): Pair<FirResult, GenerationState>? { private fun CompilationContext.compileModule(): Pair<FirResult, GenerationState>? {
performanceManager?.notifyAnalysisStarted()
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
if (!checkKotlinPackageUsageForPsi(configuration, allSources)) return null if (!checkKotlinPackageUsageForPsi(configuration, allSources)) return null
@@ -149,9 +148,7 @@ object FirKotlinToJvmBytecodeCompiler {
val renderDiagnosticNames = configuration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME) val renderDiagnosticNames = configuration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
val diagnosticsReporter = createPendingReporter(messageCollector) val diagnosticsReporter = createPendingReporter(messageCollector)
val firResult = runFrontend(allSources, diagnosticsReporter, module.getModuleName(), module.getFriendPaths()).also { val firResult = runFrontend(allSources, diagnosticsReporter, module.getModuleName(), module.getFriendPaths())
performanceManager?.notifyAnalysisFinished()
}
if (firResult == null) { if (firResult == null) {
FirDiagnosticsCompilerResultsReporter.reportToMessageCollector(diagnosticsReporter, messageCollector, renderDiagnosticNames) FirDiagnosticsCompilerResultsReporter.reportToMessageCollector(diagnosticsReporter, messageCollector, renderDiagnosticNames)
return null return null
@@ -192,6 +189,9 @@ object FirKotlinToJvmBytecodeCompiler {
rootModuleName: String, rootModuleName: String,
friendPaths: List<String>, friendPaths: List<String>,
): FirResult? { ): FirResult? {
val performanceManager = configuration.get(CLIConfigurationKeys.PERF_MANAGER)
performanceManager?.notifyAnalysisStarted()
val syntaxErrors = ktFiles.fold(false) { errorsFound, ktFile -> val syntaxErrors = ktFiles.fold(false) { errorsFound, ktFile ->
AnalyzerWithCompilerReport.reportSyntaxErrors(ktFile, messageCollector).isHasErrors or errorsFound AnalyzerWithCompilerReport.reportSyntaxErrors(ktFile, messageCollector).isHasErrors or errorsFound
} }
@@ -228,6 +228,7 @@ object FirKotlinToJvmBytecodeCompiler {
} }
outputs.runPlatformCheckers(diagnosticsReporter) outputs.runPlatformCheckers(diagnosticsReporter)
performanceManager?.notifyAnalysisFinished()
return runUnless(syntaxErrors || scriptsInCommonSourcesErrors || diagnosticsReporter.hasErrors) { FirResult(outputs) } return runUnless(syntaxErrors || scriptsInCommonSourcesErrors || diagnosticsReporter.hasErrors) { FirResult(outputs) }
} }
@@ -111,9 +111,6 @@ fun compileModulesUsingFrontendIrAndLightTree(
val renderDiagnosticNames = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME) val renderDiagnosticNames = moduleConfiguration.getBoolean(CLIConfigurationKeys.RENDER_DIAGNOSTIC_INTERNAL_NAME)
val diagnosticsReporter = FirKotlinToJvmBytecodeCompiler.createPendingReporter(messageCollector) val diagnosticsReporter = FirKotlinToJvmBytecodeCompiler.createPendingReporter(messageCollector)
performanceManager?.notifyAnalysisStarted()
val analysisResults = compileModuleToAnalyzedFir( val analysisResults = compileModuleToAnalyzedFir(
compilerInput, compilerInput,
projectEnvironment, projectEnvironment,
@@ -127,8 +124,6 @@ fun compileModulesUsingFrontendIrAndLightTree(
return false return false
} }
performanceManager?.notifyAnalysisFinished()
val mainClassFqName = runIf(moduleConfiguration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) { val mainClassFqName = runIf(moduleConfiguration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) {
findMainClass(analysisResults.outputs.last().fir) findMainClass(analysisResults.outputs.last().fir)
} }
@@ -273,6 +268,7 @@ fun compileModuleToAnalyzedFir(
diagnosticsReporter: BaseDiagnosticsCollector, diagnosticsReporter: BaseDiagnosticsCollector,
performanceManager: CommonCompilerPerformanceManager? performanceManager: CommonCompilerPerformanceManager?
): FirResult { ): FirResult {
performanceManager?.notifyAnalysisStarted()
val moduleConfiguration = input.configuration val moduleConfiguration = input.configuration
var librariesScope = projectEnvironment.getSearchScopeForProjectLibraries() var librariesScope = projectEnvironment.getSearchScopeForProjectLibraries()
@@ -317,6 +313,7 @@ fun compileModuleToAnalyzedFir(
} }
outputs.runPlatformCheckers(diagnosticsReporter) outputs.runPlatformCheckers(diagnosticsReporter)
performanceManager?.notifyAnalysisFinished()
return FirResult(outputs) return FirResult(outputs)
} }
@@ -213,8 +213,6 @@ open class IncrementalFirJvmCompilerRunner(
configuration configuration
) )
performanceManager?.notifyAnalysisStarted()
val analysisResults = val analysisResults =
compileModuleToAnalyzedFir( compileModuleToAnalyzedFir(
compilerInput, compilerInput,
@@ -225,8 +223,6 @@ open class IncrementalFirJvmCompilerRunner(
performanceManager performanceManager
) )
performanceManager?.notifyAnalysisFinished()
// TODO: consider what to do if many compilations find a main class // TODO: consider what to do if many compilations find a main class
if (mainClassFqName == null && configuration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) { if (mainClassFqName == null && configuration.get(JVMConfigurationKeys.OUTPUT_JAR) != null) {
mainClassFqName = findMainClass(analysisResults.outputs.last().fir) mainClassFqName = findMainClass(analysisResults.outputs.last().fir)