Skip to content

Commit 614243c

Browse files
committed
Add -header mode flag and configuration to the compiler in preparation for header mode compilation
1 parent 3d042b6 commit 614243c

File tree

12 files changed

+98
-0
lines changed

12 files changed

+98
-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": "2.2.0",
1103+
"stabilizedVersion": "2.2.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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ val actualCommonCompilerArguments by compilerArgumentsLevel(CompilerArgumentsLev
5555
)
5656
}
5757

58+
compilerArgument {
59+
name = "header"
60+
compilerName = "headerMode"
61+
description = """
62+
Enable header compilation mode.
63+
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
64+
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
65+
build systems where header libraries can be used to replace downstream dependencies for which we only need to
66+
see the type names and method signatures required to compile a given translation unit.
67+
""".trimIndent().asReleaseDependent()
68+
valueType = BooleanType.defaultFalse
69+
70+
lifecycle(
71+
introducedVersion = KotlinReleaseVersion.v2_2_0,
72+
stabilizedVersion = KotlinReleaseVersion.v2_2_0,
73+
)
74+
}
75+
5876
compilerArgument {
5977
name = "progressive"
6078
deprecatedName = "Xprogressive"

compiler/build-tools/kotlin-build-tools-api/api/kotlin-build-tools-api.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public final class org/jetbrains/kotlin/buildtools/api/SourcesChanges$Unknown :
154154
public abstract interface class org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments : org/jetbrains/kotlin/buildtools/api/arguments/CommonToolArguments {
155155
public static final field API_VERSION Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
156156
public static final field Companion Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$Companion;
157+
public static final field HEADER Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
157158
public static final field KOTLIN_HOME Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
158159
public static final field LANGUAGE_VERSION Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
159160
public static final field OPT_IN Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public interface CommonCompilerArguments : CommonToolArguments {
6868
@JvmField
6969
public val KOTLIN_HOME: CommonCompilerArgument<String?> = CommonCompilerArgument("KOTLIN_HOME")
7070

71+
/**
72+
* Enable header compilation mode.
73+
* In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
74+
* compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
75+
* build systems where header libraries can be used to replace downstream dependencies for which we only need to
76+
* see the type names and method signatures required to compile a given translation unit.
77+
*/
78+
@JvmField
79+
public val HEADER: CommonCompilerArgument<Boolean> = CommonCompilerArgument("HEADER")
80+
7181
/**
7282
* Enable progressive compiler mode.
7383
* In this mode, deprecations and bug fixes for unstable code take effect immediately

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlin.collections.MutableMap
1616
import kotlin.collections.mutableListOf
1717
import kotlin.collections.mutableMapOf
1818
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.API_VERSION
19+
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.HEADER
1920
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.KOTLIN_HOME
2021
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.LANGUAGE_VERSION
2122
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.OPT_IN
@@ -125,6 +126,7 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
125126
if ("LANGUAGE_VERSION" in optionsMap) { arguments.add("-language-version=" + get(LANGUAGE_VERSION)?.stringValue) }
126127
if ("API_VERSION" in optionsMap) { arguments.add("-api-version=" + get(API_VERSION)?.stringValue) }
127128
if ("KOTLIN_HOME" in optionsMap) { arguments.add("-kotlin-home=" + get(KOTLIN_HOME)) }
129+
if ("HEADER" in optionsMap) { arguments.add("-header=" + get(HEADER)) }
128130
if ("PROGRESSIVE" in optionsMap) { arguments.add("-progressive=" + get(PROGRESSIVE)) }
129131
if ("OPT_IN" in optionsMap) { arguments.add("-opt-in=" + get(OPT_IN)) }
130132
if ("X_NO_INLINE" in optionsMap) { arguments.add("-Xno-inline=" + get(X_NO_INLINE)) }
@@ -198,6 +200,7 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
198200
this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.valueOf(it) }
199201
this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.valueOf(it) }
200202
this[KOTLIN_HOME] = arguments.kotlinHome
203+
this[HEADER] = arguments.headerMode
201204
this[PROGRESSIVE] = arguments.progressiveMode
202205
this[OPT_IN] = arguments.optIn
203206
this[X_NO_INLINE] = arguments.noInline
@@ -277,6 +280,8 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
277280

278281
public val KOTLIN_HOME: CommonCompilerArgument<String?> = CommonCompilerArgument("KOTLIN_HOME")
279282

283+
public val HEADER: CommonCompilerArgument<Boolean> = CommonCompilerArgument("HEADER")
284+
280285
public val PROGRESSIVE: CommonCompilerArgument<Boolean> = CommonCompilerArgument("PROGRESSIVE")
281286

282287
public val OPT_IN: CommonCompilerArgument<Array<String>?> = CommonCompilerArgument("OPT_IN")

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
@@ -17,6 +17,7 @@ import kotlin.collections.mutableListOf
1717
import kotlin.collections.mutableMapOf
1818
import org.jetbrains.kotlin.buildtools.`internal`.UseFromImplModuleRestricted
1919
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.API_VERSION
20+
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.HEADER
2021
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.KOTLIN_HOME
2122
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.LANGUAGE_VERSION
2223
import org.jetbrains.kotlin.buildtools.api.arguments.CommonCompilerArguments.Companion.OPT_IN
@@ -121,6 +122,7 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
121122
if ("LANGUAGE_VERSION" in optionsMap) { arguments.languageVersion = get(LANGUAGE_VERSION)?.stringValue }
122123
if ("API_VERSION" in optionsMap) { arguments.apiVersion = get(API_VERSION)?.stringValue }
123124
if ("KOTLIN_HOME" in optionsMap) { arguments.kotlinHome = get(KOTLIN_HOME) }
125+
if ("HEADER" in optionsMap) { arguments.headerMode = get(HEADER) }
124126
if ("PROGRESSIVE" in optionsMap) { arguments.progressiveMode = get(PROGRESSIVE) }
125127
if ("OPT_IN" in optionsMap) { arguments.optIn = get(OPT_IN) }
126128
if ("X_NO_INLINE" in optionsMap) { arguments.noInline = get(X_NO_INLINE) }
@@ -201,6 +203,7 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
201203
if ("LANGUAGE_VERSION" in optionsMap) { arguments.add("-language-version=" + get(LANGUAGE_VERSION)?.stringValue) }
202204
if ("API_VERSION" in optionsMap) { arguments.add("-api-version=" + get(API_VERSION)?.stringValue) }
203205
if ("KOTLIN_HOME" in optionsMap) { arguments.add("-kotlin-home=" + get(KOTLIN_HOME)) }
206+
if ("HEADER" in optionsMap) { arguments.add("-header=" + get(HEADER)) }
204207
if ("PROGRESSIVE" in optionsMap) { arguments.add("-progressive=" + get(PROGRESSIVE)) }
205208
if ("OPT_IN" in optionsMap) { arguments.add("-opt-in=" + get(OPT_IN)) }
206209
if ("X_NO_INLINE" in optionsMap) { arguments.add("-Xno-inline=" + get(X_NO_INLINE)) }
@@ -274,6 +277,7 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
274277
this[LANGUAGE_VERSION] = arguments.languageVersion?.let { KotlinVersion.valueOf(it) }
275278
this[API_VERSION] = arguments.apiVersion?.let { KotlinVersion.valueOf(it) }
276279
this[KOTLIN_HOME] = arguments.kotlinHome
280+
this[HEADER] = arguments.headerMode
277281
this[PROGRESSIVE] = arguments.progressiveMode
278282
this[OPT_IN] = arguments.optIn
279283
this[X_NO_INLINE] = arguments.noInline
@@ -353,6 +357,8 @@ internal open class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
353357

354358
public val KOTLIN_HOME: CommonCompilerArgument<String?> = CommonCompilerArgument("KOTLIN_HOME")
355359

360+
public val HEADER: CommonCompilerArgument<Boolean> = CommonCompilerArgument("HEADER")
361+
356362
public val PROGRESSIVE: CommonCompilerArgument<Boolean> = CommonCompilerArgument("PROGRESSIVE")
357363

358364
public val OPT_IN: CommonCompilerArgument<Array<String>?> = CommonCompilerArgument("OPT_IN")

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
@@ -59,6 +59,20 @@ 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+
6276
@Argument(
6377
value = "-progressive",
6478
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
@@ -46,6 +46,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile
4646
to.fragmentRefines = from.fragmentRefines?.copyOf()
4747
to.fragmentSources = from.fragmentSources?.copyOf()
4848
to.fragments = from.fragments?.copyOf()
49+
to.headerMode = from.headerMode
4950
to.ignoreConstOptimizationErrors = from.ignoreConstOptimizationErrors
5051
to.incrementalCompilation = from.incrementalCompilation
5152
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/cli/src/org/jetbrains/kotlin/cli/common/klibArguments.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ fun CompilerConfiguration.copyCommonKlibArgumentsFrom(source: CompilerConfigurat
7676
klibAbiCompatibilityLevel = source.klibAbiCompatibilityLevel
7777

7878
zipFileSystemAccessor = source.zipFileSystemAccessor
79+
80+
// Header compilation mode needs to be propagated to KLIB compilation.
81+
headerCompilation = source.headerCompilation
7982
}
8083

8184
private fun parseCustomKotlinAbiVersion(customKlibAbiVersion: String?, collector: MessageCollector): KotlinAbiVersion? {

0 commit comments

Comments
 (0)