diff --git a/compiler/arguments/resources/kotlin-compiler-arguments.json b/compiler/arguments/resources/kotlin-compiler-arguments.json index 4fe6c6537638c..a33218ebe4ae4 100644 --- a/compiler/arguments/resources/kotlin-compiler-arguments.json +++ b/compiler/arguments/resources/kotlin-compiler-arguments.json @@ -3842,6 +3842,37 @@ "deprecatedVersion": null, "removedVersion": null } + }, + { + "name": "Xheader-mode", + "shortName": null, + "deprecatedName": null, + "description": { + "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.", + "valueInVersions": [] + }, + "delimiter": null, + "valueType": { + "type": "org.jetbrains.kotlin.arguments.dsl.types.BooleanType", + "isNullable": { + "current": false, + "valueInVersions": [] + }, + "defaultValue": { + "current": false, + "valueInVersions": [] + } + }, + "valueDescription": { + "current": null, + "valueInVersions": [] + }, + "releaseVersionsMetadata": { + "introducedVersion": "2.3.0", + "stabilizedVersion": null, + "deprecatedVersion": null, + "removedVersion": null + } } ], "nestedLevels": [ diff --git a/compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt b/compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt index ffd49207c1e4c..ba95b62ec7ae2 100644 --- a/compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt +++ b/compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt @@ -1183,4 +1183,21 @@ Warning: this flag is not intended for production use. If you want to configure introducedVersion = KotlinReleaseVersion.v1_0_0 ) } + + compilerArgument { + name = "Xheader-mode" + description = """ + Enable header compilation mode. + In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be + compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation + build systems where header libraries can be used to replace downstream dependencies for which we only need to + see the type names and method signatures required to compile a given translation unit. Inline functions are still kept + with bodies. + """.trimIndent().asReleaseDependent() + valueType = BooleanType.defaultFalse + + lifecycle( + introducedVersion = KotlinReleaseVersion.v2_3_0 + ) + } } diff --git a/compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt b/compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt index 2eb9d4535641c..4f4e0fed93e8a 100644 --- a/compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt +++ b/compiler/build-tools/kotlin-build-tools-api/gen/org/jetbrains/kotlin/buildtools/api/arguments/CommonCompilerArguments.kt @@ -737,5 +737,20 @@ public interface CommonCompilerArguments : CommonToolArguments { @ExperimentalCompilerArgument public val X_NAME_BASED_DESTRUCTURING: CommonCompilerArgument = CommonCompilerArgument("X_NAME_BASED_DESTRUCTURING", KotlinKotlinVersion(2, 3, 0)) + + /** + * Enable header compilation mode. + * In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be + * compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation + * build systems where header libraries can be used to replace downstream dependencies for which we only need to + * see the type names and method signatures required to compile a given translation unit. Inline functions are still kept + * with bodies. + * + * WARNING: this option is EXPERIMENTAL and it may be changed in the future without notice or may be removed entirely. + */ + @JvmField + @ExperimentalCompilerArgument + public val X_HEADER_MODE: CommonCompilerArgument = + CommonCompilerArgument("X_HEADER_MODE", KotlinKotlinVersion(2, 3, 0)) } } diff --git a/compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt b/compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt index e6704b8d1b47c..d12eea7c29e8d 100644 --- a/compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt +++ b/compiler/build-tools/kotlin-build-tools-impl/gen/org/jetbrains/kotlin/buildtools/internal/arguments/CommonCompilerArgumentsImpl.kt @@ -63,6 +63,7 @@ import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgume import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_FRIEND_DEPENDENCY import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_REFINES import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_FRAGMENT_SOURCES +import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_HEADER_MODE import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_IGNORE_CONST_OPTIMIZATION_ERRORS import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_INLINE_CLASSES import org.jetbrains.kotlin.buildtools.`internal`.arguments.CommonCompilerArgumentsImpl.Companion.X_INTELLIJ_PLUGIN_ROOT @@ -243,6 +244,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(), if (X_ALLOW_HOLDSIN_CONTRACT in this) { arguments.allowHoldsinContract = get(X_ALLOW_HOLDSIN_CONTRACT)} if (X_NAME_BASED_DESTRUCTURING in this) { arguments.nameBasedDestructuring = get(X_NAME_BASED_DESTRUCTURING)} if (XX_LANGUAGE in this) { arguments.manuallyConfiguredFeatures = get(XX_LANGUAGE)} + if (X_HEADER_MODE in this) { arguments.headerMode = get(X_HEADER_MODE)} return arguments } @@ -340,6 +342,7 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(), try { this[X_ALLOW_HOLDSIN_CONTRACT] = arguments.allowHoldsinContract } catch (_: NoSuchMethodError) { } try { this[X_NAME_BASED_DESTRUCTURING] = arguments.nameBasedDestructuring } catch (_: NoSuchMethodError) { } try { this[XX_LANGUAGE] = arguments.manuallyConfiguredFeatures } catch (_: NoSuchMethodError) { } + try { this[X_HEADER_MODE] = arguments.headerMode } catch (_: NoSuchMethodError) { } internalArguments.addAll(arguments.internalArguments.map { it.stringRepresentation }) } @@ -615,5 +618,8 @@ internal abstract class CommonCompilerArgumentsImpl : CommonToolArgumentsImpl(), public val XX_LANGUAGE: CommonCompilerArgument?> = CommonCompilerArgument("XX_LANGUAGE") + + public val X_HEADER_MODE: CommonCompilerArgument = + CommonCompilerArgument("X_HEADER_MODE") } } diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 4adc9f7aa919d..ff56a0acc64ac 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -1045,6 +1045,21 @@ Warning: this flag is not intended for production use. If you want to configure field = value } + @Argument( + value = "-Xheader-mode", + description = """Enable header compilation mode. +In this mode, the compiler produces class files that only contain the 'skeleton' of the classes to be +compiled but the method bodies of all the implementations are empty. This is used to speed up parallel compilation +build systems where header libraries can be used to replace downstream dependencies for which we only need to +see the type names and method signatures required to compile a given translation unit. Inline functions are still kept +with bodies.""", + ) + var headerMode: Boolean = false + set(value) { + checkFrozen() + field = value + } + @get:Transient abstract val configurator: CommonCompilerArgumentsConfigurator diff --git a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt index 62815e2be7994..11132b86c904e 100644 --- a/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt +++ b/compiler/cli/cli-common/gen/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArgumentsCopyGenerated.kt @@ -47,6 +47,7 @@ fun copyCommonCompilerArguments(from: CommonCompilerArguments, to: CommonCompile to.fragmentRefines = from.fragmentRefines?.copyOf() to.fragmentSources = from.fragmentSources?.copyOf() to.fragments = from.fragments?.copyOf() + to.headerMode = from.headerMode to.ignoreConstOptimizationErrors = from.ignoreConstOptimizationErrors to.incrementalCompilation = from.incrementalCompilation to.inlineClasses = from.inlineClasses diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/pipeline/web/WebFrontendPipelinePhase.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/pipeline/web/WebFrontendPipelinePhase.kt index e453cc29645a3..70909337834c4 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/pipeline/web/WebFrontendPipelinePhase.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/pipeline/web/WebFrontendPipelinePhase.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.cli.pipeline.ConfigurationPipelineArtifact import org.jetbrains.kotlin.cli.pipeline.PerformanceNotifications import org.jetbrains.kotlin.cli.pipeline.PipelinePhase import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.config.lookupTracker import org.jetbrains.kotlin.config.messageCollector import org.jetbrains.kotlin.config.perfManager @@ -101,6 +102,7 @@ object WebFrontendPipelinePhase : PipelinePhase - buildResolveAndCheckFirFromKtFiles(session, files, diagnosticsReporter) + buildResolveAndCheckFirFromKtFiles(session, files, diagnosticsReporter, headerCompilationMode) }, useWasmPlatform = useWasmPlatform, ) - output.runPlatformCheckers(diagnosticsReporter) + output.runPlatformCheckers(diagnosticsReporter, headerCompilationMode) return AnalyzedFirWithPsiOutput(output, ktFiles) } @@ -183,6 +187,7 @@ object WebFrontendPipelinePhase : PipelinePhase groupedSources.fileBelongsToModuleForLt(file, it) }, buildResolveAndCheckFir = { session, files -> - buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, performanceManager?.let { it::addSourcesStats }) + buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, headerCompilationMode, performanceManager?.let { it::addSourcesStats }) }, useWasmPlatform = useWasmPlatform, ) - output.runPlatformCheckers(diagnosticsReporter) + output.runPlatformCheckers(diagnosticsReporter, headerCompilationMode) return AnalyzedFirOutput(output) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt index 41fa2a4368ed7..dfb2972425ff5 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt @@ -43,6 +43,7 @@ fun CompilerConfiguration.setupCommonArguments( put(CommonConfigurationKeys.INCREMENTAL_COMPILATION, incrementalCompilationIsEnabled(arguments)) put(CommonConfigurationKeys.ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS, arguments.allowAnyScriptsInSourceRoots) put(CommonConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors) + put(CommonConfigurationKeys.HEADER_COMPILATION, arguments.headerMode) val irVerificationMode = arguments.verifyIr?.let { verifyIrString -> IrVerificationMode.resolveMode(verifyIrString).also { diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/legacy/pipeline/jvmIncrementalCompilerPipelineLightTree.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/legacy/pipeline/jvmIncrementalCompilerPipelineLightTree.kt index 98e43721f4f5e..385a20ccf23a1 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/legacy/pipeline/jvmIncrementalCompilerPipelineLightTree.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/legacy/pipeline/jvmIncrementalCompilerPipelineLightTree.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.prepareJvmSessions import org.jetbrains.kotlin.cli.jvm.compiler.VfsBasedProjectEnvironment import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.config.perfManager import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar @@ -96,9 +97,9 @@ private fun FrontendContext.compileModuleToAnalyzedFirViaLightTreeIncrementally( val countFilesAndLines = if (performanceManager == null) null else performanceManager::addSourcesStats val outputs = sessionsWithSources.map { (session, sources) -> - buildResolveAndCheckFirViaLightTree(session, sources, diagnosticsReporter, countFilesAndLines) + buildResolveAndCheckFirViaLightTree(session, sources, diagnosticsReporter, configuration.headerCompilation, countFilesAndLines) } - outputs.runPlatformCheckers(diagnosticsReporter) + outputs.runPlatformCheckers(diagnosticsReporter, configuration.headerCompilation) FirResult(outputs) } } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/jvm/JvmFrontendPipelinePhase.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/jvm/JvmFrontendPipelinePhase.kt index f91ab586adaac..b1ecc0bd93975 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/jvm/JvmFrontendPipelinePhase.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/jvm/JvmFrontendPipelinePhase.kt @@ -263,12 +263,12 @@ object JvmFrontendPipelinePhase : PipelinePhase val rawFirFiles = when (configuration.useLightTree) { - true -> session.buildFirViaLightTree(sources, diagnosticsCollector, countFilesAndLines) + true -> session.buildFirViaLightTree(sources, diagnosticsCollector, configuration.headerCompilation, countFilesAndLines) else -> session.buildFirFromKtFiles(sources.asKtFilesList()) } - resolveAndCheckFir(session, rawFirFiles, diagnosticsCollector) + resolveAndCheckFir(session, rawFirFiles, diagnosticsCollector, configuration.headerCompilation) } - outputs.runPlatformCheckers(diagnosticsCollector) + outputs.runPlatformCheckers(diagnosticsCollector, configuration.headerCompilation) val kotlinPackageUsageIsFine = when (configuration.useLightTree) { true -> outputs.all { checkKotlinPackageUsageForLightTree(configuration, it.fir) } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/metadata/MetadataFrontendPipelinePhase.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/metadata/MetadataFrontendPipelinePhase.kt index ce1a1b8887c37..2c0aa30bf78ea 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/metadata/MetadataFrontendPipelinePhase.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/pipeline/metadata/MetadataFrontendPipelinePhase.kt @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.cli.pipeline.PerformanceNotifications import org.jetbrains.kotlin.cli.pipeline.PipelinePhase import org.jetbrains.kotlin.cli.pipeline.jvm.asKtFilesList import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.config.messageCollector import org.jetbrains.kotlin.config.moduleName import org.jetbrains.kotlin.config.perfManager @@ -110,10 +111,10 @@ object MetadataFrontendPipelinePhase : PipelinePhase - val firFiles = session.buildFirViaLightTree(files, diagnosticsReporter) { files, lines -> + val firFiles = session.buildFirViaLightTree(files, diagnosticsReporter, configuration.headerCompilation) { files, lines -> perfManager?.addSourcesStats(files, lines) } - resolveAndCheckFir(session, firFiles, diagnosticsReporter) + resolveAndCheckFir(session, firFiles, diagnosticsReporter, configuration.headerCompilation) } } else { val projectEnvironment = VfsBasedProjectEnvironment( @@ -149,11 +150,11 @@ object MetadataFrontendPipelinePhase : PipelinePhase val firFiles = session.buildFirFromKtFiles(files) - resolveAndCheckFir(session, firFiles, diagnosticsReporter) + resolveAndCheckFir(session, firFiles, diagnosticsReporter, configuration.headerCompilation) } } - outputs.runPlatformCheckers(diagnosticsReporter) + outputs.runPlatformCheckers(diagnosticsReporter, configuration.headerCompilation) when (configuration.useLightTree) { true -> outputs.all { checkKotlinPackageUsageForLightTree(configuration, it.fir) } diff --git a/compiler/config/configuration-keys-generator/src/org/jetbrains/kotlin/config/keys/generator/CommonConfigurationKeysContainer.kt b/compiler/config/configuration-keys-generator/src/org/jetbrains/kotlin/config/keys/generator/CommonConfigurationKeysContainer.kt index 44216a860cc26..0229bb83bd26e 100644 --- a/compiler/config/configuration-keys-generator/src/org/jetbrains/kotlin/config/keys/generator/CommonConfigurationKeysContainer.kt +++ b/compiler/config/configuration-keys-generator/src/org/jetbrains/kotlin/config/keys/generator/CommonConfigurationKeysContainer.kt @@ -47,6 +47,7 @@ object CommonConfigurationKeysContainer : KeysContainer("org.jetbrains.kotlin.co val ALLOW_ANY_SCRIPTS_IN_SOURCE_ROOTS by key("Allow to compile any scripts along with regular Kotlin sources") val IGNORE_CONST_OPTIMIZATION_ERRORS by key("Ignore errors from IrConstTransformer") val EVALUATED_CONST_TRACKER by key("Keeps track of all evaluated by IrInterpreter constants") + val HEADER_COMPILATION by key("Enable header compilation mode") val MESSAGE_COLLECTOR_KEY by key( "message collector", diff --git a/compiler/config/gen/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/config/gen/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt index 5113aabb661b3..0fcb57fab609a 100644 --- a/compiler/config/gen/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt +++ b/compiler/config/gen/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt @@ -97,6 +97,9 @@ object CommonConfigurationKeys { @JvmField val EVALUATED_CONST_TRACKER = CompilerConfigurationKey.create("Keeps track of all evaluated by IrInterpreter constants") + @JvmField + val HEADER_COMPILATION = CompilerConfigurationKey.create("Enable header compilation mode") + @JvmField val MESSAGE_COLLECTOR_KEY = CompilerConfigurationKey.create("message collector") @@ -230,6 +233,10 @@ var CompilerConfiguration.evaluatedConstTracker: EvaluatedConstTracker? get() = get(CommonConfigurationKeys.EVALUATED_CONST_TRACKER) set(value) { put(CommonConfigurationKeys.EVALUATED_CONST_TRACKER, requireNotNull(value) { "nullable values are not allowed" }) } +var CompilerConfiguration.headerCompilation: Boolean + get() = getBoolean(CommonConfigurationKeys.HEADER_COMPILATION) + set(value) { put(CommonConfigurationKeys.HEADER_COMPILATION, value) } + var CompilerConfiguration.messageCollector: MessageCollector get() = get(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE) set(value) { put(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY, value) } diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/testFixtures/org/jetbrains/kotlin/fir/java/AbstractFirOldFrontendLightClassesTest.kt b/compiler/fir/analysis-tests/legacy-fir-tests/testFixtures/org/jetbrains/kotlin/fir/java/AbstractFirOldFrontendLightClassesTest.kt index 312bf3a5864ed..1b1f2bfa299a7 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/testFixtures/org/jetbrains/kotlin/fir/java/AbstractFirOldFrontendLightClassesTest.kt +++ b/compiler/fir/analysis-tests/legacy-fir-tests/testFixtures/org/jetbrains/kotlin/fir/java/AbstractFirOldFrontendLightClassesTest.kt @@ -121,7 +121,7 @@ abstract class AbstractFirOldFrontendLightClassesTest : BaseDiagnosticsTest() { private fun mapKtFilesToFirFiles(session: FirSession, ktFiles: List, firFiles: MutableList, useLightTree: Boolean) { val firProvider = (session.firProvider as FirProviderImpl) if (useLightTree) { - val lightTreeBuilder = LightTree2Fir(session, firProvider.kotlinScopeProvider) + val lightTreeBuilder = LightTree2Fir(session, false, firProvider.kotlinScopeProvider) ktFiles.mapTo(firFiles) { val firFile = lightTreeBuilder.buildFirFile( diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt index 6de5acc30c52f..d927c4967d94e 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/convertToIr.kt @@ -76,7 +76,8 @@ data class Fir2IrActualizedResult( val symbolTable: SymbolTable, ) -fun List.runPlatformCheckers(reporter: BaseDiagnosticsCollector) { +fun List.runPlatformCheckers(reporter: BaseDiagnosticsCollector, headerCompilationMode: Boolean) { + if (headerCompilationMode) return val platformModule = this.last() val session = platformModule.session val scopeSession = platformModule.scopeSession diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/firUtils.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/firUtils.kt index 14e057025b84b..699cbbe814167 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/firUtils.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/pipeline/firUtils.kt @@ -23,11 +23,12 @@ import kotlin.reflect.KFunction2 fun FirSession.buildFirViaLightTree( files: Collection, diagnosticsReporter: DiagnosticReporter?, + headerCompilationMode: Boolean, reportFilesAndLines: ((Int, Int) -> Unit)?, ): List { val firProvider = (firProvider as FirProviderImpl) val sourcesToPathsMapper = sourcesToPathsMapper - val builder = LightTree2Fir(this, firProvider.kotlinScopeProvider, diagnosticsReporter) + val builder = LightTree2Fir(this, headerCompilationMode, firProvider.kotlinScopeProvider, diagnosticsReporter) val shouldCountLines = (reportFilesAndLines != null) var linesCount = 0 val firFiles = files.map { file -> @@ -59,9 +60,10 @@ fun FirSession.buildFirFromKtFiles(ktFiles: Collection): List { fun buildResolveAndCheckFirFromKtFiles( session: FirSession, ktFiles: List, - diagnosticsReporter: BaseDiagnosticsCollector + diagnosticsReporter: BaseDiagnosticsCollector, + headerCompilationMode: Boolean ): ModuleCompilerAnalyzedOutput { - return resolveAndCheckFir(session, session.buildFirFromKtFiles(ktFiles), diagnosticsReporter) + return resolveAndCheckFir(session, session.buildFirFromKtFiles(ktFiles), diagnosticsReporter, headerCompilationMode) } /** @@ -71,10 +73,13 @@ fun buildResolveAndCheckFirFromKtFiles( fun resolveAndCheckFir( session: FirSession, firFiles: List, - diagnosticsReporter: BaseDiagnosticsCollector + diagnosticsReporter: BaseDiagnosticsCollector, + headerCompilationMode: Boolean ): ModuleCompilerAnalyzedOutput { val (scopeSession, fir) = session.runResolution(firFiles) - session.runCheckers(scopeSession, fir, diagnosticsReporter, MppCheckerKind.Common) + if (!headerCompilationMode) { + session.runCheckers(scopeSession, fir, diagnosticsReporter, MppCheckerKind.Common) + } return ModuleCompilerAnalyzedOutput(session, scopeSession, fir) } @@ -82,8 +87,9 @@ fun buildResolveAndCheckFirViaLightTree( session: FirSession, ktFiles: Collection, diagnosticsReporter: BaseDiagnosticsCollector, + headerCompilationMode: Boolean, countFilesAndLines: KFunction2? ): ModuleCompilerAnalyzedOutput { - val firFiles = session.buildFirViaLightTree(ktFiles, diagnosticsReporter, countFilesAndLines) - return resolveAndCheckFir(session, firFiles, diagnosticsReporter) + val firFiles = session.buildFirViaLightTree(ktFiles, diagnosticsReporter, headerCompilationMode, countFilesAndLines) + return resolveAndCheckFir(session, firFiles, diagnosticsReporter, headerCompilationMode) } diff --git a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt index 1380f2b82d2b7..8f905c8dbd0fd 100644 --- a/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt +++ b/compiler/fir/modularized-tests/tests/org/jetbrains/kotlin/fir/FirResolveModularizedTotalKotlinTest.kt @@ -111,7 +111,7 @@ class FirResolveModularizedTotalKotlinTest : AbstractFrontendModularizedTest() { val firProvider = session.firProvider as FirProviderImpl val firFiles = if (USE_LIGHT_TREE) { - val lightTree2Fir = LightTree2Fir(session, firProvider.kotlinScopeProvider, diagnosticsReporter = null) + val lightTree2Fir = LightTree2Fir(session, false, firProvider.kotlinScopeProvider, diagnosticsReporter = null) bench.buildFiles(lightTree2Fir, sourceFiles) } else { val builder = PsiRawFirBuilder(session, firProvider.kotlinScopeProvider) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt index 47a1fc1d75e43..ad73e2a32c6ca 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/LightTree2Fir.kt @@ -23,6 +23,7 @@ import java.nio.file.Path class LightTree2Fir( val session: FirSession, + val headerCompilationMode: Boolean, private val scopeProvider: FirScopeProvider, private val diagnosticsReporter: DiagnosticReporter? = null, ) { @@ -43,7 +44,7 @@ class LightTree2Fir( sourceFile: KtSourceFile, linesMapping: KtSourceFileLinesMapping, ): FirFile { - return LightTreeRawFirDeclarationBuilder(session, scopeProvider, lightTree) + return LightTreeRawFirDeclarationBuilder(session, scopeProvider, lightTree, headerCompilationMode=headerCompilationMode) .convertFile(lightTree.root, sourceFile, linesMapping) } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt index 68048ed228835..9852730cb506f 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirDeclarationBuilder.kt @@ -62,9 +62,10 @@ class LightTreeRawFirDeclarationBuilder( internal val baseScopeProvider: FirScopeProvider, tree: FlyweightCapableTreeStructure, context: Context = Context(), + val headerCompilationMode: Boolean, ) : AbstractLightTreeRawFirBuilder(session, tree, context) { - private val expressionConverter = LightTreeRawFirExpressionBuilder(session, tree, this, context) + private val expressionConverter = LightTreeRawFirExpressionBuilder(session, tree, this, context, headerCompilationMode) /** * [org.jetbrains.kotlin.parsing.KotlinParsing.parseFile] @@ -95,11 +96,11 @@ class LightTreeRawFirDeclarationBuilder( packageDirective = convertPackageDirective(child).also { context.packageFqName = it.packageFqName } } IMPORT_LIST -> importList += convertImportDirectives(child) - CLASS -> firDeclarationList += convertClass(child) - FUN -> firDeclarationList += convertFunctionDeclaration(child) as FirDeclaration + CLASS -> firDeclarationList += convertClass(child, headerCompilationMode) + FUN -> firDeclarationList += convertFunctionDeclaration(child, headerCompilationMode) as FirDeclaration KtNodeTypes.PROPERTY -> firDeclarationList += convertPropertyDeclaration(child) TYPEALIAS -> firDeclarationList += convertTypeAlias(child) - OBJECT_DECLARATION -> firDeclarationList += convertClass(child) + OBJECT_DECLARATION -> firDeclarationList += convertClass(child, headerCompilationMode) DESTRUCTURING_DECLARATION -> { val initializer = buildFirDestructuringDeclarationInitializer(child) firDeclarationList += buildErrorNonLocalDestructuringDeclaration(child.toFirSourceElement(), initializer) @@ -134,21 +135,27 @@ class LightTreeRawFirDeclarationBuilder( /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseBlockExpression */ - fun convertBlockExpression(block: LighterASTNode): FirBlock { - return convertBlockExpressionWithoutBuilding(block).build() + fun convertBlockExpression(block: LighterASTNode, generateHeaders: Boolean = false): FirBlock { + return convertBlockExpressionWithoutBuilding(block, generateHeaders = generateHeaders).build() } - fun convertBlockExpressionWithoutBuilding(block: LighterASTNode, kind: KtFakeSourceElementKind? = null): FirBlockBuilder { + fun convertBlockExpressionWithoutBuilding( + block: LighterASTNode, + kind: KtFakeSourceElementKind? = null, + generateHeaders: Boolean = false + ): FirBlockBuilder { val firStatements = block.forEachChildrenReturnList { node, container -> - when (node.tokenType) { - CLASS, OBJECT_DECLARATION -> container += convertClass(node) as FirStatement - FUN -> container += convertFunctionDeclaration(node) - KtNodeTypes.PROPERTY -> container += convertPropertyDeclaration(node) as FirStatement - DESTRUCTURING_DECLARATION -> container += - convertDestructingDeclaration(node).toFirDestructingDeclaration(this, baseModuleData) - TYPEALIAS -> container += convertTypeAlias(node) as FirStatement - CLASS_INITIALIZER -> shouldNotBeCalled("CLASS_INITIALIZER expected to be processed during class body conversion") - else -> if (node.isExpression()) container += expressionConverter.getAsFirStatement(node) + if (!generateHeaders || container.isEmpty()) { // Take only the first statement which could be a contract for header generation. + when (node.tokenType) { + CLASS, OBJECT_DECLARATION -> container += convertClass(node, generateHeaders) as FirStatement + FUN -> container += convertFunctionDeclaration(node) + KtNodeTypes.PROPERTY -> container += convertPropertyDeclaration(node) as FirStatement + DESTRUCTURING_DECLARATION -> container += + convertDestructingDeclaration(node).toFirDestructingDeclaration(this, baseModuleData) + TYPEALIAS -> container += convertTypeAlias(node) as FirStatement + CLASS_INITIALIZER -> shouldNotBeCalled("CLASS_INITIALIZER expected to be processed during class body conversion") + else -> if (node.isExpression()) container += expressionConverter.getAsFirStatement(node) + } } } return FirBlockBuilder().apply { @@ -457,7 +464,7 @@ class LightTreeRawFirDeclarationBuilder( /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseClassOrObject */ - private fun convertClass(classNode: LighterASTNode): FirDeclaration { + private fun convertClass(classNode: LighterASTNode, generateHeaders: Boolean): FirDeclaration { var modifiers: ModifierList? = null var classKind: ClassKind = ClassKind.CLASS var identifier: String? = null @@ -633,7 +640,7 @@ class LightTreeRawFirDeclarationBuilder( //parse declarations classBody?.let { - addDeclarations(convertClassBody(it, classWrapper)) + addDeclarations(convertClassBody(it, classWrapper, generateHeaders)) } //parse data class @@ -919,10 +926,14 @@ class LightTreeRawFirDeclarationBuilder( * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseClassBody * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseEnumClassBody */ - private fun convertClassBody(classBody: LighterASTNode, classWrapper: ClassWrapper?): List { + private fun convertClassBody( + classBody: LighterASTNode, + classWrapper: ClassWrapper?, + generateHeaders: Boolean = false + ): List { val modifierLists = mutableListOf() val firDeclarations = classBody.forEachChildrenReturnList { node, container -> - convertDeclarationFromClassBody(node, container, classWrapper, modifierLists) + convertDeclarationFromClassBody(node, container, classWrapper, modifierLists, generateHeaders) } convertDanglingModifierListsInClassBody(modifierLists, firDeclarations) @@ -934,14 +945,15 @@ class LightTreeRawFirDeclarationBuilder( container: MutableList, classWrapper: ClassWrapper?, modifierLists: MutableList, + generateHeaders: Boolean = false ) { when (node.tokenType) { ENUM_ENTRY -> container += convertEnumEntry(node, classWrapper!!) - CLASS -> container += convertClass(node) - FUN -> container += convertFunctionDeclaration(node) as FirDeclaration + CLASS -> container += convertClass(node, generateHeaders) + FUN -> container += convertFunctionDeclaration(node, generateHeaders) as FirDeclaration KtNodeTypes.PROPERTY -> container += convertPropertyDeclaration(node, classWrapper) TYPEALIAS -> container += convertTypeAlias(node) - OBJECT_DECLARATION -> container += convertClass(node) + OBJECT_DECLARATION -> container += convertClass(node, generateHeaders) CLASS_INITIALIZER -> container += convertAnonymousInitializer(node, classWrapper!!.classBuilder.ownerRegularOrAnonymousObjectSymbol) //anonymousInitializer SECONDARY_CONSTRUCTOR -> container += convertSecondaryConstructor(node, classWrapper!!) MODIFIER_LIST -> modifierLists += node @@ -1922,7 +1934,7 @@ class LightTreeRawFirDeclarationBuilder( /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunction */ - fun convertFunctionDeclaration(functionDeclaration: LighterASTNode): FirStatement { + fun convertFunctionDeclaration(functionDeclaration: LighterASTNode, generateHeaders: Boolean = false): FirStatement { var modifiers: ModifierList? = null var identifier: String? = null var valueParametersList: LighterASTNode? = null @@ -1939,6 +1951,8 @@ class LightTreeRawFirDeclarationBuilder( identifier = it.asText } + var headerMode = generateHeaders + val isLocal = isCallableLocal(functionDeclaration) { getParent() } val functionSource = functionDeclaration.toFirSourceElement() val isAnonymousFunction = identifier == null && isLocal @@ -1970,6 +1984,11 @@ class LightTreeRawFirDeclarationBuilder( val calculatedModifiers = modifiers ?: ModifierList() + if (calculatedModifiers.hasInline()) { + // We need to disable header mode for inline functions. + headerMode = false + } + if (returnType == null) { returnType = if (block != null || !hasEqToken) implicitUnitType @@ -2065,7 +2084,7 @@ class LightTreeRawFirDeclarationBuilder( val allowLegacyContractDescription = outerContractDescription == null val bodyWithContractDescription = withForcedLocalContext { - convertFunctionBody(block, expression, allowLegacyContractDescription) + convertFunctionBody(block, expression, allowLegacyContractDescription, headerMode) } this.body = bodyWithContractDescription.first val contractDescription = outerContractDescription ?: bodyWithContractDescription.second @@ -2102,11 +2121,12 @@ class LightTreeRawFirDeclarationBuilder( private fun convertFunctionBody( blockNode: LighterASTNode?, expression: LighterASTNode?, - allowLegacyContractDescription: Boolean + allowLegacyContractDescription: Boolean, + generateHeaders: Boolean = false, ): Pair { return when { blockNode != null -> { - val block = convertBlock(blockNode) + val block = convertBlock(blockNode, generateHeaders) val contractDescription = runIf(allowLegacyContractDescription) { val blockSource = block.source val diagnostic = when { @@ -2116,7 +2136,11 @@ class LightTreeRawFirDeclarationBuilder( } processLegacyContractDescription(block, diagnostic) } - block to contractDescription + if (generateHeaders) { + null to contractDescription // We want to preserve the contract info when processing as headers. + } else { + block to contractDescription + } } expression != null -> FirSingleExpressionBlock( expressionConverter.getAsFirExpression(expression, "Function has no body (but should)").toReturn() @@ -2138,7 +2162,7 @@ class LightTreeRawFirDeclarationBuilder( /** * @see org.jetbrains.kotlin.parsing.KotlinParsing.parseBlock */ - fun convertBlock(block: LighterASTNode?): FirBlock { + fun convertBlock(block: LighterASTNode?, generateHeaders: Boolean = false): FirBlock { if (block == null) return buildEmptyExpressionBlock() if (block.tokenType != BLOCK) { return FirSingleExpressionBlock( @@ -2146,7 +2170,7 @@ class LightTreeRawFirDeclarationBuilder( ) } - return convertBlockExpression(block) + return convertBlockExpression(block, generateHeaders) } /** diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt index 18d557f3341f1..43a67a92e60e7 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt @@ -63,6 +63,7 @@ class LightTreeRawFirExpressionBuilder( tree: FlyweightCapableTreeStructure, private val declarationBuilder: LightTreeRawFirDeclarationBuilder, context: Context = Context(), + val headerCompilationMode: Boolean, ) : AbstractLightTreeRawFirBuilder(session, tree, context) { internal inline fun getAsFirExpression( diff --git a/compiler/fir/raw-fir/light-tree2fir/testFixtures/org/jetbrains/kotlin/fir/lightTree/AbstractLightTree2FirConverterTestCase.kt b/compiler/fir/raw-fir/light-tree2fir/testFixtures/org/jetbrains/kotlin/fir/lightTree/AbstractLightTree2FirConverterTestCase.kt index d3e84da34f845..e4ee354688081 100644 --- a/compiler/fir/raw-fir/light-tree2fir/testFixtures/org/jetbrains/kotlin/fir/lightTree/AbstractLightTree2FirConverterTestCase.kt +++ b/compiler/fir/raw-fir/light-tree2fir/testFixtures/org/jetbrains/kotlin/fir/lightTree/AbstractLightTree2FirConverterTestCase.kt @@ -25,6 +25,7 @@ abstract class AbstractLightTree2FirConverterTestCase : AbstractRawFirBuilderTes val path = Paths.get(filePath) val firFile = LightTree2Fir( session = FirSessionFactoryHelper.createEmptySession(parseLanguageFeatures(path.readText())), + headerCompilationMode = false, scopeProvider = StubFirScopeProvider, diagnosticsReporter = null ).buildFirFile(path) diff --git a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/TotalKotlinTest.kt b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/TotalKotlinTest.kt index 4a0629f8ba2b1..b46457ef3faa3 100644 --- a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/TotalKotlinTest.kt +++ b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/TotalKotlinTest.kt @@ -56,6 +56,7 @@ class TotalKotlinTest : AbstractRawFirBuilderTestCase() { @OptIn(ObsoleteTestInfrastructure::class) val lightTreeConverter = LightTree2Fir( session = FirSessionFactoryHelper.createEmptySession(), + headerCompilationMode = false, scopeProvider = StubFirScopeProvider, diagnosticsReporter = null ) diff --git a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt index 40927d0330fe2..0497c9476b354 100644 --- a/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt +++ b/compiler/fir/raw-fir/light-tree2fir/tests/org/jetbrains/kotlin/fir/lightTree/compare/TreesCompareTest.kt @@ -62,6 +62,7 @@ class TreesCompareTest : AbstractRawFirBuilderTestCase() { val lightTreeConverter = LightTree2Fir( session = session, + headerCompilationMode = false, scopeProvider = StubFirScopeProvider, diagnosticsReporter = null ) @@ -97,6 +98,7 @@ class TreesCompareTest : AbstractRawFirBuilderTestCase() { val lightTreeConverter = LightTree2Fir( session = session, + headerCompilationMode = false, scopeProvider = StubFirScopeProvider, diagnosticsReporter = null ) diff --git a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index b56fae4126616..c906085b565ee 100644 --- a/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/codegen/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.codegen.state.JvmBackendConfig import org.jetbrains.kotlin.config.JVMConfigurationKeys import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.DescriptorVisibilities import org.jetbrains.kotlin.descriptors.VariableAccessorDescriptor @@ -216,7 +217,7 @@ class ExpressionCodegen( mv.visitCode() val startLabel = markNewLabel() val info = BlockInfo() - if (state.classBuilderMode.generateBodies) { + if (state.classBuilderMode.generateBodies && !state.configuration.headerCompilation) { if (irFunction.isMultifileBridge()) { // Multifile bridges need to have line number 1 to be filtered out by the intellij debugging filters. mv.visitLineNumber(1, startLabel) diff --git a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt index b9dff5344d026..8553f2c114353 100644 --- a/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt +++ b/compiler/ir/serialization.js/src/org/jetbrains/kotlin/ir/backend/js/klib.kt @@ -441,7 +441,7 @@ fun serializeModuleIntoKlib( dependencies = dependencies, createModuleSerializer = { irDiagnosticReporter -> JsIrModuleSerializer( - settings = IrSerializationSettings(configuration), + settings = IrSerializationSettings(configuration, publicAbiOnly = configuration.headerCompilation), irDiagnosticReporter, irBuiltIns, ) { JsIrFileMetadata(moduleExportedNames[it]?.values?.toSmartList() ?: emptyList()) } diff --git a/compiler/ir/serialization.jvm/src/org/jetbrains/kotlin/backend/jvm/serialization/JvmIrSerializerSession.kt b/compiler/ir/serialization.jvm/src/org/jetbrains/kotlin/backend/jvm/serialization/JvmIrSerializerSession.kt index d38a143c4d733..b4d6d32389c55 100644 --- a/compiler/ir/serialization.jvm/src/org/jetbrains/kotlin/backend/jvm/serialization/JvmIrSerializerSession.kt +++ b/compiler/ir/serialization.jvm/src/org/jetbrains/kotlin/backend/jvm/serialization/JvmIrSerializerSession.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.serialization.IrSerializationSettings import org.jetbrains.kotlin.backend.jvm.serialization.proto.JvmIr import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.JvmSerializeIrMode +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.visitors.IrVisitor @@ -26,6 +27,7 @@ class JvmIrSerializerSession( IrSerializationSettings( configuration = configuration, bodiesOnlyForInlines = mode == JvmSerializeIrMode.INLINE, + publicAbiOnly = configuration.headerCompilation ), declarationTable, ) { diff --git a/compiler/tests-compiler-utils/testFixtures/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt b/compiler/tests-compiler-utils/testFixtures/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt index 6bf4a5baebdea..6cd675a8a4db6 100644 --- a/compiler/tests-compiler-utils/testFixtures/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt +++ b/compiler/tests-compiler-utils/testFixtures/org/jetbrains/kotlin/fir/FirAnalyzerFacade.kt @@ -38,7 +38,7 @@ class FirAnalyzerFacade( private fun buildRawFir() { if (firFiles != null) return firFiles = when (parser) { - FirParser.LightTree -> session.buildFirViaLightTree(lightTreeFiles, diagnosticReporterForLightTree, reportFilesAndLines = null) + FirParser.LightTree -> session.buildFirViaLightTree(lightTreeFiles, diagnosticReporterForLightTree, false, reportFilesAndLines = null) FirParser.Psi -> session.buildFirFromKtFiles(ktFiles) } } diff --git a/js/js.tests/testFixtures/org/jetbrains/kotlin/incremental/FirAbstractInvalidationTest.kt b/js/js.tests/testFixtures/org/jetbrains/kotlin/incremental/FirAbstractInvalidationTest.kt index 2d1f3d2dfb2e6..d8a204081785b 100644 --- a/js/js.tests/testFixtures/org/jetbrains/kotlin/incremental/FirAbstractInvalidationTest.kt +++ b/js/js.tests/testFixtures/org/jetbrains/kotlin/incremental/FirAbstractInvalidationTest.kt @@ -135,6 +135,7 @@ abstract class FirAbstractInvalidationTest( incrementalDataProvider = null, lookupTracker = null, useWasmPlatform = false, + headerCompilationMode = false, ) val fir2IrActualizedResult = transformFirToIr(moduleStructure, analyzedOutput.output, diagnosticsReporter) diff --git a/js/js.tests/tests/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt b/js/js.tests/tests/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt index a3e1bec603ea4..386409eae3868 100644 --- a/js/js.tests/tests/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt +++ b/js/js.tests/tests/org/jetbrains/kotlin/benchmarks/GenerateIrRuntime.kt @@ -502,7 +502,7 @@ class GenerateIrRuntime { val messageCollector = configuration.getNotNull(CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY) return JsIrModuleSerializer( - settings = IrSerializationSettings(configuration), + settings = IrSerializationSettings(configuration, publicAbiOnly = configuration.headerCompilation), KtDiagnosticReporterWithImplicitIrBasedContext( DiagnosticReporterFactory.createPendingReporter(messageCollector), configuration.languageVersionSettings, diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt index 01a9ab2d83ee3..4baa513742468 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirFrontend.kt @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.cli.common.fir.FirDiagnosticsCompilerResultsReporter import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector import org.jetbrains.kotlin.fir.* @@ -74,7 +75,7 @@ internal inline fun PhaseContext.firFrontend( } } - outputs.runPlatformCheckers(diagnosticsReporter) + outputs.runPlatformCheckers(diagnosticsReporter, configuration.headerCompilation) FirDiagnosticsCompilerResultsReporter.reportToMessageCollector(diagnosticsReporter, messageCollector, renderDiagnosticNames) return if (syntaxErrors || diagnosticsReporter.hasErrors) { @@ -99,7 +100,7 @@ internal fun PhaseContext.firFrontendWithPsi(input: KotlinCoreEnvironment): FirO isCommonSource = isCommonSourceForPsi, fileBelongsToModule = fileBelongsToModuleForPsi, buildResolveAndCheckFir = { session, files, diagnosticsReporter -> - buildResolveAndCheckFirFromKtFiles(session, files, diagnosticsReporter) + buildResolveAndCheckFirFromKtFiles(session, files, diagnosticsReporter, configuration.headerCompilation) }, ) } @@ -123,7 +124,7 @@ internal fun PhaseContext.firFrontendWithLightTree(input: KotlinCoreEnvironment) isCommonSource = { groupedSources.isCommonSourceForLt(it) }, fileBelongsToModule = { file, it -> groupedSources.fileBelongsToModuleForLt(file, it) }, buildResolveAndCheckFir = { session, files, diagnosticsReporter -> - buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, null) + buildResolveAndCheckFirViaLightTree(session, files, diagnosticsReporter, configuration.headerCompilation, null) }, ) } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirNativeSerializer.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirNativeSerializer.kt index d1ac4759963fb..809c88ed62f1c 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirNativeSerializer.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/FirNativeSerializer.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.konan.serialization.KonanIrModuleSerializer import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.fir.reportToMessageCollector import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory import org.jetbrains.kotlin.fir.moduleData import org.jetbrains.kotlin.fir.pipeline.Fir2KlibMetadataSerializer @@ -58,12 +59,12 @@ internal fun PhaseContext.firSerializerBase( dependencies = usedResolvedLibraries?.map { it.library as KonanLibrary }.orEmpty(), createModuleSerializer = { irDiagnosticReporter -> KonanIrModuleSerializer( - settings = IrSerializationSettings( - configuration = configuration, - publicAbiOnly = produceHeaderKlib, - ), - diagnosticReporter = irDiagnosticReporter, - irBuiltIns = fir2IrOutput?.fir2irActualizedResult?.irBuiltIns!!, + settings = IrSerializationSettings( + configuration = configuration, + publicAbiOnly = produceHeaderKlib || configuration.headerCompilation, + ), + diagnosticReporter = irDiagnosticReporter, + irBuiltIns = fir2IrOutput?.fir2irActualizedResult?.irBuiltIns!!, ) }, ) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt index 6d3a282094c1e..2fcab57028bc6 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/driver/phases/Serializer.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.backend.konan.PsiToIrOutput import org.jetbrains.kotlin.backend.konan.driver.PhaseContext import org.jetbrains.kotlin.backend.konan.serialization.KonanIrModuleSerializer import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.headerCompilation import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory @@ -40,7 +41,7 @@ internal val SerializerPhase = createSimpleNamedCompilerPhase