Skip to content

Commit 86026bd

Browse files
committed
Add -header mode flag and configuration to the compiler in preparation for header mode compilation
1 parent 0d83bd9 commit 86026bd

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
@@ -1115,6 +1115,37 @@
11151115
"removedVersion": null
11161116
}
11171117
},
1118+
{
1119+
"name": "header",
1120+
"shortName": null,
1121+
"deprecatedName": null,
1122+
"description": {
1123+
"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.",
1124+
"valueInVersions": []
1125+
},
1126+
"delimiter": null,
1127+
"valueType": {
1128+
"type": "org.jetbrains.kotlin.arguments.dsl.types.BooleanType",
1129+
"isNullable": {
1130+
"current": false,
1131+
"valueInVersions": []
1132+
},
1133+
"defaultValue": {
1134+
"current": false,
1135+
"valueInVersions": []
1136+
}
1137+
},
1138+
"valueDescription": {
1139+
"current": null,
1140+
"valueInVersions": []
1141+
},
1142+
"releaseVersionsMetadata": {
1143+
"introducedVersion": "2.2.0",
1144+
"stabilizedVersion": "2.2.0",
1145+
"deprecatedVersion": null,
1146+
"removedVersion": null
1147+
}
1148+
},
11181149
{
11191150
"name": "progressive",
11201151
"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
@@ -161,6 +161,7 @@ public final class org/jetbrains/kotlin/buildtools/api/SourcesChanges$Unknown :
161161
public abstract interface class org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments : org/jetbrains/kotlin/buildtools/api/arguments/CommonToolArguments {
162162
public static final field API_VERSION Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
163163
public static final field Companion Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$Companion;
164+
public static final field HEADER Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
164165
public static final field KOTLIN_HOME Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
165166
public static final field LANGUAGE_VERSION Lorg/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments$CommonCompilerArgument;
166167
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public interface CommonCompilerArguments : CommonToolArguments {
7272
public val KOTLIN_HOME: CommonCompilerArgument<String?> =
7373
CommonCompilerArgument("KOTLIN_HOME", KotlinKotlinVersion(1, 1, 50))
7474

75+
/**
76+
* Enable header compilation mode.
77+
* In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
78+
* compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
79+
* build systems where header libraries can be used to replace downstream dependencies for which we only need to
80+
* see the type names and method signatures required to compile a given translation unit.
81+
*/
82+
@JvmField
83+
public val HEADER: CommonCompilerArgument<Boolean> =
84+
CommonCompilerArgument("HEADER", KotlinKotlinVersion(2, 2, 0))
85+
7586
/**
7687
* Enable progressive compiler mode.
7788
* 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
@@ -17,6 +17,7 @@ import kotlin.collections.MutableSet
1717
import kotlin.collections.mutableMapOf
1818
import kotlin.collections.mutableSetOf
1919
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.API_VERSION
20+
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.HEADER
2021
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.KOTLIN_HOME
2122
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.LANGUAGE_VERSION
2223
import org.jetbrains.kotlin.buildtools.`internal`.compat.arguments.CommonCompilerArgumentsImpl.Companion.OPT_IN
@@ -147,6 +148,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
147148
if (LANGUAGE_VERSION in this) { arguments.languageVersion = get(LANGUAGE_VERSION)?.stringValue}
148149
if (API_VERSION in this) { arguments.apiVersion = get(API_VERSION)?.stringValue}
149150
if (KOTLIN_HOME in this) { arguments.kotlinHome = get(KOTLIN_HOME)}
151+
try { if (HEADER in this) { arguments.headerMode = get(HEADER)} } catch (e: NoSuchMethodError) { throw IllegalStateException("""Compiler parameter not recognized: HEADER. Current compiler version is: $KC_VERSION}, but the argument was introduced in 2.2.0""").initCause(e) }
150152
if (PROGRESSIVE in this) { arguments.progressiveMode = get(PROGRESSIVE)}
151153
if (SCRIPT in this) { arguments.script = get(SCRIPT)}
152154
try { if (X_REPL in this) { arguments.repl = get(X_REPL)} } catch (e: NoSuchMethodError) { throw IllegalStateException("""Compiler parameter not recognized: X_REPL. Current compiler version is: $KC_VERSION}, but the argument was introduced in 2.2.0""").initCause(e) }
@@ -239,6 +241,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
239241
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { EnumsKotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
240242
try { this[API_VERSION] = arguments.apiVersion?.let { EnumsKotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
241243
try { this[KOTLIN_HOME] = arguments.kotlinHome } catch (_: NoSuchMethodError) { }
244+
try { this[HEADER] = arguments.headerMode } catch (_: NoSuchMethodError) { }
242245
try { this[PROGRESSIVE] = arguments.progressiveMode } catch (_: NoSuchMethodError) { }
243246
try { this[SCRIPT] = arguments.script } catch (_: NoSuchMethodError) { }
244247
try { this[X_REPL] = arguments.repl } catch (_: NoSuchMethodError) { }
@@ -343,6 +346,8 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
343346

344347
public val KOTLIN_HOME: CommonCompilerArgument<String?> = CommonCompilerArgument("KOTLIN_HOME")
345348

349+
public val HEADER: CommonCompilerArgument<Boolean> = CommonCompilerArgument("HEADER")
350+
346351
public val PROGRESSIVE: CommonCompilerArgument<Boolean> = CommonCompilerArgument("PROGRESSIVE")
347352

348353
public val SCRIPT: CommonCompilerArgument<Boolean> = CommonCompilerArgument("SCRIPT")

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlin.collections.mutableMapOf
1818
import kotlin.collections.mutableSetOf
1919
import org.jetbrains.kotlin.buildtools.`internal`.UseFromImplModuleRestricted
2020
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.API_VERSION
21+
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.HEADER
2122
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.KOTLIN_HOME
2223
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.LANGUAGE_VERSION
2324
import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.OPT_IN
@@ -155,6 +156,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
155156
if (LANGUAGE_VERSION in this) { arguments.languageVersion = get(LANGUAGE_VERSION)?.stringValue}
156157
if (API_VERSION in this) { arguments.apiVersion = get(API_VERSION)?.stringValue}
157158
if (KOTLIN_HOME in this) { arguments.kotlinHome = get(KOTLIN_HOME)}
159+
if (HEADER in this) { arguments.headerMode = get(HEADER)}
158160
if (PROGRESSIVE in this) { arguments.progressiveMode = get(PROGRESSIVE)}
159161
if (SCRIPT in this) { arguments.script = get(SCRIPT)}
160162
if (X_REPL in this) { arguments.repl = get(X_REPL)}
@@ -252,6 +254,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
252254
try { this[LANGUAGE_VERSION] = arguments.languageVersion?.let { EnumsKotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
253255
try { this[API_VERSION] = arguments.apiVersion?.let { EnumsKotlinVersion.entries.first { entry -> entry.stringValue == it } } } catch (_: NoSuchMethodError) { }
254256
try { this[KOTLIN_HOME] = arguments.kotlinHome } catch (_: NoSuchMethodError) { }
257+
try { this[HEADER] = arguments.headerMode } catch (_: NoSuchMethodError) { }
255258
try { this[PROGRESSIVE] = arguments.progressiveMode } catch (_: NoSuchMethodError) { }
256259
try { this[SCRIPT] = arguments.script } catch (_: NoSuchMethodError) { }
257260
try { this[X_REPL] = arguments.repl } catch (_: NoSuchMethodError) { }
@@ -361,6 +364,8 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(),
361364

362365
public val KOTLIN_HOME: CommonCompilerArgument<String?> = CommonCompilerArgument("KOTLIN_HOME")
363366

367+
public val HEADER: CommonCompilerArgument<Boolean> = CommonCompilerArgument("HEADER")
368+
364369
public val PROGRESSIVE: CommonCompilerArgument<Boolean> = CommonCompilerArgument("PROGRESSIVE")
365370

366371
public val SCRIPT: CommonCompilerArgument<Boolean> = CommonCompilerArgument("SCRIPT")

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
@@ -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
@@ -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

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)