diff --git a/JAVA_MIGRATION.md b/JAVA_MIGRATION.md index af17712..bd1da58 100644 --- a/JAVA_MIGRATION.md +++ b/JAVA_MIGRATION.md @@ -24,9 +24,10 @@ No trustworthy tool will produce a maintainable Java port automatically. A decom ## Current status The binary and source-level consumer audits, low-coupling Phase 3 queue, audit-derived immediate compatibility gate, -focused profile, first traversal optimization, complete redstone interaction helper unit, and `MicroRecipe` port are -complete. The remaining measured hot paths are generated tile traits, so the next work starts the Phase 5 Java-trait -pilot; see `JAVA_MIGRATION_PROFILE.md`. +focused profile, first traversal optimization, complete redstone interaction helper unit, `MicroRecipe` port, and the +no-field `TPartialOcclusionTile` Java-trait pilot are complete. Direct Java source now survives the existing +`registerJavaTrait` rewrite with its generated interface, super accessor, behavior, and class caching intact. The next +checkpoint is the stateful `TSlottedTile`; see `JAVA_MIGRATION_PROFILE.md`. That audit found and this branch has now repaired one existing regression: Schematica 1.12.6 reflects the original private `MultiPartRegistry$` field `codechicken$multipart$MultiPartRegistry$$typeMap` and casts it to a Scala mutable map. The @@ -336,22 +337,25 @@ Status: active. `operate` now preserves its captured-sequence mutation semantics and the six-interface `IRedstonePart`/`RedstoneInteractions$` unit is ported with its class list and descriptors intact. The comparison proves its allocation is owned by `scalatraits/TRedstoneTile.scala`, so that part waits for Phase 5. `MicroRecipe` is also Java: all five recipe forms and precedence are characterized, its published Scala façade remains, -and its closure-backed scans and non-local returns are gone. The remaining two hot-path items are generated traits and -will be handled through Phase 5. Start with `TPartialOcclusionTile` as the simple no-field Java-trait pilot before the -stateful slot and redstone traits. +and its closure-backed scans and non-local returns are gone. `TPartialOcclusionTile` has completed the simple no-field +Java-trait pilot. The remaining two hot-path items are stateful generated traits: port `TSlottedTile` as the field and +lifecycle checkpoint before changing `TRedstoneTile` and re-running the redstone profile. Exit condition: identified steady-state Scala allocation sites are removed with compatible results. ### Phase 5 — Convert built-in tile traits through the existing Java path -- [ ] Characterize the interfaces, fields, lifecycle callbacks, and behavior of the Scala-generated pilot tile. -- [ ] Port one simple built-in trait as a pilot using `registerJavaTrait`. -- [ ] Verify generated methods, interfaces, field initialization, lifecycle callbacks, and class caching against the Scala version. +- [x] Characterize the direct class shape, generated interface, super dispatch, behavior, and class caching of a + no-field pilot. +- [x] Port one simple built-in trait as a pilot using `registerJavaTrait`. +- [ ] Verify generated field accessors, initialization, copying, lifecycle callbacks, and class caching on the + stateful `TSlottedTile` checkpoint. The no-field pilot proves methods/interfaces/caching but cannot prove state. - [ ] Convert remaining traits in small related groups. - [ ] Document or deliberately relax the Java trait restrictions only when a real trait requires it. - [ ] Preserve pass-through interface behavior. -- [ ] For the pilot, explicitly cover OpenComputers' `TSlottedTile.v_partMap` rebinding, AE2's - `TIInventoryTile.rebuildSlotMap`, and ProjectRed/Extra Utilities `TRedstoneTile` behavior. +- [ ] Explicitly cover OpenComputers' `TSlottedTile.v_partMap` mutation/rebinding before that port, AE2's + `TIInventoryTile.rebuildSlotMap` before the inventory trait, and ProjectRed/Extra Utilities behavior before + `TRedstoneTile`. Exit condition: built-in behavior is implemented in Java while the established runtime composition mechanism remains stable. @@ -668,5 +672,11 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec - Ported the recipe singleton to Java with ordinary loops. The published `MicroRecipe` static façade, `MicroRecipe$.MODULE$`, `scala.Tuple3` return and immutable Scala map descriptors remain; the 12 private Scala closure classes and their `NonLocalReturnControl` exits are gone. -- The recipe port passes all 141 plain-JVM and 37 Forge tests. The next step is the Phase 5 - `TPartialOcclusionTile` Java-trait pilot, whose generated override dispatch is already covered by the Forge harness. +- The recipe port passes all 141 plain-JVM and 37 Forge tests. +- Characterized `TPartialOcclusionTile` against the untouched Scala implementation with four focused tests covering + its exact direct class shape, partial/normal precedence, complete-occlusion behavior, and both short-circuit paths. +- Ported `TPartialOcclusionTile` to direct Java source without changing the generator. Its compiled input still has + one no-arg constructor, no fields, and the same two public descriptors; the Forge rewrite still exposes exactly the + two behavior methods plus its super accessor, caches the generated class, and passes all 37 server tests. +- The pilot raises the plain-JVM baseline to 145 tests. It deliberately proves no field or lifecycle behavior, so the + next checkpoint is `TSlottedTile`, not a bulk conversion of the remaining traits. diff --git a/JAVA_MIGRATION_CONSUMER_AUDIT.md b/JAVA_MIGRATION_CONSUMER_AUDIT.md index 048486a..5c414d1 100644 --- a/JAVA_MIGRATION_CONSUMER_AUDIT.md +++ b/JAVA_MIGRATION_CONSUMER_AUDIT.md @@ -502,7 +502,7 @@ behavior: 6. Treat Scala runtime removal as downstream coordination work after the Java port, not as a requirement of it. Current-branch generator verification: `ForgeEnvironmentSmokeTest` pins cached built-in `TSlottedTile` generation, -an external Scala microblock trait registered by name like ProjectRed's `LightMicroblock`, Java +an external Scala microblock trait registered by name like ProjectRed's `LightMicroblock`, direct-Java-source `TPartialOcclusionTile` rewriting and override dispatch, and server-only pass-through forwarding, overloading, single-implementor selection, copying/rebinding, and removal cleanup. Full downstream mixed tiles and client-side selection remain Phase 7 integration cases. diff --git a/JAVA_MIGRATION_DIVERGENCES.md b/JAVA_MIGRATION_DIVERGENCES.md index f479937..9f4582e 100644 --- a/JAVA_MIGRATION_DIVERGENCES.md +++ b/JAVA_MIGRATION_DIVERGENCES.md @@ -1361,3 +1361,49 @@ paths no longer pay for it. - Complete plain-JVM suite: 141 tests, 0 failures, 0 errors. - Java 8 Forge dedicated-server suite: 37 tests, 0 failures, 0 errors. - Class list and public members compared with the pre-port build; no characterization assertion changed. + +## 2026-08-28 — TPartialOcclusionTile Java-trait pilot + +This is the first built-in generated tile implementation whose source moved directly to Java. It was already a +concrete Scala class, so the existing registration path treated it as a Java trait and rewrote it at class-load time; +the port changes the compiler input without changing that generator. + +### Observable behavior + +No known divergence. A partial-occlusion candidate is still appended to the existing Scala `Seq` and tested before +the normal superclass pairwise chain. Failure still short-circuits that chain. Non-partial candidates still go directly +to the superclass. `partialOcclusionTest` still fills only `JPartialOcclusion` entries at their original indices and +retains `PartialOcclusionTest`'s exclusive-voxel and complete-occlusion rules. + +Java uses a Scala `Seq` builder for the appended candidate because Scala 2.11's `Seq.:+` builder signature is not +expressible type-safely from javac with its wildcarded `CanBuildFrom`. The resulting call still dispatches through the +public `partialOcclusionTest(Seq)` method, preserving subclass/generated override behavior. + +### Supported JVM and generated APIs + +The direct compiled class still extends `TileMultipart`, has no fields or interfaces, one public no-arg constructor, +and exactly the same two public method descriptors. No anonymous or helper class is emitted. There were no direct +downstream references to this class in the audited mod corpus; consumers reach the behavior through +`JPartialOcclusion` parts and generated tiles. + +At Forge class-load time the same name is still rewritten to a public interface with no fields and exactly three +methods: `occlusionTest`, `partialOcclusionTest`, and the generated +`codechicken$multipart$scalatraits$TPartialOcclusionTile$$super$occlusionTest` accessor. Generated composite instances +still implement it, and equal trait sets still reuse the same generated class. + +The Scala source signature disappears from the untransformed class. No supported consumer used it, no `$class` helper +existed in the input artifact, and the runtime generator continues to create the implementation helper it requires. + +### Scope boundary + +This pilot has no fields or lifecycle callbacks. It therefore does not validate field-to-accessor rewriting, +constructor initialization injection, setter rebinding, copying, or part add/remove lifecycle order. Those are not +assumed safe from this result; `TSlottedTile` is the explicit stateful checkpoint before broader trait conversion. + +### Validation + +- `TPartialOcclusionTileCharacterizationTest`: 4 tests covering exact direct shape, partial/normal precedence, + exclusive visibility, complete-occlusion exemption, and both short-circuit paths. +- Complete plain-JVM suite: 145 tests, 0 failures, 0 errors. +- Java 8 Forge dedicated-server suite: 37 tests, 0 failures, 0 errors. +- Runtime reflection verifies the exact generated interface methods, no fields, override behavior, and class reuse. diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index 899e3b6..fb3834a 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -12,7 +12,7 @@ what breaks, and what is left. The other documents hold the reasoning. | `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client | | `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command | -Branch: `algent/java`. Base: `master`. 68 commits including the `MicroRecipe` unit. +Branch: `algent/java`. Base: `master`. 70 commits including the `TPartialOcclusionTile` characterization and Java port. ## The one rule that matters @@ -66,7 +66,7 @@ awk -F'"' '/ parts, TMultiPart newPart) { + if (newPart instanceof JPartialOcclusion) { + Builder> builder = Seq$.MODULE$.newBuilder(); + builder.$plus$plus$eq(parts); + builder.$plus$eq(newPart); + if (!partialOcclusionTest(builder.result())) { + return false; + } + } + return super.occlusionTest(parts, newPart); + } + + public boolean partialOcclusionTest(Seq parts) { + PartialOcclusionTest test = new PartialOcclusionTest(parts.length()); + for (int index = 0; index < parts.length(); index++) { + TMultiPart part = parts.apply(index); + if (part instanceof JPartialOcclusion) { + test.fill(index, (JPartialOcclusion) part); + } + } + return test.apply(); + } +} diff --git a/src/main/scala/codechicken/multipart/scalatraits/TPartialOcclusionTile.scala b/src/main/scala/codechicken/multipart/scalatraits/TPartialOcclusionTile.scala deleted file mode 100644 index f5d22f1..0000000 --- a/src/main/scala/codechicken/multipart/scalatraits/TPartialOcclusionTile.scala +++ /dev/null @@ -1,36 +0,0 @@ -package codechicken.multipart.scalatraits - -import codechicken.multipart.TileMultipart -import codechicken.multipart.TMultiPart -import codechicken.multipart.JPartialOcclusion -import codechicken.multipart.PartialOcclusionTest - -/** Implementation for the partial occlusion test. - */ -class TPartialOcclusionTile extends TileMultipart { - override def occlusionTest( - parts: Seq[TMultiPart], - npart: TMultiPart - ): Boolean = { - if ( - npart.isInstanceOf[JPartialOcclusion] && !partialOcclusionTest( - parts :+ npart - ) - ) - return false - - return super.occlusionTest(parts, npart) - } - - def partialOcclusionTest(parts: Seq[TMultiPart]): Boolean = { - val test = new PartialOcclusionTest(parts.length) - var i = 0 - while (i < parts.length) { - val part = parts(i) - if (part.isInstanceOf[JPartialOcclusion]) - test.fill(i, part.asInstanceOf[JPartialOcclusion]) - i += 1 - } - return test() - } -}