diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-15 13:22:39 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-15 13:22:39 +0100 |
| commit | 1d6d1a8ee90f407fc6461c18db2811ac672bd1c5 (patch) | |
| tree | 75eb5114f9e9f1a753a4bc548d72072cf7d472f5 /CLAUDE.md | |
| parent | 5df7cb16a9e2a38014deafda99e0b3256acc0040 (diff) | |
Generate argument handling from kotlin-compiler-arguments-description
Diffstat (limited to 'CLAUDE.md')
| -rw-r--r-- | CLAUDE.md | 68 |
1 files changed, 51 insertions, 17 deletions
@@ -9,9 +9,11 @@ ABI-identical **stub** of `org.jetbrains.kotlin.cli.jvm.K2JVMCompiler` that live on the **Kotlin daemon's** classpath. The stub logs every call (and the compiler arguments it receives) and returns JVM defaults / reflectively-built real return objects — it does **not** actually compile. This is **pure -replacement**: no passthrough, no fallback. The build is *supposed* to go red; -the point is to observe exactly what AGP/KGP hands the compiler before -implementing an alternative compile inside the stub. +replacement**: no passthrough, no fallback. With no overrides implemented +the build is *supposed* to go red; the point is to observe exactly what +AGP/KGP hands the compiler before implementing an alternative compile inside +the stub (the current `doExecutePhased` implementation does exactly that — +it drives a native-image kotlinc — so the test build is green; see Testing). `README.md` is the deep reference (bytecode format, log format, full option table). Read it before changing generation behavior. @@ -23,6 +25,18 @@ table). Read it before changing generation behavior. erased structure verbatim. - `tools/gen_jar_lists.py` — regenerates the `jars/*.txt` lists from the local Gradle cache (see Building). +- `tools/gen_arg_table.py` + `tools/ArgProbe.java` — generate the CLI + argument table (`stubs/gen/kotlin/proxy/GeneratedJvmArguments.java`): + translates the daemon-populated `K2JVMCompilerArguments` into kotlinc CLI + tokens for the alternative compile. The probe (reflection, no bytecode + parsing) reads the `@Argument` annotations off the real class — flag + names, delimiters, deprecated/removed markers, and the defaults the no-arg + constructor leaves behind — because the flag names are *not* derivable + from the descriptions (e.g. `-Xdebug` → `enableDebugMode`). The + `kotlin-compiler-arguments.json` from the + `kotlin-compiler-arguments-description` Maven artifact (fetched into + `vendor/` by a curl make target, pinned to `KOTLIN_VERSION`) is only + cross-checked for coverage. - `docs/opcodes.html` — JVM bytecode opcode reference. **Consult it whenever hand-rolling bytecode in `gen_class.py`** — opcodes like `putstatic` (0xb3) and stack peaks are easy to get wrong, and the JVM only complains with an @@ -31,6 +45,10 @@ table). Read it before changing generation behavior. stub calls into. - `stubs/src/kotlin/proxy/KotlinProxyOverrides.java` — per-method custom return values: the extension point for actually *implementing* stub methods. +- `stubs/gen/kotlin/proxy/GeneratedJvmArguments.java` — generated CLI + argument table (gitignored, see `tools/gen_arg_table.py`). +- `vendor/kotlin-compiler-arguments-description-<v>.jar` — the Maven + artifact the generator cross-checks against (gitignored, curl-fetched). - `stubs/src/kotlin/proxy/ProxyPerformanceManager.java` — override support class (per-compiler-instance perf manager) returned by the overrides. - `jars/defs.txt`, `jars/scan.txt`, `jars/fallback.txt`, `jars/.stamp` — @@ -47,22 +65,31 @@ table). Read it before changing generation behavior. make ``` -The Makefile runs the 3 real steps in order: +The Makefile runs the 5 real steps in order: -1. Regenerate `jars/*.txt` via `tools/gen_jar_lists.py` when the pinned +1. Fetch `vendor/kotlin-compiler-arguments-description-<v>.jar` from Maven + Central via curl when missing (pinned to `KOTLIN_VERSION`; needs network). +2. Regenerate the CLI argument table + `stubs/gen/kotlin/proxy/GeneratedJvmArguments.java` when the + tool/probe/vendor-jar/defs list changed (`tools/gen_arg_table.py`; it + prints a coverage report both directions — JSON args with no class field + and vice versa — to stderr). +3. Regenerate `jars/*.txt` via `tools/gen_jar_lists.py` when the pinned versions (Makefile vars `KOTLIN_VERSION` / `AGP_VERSION`, kept in sync with `test_project/gradle/libs.versions.toml`) drift from `jars/.stamp`. The Gradle cache must already hold those versions — run the test_project once first (even a red build resolves everything). -2. Generate the stub classes (`tools/gen_class.py`, **wipes** `stubs/classes_min` +4. Generate the stub classes (`tools/gen_class.py`, **wipes** `stubs/classes_min` first — put nothing you need there): `--seed-only --no-closure --seed '…K2JVMCompiler,…K2JVMCompiler$Companion,…K2JVMCompilerKt'`. -3. Compile the `kotlin.proxy.*` classes into the same tree (the `-cp` lets - `KotlinProxyOverrides` import real compiler types), then package the jar. +5. Compile the `kotlin.proxy.*` classes **and the generated argument table** + into the same tree (the `-cp` lets `KotlinProxyOverrides` import real + compiler types), then package the jar. -The result is 7 class files + manifest: the three seeded stubs plus +The result is 8 class files + manifest: the three seeded stubs plus `kotlin/proxy/KotlinProxyLog`, `kotlin/proxy/KotlinProxyOverrides` -(+ inner `$Compiler`), and `kotlin/proxy/ProxyPerformanceManager`. The +(+ inner `$Compiler`), `kotlin/proxy/ProxyPerformanceManager`, and +`kotlin/proxy/GeneratedJvmArguments`. The seed trio are **the only** classes stubbed (the "trio" mode); their superclasses/interfaces (`CLICompiler`, `K2JVMCompilerArguments`, …) are *not* stubbed and resolve from the real jars on the daemon classpath. @@ -75,10 +102,15 @@ The "test" is the test project. From `test_project/`: ./gradlew :app:compileDebugKotlin ``` -Expected outcome: **red** (`compileDebugKotlin FAILED`, "Internal compiler -error" — the stub returns defaults, so the real compiler machinery fails -after calling into the stub). That is the intended state. To confirm the stub -actually ran *inside the out-of-process daemon*, read the marker file +Expected outcome depends on which overrides are implemented: with none, the +build is **red** (`compileDebugKotlin FAILED`, "Internal compiler error" — +the stub returns defaults, so the real compiler machinery fails after +calling into the stub). With the current `doExecutePhased` implementation +(it hands the generated CLI table to a native-image kotlinc), the build is +**green** and the compiled output lands in +`test_project/app/build/intermediates/built_in_kotlinc/…/classes` (e.g. +`…/org/the_jk/testproject/Hello.class`). To confirm the stub actually ran +*inside the out-of-process daemon*, read the marker file `/tmp/kotlin-proxy-marker.txt` — a daemon run shows thread names `RMI TCP Connection(N)` and `LOAD …/dist/kotlin-proxy-compiler-stubs.jar` lines (the trio's `<clinit>`s also `LOAD` `…$Companion`). An @@ -160,6 +192,8 @@ re-verifying, and `rm /tmp/kotlin-proxy-marker.txt` for a fresh marker. jar). The default mode is a full transitive closure from the AGP scan jars + KGP plugin entry points — a much larger jar; only use it when you actually want to stub a broader surface. -- **Build artifacts are gitignored:** `dist/` (whole dir) and - `stubs/classes_min/` are not tracked. If you need the jar and it's missing, - run `make`. +- **Build artifacts are gitignored:** `dist/` (whole dir), + `stubs/classes_min/`, `stubs/gen/` (generated argument table) and + `vendor/` (curl-fetched Maven artifact) are not tracked. If you need the + jar and it's missing, run `make` (the arg table and vendor jar are + regenerated/fetched as needed; the fetch needs network). |
