feat(vm): add reference identity and deterministic value hashing

This commit is contained in:
2026-10-23 14:29:00 +01:00
parent 57992cf214
commit 69ad1931de
41 changed files with 2521 additions and 121 deletions
@@ -7,6 +7,8 @@ mod collections_tests;
mod control;
mod dynamic;
mod gc;
mod identity;
mod intrinsic;
mod lifecycle;
mod loader;
mod native_arrays;
@@ -330,8 +332,10 @@ impl VirtualMachine {
}
let charged_math = if opcode == OpCode::Intrinsic {
lookup_intrinsic_by_id(instr.imm_u32().unwrap())
.filter(|m| m.owner == "vec2" || m.owner == "mathf" || m.owner.starts_with("math."))
lookup_intrinsic_by_id(instr.imm_u32().unwrap()).filter(|m| {
matches!(m.implementation, crate::IntrinsicImplementation::Host(_))
&& (m.owner == "vec2" || m.owner == "mathf" || m.owner.starts_with("math."))
})
} else {
None
};
@@ -955,6 +959,12 @@ impl VirtualMachine {
)
})?;
if matches!(
intrinsic.implementation,
crate::IntrinsicImplementation::BorrowedInline(_)
) {
return self.execute_inline_intrinsic(intrinsic, pc_at_intrinsic);
}
if matches!(intrinsic.implementation, crate::IntrinsicImplementation::VmOwned) {
return self.execute_random(intrinsic, pc_at_intrinsic);
}
@@ -1086,6 +1096,15 @@ impl VirtualMachine {
let (source, target) = instr.imm_u32x2().unwrap();
return self.execute_reference(opcode, source, target, start_pc as u32);
}
OpCode::RefIdentityHash | OpCode::RefIdentityEq => {
let (left, right) = if opcode == OpCode::RefIdentityHash {
(instr.imm_u32().unwrap(), None)
} else {
let (left, right) = instr.imm_u32x2().unwrap();
(left, Some(right))
};
return self.execute_identity(opcode, left, right, start_pc as u32);
}
OpCode::FieldsPublish => {
return self.execute_fields_publication(instr.imm_u32().unwrap(), start_pc as u32);
}
@@ -3910,3 +3929,7 @@ mod callable_tests;
#[cfg(feature = "resource-diagnostics")]
pub mod string_provenance_qualification;
#[cfg(test)]
#[path = "virtual_machine/identity_tests.rs"]
mod identity_tests;