feat(pbs): add linked collections and bidirectional snapshots

Implement SDK linked<T> with forward and reverse Cursor snapshots, trusted compiler integration, and neutral FIELDS_PUBLISH producer support. Pin the tested runtime revision and include specs, editor and installed knowledge coverage, conformance fixtures, and DSC-0091 lessons and evidence.
This commit is contained in:
2026-10-23 10:28:44 +01:00
parent c410e35001
commit 77aada6259
38 changed files with 3040 additions and 57 deletions
@@ -8,7 +8,7 @@ final class BytecodeOpcodeLayout {
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x51,0x80,0xa7 -> 2;
case 0x16 -> 3;
case 0x02,0x03,0x04,0x10,0x17,0x18,0x40,0x41,0x42,0x43,0x50,0x53,0x57,0x70,0x71,0x72,
0x90,0x91,0x92,0xa0,0xa3,0xa4,0xa5,0xa6,0xa8,0xa9 -> 6;
0x90,0x91,0x92,0xa0,0xa3,0xa4,0xa5,0xa6,0xa8,0xa9,0xab -> 6;
case 0x14,0x15,0x52,0x58,0x93,0x94,0x95,0x96,0xa1,0xa2 -> 10;
case 0xaa -> 18;
default -> throw new BytecodeMarshalingException(BytecodeMarshalingErrorCode.MARSHAL_VERIFY_PRECHECK_UNKNOWN_OPCODE,
@@ -59,6 +59,10 @@ public class BytecodePreloadVerifierService {
case 0xa0 -> check(type(r,a).body() instanceof Struct,"Struct category");
case 0xa1,0xa2 -> field(r,a,b);
case 0xa3,0xa4,0xa5,0xa6,0xa8,0xa9 -> array(r,a);
case 0xab -> {
check(type(r,a).body() instanceof Struct,"Struct publication schema");
for (var entry : ((Struct)type(r,a).body()).fields()) check(r.type(entry.type()).body() instanceof Struct,"Struct publication destination");
}
case 0xaa -> {array(r,a);field(r,b,instruction.third());field(r,b,instruction.fourth());check(instruction.third()!=instruction.fourth(),"publication fields must differ");}
default -> { }
}
@@ -167,6 +171,14 @@ public class BytecodePreloadVerifierService {
case 0xa4 -> {consume(s,facts(r,type(r,a).identity()),typed);s.stack.add(carrier("i64"));}
case 0xa5 -> {consume(s,List.of(carrier("i64")),typed);consume(s,facts(r,type(r,a).identity()),typed);produce(s,facts(r,array(r,a).element()),i.pc());}
case 0xa6 -> {consume(s,facts(r,array(r,a).element()),typed);consume(s,List.of(carrier("i64")),typed);consume(s,facts(r,type(r,a).identity()),typed);}
case 0xab -> {
var expected=new ArrayList<Fact>();
for(var entry:((Struct)type(r,a).body()).fields()) {
expected.addAll(facts(r,entry.type()));
for(var field:((Struct)r.type(entry.type()).body()).fields()) expected.addAll(facts(r,field.type()));
}
consume(s,expected,typed);
}
case 0xa7 -> consume(s,List.of(carrier("i64"),carrier("i64")),typed);
case 0xa8 -> consume(s,List.of(carrier("i64")),typed);
case 0xa9,0xaa -> {
@@ -51,6 +51,14 @@ public final class RegistryInstructionLowerer {
pops=instruction.kind()==IRRegistryInstruction.Kind.STRUCT_SET?1+width:1;pushes=instruction.kind()==IRRegistryInstruction.Kind.STRUCT_GET?width:0;
}
}
case FIELDS_PUBLISH -> {
if (!(body instanceof Struct schema)) throw new IllegalArgumentException("Struct publication schema required");
for (var entry : schema.fields()) {
if (!(registry.type(entry.type()).body() instanceof Struct owner)) throw new IllegalArgumentException("Struct publication destination required");
pops = Math.addExact(pops, 1);
for (var field : owner.fields()) pops = Math.addExact(pops, registry.width(field.type()));
}
}
case INDEX_GUARD -> pops=2;
case ARRAY_CHECK_LENGTH,ARRAY_COPY,STORAGE_PUBLISH -> {
if(!(body instanceof Array array))throw new IllegalArgumentException("Array category required");
@@ -77,7 +77,7 @@ class IRVMIntrinsicRegistryParityTest {
assertNotNull(input);
properties.load(input);
}
assertEquals("f7d7c167531bb662a1af9d73fc326bb476bf8aa7", properties.getProperty("runtime.revision"));
assertEquals("57992cf214e8a5f9de53a40dba9aaa7fab038c91", properties.getProperty("runtime.revision"));
for (var name : List.of("INTRINSICS.csv", "BUILTIN_CONSTANTS.csv")) {
assertEquals(properties.getProperty(name + ".sha256"),
HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes(name))));
@@ -31,6 +31,35 @@ class StoragePublicationPipelineTest {
}
private void number(long value){literal(PUSH_I64,Long.toString(value));}
@Test void multiObjectFieldsPublishThroughNeutralOrdinaryAndOptimizedProducers() throws Exception {
var schema = new TypeRef("synthetic:publication-schema");
var registry = new IRRegistry(ReadOnlyList.from(
new TypeDeclaration(INTEGER,null,new Builtin(0x10)),
new TypeDeclaration(LONG,null,new Builtin(0x11)),
new TypeDeclaration(OWNER,"State",new Struct(ReadOnlyList.from(
new NamedType(LONG,"generation"),new NamedType(INTEGER,"answer")))),
new TypeDeclaration(schema,null,new Struct(ReadOnlyList.from(
new NamedType(OWNER,null),new NamedType(OWNER,null))))),null);
typed(STRUCT_NEW,OWNER,0);local(SET_LOCAL,0);
typed(STRUCT_NEW,OWNER,0);local(SET_LOCAL,1);
local(GET_LOCAL,0);number(7);literal(PUSH_I32,"20");
local(GET_LOCAL,1);number(9);literal(PUSH_I32,"42");
typed(FIELDS_PUBLISH,schema,0);
local(GET_LOCAL,1);typed(STRUCT_GET,OWNER,1);literal(RET,null);
var function=new IRBackendExecutableFunction(new FileId(0),new ModuleId(0),"main",new CallableId(0),0,0,0,2,1,6,
ReadOnlyList.wrap(instructions),null,new FunctionMetadata(new Signature(null,ReadOnlyList.from(INTEGER)),null,Role.NONE));
var backend=IRBackend.builder().entryPointModuleId(new ModuleId(0)).entryPointCallableName("main")
.registry(registry).executableFunctions(ReadOnlyList.from(function)).build();
for(boolean optimize:new boolean[]{false,true}) {
var program=new LowerToIRVMService().lower(backend);
if(optimize)program=new OptimizeIRVMService().optimize(program);
var module=new BytecodeEmitter().emit(program.coherentEmissionPlan());
new BytecodePreloadVerifierService().verify(module);
var directory=Path.of("build/registry-conformance");Files.createDirectories(directory);
Files.write(directory.resolve("common-fields"+(optimize?"-optimized":"")+".pbx"),module.serialize());
}
}
@Test void guardsTransfersAndPublicationSurviveBothProducerPaths() throws Exception {
var registry=new IRRegistry(ReadOnlyList.from(
new TypeDeclaration(INTEGER,null,new Builtin(0x10)),new TypeDeclaration(LONG,null,new Builtin(0x11)),