From 983f487f6c9740fb354917e7e3a812afe5ffa4ed Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Mon, 18 Oct 2021 11:23:35 +0200 Subject: [PATCH] [CHERRY PICKED FROM IJ] [kotlin] optimisation: make argument modification for each chunk lazy GitOrigin-RevId: 0f8b66d14f0816a108afa749548420489e875f3b Original commit: https://github.com/JetBrains/intellij-community/commit/1f23948ddbce1069b4deadec64d9c53272d95ae3 --- .../jetbrains/kotlin/jps/build/KotlinChunk.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt index 3f4079b0ab8..a649372de04 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinChunk.kt @@ -45,24 +45,30 @@ class KotlinChunk internal constructor(val context: KotlinCompileContext, val ta private val defaultLanguageVersion = VersionView.RELEASED_VERSION - val compilerArguments = representativeTarget.jpsModuleBuildTarget.module.kotlinCompilerArguments.also { - it.reportOutputFiles = true + val compilerArguments by lazy { + representativeTarget.jpsModuleBuildTarget.module.kotlinCompilerArguments.also { + it.reportOutputFiles = true - // Always report the version to help diagnosing user issues if they submit the compiler output - it.version = true + // Always report the version to help diagnosing user issues if they submit the compiler output + it.version = true - if (it.languageVersion == null) it.languageVersion = defaultLanguageVersion.versionString + if (it.languageVersion == null) it.languageVersion = defaultLanguageVersion.versionString + } } - val langVersion = + val langVersion by lazy { compilerArguments.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: defaultLanguageVersion // use default language version when version string is invalid (todo: report warning?) + } - val apiVersion = + val apiVersion by lazy { compilerArguments.apiVersion?.let { ApiVersion.parse(it) } ?: ApiVersion.createByLanguageVersion(langVersion) // todo: report version parse error? + } - val isEnabled: Boolean = representativeTarget.isEnabled(compilerArguments) + val isEnabled: Boolean by lazy { + representativeTarget.isEnabled(compilerArguments) + } fun shouldRebuild(): Boolean { val buildMetaInfo = representativeTarget.buildMetaInfoFactory.create(compilerArguments)