refactor(vm)!: remove publication and logical guard opcodes
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good

Remove INDEX_GUARD, ARRAY_CHECK_LENGTH, STORAGE_PUBLISH and FIELDS_PUBLISH
from decoding, metadata, tooling, verification and execution. Keep ARRAY_LEN
and overlap-safe ARRAY_COPY with complete-group ownership and early charging
of calculable copy work, including refused attempts.

Update specifications, producer handoff, qualification evidence and lessons.
Share collection test support and remove redundant Copy clones for Clippy.

Validation: make ci-domains passed with 1,095 workspace tests, five separately
executed debugger socket tests and all 15 unchanged coverage domain gates.
VM release, resource diagnostics and layer/quality suites also passed.

BREAKING CHANGE: PBX using opcodes 0xA7, 0xA8, 0xAA or 0xAB is rejected,
including unreachable instructions. Consumers must adapt their emission and
collection algorithms or operational guarantees.
This commit is contained in:
2026-10-23 23:37:56 +01:00
parent 69ad1931de
commit dcf6561ea7
27 changed files with 1407 additions and 1013 deletions
@@ -0,0 +1,110 @@
//! Complete-group snapshot copy: charge, validate, prepare, then commit.
use super::*;
use crate::value_contract::{ValueError, ValueGroup};
use prometeu_bytecode::registry::TypeId;
fn planned_cost(count: u32, width: u64) -> Option<u64> {
u64::from(count).checked_mul(2)?.checked_mul(width)?.checked_add(4)
}
impl VirtualMachine {
pub(super) fn execute_array_copy(
&mut self,
array_id: u32,
pc: u32,
) -> Result<(), LogicalFrameEndingReason> {
let opcode = OpCode::ArrayCopy;
self.cycles += opcode.cycles();
let image = self.validated_image.clone().expect("validated Array TypeId");
let registry = image.registry();
let array_ty = TypeId(array_id);
let element = registry.type_layout(array_ty).unwrap().array.unwrap().element_type_id;
let width = registry.type_layout(element).unwrap().storage.slots;
if self.temporary_slots() < 5 {
return Err(self.trap(
TRAP_STACK_UNDERFLOW,
opcode as u16,
"Incomplete array copy operands".into(),
pc,
));
}
let base = self.operand_stack.len() - 5;
// Inspect count only to select cost, without changing ordinary fault order.
if let Value::Int64(n) = self.operand_stack[base + 4]
&& let Ok(n) = u32::try_from(n)
{
let cost = planned_cost(n, u64::from(width))
.ok_or_else(|| self.collection_size_trap(opcode, pc, u64::MAX))?;
self.cycles += cost - opcode.cycles();
}
let receiver = |offset: usize| {
let r = match self.operand_stack[base + offset] {
Value::HeapRef(r) => r,
Value::Null => return Err(self.value_trap(ValueError::NullReference, opcode, pc)),
_ => return Err(self.value_trap(ValueError::Type, opcode, pc)),
};
if self.heap.concrete_type(r, registry).map_err(|e| self.value_trap(e, opcode, pc))?
!= array_ty
{
return Err(self.value_trap(ValueError::Type, opcode, pc));
}
Ok(r)
};
let source = receiver(0)?;
let target = receiver(2)?;
let integer = |offset: usize| match self.operand_stack[base + offset] {
Value::Int64(n) => Ok(n),
_ => Err(self.value_trap(ValueError::Type, opcode, pc)),
};
let source_start = integer(1)?;
let target_start = integer(3)?;
let count = integer(4)?;
let range = |r, start: i64| {
let len = self
.heap
.typed_array_len(r, registry)
.map_err(|e| self.value_trap(e, opcode, pc))?;
if start < 0 || count < 0 || start > len as i64 || count > len as i64 - start {
return Err(self.value_trap(ValueError::Bounds, opcode, pc));
}
Ok(start as usize)
};
let source_start = range(source, source_start)?;
let target_start = range(target, target_start)?;
let count = count as usize;
// Operands remain roots; every fallible operation precedes shared writes.
let mut prepared =
BudgetVec::<ValueGroup>::new(&self.budget, RuntimeResource::TemporaryBytes);
prepared.reserve(count).map_err(|e| self.resource_trap(e, opcode, pc))?;
for i in 0..count {
let group = self
.heap
.load_typed(registry, source, source_start + i)
.map_err(|e| self.value_trap(e, opcode, pc))?;
prepared.push(group).expect("complete scratch reservation");
}
// Snapshot captured. No allocation, validation, GC, callback or scheduler.
for (i, group) in prepared.iter().enumerate() {
self.heap.commit_typed(target, target_start + i, group.as_slice());
}
self.operand_stack.truncate(base);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::planned_cost;
#[test]
fn checked_cost_covers_the_full_sum_without_wrap_or_saturation() {
assert_eq!(planned_cost(10, 1), Some(24));
assert_eq!(planned_cost(10, 3), Some(64));
assert_eq!(planned_cost(0, u64::MAX), Some(4));
assert_eq!(planned_cost(u32::MAX, 3), Some(25_769_803_774));
// Synthetic widths exercise defensive overflow, not valid guest layouts.
assert_eq!(planned_cost(1, u64::MAX), None);
assert_eq!(planned_cost(1, u64::MAX / 2), None);
assert_eq!(planned_cost(u32::MAX, u64::MAX), None);
}
}