Skip to content

Conversation

aviroop-123
Copy link
Contributor

  • Create -Xheader-mode compiler argument to enable header generation.
  • Skip converting function and method body code to FIR.
  • Skip inline functions, objects and functions.
  • Handle null body during FIR -> IR conversion.
  • Handle contracts.
  • Disable checkers during header compilation.

More in https://youtrack.jetbrains.com/issue/KT-78422

@ddolovov
Copy link
Contributor

ddolovov commented Oct 2, 2025

Is this a Kotlin/JVM-only feature?

If yes, then why the CLI flag is available for other Kotlin compilers?

If no, then what's the plan towards the exising -Xheader-klib-path CLI flag in Kotlin/Native?

@aviroop-123
Copy link
Contributor Author

Is this a Kotlin/JVM-only feature? If yes, then why the CLI flag is available for other Kotlin compilers? If no, then what's the plan towards the exising -Xheader-klib-path CLI flag in Kotlin/Native?

No, we should change the description of the issue. It should work atleast across the JVM and native compiler. Once all the features are implemented, we might be able to deprecate the Xheader-klib-path.

@ddolovov
Copy link
Contributor

ddolovov commented Oct 2, 2025

I think, it's also important to pass the "header mode" flag down to IrSerializationSettings.publicAbiOnly. This way you can instruct the IR serializer to avoid serializing data that is not part of KLIB ABI, for example, IR element offsets.

@aviroop-123 aviroop-123 requested a review from a team as a code owner October 4, 2025 04:21
… and expression builders across all compilers.

^KT-78422
@aviroop-123 aviroop-123 force-pushed the header-compilation-1 branch from d5b4265 to e6c6a4e Compare October 4, 2025 05:35
@aviroop-123 aviroop-123 force-pushed the header-compilation-1 branch from e6c6a4e to e4690f2 Compare October 6, 2025 04:04
@mglukhikh
Copy link
Contributor

I don't see any tests for the feature and it seems quite strange for me. As a very minimum, I'd recommend to add some new tests to compiler/fir/analysis-tests/testData/resolve with the new flag enabled and FIR_DUMP also enabled. This will allow you to check if the necessary body parts (like contracts) are generated and unnecessary parts are not generated.


class LightTree2Fir(
val session: FirSession,
val headerCompilationMode: Boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this flag is not needed as you can access it via session.languageVersionSettings.getFlag(...). As an example you can see how it's done for lenientMode. I don't see it's a good idea adding any flag we need as an argument everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants