feat(vm): publish typed fields across multiple structs atomically

Add schema-driven FIELDS_PUBLISH without collection-specific runtime behavior. Validate every nullable destination and complete field group before allocation-free publication, with neutral ownership, malformed-input and quota coverage.
This commit is contained in:
Nilton Constantino
2026-10-23 09:53:40 +01:00
committed by bquarkz
parent d9b9eeb171
commit 57992cf214
13 changed files with 384 additions and 12 deletions
@@ -86,7 +86,7 @@ impl DecodedInstr<'_> {
)
}
Op::GetCapture => {
return Err(LoadFailure::new(LoadCode::InvalidReference, LoadReason::CaptureIndex))
return Err(LoadFailure::new(LoadCode::InvalidReference, LoadReason::CaptureIndex));
}
Op::CallTrait => {
let (ty, method) = self.imm_u32x2().map_err(|_| malformed())?;
@@ -133,6 +133,28 @@ impl DecodedInstr<'_> {
};
(source_layout.storage.slots, pushes)
}
Op::FieldsPublish => {
let schema = self.imm_u32().map_err(|_| malformed())?;
let (decl, _) = type_info(schema)?;
let TypeKind::Struct(entries) = &decl.kind else {
return Err(bad_category(schema));
};
let mut slots = 0u32;
for entry in entries {
let (owner, layout) = type_info(entry.type_id.0)?;
if !matches!(owner.kind, TypeKind::Struct(_)) {
return Err(bad_category(entry.type_id.0));
}
let fields =
u32::try_from(layout.instance.as_ref().unwrap().initialization_slots)
.map_err(|_| malformed())?;
slots = slots
.checked_add(1)
.and_then(|n| n.checked_add(fields))
.ok_or_else(malformed)?;
}
(slots, 0)
}
Op::ArrayCheckLength | Op::ArrayCopy | Op::StoragePublish => {
let (array, owner, first, second) = if self.opcode == Op::StoragePublish {
let [a, o, f, s] = self.imm_u32x4().map_err(|_| malformed())?;
@@ -188,11 +210,7 @@ impl DecodedInstr<'_> {
.get(field as usize)
.ok_or_else(|| bad_category(id).member(field))?;
let w = registry.type_layout(f.type_id).unwrap().storage.slots;
if op == Op::StructGet {
(1, w)
} else {
(1 + w, 0)
}
if op == Op::StructGet { (1, w) } else { (1 + w, 0) }
}
}
} else {