mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 04:32:24 +00:00
refactor: port Scala signature reader to Java
This commit is contained in:
1 parent
9f927046b9
commit
f7be2b163d
6 files changed
+112
-47
No files matched your search
@@ -1287,3 +1287,15 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
unchanged. All 140 retained `ScalaSignature`, `ScalaSigReader` and `ASMMixinCompiler` types have identical
|
||||
disassembly. Recompiled Scala uses `pos_$eq` and `advance(length, value)`; the latter source-syntax difference is
|
||||
recorded in the ledger. `ScalaSigReader` in `multipart/asm/ScalaSignature.scala` is the next isolated target.
|
||||
- Extracted `ScalaSigReader` to a Java facade and companion, retaining all five methods on each and the singleton
|
||||
field. Decode still uses the platform charset; encode keeps UTF-8 and the reference's trailing-byte truncation,
|
||||
including empty input. Annotation reads still use `ScalaSignature.Bytes$`, writes return the replaced list value,
|
||||
and lookup returns the first match as a Scala `Option` with the original malformed-entry failures.
|
||||
- Replaced Scala array slicing and annotation traversal with standard-library operations. Only two compiler calls
|
||||
explicitly name the companion; no signature-model, byte-codec or compiler algorithm changed. Both Java 8 public
|
||||
surfaces match the saved `9f92704` reference, and all 137 retained signature/compiler types have identical
|
||||
disassembly. Only the private annotation-search closure disappears, taking the packaged inventory from 463 to 462.
|
||||
- No tests were added, per the current user instruction. A clean formatting/checkstyle/build passes all 276 existing
|
||||
JVM tests; Java 8 Forge passes all 116 tests, including external Scala-trait generation. All 39 generated dump names
|
||||
and SHA-256 hashes match the reference. No new ledger entry is needed. `multipart/asm/ASMMixinFactory.scala` is next
|
||||
as a single factory port before the larger nested signature model and compiler.
|
||||
@@ -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`. 160 commits including the API-cleanup plan, divergence-log cleanup and ports
|
||||
through `ByteCodeReader`.
|
||||
Branch: `algent/java`. Base: `master`. 161 commits including the API-cleanup plan, divergence-log cleanup and ports
|
||||
through `ScalaSigReader`.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -278,7 +278,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.
|
||||
|
||||
200 Java files, 11 Scala files, 2,286 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
202 Java files, 11 Scala files, 2,254 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -576,10 +576,18 @@ Only the position setter and two-argument `advance` syntax changed in the signat
|
||||
and compiler types have identical disassembly, the 463-class inventory is unchanged, and all 39 Forge-suite dump names
|
||||
and contents match the reference. Existing suites remain at 276 JVM and 116 Forge tests; no tests were added.
|
||||
|
||||
**Next: `ScalaSigReader` in `multipart/asm/ScalaSignature.scala`.** Extract the facade/companion around annotation
|
||||
encoding and decoding before the signature model. Preserve both charsets, the exact byte slicing/packing, `write`'s
|
||||
returned previous annotation value and the first-match Scala `Option` lookup. Keep the signature model, byte codecs
|
||||
and compiler algorithms unchanged, with only required source-call adjustments.
|
||||
`ScalaSigReader` is now a Java facade and companion, retaining all five methods on each. Platform-charset decoding,
|
||||
UTF-8 encoding, legacy trailing-byte truncation, `write`'s previous-value result and the first-match Scala `Option`
|
||||
lookup are preserved. Both public surfaces match the reference. All 137 retained signature/compiler types have
|
||||
identical disassembly, and all 39 Forge-suite dump names and contents match. Only the private annotation-search
|
||||
closure disappears, reducing the packaged inventory from 463 to 462 classes. Existing suites remain at 276 JVM and
|
||||
116 Forge tests; no tests were added.
|
||||
|
||||
**Next: `multipart/asm/ASMMixinFactory.scala`.** Port this single factory before the larger nested signature model.
|
||||
Preserve its Scala `Seq` constructor/argument boundaries, protected callbacks, synchronized construction, copied
|
||||
BitSet cache keys, generated-name sequence and registration/parent-validation order. Keep both Scala- and Java-trait
|
||||
registration paths and the existing maps. Leave `MultipartMixinFactory`, the signature model and compiler algorithms
|
||||
unchanged apart from necessary source-call adjustments.
|
||||
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.
|
||||
|
||||
|
||||
@@ -213,8 +213,8 @@ object ASMMixinCompiler {
|
||||
if (name == null) return null
|
||||
|
||||
def scalaInfo(cnode: ClassNode, obj: Boolean) =
|
||||
ScalaSigReader.ann(cnode).flatMap { ann =>
|
||||
val sig = ScalaSigReader.read(ann)
|
||||
ScalaSigReader$.MODULE$.ann(cnode).flatMap { ann =>
|
||||
val sig = ScalaSigReader$.MODULE$.read(ann)
|
||||
val name = cnode.name.replace('/', '.')
|
||||
(if (obj) sig.findObject(name) else sig.findClass(name))
|
||||
.map(csym => new ScalaClassInfo(cnode, sig, csym))
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import codechicken.multipart.asm.ScalaSignature.Bytes$;
|
||||
import scala.Option;
|
||||
import scala.Some;
|
||||
|
||||
public final class ScalaSigReader$ {
|
||||
|
||||
public static final ScalaSigReader$ MODULE$ = new ScalaSigReader$();
|
||||
|
||||
private ScalaSigReader$() {}
|
||||
|
||||
public byte[] decode(String s) {
|
||||
// The reference decodes with the platform charset, not the UTF-8 used by encode.
|
||||
byte[] bytes = s.getBytes();
|
||||
int length = ByteCodecs.decode(bytes);
|
||||
return Arrays.copyOf(bytes, Math.min(bytes.length, Math.max(0, length)));
|
||||
}
|
||||
|
||||
public String encode(byte[] b) {
|
||||
byte[] bytes = ByteCodecs.encode8to7(b);
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = (byte) ((bytes[i] + 1) & 0x7f);
|
||||
}
|
||||
return new String(bytes, 0, Math.max(0, bytes.length - 1), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public ScalaSignature read(AnnotationNode ann) {
|
||||
return new ScalaSignature(Bytes$.MODULE$.apply(decode((String) ann.values.get(1))));
|
||||
}
|
||||
|
||||
public Object write(ScalaSignature sig, AnnotationNode ann) {
|
||||
return ann.values.set(1, encode(sig.bytes().arr()));
|
||||
}
|
||||
|
||||
public Option<AnnotationNode> ann(ClassNode cnode) {
|
||||
List<AnnotationNode> annotations = cnode.visibleAnnotations;
|
||||
if (annotations != null) {
|
||||
for (AnnotationNode annotation : annotations) {
|
||||
if (annotation.desc.equals("Lscala/reflect/ScalaSignature;")) return new Some<>(annotation);
|
||||
}
|
||||
}
|
||||
return Option.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import scala.Option;
|
||||
|
||||
public final class ScalaSigReader {
|
||||
|
||||
private ScalaSigReader() {}
|
||||
|
||||
public static byte[] decode(String s) {
|
||||
return ScalaSigReader$.MODULE$.decode(s);
|
||||
}
|
||||
|
||||
public static String encode(byte[] b) {
|
||||
return ScalaSigReader$.MODULE$.encode(b);
|
||||
}
|
||||
|
||||
public static ScalaSignature read(AnnotationNode ann) {
|
||||
return ScalaSigReader$.MODULE$.read(ann);
|
||||
}
|
||||
|
||||
public static Object write(ScalaSignature sig, AnnotationNode ann) {
|
||||
return ScalaSigReader$.MODULE$.write(sig, ann);
|
||||
}
|
||||
|
||||
public static Option<AnnotationNode> ann(ClassNode cnode) {
|
||||
return ScalaSigReader$.MODULE$.ann(cnode);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
package codechicken.multipart.asm
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode
|
||||
import org.objectweb.asm.tree.AnnotationNode
|
||||
import org.objectweb.asm.tree.FieldNode
|
||||
import org.objectweb.asm.tree.MethodNode
|
||||
import java.util.{List => JList}
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.JavaConversions._
|
||||
|
||||
import ScalaSignature._
|
||||
|
||||
object ScalaSignature {
|
||||
@@ -300,33 +292,3 @@ class ScalaSignature(val bytes: Bytes) {
|
||||
def findClass(name: String) =
|
||||
collect[ClassSymbol](6).find(c => !c.isModule && c.full == name)
|
||||
}
|
||||
|
||||
object ScalaSigReader {
|
||||
def decode(s: String) = {
|
||||
val bytes = s.getBytes
|
||||
bytes take ByteCodecs.decode(bytes)
|
||||
}
|
||||
|
||||
def encode(b: Array[Byte]) = {
|
||||
val bytes = ByteCodecs.encode8to7(b)
|
||||
var i = 0
|
||||
while (i < bytes.length) {
|
||||
bytes(i) = ((bytes(i) + 1) & 0x7f).toByte
|
||||
i += 1
|
||||
}
|
||||
new String(bytes.take(bytes.length - 1), "UTF-8")
|
||||
}
|
||||
|
||||
def read(ann: AnnotationNode): ScalaSignature = new ScalaSignature(
|
||||
Bytes(decode(ann.values.get(1).asInstanceOf[String]))
|
||||
)
|
||||
|
||||
def write(sig: ScalaSignature, ann: AnnotationNode) =
|
||||
ann.values.set(1, encode(sig.bytes.arr))
|
||||
|
||||
def ann(cnode: ClassNode): Option[AnnotationNode] =
|
||||
cnode.visibleAnnotations match {
|
||||
case null => None
|
||||
case a => a.find(ann => ann.desc.equals("Lscala/reflect/ScalaSignature;"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user