Skip to content

Commit 5c9dd80

Browse files
committed
Aleksey review part 1
1 parent 1cefa1c commit 5c9dd80

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

docs/topics/compiler-plugins.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[//]: # (title: Compiler plugins)
22

3-
This page explains the Kotlin compiler plugins available to you and what you can do if none of them suits your use case.
4-
53
Compiler plugins hook into the compilation process to analyze or change code while it's being compiled, without modifying the compiler itself. For example, they can annotate code or generate new code to make it compatible with other frameworks or APIs.
64

5+
This page explains the Kotlin compiler plugins available to you and what you can do if none of them suits your use case.
6+
77
The Kotlin team maintains the following compiler plugins:
88
* [All-open](all-open-plugin.md)
99
* [AtomicFU](https://github.com/Kotlin/kotlinx-atomicfu)
@@ -17,8 +17,9 @@ The Kotlin team maintains the following compiler plugins:
1717
* [SAM with receiver](sam-with-receiver-plugin.md)
1818
* [Serialization](serialization.md)
1919

20-
The Android team at Google maintains the [Compose compiler Gradle plugin](https://developer.android.com/develop/ui/compose/compiler)
21-
and the [Parcelize plugin](https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize).
20+
The Android team at Google maintains:
21+
* [Compose compiler Gradle plugin](https://developer.android.com/develop/ui/compose/compiler)
22+
* [Parcelize plugin](https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize)
2223

2324
If you need to adapt the compilation process in a way that these plugins don't cover, first check whether you can use the
2425
[Kotlin Symbol Processing (KSP) API](https://kotlinlang.org/docs/ksp-overview.html) or an external linter such as [Android lint](https://developer.android.com/studio/write/lint).
@@ -27,15 +28,15 @@ and ask for advice about your use case.
2728

2829
If you _still_ can't find what you need, you can create a custom compiler plugin. Use this approach only as a last resort,
2930
because the Kotlin compiler plugin API is **unstable**. Maintaining a custom compiler plugin requires significant ongoing
30-
effort, since each new compiler release introduces breaking changes.
31+
effort, because each new compiler release introduces breaking changes.
3132

3233
## Custom compiler plugins
3334

34-
> The Kotlin compiler plugin API is unstable and includes breaking changes in every release.
35+
> The Kotlin compiler plugin API is unstable and introduces breaking changes in every release.
3536
>
3637
{style="warning"}
3738

38-
Compiler plugins can influence different stages of the compilation process depending on their use case.
39+
Compiler plugins can influence different stages of the compilation process.
3940

4041
![Kotlin compiler stages](compiler-stages.svg){width=650}
4142

@@ -109,10 +110,17 @@ The backend plugin API, also known as IR, has a single extension point: [`IrGene
109110
Use this extension point and override the `generate()` function to add bodies to declarations already generated by the
110111
frontend or change existing declaration bodies.
111112

112-
Changes made through this extension point are **not checked**. You must ensure that your changes don't break the compiler's
113+
Changes made through this extension point are **not checked** by the compiler. You must ensure that your changes don't break the compiler's
113114
expectations at this stage. For example, you might accidentally introduce an invalid type, an incorrect function reference,
114115
or a reference outside the correct scope.
115116

117+
### Explore backend plugin code
118+
119+
You can explore the Kotlin serialization plugin code to see what backend plugin compiler code looks like in practice.
120+
For example, [`SerializableCompanionIrGenerator.kt`](https://github.com/JetBrains/kotlin/blob/master/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt)
121+
fills in missing bodies for key serializer members. One example is the [`generateChildSerializersGetter()`](https://github.com/JetBrains/kotlin/blob/9cfa558902abc13d245c825717026af63ef82dd2/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt#L242)
122+
function, which collects a list of `KSerializer` expressions and returns them in an array.
123+
116124
#### Check your backend plugin for problems
117125

118126
You can check for problems in your backend plugin code in three main ways:
@@ -129,11 +137,6 @@ You can check for problems in your backend plugin code in three main ways:
129137

130138
In the `convertToIr.kt` file, add breakpoints in the `convertToIrAndActualize()` function and run the compiler in debug mode to get more detailed information during compilation.
131139

132-
You can also explore the Kotlin serialization plugin code to see what backend plugin compiler code looks like in practice.
133-
For example, [`SerializableCompanionIrGenerator.kt`](https://github.com/JetBrains/kotlin/blob/master/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt)
134-
fills in missing bodies for key serializer members. One example is the [`generateChildSerializersGetter()`](https://github.com/JetBrains/kotlin/blob/9cfa558902abc13d245c825717026af63ef82dd2/plugins/kotlinx-serialization/kotlinx-serialization.backend/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt#L242)
135-
function, which collects a list of `KSerializer` expressions and returns them in an array.
136-
137140
### Test your plugin
138141

139142
Once you implement your plugin, test it thoroughly. The [Kotlin compiler plugin template](https://github.com/Kotlin/compiler-plugin-template)
@@ -157,5 +160,5 @@ new dump files become your latest _golden_ files: an approved and trusted source
157160
### Get help
158161

159162
If you run into issues developing a custom compiler plugin, reach out in [Kotlin Slack](https://surveys.jetbrains.com/s3/kotlin-slack-sign-up)
160-
in the [#compiler](https://kotlinlang.slack.com/archives/C7L3JB43G) channel. We can't promise a solution but we will try
163+
in the [#compiler](https://slack-chats.kotlinlang.org/c/compiler) channel. We can't promise a solution but we will try
161164
to help if we can.

0 commit comments

Comments
 (0)