From 24c772310fb1809b5d5daf1074a42fcb7fb1c0c3 Mon Sep 17 00:00:00 2001 From: Algent Date: Fri, 4 Sep 2026 20:44:35 +0200 Subject: [PATCH] refactor: port applied type descriptors to Java --- JAVA_MIGRATION_HANDOFF.md | 22 +++++++++---------- docs/migration/HISTORY.md | 22 +++++++++++++++++++ .../multipart/asm/ScalaSignature.scala | 5 +---- .../multipart/asm/ScalaSignatureParser.java | 6 +++++ 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/JAVA_MIGRATION_HANDOFF.md b/JAVA_MIGRATION_HANDOFF.md index c9e3520..95f9b64 100644 --- a/JAVA_MIGRATION_HANDOFF.md +++ b/JAVA_MIGRATION_HANDOFF.md @@ -16,24 +16,24 @@ migration checkout; `codex/tile-compatibility-fixes` was deleted after its fixes ## Current state and next target -**477 plain-JVM tests and 237 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java -files and 9 Scala files / 747 nonblank Scala lines**. The packaged inventory has 443 classes. +**484 plain-JVM tests and 237 Java 8 Forge tests pass, with zero failures/errors/skips.** Sources total **224 Java +files and 9 Scala files / 744 nonblank Scala lines**. The packaged inventory has 443 classes. Review follow-up: restored packet-scheduler callback mutation behavior with the original Scala hash-map traversal, virtual tile accessor dispatch throughout `TMultiPart`, and null-safe equality for scheduled-tick deduplication. Six JVM and two Forge regression cases cover the fixes. Callable signatures remain unchanged; the packet traversal callback adds one anonymous class. See the latest history entries for the individual fixes and validation. -Latest bounded target: `ScalaSignature.MethodSymbol.toString` delegates formatting to -`ScalaSignatureParser.methodSymbolString`. Seven characterization tests were committed first as `d81195a`. They pin -the fixed MethodSymbol prefix for concrete/anonymous instances, literal/null values, two's-complement hexadecimal -flags, repeated virtual getter order, owner formatting/failures and the absence of derived-info reads. All 477 frozen -JVM consumers pass; checks preserve 442 retained class/member APIs, all 17 ScalaSignature payloads, 3,738 unrelated -method bodies and all 116 generated dumps. No class is added or removed; the total stays 443 classes. -Evidence: `run/migration-method-symbol-string-reference/`. +Latest bounded target: `ScalaSignature.TypeRefType.jDesc` delegates applied-type descriptor routing to +`ScalaSignatureParser.appliedTypeDescriptor`. Seven characterization tests were committed first as `5493086`. They +pin array argument and fallback routing, two/three virtual name reads, repeated uncached reads, malformed/null type +arguments, failure order and the retained method-type view. A frozen Scala 2.11.5 caller and subclass preserve the +old descriptor. All 484 frozen JVM consumers pass; checks preserve 442 retained class/member APIs, all 17 +ScalaSignature payloads, 3,739 unrelated method bodies and all 116 generated dumps. No class is added or removed; +the total stays 443 classes. Evidence: `run/migration-applied-type-descriptor-reference/`. -**Next bounded candidate: `ScalaSignature.TypeRefType.jDesc`.** Characterize array argument/super routing, virtual -name/typArgs reads, malformed lists, nulls and failure order while retaining the case-class and trait declarations. +**Next bounded candidate: `ScalaSignature.ClassSymbolRef.full`.** Characterize owner/name concatenation, virtual +read order, nulls and failures while retaining the trait, case-class and path-dependent declarations. Keep case-class/product/serialization shapes and simple model accessors. Broader shell replacement and opcode algorithm fixes remain separate work. The external ProjectRed Scala-trait fixture and ScalaSignature model bridges remain required. Actual client diff --git a/docs/migration/HISTORY.md b/docs/migration/HISTORY.md index 4304e61..922f40f 100644 --- a/docs/migration/HISTORY.md +++ b/docs/migration/HISTORY.md @@ -1558,3 +1558,25 @@ differences belong in the [divergence ledger](../../JAVA_MIGRATION_DIVERGENCES.m tests/resources, reports and comparison tools. Frozen runs use its `version.txt`; final builds use the committed version. Source totals are 224 Java files and nine Scala files / 747 nonblank lines. Next: `TypeRefType.jDesc`, preserving array/super routing, virtual reads and malformed-input behavior. + +### 2026-09-04 — ScalaSignature applied-type descriptors + +- Committed seven JVM characterization cases first as `5493086` against the untouched `TypeRefType.jDesc`. They pin + the array branch's first argument descriptor, fallback routing through `TypeRef.jDesc` and `jName`, two/three + virtual name reads, repeated uncached queries, malformed/null argument lists, null descriptors, failure boundaries + and the retained `TMethodType` parameter/return view. +- Added `ReferenceScalaAppliedTypeDescriptor`, compiled once with Scala 2.11.5 under Java 8 against the unchanged dev + jar at `d5bf16f`. Its frozen Scala caller and `TypeRefType` subclass preserve the old method descriptor and virtual + override dispatch. Source, encoded classes and SHA-256 provenance are committed under `src/test/fixtures/` and + `src/test/resources/compat/`; do not regenerate them against the port. +- Extracted the applied-type branch into `ScalaSignatureParser.appliedTypeDescriptor(Object)`. The array path reads + only the first type argument; the fallback reuses `typeDescriptor`, preserving its virtual name and `jName` order. + Scala retains the inferred return type, case class, method-type mixin, product members and serialization shape. +- Normal and clean validation pass 484 JVM tests, all 484 frozen consumers and 237 Java 8 Forge tests with zero + failures/errors/skips. All 116 generated dumps match. Both jars contain 443 Java 8 classes and matching sources; + comparison preserves 442 retained class/member APIs, all 17 ScalaSignature payloads and 3,739 unrelated method + bodies. The helper adds one package-private method; no class inventory or effective divergence changes. +- Evidence is under ignored `run/migration-applied-type-descriptor-reference/`, including the reference/fixture jars, + frozen tests/resources, reports, logs and comparison tools. Frozen runs use its `version.txt`; final builds use the + committed version. Source totals are 224 Java files and nine Scala files / 744 nonblank lines. Next: + `ClassSymbolRef.full`, preserving owner/name concatenation, virtual reads and failure order. diff --git a/src/main/scala/codechicken/multipart/asm/ScalaSignature.scala b/src/main/scala/codechicken/multipart/asm/ScalaSignature.scala index 97cf493..7bf069e 100644 --- a/src/main/scala/codechicken/multipart/asm/ScalaSignature.scala +++ b/src/main/scala/codechicken/multipart/asm/ScalaSignature.scala @@ -132,10 +132,7 @@ class ScalaSignature(val bytes: Bytes) { def returnType = this - override def jDesc = name match { - case "scala.Array" => "[" + typArgs(0).jDesc - case _ => super.jDesc - } + override def jDesc = ScalaSignatureParser.appliedTypeDescriptor(this) } case class ThisType(sym: SymbolRef) extends TypeRef diff --git a/src/main/scala/codechicken/multipart/asm/ScalaSignatureParser.java b/src/main/scala/codechicken/multipart/asm/ScalaSignatureParser.java index b671b9a..13d5847 100644 --- a/src/main/scala/codechicken/multipart/asm/ScalaSignatureParser.java +++ b/src/main/scala/codechicken/multipart/asm/ScalaSignatureParser.java @@ -44,6 +44,12 @@ final class ScalaSignatureParser { return "L" + ref.jName() + ";"; } + static String appliedTypeDescriptor(Object value) { + ScalaSignature.TypeRefType ref = (ScalaSignature.TypeRefType) value; + if ("scala.Array".equals(ref.name())) return "[" + ref.typArgs().apply(0).jDesc(); + return typeDescriptor(ref); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) static String methodDescriptor(Object value) { ScalaSignature.TMethodType method = (ScalaSignature.TMethodType) value;