diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-05 20:41:25 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-05 20:41:25 +0100 |
| commit | aefb3dbf687b46775bca1b600317bc053648b211 (patch) | |
| tree | fc20afdc03ee7cd60bb7fa7bae438fcad033fa5a /CLAUDE.md | |
| parent | a22e0810f6473ff9063166f75b7e4e0236324b6b (diff) | |
First steps for overrides
Diffstat (limited to 'CLAUDE.md')
| -rw-r--r-- | CLAUDE.md | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -21,8 +21,10 @@ table). Read it before changing generation behavior. - `tools/gen_class.py` — self-contained Python stub generator (the core). Emits `.class` files **directly** (not Java source) by copying the real class's erased structure verbatim. -- `stubs/src/kotlin/proxy/KotlinProxyLog.java` — the one *real* class in the jar; - every generated stub calls into it. +- `stubs/src/kotlin/proxy/KotlinProxyLog.java` — the logger every generated + stub calls into. +- `stubs/src/kotlin/proxy/KotlinProxyOverrides.java` — per-method custom return + values: the extension point for actually *implementing* stub methods. - `jars/defs.txt`, `jars/scan.txt`, `jars/fallback.txt` — jar list files feeding the generator (one jar path per line, `#` = comment). - `dist/kotlin-proxy-compiler-stubs.jar` — the build artifact (gitignored). @@ -39,18 +41,22 @@ python3 tools/gen_class.py \ --seed 'org/jetbrains/kotlin/cli/jvm/K2JVMCompiler,org/jetbrains/kotlin/cli/jvm/K2JVMCompiler$Companion,org/jetbrains/kotlin/cli/jvm/K2JVMCompilerKt' \ --out stubs/classes_min -# 2. Compile the logger into the SAME tree (MUST run after step 1, which wiped it) -javac -nowarn -proc:none -d stubs/classes_min stubs/src/kotlin/proxy/KotlinProxyLog.java +# 2. Compile the real classes into the SAME tree (MUST run after step 1, which +# wiped it). The -cp lets KotlinProxyOverrides import real compiler types. +javac -nowarn -proc:none -d stubs/classes_min \ + -cp "$(grep -v '^[[:space:]]*#' jars/defs.txt | tr '\n' ':')" \ + stubs/src/kotlin/proxy/KotlinProxyLog.java \ + stubs/src/kotlin/proxy/KotlinProxyOverrides.java # 3. Package jar cf dist/kotlin-proxy-compiler-stubs.jar -C stubs/classes_min . ``` -The result is 4 class files + manifest: the three seeded stubs plus -`kotlin/proxy/KotlinProxyLog`. 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. +The result is 5 class files + manifest: the three seeded stubs plus +`kotlin/proxy/KotlinProxyLog` and `kotlin/proxy/KotlinProxyOverrides`. 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. ## Testing / verifying (there is no unit-test suite) @@ -65,6 +71,8 @@ machinery NPEs 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 `/tmp/kotlin-proxy-marker.txt` — a daemon run shows thread names `RMI TCP Connection(N)` and `LOAD …/dist/kotlin-proxy-compiler-stubs.jar` lines. +An `OVERRIDE <owner>.<member> -> <dump>` line shows a +`KotlinProxyOverrides.invoke` implementation supplied the return value. The marker path is fixed regardless of the daemon's working dir or missing `-Dkotlin.proxy.log`, so it is the reliable proof. @@ -83,8 +91,13 @@ Sanity-check generated bytecode with `javap -c stubs/classes_min/org/jetbrains/k `StackMapTable` frames are needed. `<clinit>` calls `KotlinProxyLog.loaded`; constructors call `super()` (enums call `Enum.<init>("stub",0)`); concrete methods log and then return a default — but reference-class returns - (except `String`) materialize a *real* instance via `newInstance` so the daemon - can proceed (e.g. `createArguments()` yields a real `K2JVMCompilerArguments`). + (except `String`) build an `Object[]` of the call's arguments (primitives + boxed; `null` when param-less) and ask `KotlinProxyLog.returnValue`, which + consults `KotlinProxyOverrides.invoke` first (per-method custom + implementations — the hook for actually *implementing* a stub method with + real arguments) and falls back to materializing a *real* instance of the + declared return type so the daemon can proceed (e.g. `createArguments()` + yields a real `K2JVMCompilerArguments`). Param-less erasure bridges forward to their concrete sibling instead of logging+null (the daemon dispatches through bridges). - **Classpath shadowing (the subtle part):** KGP seeds the daemon classpath from |
