Skip to content

Commit

Permalink
update compiler page
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso committed Jul 10, 2022
1 parent 2260c4c commit 9775e72
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion docs/general/compiler_plugin.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
# Compiler Plugin

Compose works by transforming all Kotlin functions that are annotated with @Composable.
Compose works by transforming all Kotlin functions that are annotated with **@Composable** and adding code for the Compose Runtime.
To do that it uses a Kotlin Compiler Plugin.


For instance, this Composable:
```kotlin
@Composable
fun Hello(name: String) {
Text(name)
}
```


will be transformed and compiled to Jvm ByteCode. Below you can see the decompiled code as Java code

```java
@Metadata(
mv = {1, 5, 1},
k = 2,
xi = 48,
d1 = {"\u0000\u0010\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\u001a\u0015\u0010\u0000\u001a\u00020\u00012\u0006\u0010\u0002\u001a\u00020\u0003H\u0007¢\u0006\u0002\u0010\u0004¨\u0006\u0005"},
d2 = {"Hello", "", "name", "", "(Ljava/lang/String;Landroidx/compose/runtime/Composer;I)V", "app_debug"}
)
public final class GreetingKt {
@Composable
public static final void Hello(@NotNull final String name, @Nullable Composer $composer, final int $changed) {
Intrinsics.checkNotNullParameter(name, "name");
$composer = $composer.startRestartGroup(274849561);
ComposerKt.sourceInformation($composer, "C(Hello)7@166L10:Greeting.kt#tlkiwl");
int $dirty = $changed;
if (($changed & 14) == 0) {
$dirty = $changed | ($composer.changed(name) ? 4 : 2);
}

if (($dirty & 11 ^ 2) == 0 && $composer.getSkipping()) {
$composer.skipToGroupEnd();
} else {
TextKt.Text-fLXpl1I(name, (Modifier)null, 0L, 0L, (FontStyle)null, (FontWeight)null, (FontFamily)null, 0L, (TextDecoration)null, (TextAlign)null, 0L, 0, false, 0, (Function1)null, (TextStyle)null, $composer, 14 & $dirty, 0, 65534);
}

ScopeUpdateScope var4 = $composer.endRestartGroup();
if (var4 != null) {
var4.updateScope((Function2)(new Function2() {
public final void invoke(@Nullable Composer $composer, int $force) {
GreetingKt.Hello(name, $composer, $changed | 1);
}
}));
}

}
}
```


## Where can i find the source code
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/compose/compiler/compiler-hosted/

Expand Down

0 comments on commit 9775e72

Please sign in to comment.