Skip to content

Commit 852341e

Browse files
committed
Introduce -header compiler flag for header compilation
1 parent 72bac8f commit 852341e

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,37 @@
10741074
"removedVersion": null
10751075
}
10761076
},
1077+
{
1078+
"name": "header",
1079+
"shortName": null,
1080+
"deprecatedName": null,
1081+
"description": {
1082+
"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.",
1083+
"valueInVersions": []
1084+
},
1085+
"delimiter": null,
1086+
"valueType": {
1087+
"type": "org.jetbrains.kotlin.arguments.dsl.types.BooleanType",
1088+
"isNullable": {
1089+
"current": false,
1090+
"valueInVersions": []
1091+
},
1092+
"defaultValue": {
1093+
"current": false,
1094+
"valueInVersions": []
1095+
}
1096+
},
1097+
"valueDescription": {
1098+
"current": null,
1099+
"valueInVersions": []
1100+
},
1101+
"releaseVersionsMetadata": {
1102+
"introducedVersion": "1.4.0",
1103+
"stabilizedVersion": "1.4.0",
1104+
"deprecatedVersion": null,
1105+
"removedVersion": null
1106+
}
1107+
},
10771108
{
10781109
"name": "progressive",
10791110
"shortName": null,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ val actualCommonCompilerArguments by compilerArgumentsLevel(CompilerArgumentsLev
7171
)
7272
}
7373

74+
compilerArgument {
75+
name = "header"
76+
compilerName = "headerMode"
77+
description = """
78+
Enable header compilation mode.
79+
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
80+
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
81+
build systems where header libraries can be used to replace downstream dependencies for which we only need to
82+
see the type names and method signatures required to compile a given translation unit.
83+
""".trimIndent().asReleaseDependent()
84+
valueType = BooleanType.defaultFalse
85+
86+
additionalAnnotations(
87+
GradleOption(
88+
value = DefaultValue.BOOLEAN_FALSE_DEFAULT,
89+
gradleInputType = GradleInputTypes.INPUT
90+
)
91+
)
92+
93+
@OptIn(TemporaryCompilerArgumentLifecycle::class)
94+
stubLifecycle()
95+
}
96+
7497
compilerArgument {
7598
name = "progressive"
7699
deprecatedName = "Xprogressive"

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
5959
field = if (value.isNullOrEmpty()) null else value
6060
}
6161

62+
@Argument(
63+
value = "-header",
64+
description = """Enable header compilation mode.
65+
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
66+
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
67+
build systems where header libraries can be used to replace downstream dependencies for which we only need to
68+
see the type names and method signatures required to compile a given translation unit.""",
69+
)
70+
var headerMode: Boolean = false
71+
set(value) {
72+
checkFrozen()
73+
field = value
74+
}
75+
76+
@GradleOption(
77+
value = DefaultValue.BOOLEAN_FALSE_DEFAULT,
78+
gradleInputType = GradleInputTypes.INPUT,
79+
)
6280
@Argument(
6381
value = "-progressive",
6482
deprecatedName = "-Xprogressive",

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
@@ -42,6 +42,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
4242
to.fragmentRefines = from.fragmentRefines?.copyOf()
4343
to.fragmentSources = from.fragmentSources?.copyOf()
4444
to.fragments = from.fragments?.copyOf()
45+
to.headerMode = from.headerMode
4546
to.ignoreConstOptimizationErrors = from.ignoreConstOptimizationErrors
4647
to.incrementalCompilation = from.incrementalCompilation
4748
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
@@ -30,6 +30,7 @@ fun CompilerConfiguration.setupCommonArguments(
3030
val messageCollector = getNotNull(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY)
3131

3232
put(CommonConfigurationKeys.DISABLE_INLINE, arguments.noInline)
33+
put(CommonConfigurationKeys.HEADER_COMPILATION, arguments.headerMode)
3334
put(CommonConfigurationKeys.USE_FIR_EXTRA_CHECKERS, arguments.extraWarnings)
3435
put(CommonConfigurationKeys.METADATA_KLIB, arguments.metadataKlib)
3536
putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot)

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
@@ -41,6 +41,7 @@ object CommonConfigurationKeysContainer : KeysContainer("org.jetbrains.kotlin.co
4141
val DUMP_INFERENCE_LOGS by key<Boolean>("render the inference constraints dump file")
4242
val PARALLEL_BACKEND_THREADS by key<Int>("Run codegen phase in parallel with N threads")
4343
val INCREMENTAL_COMPILATION by key<Boolean>("Enable incremental compilation")
44+
val HEADER_COMPILATION by key<Boolean>("Enable header compilation mode")
4445
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS by key<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
4546
val IGNORE_CONST_OPTIMIZATION_ERRORS by key<Boolean>("Ignore errors from IrConstTransformer")
4647
val EVALUATED_CONST_TRACKER by key<EvaluatedConstTracker>("Keeps track of all evaluated by IrInterpreter constants")

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ object CommonConfigurationKeys {
8080
@JvmField
8181
val INCREMENTAL_COMPILATION = CompilerConfigurationKey.create<Boolean>("Enable incremental compilation")
8282

83+
@JvmField
84+
val HEADER_COMPILATION = CompilerConfigurationKey.create<Boolean>("Enable header compilation mode")
85+
8386
@JvmField
8487
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS = CompilerConfigurationKey.create<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
8588

@@ -194,6 +197,10 @@ var CompilerConfiguration.incrementalCompilation: Boolean
194197
get() = getBoolean(CommonConfigurationKeys.INCREMENTAL_COMPILATION)
195198
set(value) { put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, value) }
196199

200+
var CompilerConfiguration.headerCompilation: Boolean
201+
get() = getBoolean(CommonConfigurationKeys.HEADER_COMPILATION)
202+
set(value) { put(CommonConfigurationKeys.HEADER_COMPILATION, value) }
203+
197204
var CompilerConfiguration.allowAnyScriptsInSourceRoots: Boolean
198205
get() = getBoolean(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS)
199206
set(value) { put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, value) }

0 commit comments

Comments
 (0)