Skip to content

Commit c31fa02

Browse files
committed
Pass header compilation configuration to LightTree -> Fir declaration and expression builders across all compilers.
^KT-78422
1 parent 1499cfb commit c31fa02

File tree

20 files changed

+35
-16
lines changed

20 files changed

+35
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,7 +3848,7 @@
38483848
"shortName": null,
38493849
"deprecatedName": null,
38503850
"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.",
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. Inline functions are still kept\nwith bodies.",
38523852
"valueInVersions": []
38533853
},
38543854
"delimiter": null,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,8 @@ Warning: this flag is not intended for production use. If you want to configure
11911191
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
11921192
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
11931193
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.
1194+
see the type names and method signatures required to compile a given translation unit. Inline functions are still kept
1195+
with bodies.
11951196
""".trimIndent().asReleaseDependent()
11961197
valueType = BooleanType.defaultFalse
11971198

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ public interface CommonCompilerArguments : CommonToolArguments {
743743
* In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
744744
* compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
745745
* 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.
746+
* see the type names and method signatures required to compile a given translation unit. Inline functions are still kept
747+
* with bodies.
747748
*
748749
* WARNING: this option is EXPERIMENTAL and it may be changed in the future without notice or may be removed entirely.
749750
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@ Warning: this flag is not intended for production use. If you want to configure
10511051
In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be
10521052
compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation
10531053
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.""",
1054+
see the type names and method signatures required to compile a given translation unit. Inline functions are still kept
1055+
with bodies.""",
10551056
)
10561057
var headerMode: Boolean = false
10571058
set(value) {

compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/pipeline/web/WebFrontendPipelinePhase.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.cli.pipeline.ConfigurationPipelineArtifact
1717
import org.jetbrains.kotlin.cli.pipeline.PerformanceNotifications
1818
import org.jetbrains.kotlin.cli.pipeline.PipelinePhase
1919
import org.jetbrains.kotlin.config.CommonConfigurationKeys
20+
import org.jetbrains.kotlin.config.headerCompilation
2021
import org.jetbrains.kotlin.config.lookupTracker
2122
import org.jetbrains.kotlin.config.messageCollector
2223
import org.jetbrains.kotlin.config.perfManager
@@ -101,6 +102,7 @@ object WebFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, W
101102
incrementalDataProvider = configuration.incrementalDataProvider,
102103
lookupTracker = lookupTracker,
103104
useWasmPlatform = isWasm,
105+
configuration.headerCompilation,
104106
).also {
105107
kotlinPackageUsageIsFine = it.output.all { checkKotlinPackageUsageForLightTree(configuration, it.fir) }
106108
}
@@ -183,6 +185,7 @@ object WebFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, W
183185
incrementalDataProvider: IncrementalDataProvider?,
184186
lookupTracker: LookupTracker?,
185187
useWasmPlatform: Boolean,
188+
headerCompilationMode: Boolean,
186189
): AnalyzedFirOutput {
187190
val output = compileModuleToAnalyzedFir(
188191
moduleStructure,
@@ -194,7 +197,7 @@ object WebFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, W
194197
isCommonSource = { groupedSources.isCommonSourceForLt(it) },
195198
fileBelongsToModule = { file, it -> groupedSources.fileBelongsToModuleForLt(file, it) },
196199
buildResolveAndCheckFir = { session, files ->
197-
buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, performanceManager?.let { it::addSourcesStats })
200+
buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, headerCompilationMode, performanceManager?.let { it::addSourcesStats })
198201
},
199202
useWasmPlatform = useWasmPlatform,
200203
)

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/legacy/pipeline/jvmIncrementalCompilerPipelineLightTree.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector
1313
import org.jetbrains.kotlin.cli.common.prepareJvmSessions
1414
import org.jetbrains.kotlin.cli.jvm.compiler.VfsBasedProjectEnvironment
1515
import org.jetbrains.kotlin.config.CompilerConfiguration
16+
import org.jetbrains.kotlin.config.headerCompilation
1617
import org.jetbrains.kotlin.config.perfManager
1718
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
1819
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar
@@ -96,7 +97,7 @@ private fun FrontendContext.compileModuleToAnalyzedFirViaLightTreeIncrementally(
9697
val countFilesAndLines = if (performanceManager == null) null else performanceManager::addSourcesStats
9798

9899
val outputs = sessionsWithSources.map { (session, sources) ->
99-
buildResolveAndCheckFirViaLightTree(session, sources, diagnosticsReporter, countFilesAndLines)
100+
buildResolveAndCheckFirViaLightTree(session, sources, diagnosticsReporter, configuration.headerCompilation, countFilesAndLines)
100101
}
101102
outputs.runPlatformCheckers(diagnosticsReporter)
102103
FirResult(outputs)

compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/jvm/JvmFrontendPipelinePhase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ object JvmFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifact, J
263263
val countFilesAndLines = if (perfManager == null) null else perfManager::addSourcesStats
264264
val outputs = sessionsWithSources.map { (session, sources) ->
265265
val rawFirFiles = when (configuration.useLightTree) {
266-
true -> session.buildFirViaLightTree(sources, diagnosticsCollector, countFilesAndLines)
266+
true -> session.buildFirViaLightTree(sources, diagnosticsCollector, configuration.headerCompilation, countFilesAndLines)
267267
else -> session.buildFirFromKtFiles(sources.asKtFilesList())
268268
}
269269
resolveAndCheckFir(session, rawFirFiles, diagnosticsCollector)

compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/metadata/MetadataFrontendPipelinePhase.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.cli.pipeline.PerformanceNotifications
3232
import org.jetbrains.kotlin.cli.pipeline.PipelinePhase
3333
import org.jetbrains.kotlin.cli.pipeline.jvm.asKtFilesList
3434
import org.jetbrains.kotlin.config.CommonConfigurationKeys
35+
import org.jetbrains.kotlin.config.headerCompilation
3536
import org.jetbrains.kotlin.config.messageCollector
3637
import org.jetbrains.kotlin.config.moduleName
3738
import org.jetbrains.kotlin.config.perfManager
@@ -110,7 +111,7 @@ object MetadataFrontendPipelinePhase : PipelinePhase<ConfigurationPipelineArtifa
110111
}
111112
)
112113
sessionsWithSources.map { (session, files) ->
113-
val firFiles = session.buildFirViaLightTree(files, diagnosticsReporter) { files, lines ->
114+
val firFiles = session.buildFirViaLightTree(files, diagnosticsReporter, configuration.headerCompilation) { files, lines ->
114115
perfManager?.addSourcesStats(files, lines)
115116
}
116117
resolveAndCheckFir(session, firFiles, diagnosticsReporter)

compiler/fir/analysis-tests/legacy-fir-tests/testFixtures/org/jetbrains/kotlin/fir/java/AbstractFirOldFrontendLightClassesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ abstract class AbstractFirOldFrontendLightClassesTest : BaseDiagnosticsTest() {
121121
private fun mapKtFilesToFirFiles(session: FirSession, ktFiles: List<KtFile>, firFiles: MutableList<FirFile>, useLightTree: Boolean) {
122122
val firProvider = (session.firProvider as FirProviderImpl)
123123
if (useLightTree) {
124-
val lightTreeBuilder = LightTree2Fir(session, firProvider.kotlinScopeProvider)
124+
val lightTreeBuilder = LightTree2Fir(session, false, firProvider.kotlinScopeProvider)
125125
ktFiles.mapTo(firFiles) {
126126
val firFile =
127127
lightTreeBuilder.buildFirFile(

compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/firUtils.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import kotlin.reflect.KFunction2
2323
fun FirSession.buildFirViaLightTree(
2424
files: Collection<KtSourceFile>,
2525
diagnosticsReporter: DiagnosticReporter?,
26+
headerCompilationMode: Boolean,
2627
reportFilesAndLines: ((Int, Int) -> Unit)?,
2728
): List<FirFile> {
2829
val firProvider = (firProvider as FirProviderImpl)
2930
val sourcesToPathsMapper = sourcesToPathsMapper
30-
val builder = LightTree2Fir(this, firProvider.kotlinScopeProvider, diagnosticsReporter)
31+
val builder = LightTree2Fir(this, headerCompilationMode, firProvider.kotlinScopeProvider, diagnosticsReporter)
3132
val shouldCountLines = (reportFilesAndLines != null)
3233
var linesCount = 0
3334
val firFiles = files.map { file ->
@@ -82,8 +83,9 @@ fun buildResolveAndCheckFirViaLightTree(
8283
session: FirSession,
8384
ktFiles: Collection<KtSourceFile>,
8485
diagnosticsReporter: BaseDiagnosticsCollector,
86+
headerCompilationMode: Boolean,
8587
countFilesAndLines: KFunction2<Int, Int, Unit>?
8688
): ModuleCompilerAnalyzedOutput {
87-
val firFiles = session.buildFirViaLightTree(ktFiles, diagnosticsReporter, countFilesAndLines)
89+
val firFiles = session.buildFirViaLightTree(ktFiles, diagnosticsReporter, headerCompilationMode, countFilesAndLines)
8890
return resolveAndCheckFir(session, firFiles, diagnosticsReporter)
8991
}

0 commit comments

Comments
 (0)