Skip to content

Commit d2a02a7

Browse files
committed
Introduce -header compiler flag for header compilation
1 parent 4131e80 commit d2a02a7

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
@@ -45,6 +45,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
4545
to.fragmentRefines = from.fragmentRefines?.copyOf()
4646
to.fragmentSources = from.fragmentSources?.copyOf()
4747
to.fragments = from.fragments?.copyOf()
48+
to.headerMode = from.headerMode
4849
to.ignoreConstOptimizationErrors = from.ignoreConstOptimizationErrors
4950
to.incrementalCompilation = from.incrementalCompilation
5051
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
@@ -42,6 +42,7 @@ object CommonConfigurationKeysContainer : KeysContainer("org.jetbrains.kotlin.co
4242
val DUMP_INFERENCE_LOGS by key<Boolean>("render the inference constraints dump file")
4343
val PARALLEL_BACKEND_THREADS by key<Int>("Run codegen phase in parallel with N threads")
4444
val INCREMENTAL_COMPILATION by key<Boolean>("Enable incremental compilation")
45+
val HEADER_COMPILATION by key<Boolean>("Enable header compilation mode")
4546
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS by key<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
4647
val IGNORE_CONST_OPTIMIZATION_ERRORS by key<Boolean>("Ignore errors from IrConstTransformer")
4748
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
@@ -84,6 +84,9 @@ object CommonConfigurationKeys {
8484
@JvmField
8585
val INCREMENTAL_COMPILATION = CompilerConfigurationKey.create<Boolean>("Enable incremental compilation")
8686

87+
@JvmField
88+
val HEADER_COMPILATION = CompilerConfigurationKey.create<Boolean>("Enable header compilation mode")
89+
8790
@JvmField
8891
val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS = CompilerConfigurationKey.create<Boolean>("Allow to compile any scripts along with regular Kotlin sources")
8992

@@ -202,6 +205,10 @@ var CompilerConfiguration.incrementalCompilation: Boolean
202205
get() = getBoolean(CommonConfigurationKeys.INCREMENTAL_COMPILATION)
203206
set(value) { put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, value) }
204207

208+
var CompilerConfiguration.headerCompilation: Boolean
209+
get() = getBoolean(CommonConfigurationKeys.HEADER_COMPILATION)
210+
set(value) { put(CommonConfigurationKeys.HEADER_COMPILATION, value) }
211+
205212
var CompilerConfiguration.allowAnyScriptsInSourceRoots: Boolean
206213
get() = getBoolean(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS)
207214
set(value) { put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, value) }

0 commit comments

Comments
 (0)