refactor: port ASM implicits to Java

This commit is contained in:
Algent committed 2026-09-02 17:37:54 +02:00
1 parent 2a7d2653e0
commit 1faf0ddca2
8 files changed
+193 -37

No files matched your search

+15
View File
@@ -1248,3 +1248,18 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
six methods plus randomized lengths through 256, null and invalid decode lengths: all 450,790 cases matched on
return values, exception types and full mutated arrays. No new difference needs a separate ledger entry.
`multipart/asm/ASMImplicits.scala` is next; compiler behavior changes remain separate work.
- Characterized `ASMImplicits` against untouched Scala in five plain-JVM cases: all six runtime surfaces, identity
conversions, node names, null handling, BitSet self-replacement and clear-before-failure, independent plain-BitSet
copies, and boxed equality/hash behavior. Neither consumer audit identifies a direct external user.
- A follow-up characterization, also passed against the saved Scala reference jar, pins virtual `BitSet.equals`
dispatch even for identical references. The Java implementation uses an explicit null check here because
`Objects.equals` would skip that call.
- Ported the facade, companion and four nested value-class/extension types to two Java sources, retaining every
callable public name, descriptor and modifier. Seven Scala compiler/factory call sites now explicitly invoke the
helpers; compiler algorithms and trait registration are unchanged. The ledger records the lost implicit syntax and
the Java publication rule: explicitly constructing either public extension companion no longer replaces `MODULE$`,
verified against the reference in isolated class loaders.
- Clean formatting/checkstyle/build passes all 276 plain-JVM tests, and Java 8 Forge passes all 116 tests. All six
helpers have Java source markers and Java 8 class versions; compiler/factory public descriptors and the full
464-class packaged inventory match the reference. `MultipartGenerator$` disassembly is unchanged. The next bounded
target is extracting `DebugPrinter` from `ASMMixinCompiler.scala`, leaving the compiler algorithms for later.
+4
View File
@@ -18,6 +18,7 @@ and `JAVA_MIGRATION_CONSUMER_AUDIT.md` before extending this list.
| `NormalOcclusionTest.apply(Traversable, Traversable)` | Materializes both inputs into Java lists before testing instead of nested Scala `forall`. Finite, side-effect-free collections give the same result; eager traversal can change side effects, failure timing and termination for unusual inputs. |
| `MultipartRenderer` dynamic-part guard | Uses short-circuit `\|\|` instead of `\|`; the second getter is no longer evaluated when the first operand succeeds. Ordinary getters give the same render decision. |
| `ControlKeyModifer.map()` | The exposed Java map has no Scala default-value wrapper: an absent key returns null from `get`, not false from Scala `apply`. Use `isControlDown` for the unchanged absent-means-false behavior. |
| Public companion constructors, including `ASMImplicits.ExtBitSet$` / `ExtClass$` | Explicit construction creates an independent instance instead of replacing `MODULE$`. Java initializes the retained final module field in its static initializer; use `MODULE$` for singleton identity. |
Concrete collection implementations also change without changing the declared `java.lang.Iterable`/`List` contracts:
@@ -125,6 +126,9 @@ Previously compiled calls to **retained** `$class` bridges still link. This does
recipes, packet handlers, materials and generators). Static calls alone do not supply a singleton value.
- Object-application sugar becomes explicit `.apply(...)`, e.g. `NormalOcclusionTest.apply(...)` and
`MicroblockPlacement$.MODULE$.apply(...)`.
- `ASMImplicits` no longer provides Scala implicit/value-class syntax. Use `nodeName(clazz.getName)` and
`ExtBitSet$.MODULE$.copy$extension(bits)` explicitly, or construct its retained Java wrappers. Existing boxed and
`$extension` binary entry points remain; implicit conversion requires Scala metadata Java cannot emit.
- Scala property assignment needs the explicit Java-authored `_$eq(...)` method, e.g. `renderID`, `loadingWorld`,
`angelicaCompat` and microblock `shape`.
- `tile.partList(i)` becomes `tile.partList.apply(i)`. Static bounds getters on Face, Corner, Edge and Post factories
+15 -8
View File
@@ -12,8 +12,8 @@ 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`. 155 commits including the API-cleanup plan, divergence-log cleanup and separate
characterization and port commits through the byte codec.
Branch: `algent/java`. Base: `master`. 158 commits including the API-cleanup plan, divergence-log cleanup and separate
characterization and port commits through the ASM implicit helpers.
## The one rule that matters
@@ -68,7 +68,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
```
Current baseline: **271 plain-JVM tests and 116 Java 8 Forge dedicated-server tests passing.** The ignored local server
Current baseline: **276 plain-JVM tests and 116 Java 8 Forge dedicated-server tests passing.** The ignored local server
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
the shared GTNH build; keep both jobs required.
@@ -274,7 +274,7 @@ across the port. It is also where the two shim constraints in the gotchas list w
`rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written
into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block.
195 Java files, 12 Scala files, 2,367 Scala lines left (non-blank; that is the metric this figure has always used).
197 Java files, 11 Scala files, 2,352 Scala lines left (non-blank; that is the metric this figure has always used).
## What is left, and in what order
@@ -551,10 +551,17 @@ unchecked malformed-input failures. A clean jar confirms both Java source marker
450,790 additional reference/port cases match. The signature-parser source and external Scala-trait fixtures remain
unchanged; recompiled `ScalaSigReader` calls the retained static facade instead of the companion directly.
**Next: `multipart/asm/ASMImplicits.scala`.** Characterize the BitSet copy/replacement helpers, alias/null behavior,
node-name conversion and emitted value-class/extension surfaces before porting. Check both consumer audits before
deciding which compiler-generated entry points to keep. Recompiled Scala callers will need explicit helper calls;
keep those changes mechanical and leave trait registration, signature parsing and compiler algorithms alone.
`ASMImplicits` is now Java, retaining the facade, companion, both boxed value classes and both extension companions.
Five plain-JVM cases freeze their exact surfaces, name/null conversion, BitSet aliasing and partial failure, copy
independence and boxed equality/hash behavior. Only seven implicit call sites in the Scala compiler/factory changed;
the packaged class inventory and the multipart generator companion's disassembly are unchanged. Source callers need
explicit helper calls; normal calls retain the same results. The ledger records Java's public-companion constructor
publication difference as well.
**Next: `DebugPrinter` in `multipart/asm/ASMMixinCompiler.scala`.** Extract the diagnostic singleton without changing
the compiler itself. Characterize configuration gating, initial directory cleanup, dump naming/content and the
16,000-byte logging threshold first. Isolate file-writing checks in temporary directories so they cannot purge real
debug output. Keep the facade/companion boundary and make only required source-call adjustments in the compiler.
The remaining generated microblock traits still need the Phase 7 abstract-Java-mixin and side-only-member support
before their Java mixin inputs are safe; do not bypass those prerequisites by flattening their inheritance.
@@ -0,0 +1,22 @@
package codechicken.multipart.asm;
import java.util.BitSet;
public final class ASMImplicits$ {
public static final ASMImplicits$ MODULE$ = new ASMImplicits$();
private ASMImplicits$() {}
public BitSet ExtBitSet(BitSet bitset) {
return bitset;
}
public Class<?> ExtClass(Class<?> clazz) {
return clazz;
}
public String nodeName(String name) {
return name == null ? null : name.replace('.', '/');
}
}
@@ -0,0 +1,128 @@
package codechicken.multipart.asm;
import java.util.BitSet;
import java.util.Objects;
/** Name and BitSet helpers, retaining the Scala value-class entry points for compiled callers. */
public final class ASMImplicits {
private ASMImplicits() {}
public static BitSet ExtBitSet(BitSet bitset) {
return ASMImplicits$.MODULE$.ExtBitSet(bitset);
}
public static Class ExtClass(Class clazz) {
return ASMImplicits$.MODULE$.ExtClass(clazz);
}
public static String nodeName(String name) {
return ASMImplicits$.MODULE$.nodeName(name);
}
public static final class ExtBitSet {
private final BitSet bitset;
public ExtBitSet(BitSet bitset) {
this.bitset = bitset;
}
public BitSet bitset() {
return bitset;
}
public BitSet set(BitSet other) {
return ExtBitSet$.MODULE$.set$extension(bitset, other);
}
public BitSet copy() {
return ExtBitSet$.MODULE$.copy$extension(bitset);
}
@Override
public int hashCode() {
return ExtBitSet$.MODULE$.hashCode$extension(bitset);
}
@Override
public boolean equals(Object other) {
return ExtBitSet$.MODULE$.equals$extension(bitset, other);
}
}
public static class ExtBitSet$ {
public static final ExtBitSet$ MODULE$ = new ExtBitSet$();
public ExtBitSet$() {}
public final BitSet set$extension(BitSet bitset, BitSet other) {
// Preserve clear-before-read: self-replacement empties the set, and a null source fails after clearing.
bitset.clear();
bitset.or(other);
return bitset;
}
public final BitSet copy$extension(BitSet bitset) {
return set$extension(new BitSet(), bitset);
}
public final int hashCode$extension(BitSet bitset) {
return bitset.hashCode();
}
public final boolean equals$extension(BitSet bitset, Object other) {
if (!(other instanceof ExtBitSet)) return false;
BitSet otherBits = ((ExtBitSet) other).bitset();
// Scala still dispatches equals for identical non-null references; Objects.equals would skip it.
return bitset == null ? otherBits == null : bitset.equals(otherBits);
}
}
public static final class ExtClass {
private final Class<?> clazz;
public ExtClass(Class<?> clazz) {
this.clazz = clazz;
}
public Class<?> clazz() {
return clazz;
}
public String nodeName() {
return ExtClass$.MODULE$.nodeName$extension(clazz);
}
@Override
public int hashCode() {
return ExtClass$.MODULE$.hashCode$extension(clazz);
}
@Override
public boolean equals(Object other) {
return ExtClass$.MODULE$.equals$extension(clazz, other);
}
}
public static class ExtClass$ {
public static final ExtClass$ MODULE$ = new ExtClass$();
public ExtClass$() {}
public final String nodeName$extension(Class clazz) {
return ASMImplicits$.MODULE$.nodeName(clazz.getName());
}
public final int hashCode$extension(Class clazz) {
return clazz.hashCode();
}
public final boolean equals$extension(Class clazz, Object other) {
return other instanceof ExtClass && Objects.equals(clazz, ((ExtClass) other).clazz());
}
}
}
@@ -1,22 +0,0 @@
package codechicken.multipart.asm
import java.util.BitSet
object ASMImplicits {
implicit class ExtBitSet(val bitset: BitSet) extends AnyVal {
def set(b: BitSet) = {
bitset.clear()
bitset.or(b)
bitset
}
def copy = new BitSet().set(bitset)
}
def nodeName(name: String) =
if (name == null) null else name.replace('.', '/')
implicit class ExtClass(val clazz: Class[_]) extends AnyVal {
def nodeName = ASMImplicits.nodeName(clazz.getName)
}
}
@@ -204,7 +204,7 @@ object ASMMixinCompiler {
cnode.name
)
implicit def getClassInfo(clazz: Class[_]): ClassInfo =
if (clazz == null) null else getClassInfo(clazz.nodeName)
if (clazz == null) null else getClassInfo(nodeName(clazz.getName))
object ClassInfo {
class ReflectionClassInfo(clazz: Class[_]) extends ClassInfo {
@@ -212,12 +212,12 @@ object ASMMixinCompiler {
def owner = ReflectionClassInfo.this
def name = method.getName
def desc = getType(method).getDescriptor
def exceptions = method.getExceptionTypes.map(_.nodeName)
def exceptions = method.getExceptionTypes.map(c => nodeName(c.getName))
def isPrivate = Modifier.isPrivate(method.getModifiers)
def isAbstract = Modifier.isAbstract(method.getModifiers)
}
def name = clazz.nodeName
def name = nodeName(clazz.getName)
def superClass = Option(clazz.getSuperclass)
def interfaces = clazz.getInterfaces.map(getClassInfo)
def methods = clazz.getMethods.map(ReflectionMethodInfo(_))
@@ -31,7 +31,7 @@ class ASMMixinFactory[T](
seq += traits(i)
val c = ASMMixinCompiler
.mixinClasses(nextName(), baseType.nodeName, seq.result())
.mixinClasses(nextName(), nodeName(baseType.getName), seq.result())
.asInstanceOf[Class[_ <: T]]
onCompiled(c, traitSet)
c.getDeclaredConstructor(paramTypes: _*)
@@ -45,7 +45,7 @@ class ASMMixinFactory[T](
case Some(c) => c
case None =>
val c = compile(traitSet)
classMap.put(traitSet.copy, c)
classMap.put(ExtBitSet$.MODULE$.copy$extension(traitSet), c)
c
}).newInstance(args: _*)
}
@@ -53,7 +53,7 @@ class ASMMixinFactory[T](
def getId(s_trait: String) = traitMap(s_trait)
def registerTrait(traitClass: Class[_]): Int = registerTrait(
traitClass.nodeName
nodeName(traitClass.getName)
)
def registerTrait(s_trait: String): Int = {
@@ -84,7 +84,9 @@ class ASMMixinFactory[T](
info.name == parentName || info.superClass.exists(checkParent)
if (!checkParent(getClassInfo(baseType)))
throw new IllegalArgumentException(
baseType.nodeName + " does not extend parent " + parentName + " of mixin trait " + s_trait
nodeName(
baseType.getName
) + " does not extend parent " + parentName + " of mixin trait " + s_trait
)
if (info.isTrait) {