Skip to content

Commit 1499cfb

Browse files
committed
Create compiler arguments and configurations for enabling header mode.
^KT-78422
1 parent e5c6b4f commit 1499cfb

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed

compiler/arguments/resources/kotlin-compiler-arguments.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,6 +3842,37 @@
38423842
"deprecatedVersion": null,
38433843
"removedVersion": null
38443844
}
3845+
},
3846+
{
3847+
"name": "Xheader-mode",
3848+
"shortName": null,
3849+
"deprecatedName": null,
3850+
"description": {
3851+
"current": "Enable header compilation mode.\nIn this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be\ncompiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation\nbuild systems where header libraries can be used to replace downstream dependencies for which we only need to\nsee the type names and method signatures required to compile a given translation unit.",
3852+
"valueInVersions": []
3853+
},
3854+
"delimiter": null,
3855+
"valueType": {
3856+
"type": "org.jetbrains.kotlin.arguments.dsl.types.BooleanType",
3857+
"isNullable": {
3858+
"current": false,
3859+
"valueInVersions": []
3860+
},
3861+
"defaultValue": {
3862+
"current": false,
3863+
"valueInVersions": []
3864+
}
3865+
},
3866+
"valueDescription": {
3867+
"current": null,
3868+
"valueInVersions": []
3869+
},
3870+
"releaseVersionsMetadata": {
3871+
"introducedVersion": "2.3.0",
3872+
"stabilizedVersion": null,
3873+
"deprecatedVersion": null,
3874+
"removedVersion": null
3875+
}
38453876
}
38463877
],
38473878
"nestedLevels": [

compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,4 +1183,20 @@ Warning: this flag is not intended for production use. If you want to configure
11831183
introducedVersion = KotlinReleaseVersion.v1_0_0
11841184
)
11851185
}
1186+
1187+
compilerArgument {
1188+
name = "Xheader-mode"
1189+
description = """
1190+
Enable header compilation mode.
1191+
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
1192+
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
1193+
build systems where header libraries can be used to replace downstream dependencies for which we only need to
1194+
see the type names and method signatures required to compile a given translation unit.
1195+
""".trimIndent().asReleaseDependent()
1196+
valueType = BooleanType.defaultFalse
1197+
1198+
lifecycle(
1199+
introducedVersion = KotlinReleaseVersion.v2_3_0
1200+
)
1201+
}
11861202
}

compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,19 @@ public interface CommonCompilerArguments : CommonToolArguments {
737737
@ExperimentalCompilerArgument
738738
public val X_NAME_BASED_DESTRUCTURING: CommonCompilerArgument<String?> =
739739
CommonCompilerArgument("X_NAME_BASED_DESTRUCTURING", KotlinKotlinVersion(2, 3, 0))
740+
741+
/**
742+
* Enable header compilation mode.
743+
* In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
744+
* compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
745+
* build systems where header libraries can be used to replace downstream dependencies for which we only need to
746+
* see the type names and method signatures required to compile a given translation unit.
747+
*
748+
* WARNING: this option is EXPERIMENTAL and it may be changed in the future without notice or may be removed entirely.
749+
*/
750+
@JvmField
751+
@ExperimentalCompilerArgument
752+
public val X_HEADER_MODE: CommonCompilerArgument<Boolean> =
753+
CommonCompilerArgument("X_HEADER_MODE", KotlinKotlinVersion(2, 3, 0))
740754
}
741755
}

compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgume
6363
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_FRIEND_DEPENDENCY
6464
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_REFINES
6565
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_SOURCES
66+
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_HEADER_MODE
6667
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_IGNORE_CONST_OPTIMIZATION_ERRORS
6768
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_INLINE_CLASSES
6869
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_INTELLIJ_PLUGIN_ROOT
@@ -243,6 +244,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
243244
if (X_ALLOW_HOLDSIN_CONTRACT in this) { arguments.allowHoldsinContract = get(X_ALLOW_HOLDSIN_CONTRACT)}
244245
if (X_NAME_BASED_DESTRUCTURING in this) { arguments.nameBasedDestructuring = get(X_NAME_BASED_DESTRUCTURING)}
245246
if (XX_LANGUAGE in this) { arguments.manuallyConfiguredFeatures = get(XX_LANGUAGE)}
247+
if (X_HEADER_MODE in this) { arguments.headerMode = get(X_HEADER_MODE)}
246248
return arguments
247249
}
248250

@@ -340,6 +342,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
340342
try { this[X_ALLOW_HOLDSIN_CONTRACT] = arguments.allowHoldsinContract } catch (_: NoSuchMethodError) { }
341343
try { this[X_NAME_BASED_DESTRUCTURING] = arguments.nameBasedDestructuring } catch (_: NoSuchMethodError) { }
342344
try { this[XX_LANGUAGE] = arguments.manuallyConfiguredFeatures } catch (_: NoSuchMethodError) { }
345+
try { this[X_HEADER_MODE] = arguments.headerMode } catch (_: NoSuchMethodError) { }
343346
internalArguments.addAll(arguments.internalArguments.map { it.stringRepresentation })
344347
}
345348

@@ -615,5 +618,8 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
615618

616619
public val XX_LANGUAGE: CommonCompilerArgument<Array<String>?> =
617620
CommonCompilerArgument("XX_LANGUAGE")
621+
622+
public val X_HEADER_MODE: CommonCompilerArgument<Boolean> =
623+
CommonCompilerArgument("X_HEADER_MODE")
618624
}
619625
}

compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,20 @@ Warning: this flag is not intended for production use. If you want to configure
10451045
field = value
10461046
}
10471047

1048+
@Argument(
1049+
value = "-Xheader-mode",
1050+
description = """Enable header compilation mode.
1051+
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
1052+
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
1053+
build systems where header libraries can be used to replace downstream dependencies for which we only need to
1054+
see the type names and method signatures required to compile a given translation unit.""",
1055+
)
1056+
var headerMode: Boolean = false
1057+
set(value) {
1058+
checkFrozen()
1059+
field = value
1060+
}
1061+
10481062
@get:Transient
10491063
abstract val configurator: CommonCompilerArgumentsConfigurator
10501064

compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
4747
to.fragmentRefines = from.fragmentRefines?.copyOf()
4848
to.fragmentSources = from.fragmentSources?.copyOf()
4949
to.fragments = from.fragments?.copyOf()
50+
to.headerMode = from.headerMode
5051
to.ignoreConstOptimizationErrors = from.ignoreConstOptimizationErrors
5152
to.incrementalCompilation = from.incrementalCompilation
5253
to.inlineClasses = from.inlineClasses

compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fun CompilerConfiguration.setupCommonArguments(
4343
put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments))
4444
put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, arguments.allowAnyScriptsInSourceRoots)
4545
put(CommonConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors)
46+
put(CommonConfigurationKeys.HEADER_COMPILATION, arguments.headerMode)
4647

4748
val irVerificationMode = arguments.verifyIr?.let { verifyIrString ->
4849
IrVerificationMode.resolveMode(verifyIrString).also {

compiler/config/configuration-keys-generator/src/org/jetbrains/kotlin/config/keys/generator/CommonConfigurationKeysContainer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ object CommonConfigurationKeysContainer : KeysContainer("org.jetbrains.kotlin.co
4747
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS by key<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
4848
val IGNORE_CONST_OPTIMIZATION_ERRORS by key<Boolean>("Ignore errors from IrConstTransformer")
4949
val EVALUATED_CONST_TRACKER by key<EvaluatedConstTracker>("Keeps track of all evaluated by IrInterpreter constants")
50+
val HEADER_COMPILATION by key<Boolean>("Enable header compilation mode")
5051

5152
val MESSAGE_COLLECTOR_KEY by key<MessageCollector>(
5253
"message collector",

compiler/config/gen/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ object CommonConfigurationKeys {
9797
@JvmField
9898
val EVALUATED_CONST_TRACKER = CompilerConfigurationKey.create<EvaluatedConstTracker>("Keeps track of all evaluated by IrInterpreter constants")
9999

100+
@JvmField
101+
val HEADER_COMPILATION = CompilerConfigurationKey.create<Boolean>("Enable header compilation mode")
102+
100103
@JvmField
101104
val MESSAGE_COLLECTOR_KEY = CompilerConfigurationKey.create<MessageCollector>("message collector")
102105

@@ -230,6 +233,10 @@ var CompilerConfiguration.evaluatedConstTracker: EvaluatedConstTracker?
230233
get() = get(CommonConfigurationKeys.EVALUATED_CONST_TRACKER)
231234
set(value) { put(CommonConfigurationKeys.EVALUATED_CONST_TRACKER, requireNotNull(value) { "nullable values are not allowed" }) }
232235

236+
var CompilerConfiguration.headerCompilation: Boolean
237+
get() = getBoolean(CommonConfigurationKeys.HEADER_COMPILATION)
238+
set(value) { put(CommonConfigurationKeys.HEADER_COMPILATION, value) }
239+
233240
var CompilerConfiguration.messageCollector: MessageCollector
234241
get() = get(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
235242
set(value) { put(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, value) }

0 commit comments

Comments
 (0)