feat(vm): add VM-owned PCG64 random and coverage headroom
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good

Implement GC-managed random generators, next/nextf intrinsics, bounded ranges and deterministic conformance coverage. Publish the runtime contract and producer guidance.

Give coverage domains at least five percentage points of measured headroom while preserving sufficient floors. Record local qualification: make ci-domains passes with 939 tests and all domain gates green.
This commit is contained in:
2026-10-09 12:51:05 +01:00
parent 9318cf7cd3
commit 3e39a90083
50 changed files with 2545 additions and 189 deletions
@@ -65,3 +65,6 @@ pub struct TrapInfo {
/// Machine-readable quota context; messages are not its serialization.
pub resource: Option<crate::ResourceFailure>,
}
/// All 64 unbiased bounded-random candidates were rejected.
pub const TRAP_RANDOM_REJECTION_LIMIT: u32 = 0x0000_0015;
+2 -2
View File
@@ -14,8 +14,8 @@ pub use abi::{
SourceSpan, TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_EXPLICIT,
TRAP_ILLEGAL_INSTRUCTION, TRAP_INVALID_FUNC, TRAP_INVALID_HANDLE, TRAP_INVALID_INTRINSIC,
TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_NON_FINITE, TRAP_NULL_REFERENCE,
TRAP_NUMERIC_DOMAIN, TRAP_NUMERIC_RANGE, TRAP_OOB, TRAP_RESOURCE_LIMIT, TRAP_STACK_UNDERFLOW,
TRAP_TYPE, TRAP_UNAVAILABLE,
TRAP_NUMERIC_DOMAIN, TRAP_NUMERIC_RANGE, TRAP_OOB, TRAP_RANDOM_REJECTION_LIMIT,
TRAP_RESOURCE_LIMIT, TRAP_STACK_UNDERFLOW, TRAP_TYPE, TRAP_UNAVAILABLE,
};
pub use assembler::{assemble, AsmError};
pub use decoder::{decode_next, DecodeError, DecodedInstr};
@@ -158,6 +158,7 @@ impl BuiltinId {
pub const BOOL: Self = Self(0x13);
pub const STRING: Self = Self(0x14);
pub const DYNAMIC: Self = Self(0x15);
pub const RANDOM: Self = Self(0x16);
pub fn layout(self) -> Result<StorageLayout, E> {
use DefaultKind as D;
use Ownership as O;
@@ -169,6 +170,7 @@ impl BuiltinId {
Self::INT64 => (8, 8, 1, O::Plain, D::Int64),
Self::FLOAT => (8, 8, 1, O::Plain, D::Float),
Self::BOOL => (1, 1, 1, O::Plain, D::Bool),
Self::RANDOM => (8, 8, 1, O::GuestReference, D::Null),
Self::STRING => {
(size_of::<StringSlot>(), align_of::<StringSlot>(), 1, O::NativeString, D::Null)
}
@@ -17,11 +17,23 @@ fn main() {
let m = lookup_intrinsic_by_id(id).unwrap();
let mut ctx = HostContext::new(None);
for _ in 0..100 {
black_box((m.implementation)(black_box(&args), &mut ctx).unwrap());
black_box(
(m.implementation.host_callback().expect("host intrinsic"))(
black_box(&args),
&mut ctx,
)
.unwrap(),
);
}
let start = Instant::now();
for _ in 0..iterations {
black_box((m.implementation)(black_box(&args), &mut ctx).unwrap());
black_box(
(m.implementation.host_callback().expect("host intrinsic"))(
black_box(&args),
&mut ctx,
)
.unwrap(),
);
}
let elapsed = start.elapsed().as_nanos();
println!(
@@ -47,7 +47,10 @@ fn main() {
if !matches!(op, "ADD" | "SUB" | "MUL" | "DIV") {
let id = u32::from_str_radix(op, 16).unwrap();
let m = lookup_intrinsic_by_id(id).unwrap();
match (m.implementation)(&args, &mut HostContext::new(None)) {
match (m.implementation.host_callback().expect("host intrinsic"))(
&args,
&mut HostContext::new(None),
) {
Ok(v) => println!("{} {}", text(&v[0]), m.cost_cycles),
Err(prometeu_vm::IntrinsicExecutionError::Numeric(e)) => {
println!("trap:{:x} {}", e.code, m.cost_cycles)
+187 -34
View File
@@ -83,6 +83,7 @@ pub enum BuiltinTypeShape {
Scalar,
Aggregate,
Dynamic,
Reference,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -137,13 +138,23 @@ impl BuiltinTypeMeta {
// This context-free catalogue must never claim to validate it.
return Err(BuiltinValueError::RegistryRequired);
}
if self.shape == BuiltinTypeShape::Reference {
if values.len() != 1 {
return Err(BuiltinValueError::ArityMismatch { expected: 1, got: values.len() });
}
return if matches!(values, [Value::Null]) {
Ok(())
} else {
Err(BuiltinValueError::RegistryRequired)
};
}
let layout = self.flatten_layout();
validate_values_against_layout(values, &layout)
}
fn flatten_into(&self, out: &mut Vec<AbiType>) {
match self.shape {
BuiltinTypeShape::Scalar | BuiltinTypeShape::Dynamic => {
BuiltinTypeShape::Scalar | BuiltinTypeShape::Dynamic | BuiltinTypeShape::Reference => {
out.extend_from_slice(self.flat_slot_layout)
}
BuiltinTypeShape::Aggregate => {
@@ -216,9 +227,38 @@ pub enum BuiltinValueError {
TypeMismatch { index: usize, expected: AbiType },
}
pub type IntrinsicImplementation =
pub type IntrinsicHostImplementation =
fn(&[Value], &mut HostContext<'_>) -> Result<Vec<Value>, IntrinsicExecutionError>;
/// VM-owned operations cannot be invoked through a HostContext callback.
#[derive(Debug, Clone, Copy)]
pub enum IntrinsicImplementation {
Host(IntrinsicHostImplementation),
VmOwned,
}
impl IntrinsicImplementation {
pub fn host_callback(self) -> Option<IntrinsicHostImplementation> {
match self {
Self::Host(f) => Some(f),
Self::VmOwned => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IntrinsicCostModel {
Fixed,
RandomRejectionV1,
}
impl IntrinsicCostModel {
pub const fn name(self) -> &'static str {
match self {
Self::Fixed => "fixed",
Self::RandomRejectionV1 => "random_rejection_v1",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct IntrinsicMeta {
pub id: u32,
@@ -228,8 +268,12 @@ pub struct IntrinsicMeta {
pub arg_layout: &'static [AbiType],
pub ret_layout: &'static [AbiType],
pub parameter_names: &'static [&'static str],
/// Total virtual call cost; math attempts are charged before checks.
/// Full fixed cost, or base cost for a variable model.
pub cost_cycles: u64,
pub cost_model: IntrinsicCostModel,
pub attempt_cost_cycles: u64,
pub max_attempts: u32,
pub mutates_guest_state: bool,
pub deterministic: bool,
pub may_allocate: bool,
pub implementation: IntrinsicImplementation,
@@ -343,7 +387,7 @@ const PIXEL_FIELDS: [BuiltinFieldMeta; 3] = [
},
];
const BUILTIN_TYPES: [BuiltinTypeMeta; 9] = [
const BUILTIN_TYPES: [BuiltinTypeMeta; 10] = [
BuiltinTypeMeta {
id: 0x0001,
name: COLOR.name,
@@ -371,6 +415,15 @@ const BUILTIN_TYPES: [BuiltinTypeMeta; 9] = [
flat_slot_layout: &PIXEL_LAYOUT,
flat_slot_width: 3,
},
BuiltinTypeMeta {
id: 0x16,
name: "Random",
version: 1,
shape: BuiltinTypeShape::Reference,
fields: &[],
flat_slot_layout: &[AbiType::Builtin(BuiltinTypeKey::new("Random", 1))],
flat_slot_width: 1,
},
scalar_meta(0x10, "Int32", &[AbiType::Scalar(BuiltinScalarType::Int32)]),
scalar_meta(0x11, "Int64", &[AbiType::Scalar(BuiltinScalarType::Int64)]),
scalar_meta(0x12, "Float", &[AbiType::Scalar(BuiltinScalarType::Float)]),
@@ -513,9 +566,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &SINGLE_FLOAT_RET,
parameter_names: &["ax", "ay", "bx", "by"],
cost_cycles: 10,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: vec2_dot,
implementation: crate::IntrinsicImplementation::Host(vec2_dot),
},
IntrinsicMeta {
id: 0x1001,
@@ -526,9 +583,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &SINGLE_FLOAT_RET,
parameter_names: &["x", "y"],
cost_cycles: 40,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: vec2_length,
implementation: crate::IntrinsicImplementation::Host(vec2_length),
},
IntrinsicMeta {
id: 0x1100,
@@ -539,9 +600,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &["raw"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_from_raw,
implementation: crate::IntrinsicImplementation::Host(color_from_raw),
},
IntrinsicMeta {
id: 0x1101,
@@ -552,9 +617,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &["r", "g", "b"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_rgb,
implementation: crate::IntrinsicImplementation::Host(color_rgb),
},
IntrinsicMeta {
id: 0x1102,
@@ -565,9 +634,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &["r", "g", "b", "a"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_rgba,
implementation: crate::IntrinsicImplementation::Host(color_rgba),
},
IntrinsicMeta {
id: 0x1103,
@@ -578,9 +651,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &["value"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_html_rgba,
implementation: crate::IntrinsicImplementation::Host(color_html_rgba),
},
IntrinsicMeta {
id: 0x1104,
@@ -591,9 +668,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &["value"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_gray_scale,
implementation: crate::IntrinsicImplementation::Host(color_gray_scale),
},
IntrinsicMeta {
id: 0x1105,
@@ -604,9 +685,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &INT_RET,
parameter_names: &["color"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_hex,
implementation: crate::IntrinsicImplementation::Host(color_hex),
},
IntrinsicMeta {
id: 0x1106,
@@ -617,9 +702,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &INT_RET,
parameter_names: &["color"],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_alpha,
implementation: crate::IntrinsicImplementation::Host(color_alpha),
},
IntrinsicMeta {
id: 0x1120,
@@ -630,9 +719,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_black,
implementation: crate::IntrinsicImplementation::Host(color_black),
},
IntrinsicMeta {
id: 0x1121,
@@ -643,9 +736,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_white,
implementation: crate::IntrinsicImplementation::Host(color_white),
},
IntrinsicMeta {
id: 0x1122,
@@ -656,9 +753,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_red,
implementation: crate::IntrinsicImplementation::Host(color_red),
},
IntrinsicMeta {
id: 0x1123,
@@ -669,9 +770,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_green,
implementation: crate::IntrinsicImplementation::Host(color_green),
},
IntrinsicMeta {
id: 0x1124,
@@ -682,9 +787,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_blue,
implementation: crate::IntrinsicImplementation::Host(color_blue),
},
IntrinsicMeta {
id: 0x1125,
@@ -695,9 +804,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_yellow,
implementation: crate::IntrinsicImplementation::Host(color_yellow),
},
IntrinsicMeta {
id: 0x1126,
@@ -708,9 +821,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_orange,
implementation: crate::IntrinsicImplementation::Host(color_orange),
},
IntrinsicMeta {
id: 0x1127,
@@ -721,9 +838,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_indigo,
implementation: crate::IntrinsicImplementation::Host(color_indigo),
},
IntrinsicMeta {
id: 0x1128,
@@ -734,9 +855,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_gray,
implementation: crate::IntrinsicImplementation::Host(color_gray),
},
IntrinsicMeta {
id: 0x1129,
@@ -747,9 +872,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_cyan,
implementation: crate::IntrinsicImplementation::Host(color_cyan),
},
IntrinsicMeta {
id: 0x112A,
@@ -760,9 +889,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_magenta,
implementation: crate::IntrinsicImplementation::Host(color_magenta),
},
IntrinsicMeta {
id: 0x112B,
@@ -773,9 +906,13 @@ const INTRINSICS: [IntrinsicMeta; 21] = [
ret_layout: &COLOR_RET,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: color_transparent,
implementation: crate::IntrinsicImplementation::Host(color_transparent),
},
];
@@ -806,6 +943,7 @@ pub fn lookup_intrinsic(owner: &str, name: &str, version: u16) -> Option<&'stati
.iter()
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
.chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter())
.find(|meta| meta.owner == owner && meta.name == name && meta.version == version)
}
@@ -814,6 +952,7 @@ pub fn lookup_intrinsic_by_id(id: u32) -> Option<&'static IntrinsicMeta> {
.iter()
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
.chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter())
.find(|meta| meta.id == id)
}
@@ -877,6 +1016,9 @@ fn value_matches_abi_type(value: &Value, expected: AbiType) -> bool {
AbiType::Scalar(BuiltinScalarType::String) => {
matches!(value, Value::String(_) | Value::Null)
}
AbiType::Builtin(key) if key.name == "Random" && key.version == 1 => {
matches!(value, Value::HeapRef(_) | Value::Null)
}
AbiType::Builtin(key) if key == COLOR => {
matches!(value, Value::Int64(raw) if u32::try_from(*raw).is_ok())
}
@@ -1111,6 +1253,7 @@ pub(crate) fn metered_lookup_intrinsic(
.iter()
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
.chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter())
{
budget.work(1)?;
if meta.id == id {
@@ -1226,7 +1369,7 @@ mod tests {
fn intrinsic_implementations_are_registered_without_syscalls() {
let dot = lookup_intrinsic("vec2", "dot", 1).expect("vec2.dot must exist");
let mut ctx = HostContext::new(None);
let result = (dot.implementation)(
let result = (dot.implementation.host_callback().expect("host intrinsic"))(
&[Value::Float(1.0), Value::Float(2.0), Value::Float(3.0), Value::Float(4.0)],
&mut ctx,
)
@@ -1234,8 +1377,11 @@ mod tests {
assert_eq!(result, vec![Value::Float(11.0)]);
let length = lookup_intrinsic("vec2", "length", 1).expect("vec2.length must exist");
let result = (length.implementation)(&[Value::Float(3.0), Value::Float(4.0)], &mut ctx)
.expect("length implementation must execute");
let result = (length.implementation.host_callback().expect("host intrinsic"))(
&[Value::Float(3.0), Value::Float(4.0)],
&mut ctx,
)
.expect("length implementation must execute");
assert_eq!(result, vec![Value::Float(5.0)]);
}
@@ -1244,7 +1390,7 @@ mod tests {
let mut ctx = HostContext::new(None);
let rgba = lookup_intrinsic("color", "rgba", 1).expect("color.rgba must exist");
let result = (rgba.implementation)(
let result = (rgba.implementation.host_callback().expect("host intrinsic"))(
&[Value::Int64(0x11), Value::Int64(0x22), Value::Int64(0x33), Value::Int64(0x44)],
&mut ctx,
)
@@ -1252,13 +1398,19 @@ mod tests {
assert_eq!(result, vec![Value::Int64(0x11223344)]);
let html = lookup_intrinsic("color", "html_rgba", 1).expect("color.html_rgba must exist");
let result = (html.implementation)(&[Value::String("#AABBCCDD".into())], &mut ctx)
.expect("html_rgba implementation must execute");
let result = (html.implementation.host_callback().expect("host intrinsic"))(
&[Value::String("#AABBCCDD".into())],
&mut ctx,
)
.expect("html_rgba implementation must execute");
assert_eq!(result, vec![Value::Int64(0xAABBCCDD)]);
let alpha = lookup_intrinsic("color", "alpha", 1).expect("color.alpha must exist");
let result = (alpha.implementation)(&[Value::Int64(0xAABBCCDD)], &mut ctx)
.expect("alpha implementation must execute");
let result = (alpha.implementation.host_callback().expect("host intrinsic"))(
&[Value::Int64(0xAABBCCDD)],
&mut ctx,
)
.expect("alpha implementation must execute");
assert_eq!(result, vec![Value::Int64(0xDD)]);
}
@@ -1266,7 +1418,7 @@ mod tests {
fn input_intrinsic_requires_hardware_context() {
let mut ctx = HostContext::new(None);
let touch_x = lookup_intrinsic("input.touch", "x", 1).expect("input.touch.x must exist");
let err = (touch_x.implementation)(&[], &mut ctx)
let err = (touch_x.implementation.host_callback().expect("host intrinsic"))(&[], &mut ctx)
.expect_err("touch.x must fail without hardware context");
assert_eq!(err, IntrinsicExecutionError::HardwareUnavailable);
}
@@ -1287,6 +1439,7 @@ pub fn intrinsic_catalog() -> impl Iterator<Item = &'static IntrinsicMeta> {
.iter()
.chain(crate::input_intrinsics::INPUT_INTRINSICS.iter())
.chain(crate::math_intrinsics::MATH_INTRINSICS.iter())
.chain(crate::random_intrinsics::RANDOM_INTRINSICS.iter())
}
pub fn builtin_constant_catalog() -> impl Iterator<Item = &'static BuiltinConstMeta> {
BUILTIN_CONSTS.iter()
+7 -3
View File
@@ -16,14 +16,14 @@ fn atom(t: AbiType) -> String {
}
pub fn intrinsic_catalog_csv() -> String {
let mut out = String::from(
"final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles\n",
"final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts\n",
);
let mut entries: Vec<_> = intrinsic_catalog().collect();
entries.sort_by_key(|m| m.id);
for m in entries {
writeln!(
&mut out,
"0x{:04X},{},{}.{},{},{},{},{},{},{},{},{},{},{},{}",
"0x{:04X},{},{}.{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}",
m.id,
m.id,
m.owner,
@@ -38,7 +38,11 @@ pub fn intrinsic_catalog_csv() -> String {
m.deterministic,
m.may_allocate,
m.parameter_names.join("|"),
m.cost_cycles
m.cost_cycles,
m.mutates_guest_state,
m.cost_model.name(),
m.attempt_cost_cycles,
m.max_attempts
)
.unwrap();
}
+1
View File
@@ -1,4 +1,5 @@
mod dynamic_box;
mod random;
use crate::object::{ObjectHeader, ObjectKind};
use crate::resource_budget::{
BudgetVec, Reservation, ResourceFailure, ResourceReason, RuntimeBudget, RuntimeResource as Q,
@@ -0,0 +1,48 @@
//! Quota-accounted opaque leaf payload and infallible state publication.
use super::*;
use crate::random::{INCREMENT, Pcg64};
impl Heap {
pub(crate) fn allocate_random(&mut self, seed: i64) -> Result<HeapRef, ResourceFailure> {
let prepared = self.prepare_insertion()?;
let mut payload = BudgetVec::new(&self.budget, Q::GuestBytes);
payload.reserve(32)?;
let state = Pcg64::new(seed);
payload.extend_from_slice(&state.state.to_le_bytes()).expect("reserved random state");
payload.extend_from_slice(&state.inc.to_le_bytes()).expect("reserved random increment");
Ok(self.commit_insertion(
prepared,
StoredObject {
header: ObjectHeader::new(ObjectKind::Random, 32),
payload,
array_elems: None,
closure_env: None,
typed: None,
dynamic_box: None,
},
))
}
pub(crate) fn random_state(&self, r: HeapRef) -> Result<Pcg64, ValueError> {
if !self.is_valid(r) {
return Err(ValueError::InvalidHandle);
}
let obj = self.objects[r.index as usize].as_ref().unwrap();
if obj.header.kind != ObjectKind::Random || obj.payload.len() != 32 {
return Err(ValueError::Type);
}
let state = u128::from_le_bytes(obj.payload[..16].try_into().unwrap());
let inc = u128::from_le_bytes(obj.payload[16..].try_into().unwrap());
if inc != INCREMENT {
return Err(ValueError::Type);
}
Ok(Pcg64 { state, inc })
}
/// Caller validated this handle and retained its roots, with no intervening
/// safepoint. Mutation is fixed-width and cannot allocate or fail.
pub(crate) fn commit_random(&mut self, r: HeapRef, state: Pcg64) {
let obj = self.objects[r.index as usize].as_mut().expect("validated random object");
obj.payload[..16].copy_from_slice(&state.state.to_le_bytes());
}
}
@@ -12,7 +12,7 @@ const fn query(
owner: &'static str,
name: &'static str,
ret_layout: &'static [AbiType],
implementation: crate::IntrinsicImplementation,
implementation: crate::IntrinsicHostImplementation,
) -> IntrinsicMeta {
IntrinsicMeta {
id,
@@ -23,9 +23,13 @@ const fn query(
ret_layout,
parameter_names: &[],
cost_cycles: 1,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation,
implementation: crate::IntrinsicImplementation::Host(implementation),
}
}
+6 -4
View File
@@ -7,6 +7,8 @@ mod call_frame;
mod input_intrinsics;
mod math_intrinsics;
mod numeric;
mod random;
mod random_intrinsics;
pub use numeric::NumericError;
mod local_addressing;
// Keep the verifier internal in production builds, but expose it for integration tests
@@ -38,10 +40,10 @@ mod vm_init_error;
pub use builtins::{
AbiType, BuiltinConstKey, BuiltinConstMaterializer, BuiltinConstMeta, BuiltinConstSlotValue,
BuiltinFieldMeta, BuiltinLayoutType, BuiltinScalarType, BuiltinTypeKey, BuiltinTypeMeta,
BuiltinTypeShape, BuiltinValueError, IntrinsicExecutionError, IntrinsicImplementation,
IntrinsicKey, IntrinsicMeta, builtin_constant_catalog, intrinsic_catalog,
lookup_builtin_constant, lookup_builtin_type, lookup_intrinsic, lookup_intrinsic_by_id,
materialize_builtin_constant,
BuiltinTypeShape, BuiltinValueError, IntrinsicCostModel, IntrinsicExecutionError,
IntrinsicHostImplementation, IntrinsicImplementation, IntrinsicKey, IntrinsicMeta,
builtin_constant_catalog, intrinsic_catalog, lookup_builtin_constant, lookup_builtin_type,
lookup_intrinsic, lookup_intrinsic_by_id, materialize_builtin_constant,
};
pub use prometeu_hal::{HostContext, HostReturn, NativeInterface, SyscallId};
pub use virtual_machine::{BudgetReport, LogicalFrameEndingReason, VirtualMachine};
@@ -23,9 +23,13 @@ const fn entry<const ID: u32>(
ret_layout,
parameter_names,
cost_cycles,
cost_model: crate::IntrinsicCostModel::Fixed,
attempt_cost_cycles: 0,
max_attempts: 0,
mutates_guest_state: false,
deterministic: true,
may_allocate: false,
implementation: execute::<ID>,
implementation: crate::IntrinsicImplementation::Host(execute::<ID>),
}
}
pub(crate) const MATH_INTRINSICS: [IntrinsicMeta; 26] = [
+3
View File
@@ -86,6 +86,9 @@ pub enum ObjectKind {
/// Internal immutable multi-slot Dynamic payload, never a nominal guest type.
DynamicBox = 8,
/// Opaque PCG64 generator, with no transitive references.
Random = 9,
// Future kinds must be appended here to keep tag numbers stable.
}
+99
View File
@@ -0,0 +1,99 @@
//! PCG-XSL-RR 128/64 setseq. No host entropy or floating arithmetic.
use crate::numeric;
use prometeu_bytecode::TRAP_RANDOM_REJECTION_LIMIT;
const MULTIPLIER: u128 = 0x2360_ED05_1FC6_5DA4_4385_DF64_9FCC_F645;
pub(crate) const INCREMENT: u128 = 109;
pub(crate) const MAX_ATTEMPTS: u32 = 64;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct Pcg64 {
pub state: u128,
pub inc: u128,
}
impl Pcg64 {
pub fn new(seed: i64) -> Self {
let bits = u128::from(seed as u64);
Self {
state: bits.wrapping_add(INCREMENT).wrapping_mul(MULTIPLIER).wrapping_add(INCREMENT),
inc: INCREMENT,
}
}
pub fn next(&mut self) -> u64 {
self.state = self.state.wrapping_mul(MULTIPLIER).wrapping_add(self.inc);
let x = self.state as u64 ^ (self.state >> 64) as u64;
x.rotate_right((self.state >> 122) as u32)
}
}
pub(crate) fn float_word(word: u64) -> f64 {
// k <= 2^53-1 is exactly representable; dividing by 2^53 is exact.
numeric::div(numeric::from_i64((word >> 11) as i64), f64::from_bits(0x4340_0000_0000_0000))
.expect("finite exact random grid division")
}
/// Bounds were checked by the VM before reservations. The callback performs
/// one charged candidate draw. It can be injected only inside private tests.
pub(crate) fn bounded(min: i64, max: i64, mut draw: impl FnMut() -> u64) -> Result<i64, u32> {
debug_assert!(min < max);
let n = (i128::from(max) - i128::from(min)) as u64;
let threshold = n.wrapping_neg() % n;
for _ in 0..MAX_ATTEMPTS {
let word = draw();
if word >= threshold {
return Ok((i128::from(min) + i128::from(word % n)) as i64);
}
}
Err(TRAP_RANDOM_REJECTION_LIMIT)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn zero_rotation_state_and_float_endpoints() {
let mut p = Pcg64 { state: 0, inc: INCREMENT };
assert_eq!(p.next(), 109);
assert_eq!(float_word(0).to_bits(), 0);
assert_eq!(float_word(u64::MAX).to_bits(), 0x3fef_ffff_ffff_ffff);
}
#[test]
fn threshold_boundaries_full_width_and_unit_consumption() {
for (min, max) in [(0, 1), (-3, 3), (i64::MIN, i64::MAX), (-1, i64::MAX)] {
let n = (i128::from(max) - i128::from(min)) as u64;
let threshold = n.wrapping_neg() % n;
let mut attempts = 0;
let value = bounded(min, max, || {
attempts += 1;
if attempts == 1 && threshold > 0 { threshold - 1 } else { threshold }
})
.unwrap();
assert_eq!(attempts, if threshold > 0 { 2 } else { 1 });
assert_eq!(value, (i128::from(min) + i128::from(threshold % n)) as i64);
}
}
#[test]
fn sixty_fourth_success_and_cap_are_distinct() {
let mut n = 0;
assert_eq!(
bounded(0, 3, || {
n += 1;
if n == 64 { 1 } else { 0 }
}),
Ok(1)
);
assert_eq!(n, 64);
n = 0;
assert_eq!(
bounded(0, 3, || {
n += 1;
0
}),
Err(TRAP_RANDOM_REJECTION_LIMIT)
);
assert_eq!(n, 64);
}
}
@@ -0,0 +1,45 @@
//! The shared catalog owns IDs, layouts, effects and charging descriptors.
use crate::{
AbiType, BuiltinScalarType, BuiltinTypeKey, IntrinsicCostModel, IntrinsicImplementation,
IntrinsicMeta,
};
const I64: AbiType = AbiType::Scalar(BuiltinScalarType::Int64);
const FLOAT: AbiType = AbiType::Scalar(BuiltinScalarType::Float);
const RANDOM: AbiType = AbiType::Builtin(BuiltinTypeKey::new("Random", 1));
const fn entry(
id: u32,
name: &'static str,
args: &'static [AbiType],
ret: &'static [AbiType],
names: &'static [&'static str],
cost: u64,
) -> IntrinsicMeta {
let rejection = id == 0x4003;
IntrinsicMeta {
id,
owner: "random",
name,
version: 1,
arg_layout: args,
ret_layout: ret,
parameter_names: names,
cost_cycles: cost,
cost_model: if rejection {
IntrinsicCostModel::RandomRejectionV1
} else {
IntrinsicCostModel::Fixed
},
attempt_cost_cycles: if rejection { 8 } else { 0 },
max_attempts: if rejection { crate::random::MAX_ATTEMPTS } else { 0 },
deterministic: true,
mutates_guest_state: true,
may_allocate: id == 0x4000,
implementation: IntrinsicImplementation::VmOwned,
}
}
pub(crate) const RANDOM_INTRINSICS: [IntrinsicMeta; 4] = [
entry(0x4000, "new", &[I64], &[RANDOM], &["seed"], 32),
entry(0x4001, "next", &[RANDOM], &[I64], &["rng"], 8),
entry(0x4002, "nextf", &[RANDOM], &[FLOAT], &["rng"], 12),
entry(0x4003, "range", &[RANDOM, I64, I64], &[I64], &["rng", "min", "max"], 4),
];
@@ -204,6 +204,7 @@ fn component(registry: &Registry, ty: TypeId, part: u32, budget: &mut LoadBudget
TypeKind::Builtin(B::FLOAT | B::VEC2) => FLOAT,
TypeKind::Builtin(B::BOOL) => BOOL,
TypeKind::Builtin(B::STRING) => STRING | NULL,
TypeKind::Builtin(B::RANDOM) => REFERENCE | NULL,
TypeKind::Builtin(B::DYNAMIC) => {
if part == 0 {
I64 | NULL
@@ -558,6 +559,7 @@ fn abi_mask(abi: AbiType) -> u8 {
AbiType::Scalar(BuiltinScalarType::Bool) => BOOL,
AbiType::Scalar(BuiltinScalarType::String) => STRING,
AbiType::Builtin(key) if key.name == "color" => I64,
AbiType::Builtin(key) if key.name == "Random" => REFERENCE | NULL,
AbiType::DynamicTag => I64 | NULL,
_ => ANY,
}
@@ -103,9 +103,10 @@ impl TypedStorage {
// until every native value is constructed. Count advances only after init.
unsafe {
match self.registry.declarations().types[ty.0 as usize].kind {
TypeKind::Struct(_) | TypeKind::Array(_) | TypeKind::Fn(_) => {
self.data.init(offset, HeapRef::NULL)
}
TypeKind::Struct(_)
| TypeKind::Array(_)
| TypeKind::Fn(_)
| TypeKind::Builtin(B::RANDOM) => self.data.init(offset, HeapRef::NULL),
TypeKind::Trait(_) => self.data.init(
offset,
TraitSlot { receiver: HeapRef::NULL, implementation: 0, padding: 0 },
@@ -135,7 +136,10 @@ impl TypedStorage {
// immutable Registry. Only matching typed writes can change its contents.
let result = unsafe {
match self.registry.declarations().types[ty.0 as usize].kind {
TypeKind::Struct(_) | TypeKind::Array(_) | TypeKind::Fn(_) => {
TypeKind::Struct(_)
| TypeKind::Array(_)
| TypeKind::Fn(_)
| TypeKind::Builtin(B::RANDOM) => {
let r = *self.data.get::<HeapRef>(offset);
ValueGroup::new(&[if r.is_null() { Value::Null } else { Value::HeapRef(r) }])
}
@@ -205,11 +209,18 @@ impl TypedStorage {
// &mut self gives exclusive access. Native assignment drops exactly once.
unsafe {
match (&self.registry.declarations().types[ty.0 as usize].kind, values) {
(TypeKind::Struct(_) | TypeKind::Array(_) | TypeKind::Fn(_), [Value::Null]) => {
self.data.replace(offset, HeapRef::NULL)
}
(
TypeKind::Struct(_) | TypeKind::Array(_) | TypeKind::Fn(_),
TypeKind::Struct(_)
| TypeKind::Array(_)
| TypeKind::Fn(_)
| TypeKind::Builtin(B::RANDOM),
[Value::Null],
) => self.data.replace(offset, HeapRef::NULL),
(
TypeKind::Struct(_)
| TypeKind::Array(_)
| TypeKind::Fn(_)
| TypeKind::Builtin(B::RANDOM),
[Value::HeapRef(r)],
) => self.data.replace(offset, *r),
(TypeKind::Trait(_), [Value::Null, Value::Null]) => self.data.replace(
@@ -68,6 +68,14 @@ pub(crate) fn validate(
}
_ => false,
},
TypeKind::Builtin(B::RANDOM) => match &values[0] {
Value::Null => true,
Value::HeapRef(r) => {
heap.random_state(*r)?;
true
}
_ => false,
},
TypeKind::Fn(_) => match &values[0] {
Value::Null => true,
Value::HeapRef(r) if !r.is_null() => heap.closure_type(*r)? == type_id,
@@ -8,6 +8,7 @@ mod control;
mod dynamic;
mod gc;
mod loader;
mod random;
mod reference;
mod runtime;
mod stack;
@@ -892,6 +893,10 @@ impl VirtualMachine {
)
})?;
if matches!(intrinsic.implementation, crate::IntrinsicImplementation::VmOwned) {
return self.execute_random(intrinsic, pc_at_intrinsic);
}
let args_count = intrinsic.arg_slots();
let mut args = BudgetVec::new(&self.budget, RuntimeResource::TemporaryBytes);
args.reserve(args_count)
@@ -923,7 +928,11 @@ impl VirtualMachine {
.map_err(|e| self.resource_trap(e, opcode, start_pc as u32))?;
let results = intrinsic
.validate_argument_values(&args)
.and_then(|()| (intrinsic.implementation)(&args, ctx))
.and_then(|()| {
(intrinsic.implementation.host_callback().expect("host intrinsic"))(
&args, ctx,
)
})
.map_err(|err| match err {
crate::IntrinsicExecutionError::ArityMismatch { expected, got } => self
.trap(
@@ -0,0 +1,504 @@
//! Validate/reserve/stage/commit while retaining source operands and roots.
use super::*;
use crate::random::{self, Pcg64};
use crate::value_contract::ValueError;
impl VirtualMachine {
pub(super) fn execute_random(
&mut self,
meta: &crate::IntrinsicMeta,
pc: u32,
) -> Result<(), LogicalFrameEndingReason> {
self.execute_random_with(meta, pc, Pcg64::next)
}
fn execute_random_with(
&mut self,
meta: &crate::IntrinsicMeta,
pc: u32,
mut draw: impl FnMut(&mut Pcg64) -> u64,
) -> Result<(), LogicalFrameEndingReason> {
let op = OpCode::Intrinsic;
self.cycles += meta.cost_cycles;
let consumed = meta.arg_slots();
if self.temporary_slots() < consumed {
return Err(self.trap(
TRAP_STACK_UNDERFLOW,
op as u16,
"Incomplete random operands".into(),
pc,
));
}
let base = self.operand_stack.len() - consumed;
meta.validate_argument_values(&self.operand_stack[base..])
.map_err(|_| self.value_trap(ValueError::Type, op, pc))?;
let receiver = if meta.id != 0x4000 {
match self.operand_stack[base] {
Value::Null => return Err(self.value_trap(ValueError::NullReference, op, pc)),
Value::HeapRef(r) => Some(r),
_ => unreachable!("checked random carrier"),
}
} else {
None
};
let mut candidate = receiver
.map(|r| self.heap.random_state(r))
.transpose()
.map_err(|e| self.value_trap(e, op, pc))?;
let bounds = if meta.id == 0x4003 {
let (Value::Int64(min), Value::Int64(max)) =
(&self.operand_stack[base + 1], &self.operand_stack[base + 2])
else {
unreachable!("checked integer carriers")
};
if min >= max {
return Err(self.trap(
prometeu_bytecode::TRAP_NUMERIC_DOMAIN,
op as u16,
"random.range requires min < max".into(),
pc,
));
}
Some((*min, *max))
} else {
None
};
let growth = self
.operand_stack
.prepare_growth(meta.ret_slots().saturating_sub(consumed))
.map_err(|e| self.resource_trap(e, op, pc))?;
let _result_charge = self
.budget
.reserve(
RuntimeResource::TemporaryBytes,
self.budget
.bytes::<Value>(1, RuntimeResource::TemporaryBytes)
.map_err(|e| self.resource_trap(e, op, pc))?,
)
.map_err(|e| self.resource_trap(e, op, pc))?;
let result = match meta.id {
0x4000 => {
let Value::Int64(seed) = self.operand_stack[base] else {
unreachable!("checked seed carrier")
};
Value::HeapRef(
self.heap.allocate_random(seed).map_err(|e| self.resource_trap(e, op, pc))?,
)
}
0x4001 => Value::Int64(draw(candidate.as_mut().unwrap()) as i64),
0x4002 => Value::Float(random::float_word(draw(candidate.as_mut().unwrap()))),
0x4003 => {
let (min, max) = bounds.unwrap();
let value = random::bounded(min, max, || {
self.cycles += meta.attempt_cost_cycles;
draw(candidate.as_mut().unwrap())
})
.map_err(|code| {
self.trap(code, op as u16, "Random rejection limit reached".into(), pc)
})?;
Value::Int64(value)
}
_ => unreachable!("shared catalog VM-owned identity"),
};
// All fallible work finished. Source roots remained live throughout.
if let Some(r) = receiver {
self.heap.commit_random(r, candidate.unwrap());
}
self.operand_stack.commit_growth(growth);
self.operand_stack.truncate(base);
self.operand_stack.push(result).expect("reserved random result slot");
Ok(())
}
}
#[cfg(test)]
#[path = "../../tests/support/random.rs"]
mod support;
#[cfg(test)]
mod tests {
use super::*;
use crate::object::ObjectKind;
use crate::random::MAX_ATTEMPTS;
use prometeu_bytecode::registry::TypeId;
use prometeu_bytecode::{TRAP_NUMERIC_DOMAIN, TRAP_RANDOM_REJECTION_LIMIT, assemble};
use support::{Native, run, sig, step, vm};
fn trap_code(r: &LogicalFrameEndingReason) -> u32 {
let LogicalFrameEndingReason::Trap(t) = r else { panic!("{r:?}") };
t.code
}
fn fault_vm(id: u32, args: &[Value]) -> VirtualMachine {
let mut v =
VirtualMachine::fault_session(assemble(&format!("INTRINSIC {id}")).unwrap(), vec![]);
v.operand_stack.extend_from_slice(args).unwrap();
v
}
fn charges(v: &VirtualMachine) -> Vec<u64> {
[
RuntimeResource::GuestBytes,
RuntimeResource::HandleSlots,
RuntimeResource::AuxiliaryBytes,
RuntimeResource::TemporaryBytes,
]
.iter()
.map(|&q| v.budget.used(q))
.collect()
}
#[test]
fn carrier_receiver_bounds_precedence_and_all_faults_retain_sources() {
for id in [0x4001, 0x4002, 0x4003] {
for case in 0..9 {
let mut v = fault_vm(id, &[]);
let live = v.heap.allocate_random(42).unwrap();
let wrong = v.heap.allocate_object(ObjectKind::Bytes, &[]).unwrap();
let (receiver, lo, hi, code) = match case {
0 => (Value::Boolean(false), Value::Int64(1), Value::Int64(2), TRAP_TYPE),
1 => (
Value::Null,
Value::Int32(1),
Value::Int64(2),
if id == 0x4003 { TRAP_TYPE } else { TRAP_NULL_REFERENCE },
),
2 => (
Value::HeapRef(HeapRef { index: 99, generation: 1 }),
Value::Int64(2),
Value::Int64(1),
TRAP_INVALID_HANDLE,
),
3 => (
Value::HeapRef(HeapRef {
index: live.index,
generation: live.generation + 1,
}),
Value::Int64(1),
Value::Int64(2),
TRAP_INVALID_HANDLE,
),
4 => (
Value::HeapRef(HeapRef::NULL),
Value::Int64(1),
Value::Int64(2),
TRAP_INVALID_HANDLE,
),
5 => (Value::HeapRef(wrong), Value::Int64(2), Value::Int64(1), TRAP_TYPE),
6 => (Value::Null, Value::Int64(2), Value::Int64(1), TRAP_NULL_REFERENCE),
7 => (
Value::HeapRef(live),
Value::Int64(2),
Value::Int64(1),
TRAP_NUMERIC_DOMAIN,
),
_ => (Value::HeapRef(live), Value::Int64(1), Value::Boolean(false), TRAP_TYPE),
};
if id != 0x4003 && case >= 7 {
continue;
}
let mut args = vec![receiver];
if id == 0x4003 {
args.extend([lo, hi]);
}
v.operand_stack.extend_from_slice(&args).unwrap();
let state = v.heap.random_state(live).unwrap();
let ownership = charges(&v);
let r = v.run_budget(1, &mut Native, &mut HostContext::new(None)).unwrap();
assert_eq!(trap_code(&r.reason), code, "id={id}, case={case}");
assert_eq!(
(r.cycles_used, r.steps_executed),
(
if id == 0x4001 {
8
} else if id == 0x4002 {
12
} else {
4
},
0
)
);
assert_eq!(v.operand_stack.as_slice(), args);
assert_eq!(v.heap.random_state(live).unwrap(), state);
assert_eq!(charges(&v), ownership);
let LogicalFrameEndingReason::Trap(t) = r.reason else { unreachable!() };
assert_eq!((t.pc, t.opcode), (0, OpCode::Intrinsic as u16));
}
}
}
#[test]
fn short_stack_and_seed_carriers_charge_without_consumption() {
for id in 0x4000..=0x4003 {
let mut v = fault_vm(id, &[]);
let r = run(&mut v, 1);
assert_eq!(trap_code(&r.reason), TRAP_STACK_UNDERFLOW);
assert_eq!(r.steps_executed, 0);
assert_eq!(r.cycles_used, crate::lookup_intrinsic_by_id(id).unwrap().cost_cycles);
}
for seed in [Value::Null, Value::Int32(42), Value::Float(42.)] {
let mut v = fault_vm(0x4000, std::slice::from_ref(&seed));
let r = run(&mut v, 1);
assert_eq!(trap_code(&r.reason), TRAP_TYPE);
assert_eq!(v.operand_stack.as_slice(), &[seed]);
assert_eq!(v.heap.len(), 0);
}
}
#[test]
fn synthetic_rejections_use_real_transaction_cost_and_rollback() {
for accept in [None, Some(1), Some(3), Some(MAX_ATTEMPTS)] {
let mut v = fault_vm(0x4003, &[]);
let r = v.heap.allocate_random(42).unwrap();
let args = [Value::HeapRef(r), Value::Int64(0), Value::Int64(3)];
v.operand_stack.extend_from_slice(&args).unwrap();
let original = v.heap.random_state(r).unwrap();
let owned = charges(&v);
let mut attempts = 0;
let result =
v.execute_random_with(crate::lookup_intrinsic_by_id(0x4003).unwrap(), 0, |state| {
attempts += 1;
state.next();
if Some(attempts) == accept { 1 } else { 0 }
});
assert_eq!(v.cycles, 4 + 8 * u64::from(attempts));
assert_eq!(attempts, accept.unwrap_or(64));
assert_eq!(charges(&v), owned);
if accept.is_some() {
result.unwrap();
assert_eq!(v.operand_stack.as_slice(), &[Value::Int64(1)]);
let mut expected = original;
for _ in 0..attempts {
expected.next();
}
assert_eq!(v.heap.random_state(r).unwrap(), expected);
} else {
assert_eq!(trap_code(&result.unwrap_err()), TRAP_RANDOM_REJECTION_LIMIT);
assert_eq!(v.heap.random_state(r).unwrap(), original);
assert_eq!(v.operand_stack.as_slice(), &args);
// A subsequent normal draw sees the first canonical word, proving rollback.
v.operand_stack.truncate(1);
v.execute_random(crate::lookup_intrinsic_by_id(0x4001).unwrap(), 0).unwrap();
assert_eq!(v.operand_stack[0], Value::Int64(0x86b1_da1d_7206_2b68u64 as i64));
}
}
}
#[test]
fn resource_refusals_preserve_all_charges_seed_and_candidate_state() {
for limit in [0, 1, size_of::<crate::heap::StoredObject>() as u64 + 16] {
let mut v = fault_vm(0x4000, &[Value::Int64(42)]);
v.budget.test_lower_limit(RuntimeResource::GuestBytes, limit);
let owned = charges(&v);
let err =
v.execute_random(crate::lookup_intrinsic_by_id(0x4000).unwrap(), 0).unwrap_err();
assert_eq!(trap_code(&err), TRAP_RESOURCE_LIMIT);
assert_eq!(charges(&v), owned);
assert_eq!(v.heap.allocation_count(), 0);
assert_eq!(v.operand_stack.as_slice(), &[Value::Int64(42)]);
}
for q in [RuntimeResource::AuxiliaryBytes, RuntimeResource::HandleSlots] {
let mut v = fault_vm(0x4000, &[Value::Int64(42)]);
v.budget.test_lower_limit(q, v.budget.used(q));
let owned = charges(&v);
let err =
v.execute_random(crate::lookup_intrinsic_by_id(0x4000).unwrap(), 0).unwrap_err();
assert_eq!(trap_code(&err), TRAP_RESOURCE_LIMIT);
assert_eq!(charges(&v), owned);
assert_eq!(v.heap.len(), 0);
}
for id in [0x4001, 0x4002, 0x4003] {
let mut v = fault_vm(id, &[]);
let r = v.heap.allocate_random(42).unwrap();
let state = v.heap.random_state(r).unwrap();
let mut args = vec![Value::HeapRef(r)];
if id == 0x4003 {
args.extend([Value::Int64(0), Value::Int64(3)]);
}
v.operand_stack.extend_from_slice(&args).unwrap();
v.budget.test_lower_limit(RuntimeResource::TemporaryBytes, 0);
let owned = charges(&v);
let mut draws = 0;
let err = v
.execute_random_with(crate::lookup_intrinsic_by_id(id).unwrap(), 0, |p| {
draws += 1;
p.next()
})
.unwrap_err();
assert_eq!(trap_code(&err), TRAP_RESOURCE_LIMIT);
assert_eq!(draws, 0);
assert_eq!(charges(&v), owned);
assert_eq!(v.operand_stack.as_slice(), args);
assert_eq!(v.heap.random_state(r).unwrap(), state);
assert_eq!(v.cycles, crate::lookup_intrinsic_by_id(id).unwrap().cost_cycles);
}
}
#[test]
fn every_random_root_survives_gc_then_releases_and_stale_handles_fault() {
// Local, global, typed field, typed array, capture and direct Dynamic roots.
for root in 0..6 {
let mut v = vm(&[
("RET", sig(&[], &[]), vec![], 1),
("GET_CAPTURE 0\nINTRINSIC 16385\nRET", sig(&[], &[0]), vec![TypeId(1)], 0),
]);
let registry = v.validated_image.as_ref().unwrap().registry().clone();
let r = v.heap.allocate_random(42).unwrap();
match root {
0 => v.operand_stack[0] = Value::HeapRef(r),
1 => v.globals.push(Value::HeapRef(r)).unwrap(),
2 => {
let s = v.heap.allocate_typed_struct(registry.clone(), TypeId(4)).unwrap();
v.heap.store_typed(&registry, s, 0, &[Value::HeapRef(r)]).unwrap();
v.globals.push(Value::HeapRef(s)).unwrap();
}
3 => {
let s = v.heap.allocate_typed_array(registry.clone(), TypeId(5), 1).unwrap();
v.heap.store_typed(&registry, s, 0, &[Value::HeapRef(r)]).unwrap();
v.globals.push(Value::HeapRef(s)).unwrap();
}
4 => {
let s = v.heap.alloc_typed_closure(1, TypeId(6), &[Value::HeapRef(r)]).unwrap();
v.globals.push(Value::HeapRef(s)).unwrap();
}
_ => {
let d = crate::value_contract::pack_dynamic(
&registry,
&mut v.heap,
TypeId(1),
&[Value::HeapRef(r)],
)
.unwrap();
v.globals.extend_from_slice(d.as_slice()).unwrap();
}
}
let original = v.heap.random_state(r).unwrap();
v.gc_alloc_threshold = 1;
v.handle_safepoint().unwrap();
assert!(v.heap.is_valid(r));
assert_eq!(v.heap.random_state(r).unwrap(), original);
v.globals.clear();
v.operand_stack[0] = Value::Null;
v.last_gc_live_count = 0;
v.handle_safepoint().unwrap();
assert!(!v.heap.is_valid(r));
assert_eq!(v.heap.len(), 0);
assert_eq!(v.budget.used(RuntimeResource::GuestBytes), 0);
v.operand_stack.push(Value::HeapRef(r)).unwrap();
let err =
v.execute_random(crate::lookup_intrinsic_by_id(0x4001).unwrap(), 0).unwrap_err();
assert_eq!(trap_code(&err), TRAP_INVALID_HANDLE);
}
}
#[test]
fn dynamic_defaults_exact_types_wrong_objects_and_no_trait_adaptation() {
let mut v = vm(&[("RET", sig(&[], &[]), vec![], 0)]);
let registry = v.validated_image.as_ref().unwrap().registry().clone();
let r = v.heap.allocate_random(42).unwrap();
let packed = crate::value_contract::pack_dynamic(
&registry,
&mut v.heap,
TypeId(1),
&[Value::HeapRef(r)],
)
.unwrap();
assert_eq!(packed.as_slice(), &[Value::Int64(1), Value::HeapRef(r)]);
assert_eq!(v.heap.allocation_count(), 1);
assert_eq!(
crate::value_contract::unpack_dynamic(&registry, &v.heap, TypeId(1), packed.as_slice())
.unwrap()
.as_slice(),
&[Value::HeapRef(r)]
);
assert!(
crate::value_contract::ref_to_trait(
&registry,
&v.heap,
TypeId(1),
TypeId(8),
&[Value::HeapRef(r)]
)
.is_err()
);
for ty in [4, 5] {
let object = if ty == 4 {
v.heap.allocate_typed_struct(registry.clone(), TypeId(4)).unwrap()
} else {
v.heap.allocate_typed_array(registry.clone(), TypeId(5), 1).unwrap()
};
assert_eq!(v.heap.load_typed(&registry, object, 0).unwrap().as_slice(), &[Value::Null]);
let before = v.heap.load_typed(&registry, object, 0).unwrap();
assert_eq!(
v.heap.store_typed(&registry, object, 0, &[Value::HeapRef(object)]),
Err(ValueError::Type)
);
assert_eq!(
v.heap.load_typed(&registry, object, 0).unwrap().as_slice(),
before.as_slice()
);
}
}
#[test]
fn real_unknown_carriers_wrong_kind_and_domain_rollback_resume() {
let code = "GET_GLOBAL 0\nGET_GLOBAL 1\nGET_GLOBAL 2\nINTRINSIC 16387\nPOP\nGET_GLOBAL 0\nINTRINSIC 16385\nRET";
for bad in 0..4 {
let mut v = vm(&[(code, sig(&[], &[0]), vec![], 0)]);
let r = v.heap.allocate_random(42).unwrap();
let receiver = if bad == 0 {
Value::Null
} else if bad == 1 {
Value::HeapRef(v.heap.allocate_object(ObjectKind::Bytes, &[]).unwrap())
} else {
Value::HeapRef(r)
};
let lo = if bad == 2 { Value::Int32(0) } else { Value::Int64(2) };
let hi = Value::Int64(1);
v.globals.extend_from_slice(&[receiver, lo, hi]).unwrap();
for _ in 0..3 {
step(&mut v);
}
let args = v.operand_stack.as_slice().to_vec();
let report = run(&mut v, 1);
assert_eq!(report.cycles_used, 4);
assert_eq!(report.steps_executed, 0);
assert_eq!(v.operand_stack.as_slice(), args);
assert_eq!(
trap_code(&report.reason),
[TRAP_NULL_REFERENCE, TRAP_TYPE, TRAP_TYPE, TRAP_NUMERIC_DOMAIN][bad]
);
assert_eq!(v.heap.random_state(r).unwrap(), Pcg64::new(42));
// Resume after fault with the retained generator and verify first word.
v.globals[0] = Value::HeapRef(r);
v.operand_stack.clear();
v.operand_stack.push(Value::Int64(0)).unwrap();
assert_eq!(run(&mut v, 1000).reason, LogicalFrameEndingReason::EndOfRom);
assert_eq!(v.operand_stack[0], Value::Int64(0x86b1_da1d_7206_2b68u64 as i64));
}
}
#[test]
fn reset_unload_and_other_session_do_not_import_snapshot_handles() {
let bodies = [
("PUSH_I64 42\nINTRINSIC 16384\nRET", sig(&[], &[1]), vec![], 0),
("GET_LOCAL 0\nRET", sig(&[1], &[1]), vec![], 0),
];
let mut v = vm(&bodies);
run(&mut v, 1000);
let snapshot = v.operand_stack_top(1);
let Value::HeapRef(r) = snapshot[0] else { panic!() };
let owned = v.budget.clone();
let mut other =
VirtualMachine::from_image(support::image(&bodies).unwrap(), RuntimeLimits::default());
assert!(matches!(
other.prepare_call_with_args("1", &snapshot),
Err(VmInitError::EntrypointArgumentsInvalid { trap_code: TRAP_INVALID_HANDLE, .. })
));
v.initialize(support::bytes(&bodies)).unwrap();
assert!(!v.heap.is_valid(r));
assert_eq!(owned.used(RuntimeResource::GuestBytes), 0);
assert_eq!(owned.used(RuntimeResource::HandleSlots), 0);
assert!(matches!(
v.prepare_call_with_args("1", &snapshot),
Err(VmInitError::EntrypointArgumentsInvalid { trap_code: TRAP_INVALID_HANDLE, .. })
));
v.prepare_boot_call().unwrap();
run(&mut v, 1000);
let owned = v.budget.clone();
drop(v);
assert_eq!(owned.used(RuntimeResource::GuestBytes), 0);
assert_eq!(owned.used(RuntimeResource::HandleSlots), 0);
}
}
@@ -8,11 +8,12 @@ use prometeu_vm::{
};
#[test]
fn all_nine_descriptors_match_registry_storage_and_canonical_defaults() {
fn all_ten_descriptors_match_registry_storage_and_canonical_defaults() {
for (name, id, size, alignment, width, nullable) in [
("color", 1, 4, 4, 1, false),
("vec2", 2, 16, 8, 2, false),
("pixel", 3, 24, 8, 3, false),
("Random", 0x16, 8, 8, 1, true),
("Int32", 0x10, 4, 4, 1, false),
("Int64", 0x11, 8, 8, 1, false),
("Float", 0x12, 8, 8, 1, false),
@@ -0,0 +1,49 @@
seed draw word_hex signed float_bits
0 1 9B3184D7EE6BACDB -7263878661019030309 3FE366309AFDCD75
0 2 8B7B271AA4769FD4 -8396074084920287276 3FE16F64E3548ED3
0 3 9B4DB63DFE544AAB -7255943047247803733 3FE369B6C7BFCA89
0 4 E714BA3532308667 -1795605613775911321 3FECE29746A64610
0 5 64EAF919A9A040E2 7271898436958437602 3FD93ABE466A6810
0 6 325BCFFB862545B0 3628722603971397040 3FC92DE7FDC312A0
0 7 70180161DC24B6EC 8077207451505833708 3FDC06005877092C
0 8 39257F36B038F771 4117837307161671537 3FCC92BF9B581C78
1 1 3150032F5C48AC0A 3553343607941934090 3FC8A80197AE2454
1 2 099B2F21D97DB047 692198790160822343 3FA3365E43B2FB60
1 3 7539BA4A2ED012EB 8446987403885810411 3FDD4E6E928BB404
1 4 C842BA297694C455 -4016443230415174571 3FE90857452ED298
1 5 C8AE2BB397CD3537 -3986200569830361801 3FE915C57672F9A6
1 6 C2F1AF39457336BA -4399542700451088710 3FE85E35E728AE66
1 7 8710A37C51FEC0AD -8714285524614987603 3FE0E2146F8A3FD8
1 8 A4C73DCA70459C07 -6573217191447651321 3FE498E7B94E08B3
42 1 86B1DA1D72062B68 -8740965581747508376 3FE0D63B43AE40C5
42 2 1304AA46C9853D39 1370407407632858425 3FB304AA46C98538
42 3 A3670E9E0DD50358 -6672348250926415016 3FE46CE1D3C1BAA0
42 4 F9090E529A7DAE00 -501854135533064704 3FEF2121CA534FB5
42 5 C85B9FD837996F2C -4009435292248740052 3FE90B73FB06F32D
42 6 606121F8E3919196 6944869453235589526 3FD818487E38E464
42 7 7CE1C7FF478354BA 8998693429693338810 3FDF3871FFD1E0D4
42 8 CBC4AC70E541310E -3763693787692322546 3FE978958E1CA826
-1 1 EE89537ECBD16900 -1258382816822859520 3FEDD12A6FD97A2D
-1 2 DCBE53D8A6C852E6 -2540500949814193434 3FEB97CA7B14D90A
-1 3 561BA13FFCFD5094 6204730207832461460 3FD586E84FFF3F54
-1 4 76962EA43FCF9400 8545068625962177536 3FDDA58BA90FF3E4
-1 5 A2BF24C068F28D0D -6719611710200443635 3FE457E4980D1E51
-1 6 3D575F16AA0C40D8 4420106110234280152 3FCEABAF8B550620
-1 7 032B99D40D100946 228445342143613254 3F895CCEA0688040
-1 8 7053160AB14A824F 8093837190494847567 3FDC14C582AC52A0
-9223372036854775808 1 1C08F9C51E05B9F1 2020139057883232753 3FBC08F9C51E05B8
-9223372036854775808 2 4CC379FA6A441AFF 5531398883772734207 3FD330DE7E9A9106
-9223372036854775808 3 1E9926CF448F8AA7 2204836164224912039 3FBE9926CF448F88
-9223372036854775808 4 18ADD82F6DA7760F 1778315126095967759 3FB8ADD82F6DA770
-9223372036854775808 5 77DFD36640320B00 8637855046437047040 3FDDF7F4D9900C82
-9223372036854775808 6 CE09AC671D48BD0F -3600156868233085681 3FE9C1358CE3A917
-9223372036854775808 7 B15DBA0399E9E3D1 -5666168231532305455 3FE62BB740733D3C
-9223372036854775808 8 E88252991CF3E42C -1692699692368665556 3FED104A53239E7C
9223372036854775807 1 77D44C809FDF62DB 8634610500897825499 3FDDF5132027F7D8
9223372036854775807 2 05BCF3AED615466A 413473198052820586 3F96F3CEBB585500
9223372036854775807 3 693ED392E1CE694A 7583731450345580874 3FDA4FB4E4B8739A
9223372036854775807 4 83D248E707AC837B -8948009352528362629 3FE07A491CE0F590
9223372036854775807 5 5DD1D07026E00956 6760413695766956374 3FD774741C09B802
9223372036854775807 6 5713B8336C9A861C 6274561236862141980 3FD5C4EE0CDB26A0
9223372036854775807 7 4F2E7352ED7CCE69 5705624577933889129 3FD3CB9CD4BB5F32
9223372036854775807 8 DB109447225C784B -2661464346535888821 3FEB621288E44B8F
1 seed draw word_hex signed float_bits
2 0 1 9B3184D7EE6BACDB -7263878661019030309 3FE366309AFDCD75
3 0 2 8B7B271AA4769FD4 -8396074084920287276 3FE16F64E3548ED3
4 0 3 9B4DB63DFE544AAB -7255943047247803733 3FE369B6C7BFCA89
5 0 4 E714BA3532308667 -1795605613775911321 3FECE29746A64610
6 0 5 64EAF919A9A040E2 7271898436958437602 3FD93ABE466A6810
7 0 6 325BCFFB862545B0 3628722603971397040 3FC92DE7FDC312A0
8 0 7 70180161DC24B6EC 8077207451505833708 3FDC06005877092C
9 0 8 39257F36B038F771 4117837307161671537 3FCC92BF9B581C78
10 1 1 3150032F5C48AC0A 3553343607941934090 3FC8A80197AE2454
11 1 2 099B2F21D97DB047 692198790160822343 3FA3365E43B2FB60
12 1 3 7539BA4A2ED012EB 8446987403885810411 3FDD4E6E928BB404
13 1 4 C842BA297694C455 -4016443230415174571 3FE90857452ED298
14 1 5 C8AE2BB397CD3537 -3986200569830361801 3FE915C57672F9A6
15 1 6 C2F1AF39457336BA -4399542700451088710 3FE85E35E728AE66
16 1 7 8710A37C51FEC0AD -8714285524614987603 3FE0E2146F8A3FD8
17 1 8 A4C73DCA70459C07 -6573217191447651321 3FE498E7B94E08B3
18 42 1 86B1DA1D72062B68 -8740965581747508376 3FE0D63B43AE40C5
19 42 2 1304AA46C9853D39 1370407407632858425 3FB304AA46C98538
20 42 3 A3670E9E0DD50358 -6672348250926415016 3FE46CE1D3C1BAA0
21 42 4 F9090E529A7DAE00 -501854135533064704 3FEF2121CA534FB5
22 42 5 C85B9FD837996F2C -4009435292248740052 3FE90B73FB06F32D
23 42 6 606121F8E3919196 6944869453235589526 3FD818487E38E464
24 42 7 7CE1C7FF478354BA 8998693429693338810 3FDF3871FFD1E0D4
25 42 8 CBC4AC70E541310E -3763693787692322546 3FE978958E1CA826
26 -1 1 EE89537ECBD16900 -1258382816822859520 3FEDD12A6FD97A2D
27 -1 2 DCBE53D8A6C852E6 -2540500949814193434 3FEB97CA7B14D90A
28 -1 3 561BA13FFCFD5094 6204730207832461460 3FD586E84FFF3F54
29 -1 4 76962EA43FCF9400 8545068625962177536 3FDDA58BA90FF3E4
30 -1 5 A2BF24C068F28D0D -6719611710200443635 3FE457E4980D1E51
31 -1 6 3D575F16AA0C40D8 4420106110234280152 3FCEABAF8B550620
32 -1 7 032B99D40D100946 228445342143613254 3F895CCEA0688040
33 -1 8 7053160AB14A824F 8093837190494847567 3FDC14C582AC52A0
34 -9223372036854775808 1 1C08F9C51E05B9F1 2020139057883232753 3FBC08F9C51E05B8
35 -9223372036854775808 2 4CC379FA6A441AFF 5531398883772734207 3FD330DE7E9A9106
36 -9223372036854775808 3 1E9926CF448F8AA7 2204836164224912039 3FBE9926CF448F88
37 -9223372036854775808 4 18ADD82F6DA7760F 1778315126095967759 3FB8ADD82F6DA770
38 -9223372036854775808 5 77DFD36640320B00 8637855046437047040 3FDDF7F4D9900C82
39 -9223372036854775808 6 CE09AC671D48BD0F -3600156868233085681 3FE9C1358CE3A917
40 -9223372036854775808 7 B15DBA0399E9E3D1 -5666168231532305455 3FE62BB740733D3C
41 -9223372036854775808 8 E88252991CF3E42C -1692699692368665556 3FED104A53239E7C
42 9223372036854775807 1 77D44C809FDF62DB 8634610500897825499 3FDDF5132027F7D8
43 9223372036854775807 2 05BCF3AED615466A 413473198052820586 3F96F3CEBB585500
44 9223372036854775807 3 693ED392E1CE694A 7583731450345580874 3FDA4FB4E4B8739A
45 9223372036854775807 4 83D248E707AC837B -8948009352528362629 3FE07A491CE0F590
46 9223372036854775807 5 5DD1D07026E00956 6760413695766956374 3FD774741C09B802
47 9223372036854775807 6 5713B8336C9A861C 6274561236862141980 3FD5C4EE0CDB26A0
48 9223372036854775807 7 4F2E7352ED7CCE69 5705624577933889129 3FD3CB9CD4BB5F32
49 9223372036854775807 8 DB109447225C784B -2661464346535888821 3FEB621288E44B8F
@@ -0,0 +1,19 @@
# Random fixture provenance
The canonical PCG-XSL-RR 128/64 setseq source is pcg-cpp revision
`428802d1a5634f96bcd0705fab379ff0113bcf13`.
Its [check-pcg64.out](https://github.com/imneme/pcg-cpp/blob/428802d1a5634f96bcd0705fab379ff0113bcf13/test-high/expected/check-pcg64.out)
contains the first six seed=42, seq=54 words used here.
Downloaded upstream fixture SHA-256: `afc9e7775bdc59ab90d85caebe533d58ae7324be36cf9a4c975e6d7f86b9df24`.
[random-oracle.py](random-oracle.py) independently uses Python mathematical
integers modulo 2^128, division-based rotation, and Fraction-to-binary64
conversion. It imports no VM/production RNG code and cross-checks those six
canonical words. Additional seeds 0, 1, -1, MIN/MAX and draws 7–8 are generated
by that independent arithmetic model. The Float column maps the same word;
it does not represent alternating calls. Signed values are stored explicitly.
Reproduce with `python3 crates/console/prometeu-vm/tests/fixtures/random-oracle.py`
and check the TSV diff. This is a test oracle, never a runtime dependency.
Statistical quality and sequence conformance are different evidence; these
fixtures establish bits/consumption, not cryptographic or independence claims.
@@ -0,0 +1,23 @@
"""Independent mathematical fixture model (test-only Python arbitrary precision).
Pinned canonical PCG64 seed=42 words cross-check this model; no VM code imported.
"""
from pathlib import Path
from fractions import Fraction
import struct
M = 47026247687942121848144207491837523525
mod = 2**128
rows = ['seed\tdraw\tword_hex\tsigned\tfloat_bits']
first = []
for seed in [0, 1, 42, -1, -(2**63), 2**63-1]:
state = ((seed % 2**64 + 109) * M + 109) % mod
for index in range(1, 9):
state = (state * M + 109) % mod
x = (state % 2**64) ^ (state // 2**64)
rotation = state // 2**122
word = (x // 2**rotation + (x % 2**rotation) * 2**(64-rotation)) % 2**64
signed = word if word < 2**63 else word - 2**64
bits = struct.unpack('>Q', struct.pack('>d', float(Fraction(word // 2**11, 2**53))))[0]
rows.append(f'{seed}\t{index}\t{word:016X}\t{signed}\t{bits:016X}')
if seed == 42 and index <= 6: first.append(f'{word:016X}')
assert first == ['86B1DA1D72062B68','1304AA46C9853D39','A3670E9E0DD50358','F9090E529A7DAE00','C85B9FD837996F2C','606121F8E3919196']
Path(__file__).with_name('random-conformance.tsv').write_text('\n'.join(rows)+'\n')
@@ -26,7 +26,8 @@ impl NativeInterface for NoNative {
}
fn call(id: u32, args: &[Value]) -> Result<Value, E> {
let m = lookup_intrinsic_by_id(id).unwrap();
(m.implementation)(args, &mut HostContext::new(None)).map(|mut v| v.remove(0))
(m.implementation.host_callback().expect("host intrinsic"))(args, &mut HostContext::new(None))
.map(|mut v| v.remove(0))
}
fn floats(id: u32, xs: &[f64]) -> Result<u64, u32> {
match call(id, &xs.iter().copied().map(Value::Float).collect::<Vec<_>>()) {
@@ -0,0 +1,308 @@
mod support {
pub mod random;
}
use prometeu_bytecode::registry::{BuiltinId, Ownership, TypeId};
use prometeu_bytecode::{
TRAP_NULL_REFERENCE, TRAP_NUMERIC_DOMAIN, TRAP_RESOURCE_LIMIT, TRAP_TYPE, Value,
};
use prometeu_vm::resource_budget::{RuntimeLimits, RuntimeResource as Q};
use prometeu_vm::{
IntrinsicCostModel, IntrinsicImplementation, LogicalFrameEndingReason as End, VirtualMachine,
VmInitError, lookup_builtin_type, lookup_intrinsic_by_id,
};
use support::random::*;
fn trap(r: &prometeu_vm::BudgetReport) -> &prometeu_bytecode::TrapInfo {
let End::Trap(t) = &r.reason else { panic!("{r:?}") };
t
}
fn vectors(seed: i64) -> Vec<(u64, i64, u64)> {
include_str!("fixtures/random-conformance.tsv")
.lines()
.skip(1)
.filter_map(|l| {
let cols: Vec<_> = l.split('\t').collect();
(cols[0].parse::<i64>().unwrap() == seed).then(|| {
(
u64::from_str_radix(cols[2], 16).unwrap(),
cols[3].parse().unwrap(),
u64::from_str_radix(cols[4], 16).unwrap(),
)
})
})
.collect()
}
#[test]
fn independent_words_signed_and_float_bits_for_all_seed_patterns() {
for seed in [0, 1, 42, -1, i64::MIN, i64::MAX] {
for floating in [false, true] {
let mut code = format!("PUSH_I64 {seed}\nINTRINSIC 16384\nSET_LOCAL 0\n");
for _ in 0..8 {
code.push_str(if floating {
"GET_LOCAL 0\nINTRINSIC 16386\n"
} else {
"GET_LOCAL 0\nINTRINSIC 16385\n"
});
}
code.push_str("RET");
let mut v = vm(&[(&code, sig(&[], &vec![if floating { 2 } else { 0 }; 8]), vec![], 1)]);
let r = run(&mut v, 10000);
assert_eq!(r.reason, End::EndOfRom);
let expected: Vec<_> = vectors(seed)
.iter()
.rev()
.map(|(_, signed, bits)| {
if floating {
Value::Float(f64::from_bits(*bits))
} else {
Value::Int64(*signed)
}
})
.collect();
assert_eq!(v.operand_stack_top(8), expected, "seed={seed}, Float={floating}");
}
}
}
#[test]
fn interleaving_unit_range_aliases_and_equal_seed_independent_objects() {
let mut v = vm(&[(
"PUSH_I64 42\nINTRINSIC 16384\nDUP\nSET_LOCAL 0\nSET_GLOBAL 0\nPUSH_I64 42\nINTRINSIC 16384\nSET_LOCAL 1\nGET_LOCAL 0\nINTRINSIC 16385\nGET_GLOBAL 0\nINTRINSIC 16386\nGET_LOCAL 0\nPUSH_I64 -7\nPUSH_I64 -6\nINTRINSIC 16387\nGET_LOCAL 0\nINTRINSIC 16385\nGET_LOCAL 1\nINTRINSIC 16385\nRET",
sig(&[], &[0, 2, 0, 0, 0]),
vec![],
2,
)]);
assert_eq!(run(&mut v, 1000).reason, End::EndOfRom);
let x = vectors(42);
assert_eq!(
v.operand_stack_top(5),
vec![
Value::Int64(x[0].1),
Value::Int64(x[3].1),
Value::Int64(-7),
Value::Float(f64::from_bits(x[1].2)),
Value::Int64(x[0].1)
]
);
assert_eq!(v.heap().len(), 2);
}
#[test]
fn range_all_int64_spans_and_power_of_two_consumption() {
for (min, max) in
[(0, 1), (-10, -3), (-10, 10), (0, 16), (i64::MIN, 0), (-1, i64::MAX), (i64::MIN, i64::MAX)]
{
let code = format!(
"PUSH_I64 42\nINTRINSIC 16384\nSET_LOCAL 0\nGET_LOCAL 0\nPUSH_I64 {min}\nPUSH_I64 {max}\nINTRINSIC 16387\nGET_LOCAL 0\nINTRINSIC 16385\nRET"
);
let mut v = vm(&[(&code, sig(&[], &[0, 0]), vec![], 1)]);
assert_eq!(run(&mut v, 1000).reason, End::EndOfRom);
let span = (i128::from(max) - i128::from(min)) as u64;
let first = vectors(42)[0].0;
// This fixed first word is accepted for all these spans, including > i64 MAX.
let expected = (i128::from(min) + i128::from(first % span)) as i64;
assert_eq!(
v.operand_stack_top(2),
vec![Value::Int64(vectors(42)[1].1), Value::Int64(expected)]
);
}
}
#[test]
fn random_storage_dynamic_and_capture_preserve_shared_identity() {
let body = "PUSH_I64 42\nINTRINSIC 16384\nSET_LOCAL 0\nSTRUCT_NEW 4\nDUP\nGET_LOCAL 0\nSTRUCT_SET type=4,field=0\nSET_LOCAL 1\nPUSH_I64 1\nARRAY_NEW 5\nDUP\nPUSH_I64 0\nGET_LOCAL 0\nARRAY_SET 5\nSET_LOCAL 2\nGET_LOCAL 0\nDYN_PACK 1\nDYN_UNPACK 1\nINTRINSIC 16385\nGET_LOCAL 1\nSTRUCT_GET type=4,field=0\nINTRINSIC 16385\nGET_LOCAL 2\nPUSH_I64 0\nARRAY_GET 5\nINTRINSIC 16385\nGET_LOCAL 0\nMAKE_CLOSURE fn=1,type=6\nCALL_CLOSURE 6\nRET";
let mut v = vm(&[
(body, sig(&[], &[0; 4]), vec![], 3),
("GET_CAPTURE 0\nINTRINSIC 16385\nRET", sig(&[], &[0]), vec![TypeId(1)], 0),
]);
assert_eq!(run(&mut v, 2000).reason, End::EndOfRom);
assert_eq!(
v.operand_stack_top(4),
vectors(42)[..4].iter().rev().map(|x| Value::Int64(x.1)).collect::<Vec<_>>()
);
// generator + Struct + Array + Closure; no Dynamic box for one-slot Random.
assert_eq!(v.heap().allocation_count(), 4);
}
#[test]
fn random_parameter_result_and_typed_null_have_exact_dynamic_type() {
let mut v = vm(&[
("PUSH_I64 42\nINTRINSIC 16384\nCALL 1\nINTRINSIC 16385\nRET", sig(&[], &[0]), vec![], 0),
("GET_LOCAL 0\nRET", sig(&[1], &[1]), vec![], 0),
]);
assert_eq!(run(&mut v, 1000).reason, End::EndOfRom);
assert_eq!(v.operand_stack_top(1), vec![Value::Int64(vectors(42)[0].1)]);
let mut v = vm(&[("GET_LOCAL 0\nDYN_PACK 1\nDYN_UNPACK 1\nRET", sig(&[], &[1]), vec![], 1)]);
assert_eq!(run(&mut v, 1000).reason, End::EndOfRom);
assert_eq!(v.operand_stack_top(1), vec![Value::Null]);
let mut v = vm(&[("GET_LOCAL 0\nDYN_PACK 1\nDYN_UNPACK 7\nRET", sig(&[], &[7]), vec![], 1)]);
let r = run(&mut v, 1000);
assert_eq!(trap(&r).code, TRAP_TYPE);
}
#[test]
fn all_random_attempts_charge_before_validation_and_budget_overshoot() {
for (id, cost) in [(16384, 32), (16385, 8), (16386, 12), (16387, 12)] {
let body = if id == 16384 {
"PUSH_I64 42\nINTRINSIC 16384\nPOP\nRET".into()
} else {
format!(
"PUSH_I64 42\nINTRINSIC 16384\n{}INTRINSIC {id}\nPOP\nRET",
if id == 16387 { "PUSH_I64 5\nPUSH_I64 6\n" } else { "" }
)
};
let mut v = vm(&[(&body, sig(&[], &[]), vec![], 0)]);
for _ in 0..if id == 16384 {
1
} else if id == 16387 {
4
} else {
2
} {
step(&mut v);
}
let before = (v.pc(), v.operand_stack_top(10).to_vec(), v.heap().allocation_count());
let zero = run(&mut v, 0);
assert_eq!((zero.cycles_used, zero.steps_executed), (0, 0));
assert_eq!((v.pc(), v.operand_stack_top(10).to_vec(), v.heap().allocation_count()), before);
let one = run(&mut v, 1);
assert_eq!((one.cycles_used, one.steps_executed), (cost, 1));
assert_eq!(one.reason, End::BudgetExhausted);
}
}
#[test]
fn range_domain_fault_preserves_operands_and_shared_stream() {
for (min, max) in [(1, 1), (2, 1)] {
let code = format!(
"PUSH_I64 42\nINTRINSIC 16384\nDUP\nSET_GLOBAL 0\nPUSH_I64 {min}\nPUSH_I64 {max}\nINTRINSIC 16387\nRET"
);
let mut v = vm(&[(&code, sig(&[], &[0]), vec![], 0)]);
for _ in 0..6 {
step(&mut v);
}
let args = v.operand_stack_top(3).to_vec();
let r = run(&mut v, 1);
assert_eq!(trap(&r).code, TRAP_NUMERIC_DOMAIN);
assert_eq!((r.cycles_used, r.steps_executed), (4, 0));
assert_eq!(v.operand_stack_top(3), args);
}
}
#[test]
fn quota_refusal_new_preserves_seed_and_publishes_no_handle() {
let image =
image(&[("PUSH_I64 42\nINTRINSIC 16384\nPOP\nRET", sig(&[], &[]), vec![], 0)]).unwrap();
for resource in [Q::GuestBytes, Q::HandleSlots, Q::TemporaryBytes] {
let mut v = VirtualMachine::from_image(
image.clone(),
RuntimeLimits::default().lowered(resource, 0).unwrap(),
);
v.prepare_boot_call().unwrap();
step(&mut v);
let r = run(&mut v, 1);
assert_eq!(trap(&r).code, TRAP_RESOURCE_LIMIT);
assert_eq!(trap(&r).resource.as_ref().unwrap().resource, resource);
assert_eq!((r.cycles_used, r.steps_executed), (32, 0));
assert_eq!(v.operand_stack_top(1), vec![Value::Int64(42)]);
assert_eq!(v.heap().allocation_count(), 0);
}
}
#[test]
fn unknown_analysis_checks_null_receiver_at_runtime() {
let mut v = vm(&[(
"GET_LOCAL 0\nSET_GLOBAL 0\nGET_GLOBAL 0\nINTRINSIC 16385\nRET",
sig(&[], &[0]),
vec![],
1,
)]);
for _ in 0..3 {
step(&mut v);
}
let r = run(&mut v, 1);
assert_eq!(trap(&r).code, TRAP_NULL_REFERENCE);
assert_eq!((r.cycles_used, r.steps_executed), (8, 0));
assert_eq!(v.operand_stack_top(1), vec![Value::Null]);
}
#[test]
fn loader_rejects_unknown_unreachable_ids_and_new_random_construction() {
for code in ["RET\nINTRINSIC 16388", "STRUCT_NEW 1\nRET", "PUSH_I32 42\nINTRINSIC 16384\nRET"] {
let err = image(&[(code, sig(&[], &[]), vec![], 0)]).unwrap_err();
let VmInitError::RegistryLoadFailed(failure) = err else { panic!("{err:?}") };
if code.contains("16388") {
assert_eq!(failure.code, prometeu_bytecode::load_limits::LoadCode::InvalidCode);
assert_eq!(failure.reason, prometeu_bytecode::load_limits::LoadReason::NativeId);
}
}
}
#[test]
fn catalog_reference_layout_effects_and_cost_models_are_exact() {
let b = lookup_builtin_type("Random", 1).unwrap();
assert_eq!(b.id, 0x16);
assert!(b.fields.is_empty());
let l = BuiltinId::RANDOM.layout().unwrap();
assert_eq!((l.size, l.alignment, l.slots, l.ownership), (8, 8, 1, Ownership::GuestReference));
assert_eq!(l.default_values(), &[Value::Null]);
for (id, name, cost, slots) in [
(0x4000, "new", 32, 1),
(0x4001, "next", 8, 1),
(0x4002, "nextf", 12, 1),
(0x4003, "range", 4, 3),
] {
let m = lookup_intrinsic_by_id(id).unwrap();
assert_eq!(
(m.owner, m.name, m.version, m.cost_cycles, m.arg_slots(), m.ret_slots()),
("random", name, 1, cost, slots, 1)
);
assert!(m.deterministic && m.mutates_guest_state);
assert_eq!(m.may_allocate, id == 0x4000);
assert!(matches!(m.implementation, IntrinsicImplementation::VmOwned));
assert!(m.implementation.host_callback().is_none());
assert_eq!(
(m.cost_model, m.attempt_cost_cycles, m.max_attempts),
if id == 0x4003 {
(IntrinsicCostModel::RandomRejectionV1, 8, 64)
} else {
(IntrinsicCostModel::Fixed, 0, 0)
}
);
}
assert_eq!(lookup_intrinsic_by_id(0x4003).unwrap().parameter_names, &["rng", "min", "max"]);
for m in prometeu_vm::intrinsic_catalog().filter(|m| m.id < 0x4000) {
assert!(!m.mutates_guest_state);
assert_eq!(
(m.cost_model, m.attempt_cost_cycles, m.max_attempts),
(IntrinsicCostModel::Fixed, 0, 0)
);
}
}
#[test]
fn real_pcg_rejection_consumes_two_words_and_one_instruction() {
let mut v = vm(&[(
"PUSH_I64 42\nINTRINSIC 16384\nSET_LOCAL 0\nGET_LOCAL 0\nINTRINSIC 16385\nSET_LOCAL 1\nGET_LOCAL 0\nPUSH_I64 -9223372036854775808\nPUSH_I64 1\nINTRINSIC 16387\nGET_LOCAL 0\nINTRINSIC 16385\nRET",
sig(&[], &[0, 0]),
vec![],
2,
)]);
for _ in 0..9 {
step(&mut v);
}
let r = run(&mut v, 1);
assert_eq!((r.cycles_used, r.steps_executed, r.reason), (20, 1, End::BudgetExhausted));
assert_eq!(run(&mut v, 1000).reason, End::EndOfRom);
let x = vectors(42);
let expected = (i128::from(i64::MIN) + i128::from(x[2].0 % ((1u64 << 63) + 1))) as i64;
assert_eq!(v.operand_stack_top(2), vec![Value::Int64(x[3].1), Value::Int64(expected)]);
}
#[test]
fn published_emission_example_matches_bits_consumption_and_total_cycles() {
let doc = include_str!("../../../../docs/vm-arch/random-producer-handoff.md");
let code = doc.split("```text\n").nth(1).unwrap().split("```").next().unwrap();
let mut v = vm(&[(code, sig(&[], &[0, 2, 0]), vec![], 1)]);
let r = run(&mut v, 1000);
assert_eq!(r.reason, End::EndOfRom);
assert_eq!(r.cycles_used, 82);
assert_eq!(
v.operand_stack_top(3),
vec![
Value::Int64(-7),
Value::Float(f64::from_bits(0x3fb3_04aa_46c9_8538)),
Value::Int64(0x86b1_da1d_7206_2b68u64 as i64)
]
);
}
@@ -0,0 +1,94 @@
#![allow(dead_code)]
use prometeu_bytecode::{
assemble, load_limits::LoadBudget, registry::*, registry_codec::PbxModule,
};
use prometeu_vm::resource_budget::RuntimeLimits;
use prometeu_vm::{
HostContext, HostReturn, NativeInterface, ValidatedProgramImage, VirtualMachine, VmInitError,
};
use std::sync::Arc;
pub struct Native;
impl NativeInterface for Native {
fn syscall(
&mut self,
_: u32,
_: &[prometeu_bytecode::Value],
_: &mut HostReturn,
_: &mut HostContext,
) -> Result<(), prometeu_hal::vm_fault::VmFault> {
panic!("random must not invoke host syscalls")
}
}
pub fn sig(params: &[u32], results: &[u32]) -> Signature {
Signature {
parameters: params.iter().map(|&t| NamedType { type_id: TypeId(t), name: None }).collect(),
results: results.iter().map(|&t| TypeId(t)).collect(),
}
}
pub fn declarations() -> Vec<TypeDecl> {
let mut t: Vec<_> = [BuiltinId::INT64, BuiltinId::RANDOM, BuiltinId::FLOAT, BuiltinId::DYNAMIC]
.into_iter()
.map(|b| TypeDecl { name: None, kind: TypeKind::Builtin(b) })
.collect();
t.extend([
TypeDecl {
name: None,
kind: TypeKind::Struct(vec![NamedType { type_id: TypeId(1), name: None }]),
},
TypeDecl { name: None, kind: TypeKind::Array(TypeId(1)) },
TypeDecl { name: None, kind: TypeKind::Fn(sig(&[], &[0])) },
TypeDecl { name: None, kind: TypeKind::Struct(vec![]) },
TypeDecl { name: None, kind: TypeKind::Trait(vec![]) },
TypeDecl { name: None, kind: TypeKind::Fn(sig(&[1], &[1])) },
]);
t
}
pub type Body<'a> = (&'a str, Signature, Vec<TypeId>, u32);
pub fn bytes(bodies: &[Body<'_>]) -> Vec<u8> {
let mut code = Vec::new();
let mut functions = Vec::new();
for (text, signature, captures, locals) in bodies {
let body = assemble(text).unwrap();
functions.push(FunctionDecl {
signature: signature.clone(),
captures: captures.clone(),
local_slots: *locals,
max_stack_slots: 64,
code_offset: code.len() as u32,
code_len: body.len() as u32,
..Default::default()
});
code.extend(body);
}
let mut b = LoadBudget::new(Default::default());
let registry = Registry::resolve(
RegistryDeclarations { types: declarations(), functions, implementations: vec![] },
code.len(),
&mut b,
)
.unwrap();
PbxModule {
registry: &registry,
constants: &[],
code: &code,
debug: None,
exports: &[],
syscalls: &[],
}
.serialize(&mut b)
.unwrap()
}
pub fn image(bodies: &[Body<'_>]) -> Result<Arc<ValidatedProgramImage>, VmInitError> {
ValidatedProgramImage::load(&bytes(bodies), &mut LoadBudget::new(Default::default()), 0)
}
pub fn vm(bodies: &[Body<'_>]) -> VirtualMachine {
let mut v = VirtualMachine::from_image(image(bodies).unwrap(), RuntimeLimits::default());
v.prepare_boot_call().unwrap();
v
}
pub fn run(v: &mut VirtualMachine, budget: u64) -> prometeu_vm::BudgetReport {
v.run_budget(budget, &mut Native, &mut HostContext::new(None)).unwrap()
}
pub fn step(v: &mut VirtualMachine) {
v.step(&mut Native, &mut HostContext::new(None)).unwrap();
}
@@ -141,7 +141,9 @@ fn query_all(platform: &mut TestPlatform) -> Vec<Value> {
(0x2100..=0x2135)
.map(|id| {
let meta = lookup_intrinsic_by_id(id).unwrap();
let result = (meta.implementation)(&[], &mut ctx).unwrap();
let result =
(meta.implementation.host_callback().expect("host intrinsic"))(&[], &mut ctx)
.unwrap();
meta.validate_result_values(&result).unwrap();
result.into_iter().next().unwrap()
})
@@ -211,11 +213,14 @@ fn every_known_query_faults_when_unavailable_and_rejects_arguments() {
let meta = lookup_intrinsic_by_id(id).unwrap();
let mut ctx = HostContext::new(None);
assert_eq!(
(meta.implementation)(&[], &mut ctx),
(meta.implementation.host_callback().expect("host intrinsic"))(&[], &mut ctx),
Err(IntrinsicExecutionError::HardwareUnavailable)
);
assert_eq!(
(meta.implementation)(&[Value::Int64(0)], &mut ctx),
(meta.implementation.host_callback().expect("host intrinsic"))(
&[Value::Int64(0)],
&mut ctx
),
Err(IntrinsicExecutionError::ArityMismatch { expected: 0, got: 1 })
);
let mut vm = query_vm(assemble(&format!("INTRINSIC {id}\nHALT")).unwrap());
@@ -0,0 +1,116 @@
---
id: LSN-0063
ticket: vm-owned-random-service
title: Reproducible Random Is Stateful Transactional Work
created: 2026-10-09
tags: []
---
## Context
Random generation is a useful example of deterministic work that cannot be
modeled as a pure function of its visible arguments. A seed identifies the
initial stream, but each call changes where the generator is in that stream.
The runtime must preserve identity, call order, memory ownership and consumed
work together if a cartridge is to replay the same logical behavior.
This lesson derives from accepted decision DEC-0050, executed through PLN-0181.
Its normative result is the [VM-owned random contract](../../../docs/specs/runtime/02e-vm-owned-random-core.md).
Historical lineage is retained by the [discussion index](../../index.ndjson);
completed control artifacts are disposable. The
[qualification record](../../../docs/vm-arch/RANDOM_QUALIFICATION.md) contains
executed environment, fixtures, checks and pending target comparisons.
## Key Decisions
### Identity belongs to the object, reproducibility to the ordered stream
**What:** Random is an opaque reference builtin backed by a GC-managed object.
Copies retain the same state; separate constructions with equal seed bits start
at the same point and then evolve independently. Existing fields, arrays,
Dynamic, captures and function boundaries store references, not generator copies.
**Why:** This fits the published reference/ownership model and avoids accidental
stream duplication through ordinary value copies. The frontend selects an
intrinsic; it does not implement the generator or choose host entropy.
**Trade-offs:** Consumers must distinguish aliasing from independent construction.
Reproducible generators with the same seed are not evidence of statistical
independence. Native snapshots do not become guest GC roots or import authority.
### Freeze the complete algorithm, including initialization and consumption
**What:** The implementation uses PCG-XSL-RR 128/64 setseq with explicit wrapping,
fixed increment and advance-before-output. Integer and Float calls consume the
same sequence. Seed Int64 bits are zero-extended after u64 reinterpretation.
**Why:** An algorithm family name alone is insufficient: variants, seed expansion,
old-versus-new-state output and hidden buffers all change the stream. Float
conversion also needs an exact endpoint rule; retaining the high 53 bits and
scaling with software binary64 excludes 1 without a Float32 narrowing step.
**Trade-offs:** Compatibility claims are limited to this exact contract.
Independent canonical words plus a separate arithmetic oracle are stronger
than comparing two instances of the same implementation. Debug/release equality
is necessary; it does not qualify unexecuted operating systems or targets.
### Stage state changes but retain the cost of attempted work
**What:** The interpreter validates all carriers before reference/bounds checks,
reserves resources, draws on a private state candidate, and publishes the result
and state only after success. Faults preserve operands and state while retaining
cycles. Bounded range mapping charges a base plus every attempted word.
**Why:** Popping operands first loses roots/owners and makes resource refusal
or rejection-limit failure difficult to undo. Mutating public state while
retrying creates an observable half-completed instruction. Refunding cycles,
however, would erase work that the machine actually attempted.
**Trade-offs:** Unbiased rejection may fail after its bounded work allowance.
A cap fault leaves the generator at its original state; identical inputs/state
will repeat the same failed candidate stream. Accepting the final permitted
attempt and rejecting all permitted attempts are distinct cases. Whole-instruction
budget overshoot remains sufficient; no new continuation/scheduler is needed.
## Patterns and Algorithms
Treat a stateful intrinsic as a transaction over existing VM resources:
retain source roots, validate in published order, reserve, prepare privately,
then commit without fallible operations. A leaf payload does not require a new
GC model: integrate its reference builtin with the existing ownership maps.
Use the same shared catalog for signatures, admission, execution routing and
exports. An explicit VM-owned implementation variant avoids giving host
callbacks heap mutation authority. Publish guest-state effects separately from
determinism, and publish variable cost structure rather than a misleading
fixed base-only total.
Rare paths require deliberate evidence. Test-only synthetic candidates execute
the production bounded loop and transaction for multiple rejections, final
acceptance and cap rollback. Real PCG fixtures separately prove the stream,
including a natural rejection followed by acceptance. These two tests answer
different questions and should not replace each other.
## Pitfalls
- Treating deterministic=true as permission to fold or reorder stateful calls.
- Copying a handle while expecting an independent stream.
- Reducing unsigned words with simple modulus without the rejection threshold.
- Computing an Int64 interval width in signed 64-bit arithmetic.
- Rounding W/2^64 or narrowing to Float32 and accidentally including endpoint 1.
- Committing generator state before result capacity or quota checks finish.
- Advertising local reproducibility as cross-platform qualification or game readiness.
## Published Evidence and Handoffs
The delivered core passed bytecode/VM suites in debug and release and the
workspace regression suite. Twenty-four focused random tests cover guest
fixtures and private engine/transaction behavior, including GC roots, rollback,
resource ownership and exact costs. Metadata and published CSV agree; the
constant catalog remains unchanged. Exact counts, fingerprints and commands
belong to the qualification record, not to a normative lesson.
The [producer handoff](../../../docs/vm-arch/random-producer-handoff.md) gives
emitted PBX, expected result bits/cycles and consumer acceptance tests.
Frontend projection/optimization, reference-game workloads and other-target
comparison runs remain separate deliveries. No helper selection API was added.
@@ -0,0 +1,50 @@
---
id: LSN-0064
ticket: coverage-domain-minimum-margin
title: Measured Coverage and Acceptance Floors
created: 2026-10-09
tags: [coverage, ci, measurement]
---
## Context
A coverage gate set equal to its observed percentage has almost no room for
variation. This workspace had several such floors. An explicitly reviewed
revision now provides at least five percentage points of local headroom in
all 15 domains, lowering eight floors and retaining seven.
The published contract is in [Coverage domains](../../../docs/vm-arch/COVERAGE_DOMAINS.md),
with [measured evidence](../../../docs/vm-arch/COVERAGE_DOMAINS_MARGIN.json) and
[fixed configuration](../../../files/config/runtime-edge-coverage-domains.json).
DEC-0051 and PLN-0182 record the accepted revision and execution; their lifecycle
is retained in the [discussion index](../../index.ndjson).
## Separate the Measurement from the Floor
Observed coverage describes one execution. A floor describes how much decline
the reviewed gate accepts. They serve different purposes even when their
numbers initially coincide. Five percentage points below 88.56% is 83.56%,
not a relative five-percent reduction.
Snapshot original floors before editing. For this revision, compute
`min(original_floor, measured_percent - 5.00)` in integer hundredths after
the auditor's downward truncation. This retains already sufficient floors
and prevents repeated subtraction from weakening the policy accidentally.
Keep floors fixed in later CI runs; future revisions require explicit review.
## Use Verification to Account for Observed Variation
Two full local runs passed, but system/runtime measured 81.26% initially and
81.19% during verification. The final 76.19% floor uses the lower observation.
All gates were rechecked against that unchanged verification report. Treating
the initial measurement as immutable would have left only 4.93 points of
headroom. Local evidence qualifies the executed host, not an unexecuted pipeline.
## Preserve Independent Checks
Margin changes affect acceptance floors only. Source ownership, exclusions,
nonempty evidence requirements and percentage arithmetic still apply. The
939 passing tests continue to check behavior independently of coverage.
Historical evidence remains unchanged; new evidence records the current
measurements, floors and fingerprints. A fresh snapshot explains the revision
without making an earlier run appear to have used the new configuration.
@@ -183,3 +183,7 @@ Zero budget begins no attempt; positive budget admits the complete operation
and retains the existing overshoot rule. Argument-producing bytecode costs
remain additional. Input/color and other intrinsic/opcode costs and accounting
remain unchanged. CPU timings never change guest-visible cycle weights.
## Random core integration
The [random core](02e-vm-owned-random-core.md) charges fixed calls before checks and bounded range calls as 4+8*N (at most 64 draws), retaining fault cycles and whole-instruction overshoot.
@@ -157,3 +157,7 @@ After charging the attempt, incomplete temporary operands trap with STACK_UNDERF
Publication and ownership follow [typed collection memory](03-memory-stack-heap-and-allocation.md); charging follows [time and cycles](01-time-model-and-cycles.md). See the [producer handoff](../../vm-arch/collection-producer-handoff.md) for independent byte oracles and construction examples. Production consumers must enter through the validated PBX v1 image boundary described in [Program Registry](02c-program-registry-and-pbx-v1.md).
Typed callable instructions are MAKE_CLOSURE `(FunctionId,FnTypeId)`, CALL_CLOSURE `(FnTypeId)`, GET_CAPTURE `(index)` and CALL_TRAIT `(TraitTypeId,method_index)`. Their groups, encodings and attempted costs are defined in the [Fn contract](02b-vm-function-values-and-closures.md). Numbers 0x54–0x56 stay reserved and reject anywhere at load.
## Random core integration
INTRINSIC also dispatches the [VM-owned random operations](02e-vm-owned-random-core.md), IDs 0x4000–0x4003. NEW cannot construct Random. TRAP_RANDOM_REJECTION_LIMIT is 0x00000015.
@@ -140,3 +140,7 @@ equality treats both zeros equally. Numeric overflow faults by range.
Exact Registry/intrinsic carriers prohibit implicit conversion; math/mathf
supplies explicit conversions with truncation/range and ties-even rules.
Existing arithmetic opcode promotions do not relax typed boundaries.
## Random core integration
[Random v1](02e-vm-owned-random-core.md) is BuiltinId 0x0016: one nullable HeapRef slot, eight-byte reference storage aligned to eight with GuestReference ownership. Copies alias; only random.new constructs the object.
@@ -98,3 +98,7 @@ callbacks are ordinary Fn calls in the main execution context.
See [memory](03-memory-stack-heap-and-allocation.md),
[Registry/PBX](02c-program-registry-and-pbx-v1.md) and
[host ABI](16-host-abi-and-syscalls.md).
## Random core integration
[Random references](02e-vm-owned-random-core.md) are valid capture, parameter and result groups. Existing roots retain the generator; copying captures aliases its state.
@@ -101,12 +101,13 @@ Value remains the generic stack/local representation. Structs/arrays are referen
| 0x0013 | Bool | 1 | 1 / 1 byte; canonical 0/1 |
| 0x0014 | String | 1 | native StringSlot size_of/align_of |
| 0x0015 | Dynamic | 2 | native DynamicSlot size_of/align_of |
| 0x0016 | Random | 1 | 8 / 8 bytes, nullable GuestReference |
Unlisted BuiltinIds, including zero and removed input IDs 0x0100–0x0102, cannot be imported. No implicit Int/Number/Void/Null aliases. `color` is numeric RGBA8888 `0xRRGGBBAA`; its stack carrier is Int64 constrained to u32 range. `vec2` stores f64 x/y at offsets 0/8. `pixel` stores i64 x/y at 0/8 and u32 color at 16 plus four padding bytes, with stack carriers [Int64,Int64,Int64]. Do not narrow coordinates or infer framebuffer byte order from the numeric color representation. These builtins contain no guest references/native ownership.
Unlisted BuiltinIds, including zero and removed input IDs 0x0100–0x0102, cannot be imported. No implicit Int/Number/Void/Null aliases. `color` is numeric RGBA8888 `0xRRGGBBAA`; its stack carrier is Int64 constrained to u32 range. `vec2` stores f64 x/y at offsets 0/8. `pixel` stores i64 x/y at 0/8 and u32 color at 16 plus four padding bytes, with stack carriers [Int64,Int64,Int64]. Do not narrow coordinates or infer framebuffer byte order from the numeric color representation. color, vec2 and pixel contain no guest references/native ownership. Random is an opaque reference builtin; its state is VM-owned.
Preserve declared field order; round each offset to field alignment and final payload size to maximum alignment. Empty Struct has payload zero, alignment one, but retains object identity/header. Array stride is aligned stored-element size; Array<Struct> stores references, not Struct payloads. Checked arithmetic precedes allocation. Padding is not data or a GC reference. Allocate truly aligned storage or use appropriate accesses; Vec<u8> does not justify unsafe casts. Native Arc/Value layouts are target-dependent and never a portable PBX ABI.
Defaults apply before publication/GC, including reused storage: Int32/Int64 zero, Float +0.0, Bool false, Struct/Array/Fn/String references null, vec2 (+0,+0), color transparent raw zero, pixel (0,0,transparent), trait absent, Dynamic untyped null. Do not instantiate referenced objects/subarrays or invoke source constructors. Empty arrays require no element values. Catalog defaults are resolved without arbitrary per-element callbacks. Native values must be constructed correctly rather than assumed valid after memset.
Defaults apply before publication/GC, including reused storage: Int32/Int64 zero, Float +0.0, Bool false, Struct/Array/Fn/String/Random references null, vec2 (+0,+0), color transparent raw zero, pixel (0,0,transparent), trait absent, Dynamic untyped null. Do not instantiate referenced objects/subarrays or invoke source constructors. Empty arrays require no element values. Catalog defaults are resolved without arbitrary per-element callbacks. Native values must be constructed correctly rather than assumed valid after memset.
Heap references: index:u32 + generation:u32, stored size/alignment 8, still one Value::HeapRef slot. Generation starts at one; zero is reserved. Compact null=(0,0), while index zero remains valid with a live generation. Other generation-zero pairs are invalid. Validate index/liveness/generation/type before dereference. Increment generation on reclamation; retire the slot after its maximum-generation incarnation rather than wrap. Handles belong to their heap/session; native boundaries preserve provenance without introducing a heap ID into this encoding.
@@ -197,6 +198,7 @@ Preserve typed reasons and available section/file offset, ID domain/record/membe
| TRAP_NUMERIC_DOMAIN | 0x00000012 | Invalid mathematical domain of finite arguments |
| TRAP_NUMERIC_RANGE | 0x00000013 | Finite result/destination outside representable range |
| TRAP_NON_FINITE | 0x00000014 | NaN/infinite input rejected before guest publication |
| TRAP_RANDOM_REJECTION_LIMIT | 0x00000015 | All 64 range candidates rejected; state rolls back |
Keep TrapInfo(code,opcode,pc,message,optional span) and current trap interruption behavior; no guest-catchable exception system. Untyped null to Int32 is TRAP_TYPE, not null dereference. Invalid handles never become false/null and are validated before following them. Preserve existing stack/function/return/intrinsic error categories. No promise to recover process/allocator abort; use fallible new allocation paths rather than operational panics.
@@ -255,3 +257,7 @@ No envelope/version change is introduced. Native signature import validates
complete layouts before checking Float finitude and publishing guest slots.
See [numeric semantics](02d-gameplay-math-and-numeric-semantics.md) for fault
precedence, conversions, catalog metadata and producer examples.
## Random core integration
[Random](02e-vm-owned-random-core.md) adds BuiltinId 0x0016 and intrinsic IDs 0x4000–0x4003 using existing PBX v1 encoding. Registry categories remain unchanged; unsupported identities are rejected, without fallback.
@@ -48,7 +48,9 @@ Mixed intrinsic carriers require explicit conversion.
[INTRINSICS.csv](../../vm-arch/INTRINSICS.csv) is generated from runtime
metadata: ID, owner/name/version, ordered ABI layout, parameter names,
total call cost and determinism/guest-allocation flags.
fixed cost or variable base/attempt/limit model, determinism, guest-allocation
and guest-state mutation flags. Math entries use fixed complete costs;
stateful random entries publish their variable model separately.
[BUILTIN_CONSTANTS.csv](../../vm-arch/BUILTIN_CONSTANTS.csv) publishes constant
slots and Float bits. Consumers MUST use these artifacts rather than duplicate
ID/cost maps. Math functions are pure and allocate no guest objects; runtime
@@ -305,3 +307,7 @@ crates/console/prometeu-vm/tests/fixtures/numeric-conformance.tsv.
The versioned [local qualification record](../../vm-arch/NUMERIC_QUALIFICATION.md)
reports the executed configuration, source audit, observed precision and
timings, reproducible commands and pending host comparisons.
## Random core integration
The [random core](02e-vm-owned-random-core.md) uses this software binary64 backend for exact nextf values k/2^53. Its deterministic calls mutate guest state; exported metadata includes mutates_guest_state and fixed or random_rejection_v1 cost models.
@@ -0,0 +1,170 @@
# VM-owned random core
## Identity and memory
`Random` version 1 is BuiltinId `0x0016`, an opaque nullable reference builtin.
It occupies one execution slot: present values use `Value::HeapRef`; the default
is `Value::Null`. Typed storage uses index:u32 and generation:u32, eight bytes
aligned to eight, with GuestReference ownership. Registry categories remain
Builtin, Struct, Array, Trait and Fn. PBX v1 encoding is unchanged.
ObjectKind::Random has tag 9; DynamicBox remains 8 and tag 6 remains reserved.
Its private logical payload is State:u128 and Inc:u128, 32 bytes with no child
references. Payload, header, handle tables and auxiliary storage are charged
to existing session quotas. Only `random.new` constructs Random; NEW and
Struct/array access cannot construct or expose its payload.
Random is valid in locals, globals, fields, arrays, captures and function
parameters/results. Copying a handle aliases the same state. Separate objects
with equal seeds have equal initial streams and evolve independently. Dynamic
retains the exact TypeId and direct single-slot HeapRef without copying state
or allocating a multislot box. Extraction requires that exact type, including
typed null. There is no implicit Struct or Trait adaptation.
Existing reference maps and roots retain reachable objects. Random is a GC
leaf; collection occurs only at existing safepoints. There are no guest
finalizers, callbacks or reentrant collection. Pause/resume preserves state;
reset/unload releases the session and prior handles cease to authorize access.
Existing native-boundary provenance rules apply: copying raw reference bits
between sessions is not an import operation.
## Exact algorithm
Use PCG-XSL-RR 128/64 setseq, with unsigned wrapping modulo 2^128:
```text
M = 0x2360ED051FC65DA44385DF649FCCF645
= 47026247687942121848144207491837523525
seq = 54
Inc = (seq << 1) | 1 = 109
B = zero_extend_128(bits_u64(seed))
State = ((B + 109) * M + 109) mod 2^128
each draw:
State = (State * M + 109) mod 2^128
X = low_u64(State) XOR high_u64(State)
R = State >> 122
W = rotate_right_64(X, R)
```
Int64 seed bits are reinterpreted as u64 and zero-extended, never sign-extended
or expanded. Zero, negative and extreme seeds are valid. Advance before
output; rotation zero preserves X. Inc is always 109 and State zero is valid.
There is no additional warm-up, discard, buffer, implicit global RNG or host
entropy. Explicit wrapping produces identical debug/release bits. Equivalent
limb arithmetic must match; operational host bigint/FFI or platform-selected
variants are forbidden. PCG32, PCG64DXSM and NumPy SeedSequence compatibility
is not promised.
Seed=42, seq=54 reference vectors; the Float column maps the same W:
| Draw | W hex | nextf binary64 bits |
| --- | --- | --- |
| 1 | 86B1DA1D72062B68 | 3FE0D63B43AE40C5 |
| 2 | 1304AA46C9853D39 | 3FB304AA46C98538 |
| 3 | A3670E9E0DD50358 | 3FE46CE1D3C1BAA0 |
| 4 | F9090E529A7DAE00 | 3FEF2121CA534FB5 |
| 5 | C85B9FD837996F2C | 3FE90B73FB06F32D |
| 6 | 606121F8E3919196 | 3FD818487E38E464 |
## Intrinsics and metadata
| ID | Version 1 name | Ordered signature | Virtual cycles |
| --- | --- | --- | --- |
| 0x4000 | random.new | (seed:Int64)->Random | 32 |
| 0x4001 | random.next | (rng:Random)->Int64 | 8 |
| 0x4002 | random.nextf | (rng:Random)->Float | 12 |
| 0x4003 | random.range | (rng:Random,min:Int64,max:Int64)->Int64 | 4+8*N |
There are no hidden receivers, defaults, Int32 coercions or alternative names.
Random is the type and random the namespace, not a singleton. Version 1 has
no PickRandom, collection/string/Bool helpers, destroy, reseed, clone, split,
exposed stream selector or serialization/replay API. It is not cryptographic.
All four descriptors publish deterministic=true and mutates_guest_state=true;
only new publishes may_allocate=true. Deterministic means reproducible with
the same state and ordered inputs, not pure. Compilers must preserve calls,
source evaluation order and state consumption, including named arguments.
They must not execute the generator at compile time, fold, eliminate or
reorder calls based on literals or deterministic metadata.
The shared catalog publishes cost_model. Fixed entries use `fixed`, complete
cost_cycles and zero attempt_cost_cycles/max_attempts. range uses
`random_rejection_v1`, cost_cycles=4 (base), attempt_cost_cycles=8 and
max_attempts=64. Four is not range's total cost. Existing identities and costs
are preserved. Execution is VM-owned through the same catalog/resolver/verifier,
without a HostContext RNG, host syscall or public host heap-access API.
## Outputs and bounded intervals
next consumes one W and reinterprets its bits as Int64, including negatives.
nextf consumes one W, computes k=W>>11 and returns k/2^53 through the VM's
software binary64 semantics. Values are exact points on [0,1); +0 is valid
and 1 is excluded. Float32, rounded W/2^64, host libm and frontend floating
arithmetic are forbidden. Calls share the same stream; no per-output buffers.
range requires exact Int64 min<max and returns [min,max). Compute n=max-min
in wide arithmetic, then as u64 (1 through 2^64-1). Compute threshold=2^64 mod n
using wrapping_neg(n)%n. For each word, reject W<threshold; otherwise return
min+(W%n) in wide arithmetic with exact Int64 conversion. No abs, signed
modulus, Float, swapped or clamped limits. A unit span consumes one word.
At most 64 words are attempted; acceptance on attempt 64 succeeds. Rejecting
all 64 raises TRAP_RANDOM_REJECTION_LIMIT `0x00000015`, without fallback.
The mapping removes additional modulo bias for uniform input words; it does
not promise statistical independence between deterministic words or streams.
## Validation and atomicity
Order checks as follows: instruction structure/height; all argument carriers
in parameter order; complete receiver reference; limits; resource reservations;
draws. Wrong carriers use TYPE, null receiver NULL_REFERENCE, invalid index,
generation or liveness INVALID_HANDLE, live wrong object/type TYPE, min>=max
NUMERIC_DOMAIN, and quota/recoverable allocation refusals RESOURCE_LIMIT.
Keep PC, opcode, source span and available resource details. No operational
panic, guest catchable exception or host-status substitute is introduced.
Retain operands and roots, validate, and reserve result/resources before
mutation. Stage candidate state and result, then publish and consume operands
atomically with no fallible work afterward. Every fault preserves operands,
generator state and prior owners, releases provisional resources and publishes
no partial handle. range draws on private candidate state and rolls it back
on any fault, including the rejection limit. Executed cycles are not refunded.
Loader/verifier recognize Random and all signatures without changing PBX v1.
Unknown intrinsic IDs, including unreachable ones, use LOAD_INVALID_CODE/NativeId;
runtime INVALID_INTRINSIC is invariant defense. Invalid Registry IDs/signatures
retain existing categories. Unknown type analysis requires full runtime checks.
An old VM may reject the new identities; no alternate-algorithm fallback exists.
## Budget and evidence
Charge fixed cost or range base before checks/reservations and 8 before every
draw, rejected or accepted. N counts words actually drawn: refusal before
draws costs 4, a unit interval 12, 64 attempts 516. Do not charge generic
INTRINSIC +1 or public math/next costs for private steps. Argument-producing
instructions retain their own costs.
Zero budget starts/charges no instruction. Positive budget admits the whole
instruction with existing overshoot between instructions. Fault retains cycles
and takes precedence over BudgetExhausted; failed calls are not successful steps.
There is no mid-attempt pause, continuation, added GC, tick or frame sync.
Qualification requires independently sourced words/Int64/Float bits, consumption,
faults and cycles in debug/release, seeds 0/1/42/-1/MIN/MAX, interleaving,
aliasing, storage/capture/Dynamic roots, GC/stale/provenance cases, extreme spans,
threshold boundaries, 64th acceptance, cap rollback and resource refusals.
Test-only synthetic words exercise rare paths without changing production RNG.
Record executed target/toolchain/profile and catalog fingerprints; do not
claim unexecuted host comparisons. CPU benchmarks do not set virtual costs.
Frontend and reference-game integration consume the published contract through
separate handoffs. Local core completion does not require those implementations
or acquisition of hardware. See [numeric semantics](02d-gameplay-math-and-numeric-semantics.md),
[Registry/PBX](02c-program-registry-and-pbx-v1.md),
[memory](03-memory-stack-heap-and-allocation.md) and
[cycles](01-time-model-and-cycles.md).
Producer examples and integration acceptance tests are published in the
[random handoff](../../vm-arch/random-producer-handoff.md). Executed evidence is
recorded in [random qualification](../../vm-arch/RANDOM_QUALIFICATION.md).
@@ -217,3 +217,7 @@ After validation, an attempt provisionally reserves net stack growth and constru
## Typed Fn and Root-Return Collection
Threshold GC opportunities are FRAME_SYNC and successful RET of the last root, after results are transferred and rooted. No automatic GC at ordinary callee RET, entry preparation or allocation/quota refusal. VM owns its single execution context directly. Roots include globals, all live operand values, Closures retained by every active CallFrame and legally retained native/host roots. Trace complete typed capture/cell graphs; unreachable cycles collect. Inspection snapshots and raw handle copies create no guest root or session import. Results remain roots until consumed/replaced/reset/unload. Scratch refusal preserves owners and prohibits partial sweep.
## Random core integration
[Random objects](02e-vm-owned-random-core.md) use ObjectKind tag 9 (tag 6 remains reserved), 32 logical payload bytes and quota-accounted headers/handles/auxiliary storage. They are opaque GC leaves; Dynamic holds their direct reference and exact TypeId.
@@ -3,7 +3,7 @@
Domain: portability contract
Function: normative
Didactic companion: [`../learn/mental-model-portability-and-cross-platform.md`](../runtime/learn/mental-model-portability-and-cross-platform.md)
Didactic companion: [Portability mental model](../../../discussion/lessons/DSC-0001-runtime-learn-legacy-import/LSN-0014-mental-model-portability-and-cross-platform.md)
## 1 Scope
@@ -295,3 +295,7 @@ after reset.
AI tooling may consume this generic host API from outside the machine. It does
not create an AI mode, testing mode, replay protocol, gameplay introspection
surface, or guest capability.
## Random core integration
[PCG64 random](02e-vm-owned-random-core.md) fixes unsigned wrapping state, seed-bit conversion and software Float output across targets. Qualification records only executed targets; no platform-selected RNG or host entropy is permitted.
+4
View File
@@ -128,3 +128,7 @@ In those cases:
- `docs/runtime/learn/` explains the why, the intuition, and the examples;
- the spec should point to the pedagogical companion near the top;
- the pedagogical guide should point back to the canonical spec.
## Random core integration
The [VM-owned random core](02e-vm-owned-random-core.md) defines opaque Random references, PCG64 and the random intrinsic surface.
+4
View File
@@ -198,3 +198,7 @@ The verifier statically checks bytecode for structural safety and stack‑shape
The [Program Registry contract](../specs/runtime/02c-program-registry-and-pbx-v1.md) defines immutable image-owned Type/Function metadata linked by dense IDs. Descriptors are native metadata outside guest GC; nominal identity does not depend on names. Stack/local execution retains Value, while typed storage uses resolved aligned layouts. PBX v1 is the sole target format; publication requires full bounded validation. Fn tag 4 and mandatory captures section 8 extend the Registry; no old-schema fallback is permitted.
`ValidatedProgramImage::load` publishes a shared image only after bounded decoding, native binding and Registry verification; `VirtualMachine::from_image` creates sessions that consume its typed signatures, constants and conversion instructions. Production and internal generators must use this sole sealed-v1 path. Typed Fn integration and legacy removal are implemented together; publication alone is not proof that every consumer has migrated. [Registry Boundaries and Owned Values](../../discussion/lessons/DSC-0058-program-registry-type-and-function-metadata/LSN-0059-registry-boundaries-and-owned-values.md) explains the published mechanisms. The [producer handoff](registry-producer-handoff.md) documents schema, input IDs and named-argument order, while [layout evidence](registry-layout-evidence.md) records reproducible load/access/GC measurements and the current publication boundary.
## VM-owned random core
See the [random contract](../specs/runtime/02e-vm-owned-random-core.md) for Random BuiltinId 0x0016, ObjectKind tag 9, intrinsics 0x4000–0x4003, atomic state mutation, bounded 4+8*N costs and rejection-limit trap 0x00000015. Random is managed by the VM heap and existing GC, without host entropy or PBX changes.
+51 -10
View File
@@ -42,7 +42,7 @@ LLVM lines still need an owner.
| tooling | CLI and dummy/stress PBX producers |
| dev/test-support | Shared test-program construction and development infrastructure source stubs |
Existing specialized paths and baselines retain their original values.
Existing specialized paths retain their original ownership.
Residual domains use broad crate source prefixes with explicit exclusions,
so a new module inherits the appropriate owner. A new crate or conflicting
prefix must be assigned before the ownership audit can pass.
@@ -93,9 +93,18 @@ this percentage is at least baseline_percent. Counts for functions and
regions remain supporting evidence. Scenario/contract assertions continue
to govern behavior; a percentage does not replace them.
New domains start from a fresh measured baseline, using the same truncation.
Do not lower existing thresholds to hide a failing run. An intentional scope
or baseline revision requires explicit review with measured evidence.
Measured coverage and the acceptance floor are separate values. This explicitly
reviewed revision gives every domain at least 5.00 percentage points of headroom
from the recorded local measurement. Its rule is
`new_floor = min(original_floor, measured_percent - 5.00)`, using the same
downward truncation. Floors already providing that margin remain unchanged.
Five percentage points means an 88.56% measurement permits an 83.56% floor;
it is not a relative five-percent reduction.
Floors remain fixed during CI. A failing run does not automatically lower them.
An intentional scope or floor revision requires explicit review with fresh
measured evidence. New domains also require an explicit floor supported by a
fresh measurement.
## Commands and CI
@@ -124,12 +133,13 @@ Inspect a domain:
Dependencies are the existing Rust/LLVM coverage tooling, Bash, Git, jq and rg,
plus Python 3 for the standard-library ownership auditor.
## Published local baseline
## Historical local baseline
The [measured evidence](COVERAGE_DOMAINS_EVIDENCE.json) records configuration,
The [initial measured evidence](COVERAGE_DOMAINS_EVIDENCE.json) records configuration,
source/report fingerprints, command/toolchain/host, line totals and gate
results for all 15 domains. The eight earlier domain definitions are
preserved. The seven additional baselines measured on macOS/aarch64 are:
results for all 15 domains before the margin revision. It preserves the eight
earlier domain definitions and records these seven additional starting floors
on macOS/aarch64:
| New domain | Baseline lines |
| --- | ---: |
@@ -141,7 +151,38 @@ preserved. The seven additional baselines measured on macOS/aarch64 are:
| tooling | 64.75% |
| dev/test-support | 85.96% |
These are observed starting baselines, not uniform target percentages.
These are historical starting floors; current acceptance floors appear below.
## Current local margins
The [margin evidence](COVERAGE_DOMAINS_MARGIN.json) records fresh measurements,
original and revised floors, toolchain, fingerprints and executed validation.
Only domains with less than 5.00 percentage points of headroom were adjusted.
The historical evidence above remains unchanged.
| Domain | Measured lines | Original floor | Current floor | Margin (points) |
| --- | ---: | ---: | ---: | ---: |
| system/os | 82.24% | 77.24% | 77.24% | 5.00 |
| system/runtime | 81.19% | 76.50% | 76.19% | 5.00 |
| system/fs | 81.08% | 76.08% | 76.08% | 5.00 |
| system/programs | 98.05% | 93.05% | 93.05% | 5.00 |
| asset/bank | 91.76% | 86.76% | 86.76% | 5.00 |
| firmware | 88.26% | 83.20% | 83.20% | 5.06 |
| host-dependent | 45.05% | 40.05% | 40.05% | 5.00 |
| host/headless | 88.39% | 83.39% | 83.39% | 5.00 |
| vm/core | 89.29% | 89.12% | 84.29% | 5.00 |
| bytecode | 93.26% | 93.23% | 88.26% | 5.00 |
| hal/core | 88.56% | 88.56% | 83.56% | 5.00 |
| drivers/core | 84.51% | 84.51% | 79.51% | 5.00 |
| system/core | 92.71% | 92.71% | 87.71% | 5.00 |
| tooling | 64.75% | 64.75% | 59.75% | 5.00 |
| dev/test-support | 85.96% | 85.96% | 80.96% | 5.00 |
The full local `make ci-domains` validation passed with 939 tests passed and
9 ignored. `system/runtime` measured 81.26% in the initial run and 81.19%
in verification; its final floor uses the lower measurement. All gates were
rechecked against the verification report after that final adjustment.
Platform-specific compilation and host scenarios can change report totals.
Local evidence does not certify an unexecuted Linux or Intel Mac run; evaluate
those runs using the unchanged repository policy and investigate differences.
those runs against the configured floors and investigate differences.
+235
View File
@@ -0,0 +1,235 @@
{
"date": "2026-10-09",
"host": "aarch64-apple-darwin",
"scope": "Local workspace qualification; remote pipeline failure was not reproduced locally.",
"required_margin_percentage_points": 5.0,
"rule": "floor = min(original_floor, min(initial_measured_percent, verification_measured_percent) - 5.00); all percentages truncated downward to two decimals",
"automatic_floor_updates": false,
"rustc": [
"rustc 1.98.1 (48a229cea 2026-09-01)",
"binary: rustc",
"commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985",
"commit-date: 2026-09-01",
"host: aarch64-apple-darwin",
"release: 1.98.1",
"LLVM version: 22.1.8"
],
"cargo_llvm_cov": "cargo-llvm-cov 0.8.5",
"git_head": "9318cf7cd34c98095abd6c83be2db2b507735550",
"workspace_state": "Includes the previously delivered, uncommitted random core changes.",
"source_fingerprint": {
"scope": "All Rust files under crates, including tests/examples/benches",
"files": 273,
"algorithm": "SHA-256 of sorted records: relative path + NUL + file SHA-256 hex + newline",
"sha256": "5cf23ec6bf8b0aa0866d63ccc1bf8cba2b3f0d7ed85951a085eba465d118e1a1"
},
"original_config_sha256": "209b90dc32148f2ef52a3bab72e8e9df8e3daae78d97f967b891340a0bcad184",
"config_sha256": "fbcb8d2fa7366dcba5175b42719a1adf0aaddd7e6d630c708228443150a4f78d",
"historical_evidence_sha256": "b56b328f7c01f7325aea88881ccc6e4d343405bfaee1aba02518092fc39ec088",
"llvm_report_sha256": "ad1e20ff5bd40bbf82d334967dfedc49467e69065ad02c9255600286ee7c7043",
"validation": [
{
"command": "CARGO_NET_OFFLINE=true make ci-domains",
"stage": "Before floor adjustment",
"exit_code": 0,
"tests": {
"passed": 939,
"failed": 0,
"ignored": 9
},
"log_sha256": "e65e3c44bca8abd808255e3fa65d61c791b088fed6572645e774c2dd52775b5e"
},
{
"command": "CARGO_NET_OFFLINE=true make ci-domains",
"stage": "After initial floor adjustment",
"exit_code": 0,
"tests": {
"passed": 939,
"failed": 0,
"ignored": 9
},
"config_sha256": "2eb7bb9e5f0f97eb7db4ea511dad3e51237e68ad60a08aad8e24b37c01442121",
"log_sha256": "60a2726a31c1aa0423ded7720d9e9034589b9c25617ca30ffc174833b130e188"
},
{
"command": "make coverage-domain-gate",
"stage": "Final configuration against the unchanged verification report",
"exit_code": 0,
"log_sha256": "0e52dc48cf88ec1a0aba2a39db25627098137744718aa1f7f542b66a5e335ba3"
},
{
"command": "python3 scripts/audit-coverage-domains.py --report target/llvm-cov/report.json --json",
"stage": "Final ownership/evidence audit",
"exit_code": 0,
"source_files": 236
}
],
"verification_adjustment": "system/runtime measured 81.26% initially and 81.19% on verification. Its floor was reduced from 76.26% to 76.19% after the full target passed, then all gates were rechecked against the same report. Other floors were unchanged after the full run.",
"domains": {
"system/os": {
"lines_covered": 1200,
"lines_count": 1459,
"initial_measured_percent": 82.24,
"measured_percent": 82.24,
"original_floor_percent": 77.24,
"floor_percent": 77.24,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"system/runtime": {
"lines_covered": 2466,
"lines_count": 3037,
"initial_measured_percent": 81.26,
"measured_percent": 81.19,
"original_floor_percent": 76.5,
"floor_percent": 76.19,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"system/fs": {
"lines_covered": 403,
"lines_count": 497,
"initial_measured_percent": 81.08,
"measured_percent": 81.08,
"original_floor_percent": 76.08,
"floor_percent": 76.08,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"system/programs": {
"lines_covered": 555,
"lines_count": 566,
"initial_measured_percent": 98.05,
"measured_percent": 98.05,
"original_floor_percent": 93.05,
"floor_percent": 93.05,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"asset/bank": {
"lines_covered": 2640,
"lines_count": 2877,
"initial_measured_percent": 91.76,
"measured_percent": 91.76,
"original_floor_percent": 86.76,
"floor_percent": 86.76,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"firmware": {
"lines_covered": 1384,
"lines_count": 1568,
"initial_measured_percent": 88.26,
"measured_percent": 88.26,
"original_floor_percent": 83.2,
"floor_percent": 83.2,
"margin_percentage_points": 5.06,
"adjusted": false,
"gate_passed": true
},
"host-dependent": {
"lines_covered": 779,
"lines_count": 1729,
"initial_measured_percent": 45.05,
"measured_percent": 45.05,
"original_floor_percent": 40.05,
"floor_percent": 40.05,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"host/headless": {
"lines_covered": 693,
"lines_count": 784,
"initial_measured_percent": 88.39,
"measured_percent": 88.39,
"original_floor_percent": 83.39,
"floor_percent": 83.39,
"margin_percentage_points": 5.0,
"adjusted": false,
"gate_passed": true
},
"vm/core": {
"lines_covered": 7957,
"lines_count": 8911,
"initial_measured_percent": 89.29,
"measured_percent": 89.29,
"original_floor_percent": 89.12,
"floor_percent": 84.29,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"bytecode": {
"lines_covered": 3034,
"lines_count": 3253,
"initial_measured_percent": 93.26,
"measured_percent": 93.26,
"original_floor_percent": 93.23,
"floor_percent": 88.26,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"hal/core": {
"lines_covered": 2060,
"lines_count": 2326,
"initial_measured_percent": 88.56,
"measured_percent": 88.56,
"original_floor_percent": 88.56,
"floor_percent": 83.56,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"drivers/core": {
"lines_covered": 2314,
"lines_count": 2738,
"initial_measured_percent": 84.51,
"measured_percent": 84.51,
"original_floor_percent": 84.51,
"floor_percent": 79.51,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"system/core": {
"lines_covered": 1196,
"lines_count": 1290,
"initial_measured_percent": 92.71,
"measured_percent": 92.71,
"original_floor_percent": 92.71,
"floor_percent": 87.71,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"tooling": {
"lines_covered": 395,
"lines_count": 610,
"initial_measured_percent": 64.75,
"measured_percent": 64.75,
"original_floor_percent": 64.75,
"floor_percent": 59.75,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
},
"dev/test-support": {
"lines_covered": 98,
"lines_count": 114,
"initial_measured_percent": 85.96,
"measured_percent": 85.96,
"original_floor_percent": 85.96,
"floor_percent": 80.96,
"margin_percentage_points": 5.0,
"adjusted": true,
"gate_passed": true
}
}
}
+106 -102
View File
@@ -1,102 +1,106 @@
final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles
0x1000,4096,vec2.dot,1,vec2,dot,4,1,Float|Float|Float|Float,Float,true,false,ax|ay|bx|by,10
0x1001,4097,vec2.length,1,vec2,length,2,1,Float|Float,Float,true,false,x|y,40
0x1100,4352,color.from_raw,1,color,from_raw,1,1,Int64,builtin:color,true,false,raw,1
0x1101,4353,color.rgb,1,color,rgb,3,1,Int64|Int64|Int64,builtin:color,true,false,r|g|b,1
0x1102,4354,color.rgba,1,color,rgba,4,1,Int64|Int64|Int64|Int64,builtin:color,true,false,r|g|b|a,1
0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,String,builtin:color,true,false,value,1
0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,Int64,builtin:color,true,false,value,1
0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,Int64,true,false,color,1
0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,Int64,true,false,color,1
0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false,,1
0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false,,1
0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false,,1
0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false,,1
0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false,,1
0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false,,1
0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false,,1
0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false,,1
0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false,,1
0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false,,1
0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false,,1
0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false,,1
0x2100,8448,input.pad.up.pressed,1,input.pad.up,pressed,0,1,,Bool,true,false,,1
0x2101,8449,input.pad.up.released,1,input.pad.up,released,0,1,,Bool,true,false,,1
0x2102,8450,input.pad.up.down,1,input.pad.up,down,0,1,,Bool,true,false,,1
0x2103,8451,input.pad.up.hold,1,input.pad.up,hold,0,1,,Int64,true,false,,1
0x2104,8452,input.pad.down.pressed,1,input.pad.down,pressed,0,1,,Bool,true,false,,1
0x2105,8453,input.pad.down.released,1,input.pad.down,released,0,1,,Bool,true,false,,1
0x2106,8454,input.pad.down.down,1,input.pad.down,down,0,1,,Bool,true,false,,1
0x2107,8455,input.pad.down.hold,1,input.pad.down,hold,0,1,,Int64,true,false,,1
0x2108,8456,input.pad.left.pressed,1,input.pad.left,pressed,0,1,,Bool,true,false,,1
0x2109,8457,input.pad.left.released,1,input.pad.left,released,0,1,,Bool,true,false,,1
0x210A,8458,input.pad.left.down,1,input.pad.left,down,0,1,,Bool,true,false,,1
0x210B,8459,input.pad.left.hold,1,input.pad.left,hold,0,1,,Int64,true,false,,1
0x210C,8460,input.pad.right.pressed,1,input.pad.right,pressed,0,1,,Bool,true,false,,1
0x210D,8461,input.pad.right.released,1,input.pad.right,released,0,1,,Bool,true,false,,1
0x210E,8462,input.pad.right.down,1,input.pad.right,down,0,1,,Bool,true,false,,1
0x210F,8463,input.pad.right.hold,1,input.pad.right,hold,0,1,,Int64,true,false,,1
0x2110,8464,input.pad.a.pressed,1,input.pad.a,pressed,0,1,,Bool,true,false,,1
0x2111,8465,input.pad.a.released,1,input.pad.a,released,0,1,,Bool,true,false,,1
0x2112,8466,input.pad.a.down,1,input.pad.a,down,0,1,,Bool,true,false,,1
0x2113,8467,input.pad.a.hold,1,input.pad.a,hold,0,1,,Int64,true,false,,1
0x2114,8468,input.pad.b.pressed,1,input.pad.b,pressed,0,1,,Bool,true,false,,1
0x2115,8469,input.pad.b.released,1,input.pad.b,released,0,1,,Bool,true,false,,1
0x2116,8470,input.pad.b.down,1,input.pad.b,down,0,1,,Bool,true,false,,1
0x2117,8471,input.pad.b.hold,1,input.pad.b,hold,0,1,,Int64,true,false,,1
0x2118,8472,input.pad.x.pressed,1,input.pad.x,pressed,0,1,,Bool,true,false,,1
0x2119,8473,input.pad.x.released,1,input.pad.x,released,0,1,,Bool,true,false,,1
0x211A,8474,input.pad.x.down,1,input.pad.x,down,0,1,,Bool,true,false,,1
0x211B,8475,input.pad.x.hold,1,input.pad.x,hold,0,1,,Int64,true,false,,1
0x211C,8476,input.pad.y.pressed,1,input.pad.y,pressed,0,1,,Bool,true,false,,1
0x211D,8477,input.pad.y.released,1,input.pad.y,released,0,1,,Bool,true,false,,1
0x211E,8478,input.pad.y.down,1,input.pad.y,down,0,1,,Bool,true,false,,1
0x211F,8479,input.pad.y.hold,1,input.pad.y,hold,0,1,,Int64,true,false,,1
0x2120,8480,input.pad.l.pressed,1,input.pad.l,pressed,0,1,,Bool,true,false,,1
0x2121,8481,input.pad.l.released,1,input.pad.l,released,0,1,,Bool,true,false,,1
0x2122,8482,input.pad.l.down,1,input.pad.l,down,0,1,,Bool,true,false,,1
0x2123,8483,input.pad.l.hold,1,input.pad.l,hold,0,1,,Int64,true,false,,1
0x2124,8484,input.pad.r.pressed,1,input.pad.r,pressed,0,1,,Bool,true,false,,1
0x2125,8485,input.pad.r.released,1,input.pad.r,released,0,1,,Bool,true,false,,1
0x2126,8486,input.pad.r.down,1,input.pad.r,down,0,1,,Bool,true,false,,1
0x2127,8487,input.pad.r.hold,1,input.pad.r,hold,0,1,,Int64,true,false,,1
0x2128,8488,input.pad.start.pressed,1,input.pad.start,pressed,0,1,,Bool,true,false,,1
0x2129,8489,input.pad.start.released,1,input.pad.start,released,0,1,,Bool,true,false,,1
0x212A,8490,input.pad.start.down,1,input.pad.start,down,0,1,,Bool,true,false,,1
0x212B,8491,input.pad.start.hold,1,input.pad.start,hold,0,1,,Int64,true,false,,1
0x212C,8492,input.pad.select.pressed,1,input.pad.select,pressed,0,1,,Bool,true,false,,1
0x212D,8493,input.pad.select.released,1,input.pad.select,released,0,1,,Bool,true,false,,1
0x212E,8494,input.pad.select.down,1,input.pad.select,down,0,1,,Bool,true,false,,1
0x212F,8495,input.pad.select.hold,1,input.pad.select,hold,0,1,,Int64,true,false,,1
0x2130,8496,input.touch.button.pressed,1,input.touch.button,pressed,0,1,,Bool,true,false,,1
0x2131,8497,input.touch.button.released,1,input.touch.button,released,0,1,,Bool,true,false,,1
0x2132,8498,input.touch.button.down,1,input.touch.button,down,0,1,,Bool,true,false,,1
0x2133,8499,input.touch.button.hold,1,input.touch.button,hold,0,1,,Int64,true,false,,1
0x2134,8500,input.touch.x,1,input.touch,x,0,1,,Int64,true,false,,1
0x2135,8501,input.touch.y,1,input.touch,y,0,1,,Int64,true,false,,1
0x3000,12288,math.i32.min,1,math.i32,min,2,1,Int32|Int32,Int32,true,false,a|b,2
0x3001,12289,math.i32.max,1,math.i32,max,2,1,Int32|Int32,Int32,true,false,a|b,2
0x3002,12290,math.i32.clamp,1,math.i32,clamp,3,1,Int32|Int32|Int32,Int32,true,false,value|min|max,4
0x3003,12291,math.i32.abs,1,math.i32,abs,1,1,Int32,Int32,true,false,value,2
0x3004,12292,math.i64.min,1,math.i64,min,2,1,Int64|Int64,Int64,true,false,a|b,2
0x3005,12293,math.i64.max,1,math.i64,max,2,1,Int64|Int64,Int64,true,false,a|b,2
0x3006,12294,math.i64.clamp,1,math.i64,clamp,3,1,Int64|Int64|Int64,Int64,true,false,value|min|max,4
0x3007,12295,math.i64.abs,1,math.i64,abs,1,1,Int64,Int64,true,false,value,2
0x3008,12296,mathf.min,1,mathf,min,2,1,Float|Float,Float,true,false,a|b,2
0x3009,12297,mathf.max,1,mathf,max,2,1,Float|Float,Float,true,false,a|b,2
0x300A,12298,mathf.clamp,1,mathf,clamp,3,1,Float|Float|Float,Float,true,false,value|min|max,4
0x300B,12299,mathf.abs,1,mathf,abs,1,1,Float,Float,true,false,value,2
0x300C,12300,mathf.floor,1,mathf,floor,1,1,Float,Float,true,false,value,4
0x300D,12301,mathf.ceil,1,mathf,ceil,1,1,Float,Float,true,false,value,4
0x300E,12302,mathf.trunc,1,mathf,trunc,1,1,Float,Float,true,false,value,4
0x300F,12303,mathf.round,1,mathf,round,1,1,Float,Float,true,false,value,4
0x3010,12304,mathf.sqrt,1,mathf,sqrt,1,1,Float,Float,true,false,value,16
0x3011,12305,mathf.sin,1,mathf,sin,1,1,Float,Float,true,false,angle,32
0x3012,12306,mathf.cos,1,mathf,cos,1,1,Float,Float,true,false,angle,32
0x3013,12307,mathf.atan2,1,mathf,atan2,2,1,Float|Float,Float,true,false,y|x,48
0x3014,12308,math.i32.to_i64,1,math.i32,to_i64,1,1,Int32,Int64,true,false,value,2
0x3015,12309,math.i64.to_i32,1,math.i64,to_i32,1,1,Int64,Int32,true,false,value,2
0x3016,12310,math.i32.to_float,1,math.i32,to_float,1,1,Int32,Float,true,false,value,2
0x3017,12311,math.i64.to_float,1,math.i64,to_float,1,1,Int64,Float,true,false,value,2
0x3018,12312,mathf.to_i32,1,mathf,to_i32,1,1,Float,Int32,true,false,value,2
0x3019,12313,mathf.to_i64,1,mathf,to_i64,1,1,Float,Int64,true,false,value,2
final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts
0x1000,4096,vec2.dot,1,vec2,dot,4,1,Float|Float|Float|Float,Float,true,false,ax|ay|bx|by,10,false,fixed,0,0
0x1001,4097,vec2.length,1,vec2,length,2,1,Float|Float,Float,true,false,x|y,40,false,fixed,0,0
0x1100,4352,color.from_raw,1,color,from_raw,1,1,Int64,builtin:color,true,false,raw,1,false,fixed,0,0
0x1101,4353,color.rgb,1,color,rgb,3,1,Int64|Int64|Int64,builtin:color,true,false,r|g|b,1,false,fixed,0,0
0x1102,4354,color.rgba,1,color,rgba,4,1,Int64|Int64|Int64|Int64,builtin:color,true,false,r|g|b|a,1,false,fixed,0,0
0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,String,builtin:color,true,false,value,1,false,fixed,0,0
0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,Int64,builtin:color,true,false,value,1,false,fixed,0,0
0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0
0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0
0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false,,1,false,fixed,0,0
0x2100,8448,input.pad.up.pressed,1,input.pad.up,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2101,8449,input.pad.up.released,1,input.pad.up,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2102,8450,input.pad.up.down,1,input.pad.up,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2103,8451,input.pad.up.hold,1,input.pad.up,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2104,8452,input.pad.down.pressed,1,input.pad.down,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2105,8453,input.pad.down.released,1,input.pad.down,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2106,8454,input.pad.down.down,1,input.pad.down,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2107,8455,input.pad.down.hold,1,input.pad.down,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2108,8456,input.pad.left.pressed,1,input.pad.left,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2109,8457,input.pad.left.released,1,input.pad.left,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x210A,8458,input.pad.left.down,1,input.pad.left,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x210B,8459,input.pad.left.hold,1,input.pad.left,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x210C,8460,input.pad.right.pressed,1,input.pad.right,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x210D,8461,input.pad.right.released,1,input.pad.right,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x210E,8462,input.pad.right.down,1,input.pad.right,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x210F,8463,input.pad.right.hold,1,input.pad.right,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2110,8464,input.pad.a.pressed,1,input.pad.a,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2111,8465,input.pad.a.released,1,input.pad.a,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2112,8466,input.pad.a.down,1,input.pad.a,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2113,8467,input.pad.a.hold,1,input.pad.a,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2114,8468,input.pad.b.pressed,1,input.pad.b,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2115,8469,input.pad.b.released,1,input.pad.b,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2116,8470,input.pad.b.down,1,input.pad.b,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2117,8471,input.pad.b.hold,1,input.pad.b,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2118,8472,input.pad.x.pressed,1,input.pad.x,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2119,8473,input.pad.x.released,1,input.pad.x,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x211A,8474,input.pad.x.down,1,input.pad.x,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x211B,8475,input.pad.x.hold,1,input.pad.x,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x211C,8476,input.pad.y.pressed,1,input.pad.y,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x211D,8477,input.pad.y.released,1,input.pad.y,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x211E,8478,input.pad.y.down,1,input.pad.y,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x211F,8479,input.pad.y.hold,1,input.pad.y,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2120,8480,input.pad.l.pressed,1,input.pad.l,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2121,8481,input.pad.l.released,1,input.pad.l,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2122,8482,input.pad.l.down,1,input.pad.l,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2123,8483,input.pad.l.hold,1,input.pad.l,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2124,8484,input.pad.r.pressed,1,input.pad.r,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2125,8485,input.pad.r.released,1,input.pad.r,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2126,8486,input.pad.r.down,1,input.pad.r,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2127,8487,input.pad.r.hold,1,input.pad.r,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2128,8488,input.pad.start.pressed,1,input.pad.start,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2129,8489,input.pad.start.released,1,input.pad.start,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x212A,8490,input.pad.start.down,1,input.pad.start,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x212B,8491,input.pad.start.hold,1,input.pad.start,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x212C,8492,input.pad.select.pressed,1,input.pad.select,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x212D,8493,input.pad.select.released,1,input.pad.select,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x212E,8494,input.pad.select.down,1,input.pad.select,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x212F,8495,input.pad.select.hold,1,input.pad.select,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2130,8496,input.touch.button.pressed,1,input.touch.button,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2131,8497,input.touch.button.released,1,input.touch.button,released,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2132,8498,input.touch.button.down,1,input.touch.button,down,0,1,,Bool,true,false,,1,false,fixed,0,0
0x2133,8499,input.touch.button.hold,1,input.touch.button,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2134,8500,input.touch.x,1,input.touch,x,0,1,,Int64,true,false,,1,false,fixed,0,0
0x2135,8501,input.touch.y,1,input.touch,y,0,1,,Int64,true,false,,1,false,fixed,0,0
0x3000,12288,math.i32.min,1,math.i32,min,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0
0x3001,12289,math.i32.max,1,math.i32,max,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0
0x3002,12290,math.i32.clamp,1,math.i32,clamp,3,1,Int32|Int32|Int32,Int32,true,false,value|min|max,4,false,fixed,0,0
0x3003,12291,math.i32.abs,1,math.i32,abs,1,1,Int32,Int32,true,false,value,2,false,fixed,0,0
0x3004,12292,math.i64.min,1,math.i64,min,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0
0x3005,12293,math.i64.max,1,math.i64,max,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0
0x3006,12294,math.i64.clamp,1,math.i64,clamp,3,1,Int64|Int64|Int64,Int64,true,false,value|min|max,4,false,fixed,0,0
0x3007,12295,math.i64.abs,1,math.i64,abs,1,1,Int64,Int64,true,false,value,2,false,fixed,0,0
0x3008,12296,mathf.min,1,mathf,min,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0
0x3009,12297,mathf.max,1,mathf,max,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0
0x300A,12298,mathf.clamp,1,mathf,clamp,3,1,Float|Float|Float,Float,true,false,value|min|max,4,false,fixed,0,0
0x300B,12299,mathf.abs,1,mathf,abs,1,1,Float,Float,true,false,value,2,false,fixed,0,0
0x300C,12300,mathf.floor,1,mathf,floor,1,1,Float,Float,true,false,value,4,false,fixed,0,0
0x300D,12301,mathf.ceil,1,mathf,ceil,1,1,Float,Float,true,false,value,4,false,fixed,0,0
0x300E,12302,mathf.trunc,1,mathf,trunc,1,1,Float,Float,true,false,value,4,false,fixed,0,0
0x300F,12303,mathf.round,1,mathf,round,1,1,Float,Float,true,false,value,4,false,fixed,0,0
0x3010,12304,mathf.sqrt,1,mathf,sqrt,1,1,Float,Float,true,false,value,16,false,fixed,0,0
0x3011,12305,mathf.sin,1,mathf,sin,1,1,Float,Float,true,false,angle,32,false,fixed,0,0
0x3012,12306,mathf.cos,1,mathf,cos,1,1,Float,Float,true,false,angle,32,false,fixed,0,0
0x3013,12307,mathf.atan2,1,mathf,atan2,2,1,Float|Float,Float,true,false,y|x,48,false,fixed,0,0
0x3014,12308,math.i32.to_i64,1,math.i32,to_i64,1,1,Int32,Int64,true,false,value,2,false,fixed,0,0
0x3015,12309,math.i64.to_i32,1,math.i64,to_i32,1,1,Int64,Int32,true,false,value,2,false,fixed,0,0
0x3016,12310,math.i32.to_float,1,math.i32,to_float,1,1,Int32,Float,true,false,value,2,false,fixed,0,0
0x3017,12311,math.i64.to_float,1,math.i64,to_float,1,1,Int64,Float,true,false,value,2,false,fixed,0,0
0x3018,12312,mathf.to_i32,1,mathf,to_i32,1,1,Float,Int32,true,false,value,2,false,fixed,0,0
0x3019,12313,mathf.to_i64,1,mathf,to_i64,1,1,Float,Int64,true,false,value,2,false,fixed,0,0
0x4000,16384,random.new,1,random,new,1,1,Int64,builtin:Random,true,true,seed,32,true,fixed,0,0
0x4001,16385,random.next,1,random,next,1,1,builtin:Random,Int64,true,false,rng,8,true,fixed,0,0
0x4002,16386,random.nextf,1,random,nextf,1,1,builtin:Random,Float,true,false,rng,12,true,fixed,0,0
0x4003,16387,random.range,1,random,range,3,1,builtin:Random|Int64|Int64,Int64,true,false,rng|min|max,4,true,random_rejection_v1,8,64
1 final_id_hex final_id_dec canonical_name canonical_version owner name arg_slots ret_slots arg_layout ret_layout deterministic may_allocate parameter_names cost_cycles mutates_guest_state cost_model attempt_cost_cycles max_attempts
2 0x1000 4096 vec2.dot 1 vec2 dot 4 1 Float|Float|Float|Float Float true false ax|ay|bx|by 10 false fixed 0 0
3 0x1001 4097 vec2.length 1 vec2 length 2 1 Float|Float Float true false x|y 40 false fixed 0 0
4 0x1100 4352 color.from_raw 1 color from_raw 1 1 Int64 builtin:color true false raw 1 false fixed 0 0
5 0x1101 4353 color.rgb 1 color rgb 3 1 Int64|Int64|Int64 builtin:color true false r|g|b 1 false fixed 0 0
6 0x1102 4354 color.rgba 1 color rgba 4 1 Int64|Int64|Int64|Int64 builtin:color true false r|g|b|a 1 false fixed 0 0
7 0x1103 4355 color.html_rgba 1 color html_rgba 1 1 String builtin:color true false value 1 false fixed 0 0
8 0x1104 4356 color.gray_scale 1 color gray_scale 1 1 Int64 builtin:color true false value 1 false fixed 0 0
9 0x1105 4357 color.hex 1 color hex 1 1 builtin:color Int64 true false color 1 false fixed 0 0
10 0x1106 4358 color.alpha 1 color alpha 1 1 builtin:color Int64 true false color 1 false fixed 0 0
11 0x1120 4384 color.black 1 color black 0 1 builtin:color true false 1 false fixed 0 0
12 0x1121 4385 color.white 1 color white 0 1 builtin:color true false 1 false fixed 0 0
13 0x1122 4386 color.red 1 color red 0 1 builtin:color true false 1 false fixed 0 0
14 0x1123 4387 color.green 1 color green 0 1 builtin:color true false 1 false fixed 0 0
15 0x1124 4388 color.blue 1 color blue 0 1 builtin:color true false 1 false fixed 0 0
16 0x1125 4389 color.yellow 1 color yellow 0 1 builtin:color true false 1 false fixed 0 0
17 0x1126 4390 color.orange 1 color orange 0 1 builtin:color true false 1 false fixed 0 0
18 0x1127 4391 color.indigo 1 color indigo 0 1 builtin:color true false 1 false fixed 0 0
19 0x1128 4392 color.gray 1 color gray 0 1 builtin:color true false 1 false fixed 0 0
20 0x1129 4393 color.cyan 1 color cyan 0 1 builtin:color true false 1 false fixed 0 0
21 0x112A 4394 color.magenta 1 color magenta 0 1 builtin:color true false 1 false fixed 0 0
22 0x112B 4395 color.transparent 1 color transparent 0 1 builtin:color true false 1 false fixed 0 0
23 0x2100 8448 input.pad.up.pressed 1 input.pad.up pressed 0 1 Bool true false 1 false fixed 0 0
24 0x2101 8449 input.pad.up.released 1 input.pad.up released 0 1 Bool true false 1 false fixed 0 0
25 0x2102 8450 input.pad.up.down 1 input.pad.up down 0 1 Bool true false 1 false fixed 0 0
26 0x2103 8451 input.pad.up.hold 1 input.pad.up hold 0 1 Int64 true false 1 false fixed 0 0
27 0x2104 8452 input.pad.down.pressed 1 input.pad.down pressed 0 1 Bool true false 1 false fixed 0 0
28 0x2105 8453 input.pad.down.released 1 input.pad.down released 0 1 Bool true false 1 false fixed 0 0
29 0x2106 8454 input.pad.down.down 1 input.pad.down down 0 1 Bool true false 1 false fixed 0 0
30 0x2107 8455 input.pad.down.hold 1 input.pad.down hold 0 1 Int64 true false 1 false fixed 0 0
31 0x2108 8456 input.pad.left.pressed 1 input.pad.left pressed 0 1 Bool true false 1 false fixed 0 0
32 0x2109 8457 input.pad.left.released 1 input.pad.left released 0 1 Bool true false 1 false fixed 0 0
33 0x210A 8458 input.pad.left.down 1 input.pad.left down 0 1 Bool true false 1 false fixed 0 0
34 0x210B 8459 input.pad.left.hold 1 input.pad.left hold 0 1 Int64 true false 1 false fixed 0 0
35 0x210C 8460 input.pad.right.pressed 1 input.pad.right pressed 0 1 Bool true false 1 false fixed 0 0
36 0x210D 8461 input.pad.right.released 1 input.pad.right released 0 1 Bool true false 1 false fixed 0 0
37 0x210E 8462 input.pad.right.down 1 input.pad.right down 0 1 Bool true false 1 false fixed 0 0
38 0x210F 8463 input.pad.right.hold 1 input.pad.right hold 0 1 Int64 true false 1 false fixed 0 0
39 0x2110 8464 input.pad.a.pressed 1 input.pad.a pressed 0 1 Bool true false 1 false fixed 0 0
40 0x2111 8465 input.pad.a.released 1 input.pad.a released 0 1 Bool true false 1 false fixed 0 0
41 0x2112 8466 input.pad.a.down 1 input.pad.a down 0 1 Bool true false 1 false fixed 0 0
42 0x2113 8467 input.pad.a.hold 1 input.pad.a hold 0 1 Int64 true false 1 false fixed 0 0
43 0x2114 8468 input.pad.b.pressed 1 input.pad.b pressed 0 1 Bool true false 1 false fixed 0 0
44 0x2115 8469 input.pad.b.released 1 input.pad.b released 0 1 Bool true false 1 false fixed 0 0
45 0x2116 8470 input.pad.b.down 1 input.pad.b down 0 1 Bool true false 1 false fixed 0 0
46 0x2117 8471 input.pad.b.hold 1 input.pad.b hold 0 1 Int64 true false 1 false fixed 0 0
47 0x2118 8472 input.pad.x.pressed 1 input.pad.x pressed 0 1 Bool true false 1 false fixed 0 0
48 0x2119 8473 input.pad.x.released 1 input.pad.x released 0 1 Bool true false 1 false fixed 0 0
49 0x211A 8474 input.pad.x.down 1 input.pad.x down 0 1 Bool true false 1 false fixed 0 0
50 0x211B 8475 input.pad.x.hold 1 input.pad.x hold 0 1 Int64 true false 1 false fixed 0 0
51 0x211C 8476 input.pad.y.pressed 1 input.pad.y pressed 0 1 Bool true false 1 false fixed 0 0
52 0x211D 8477 input.pad.y.released 1 input.pad.y released 0 1 Bool true false 1 false fixed 0 0
53 0x211E 8478 input.pad.y.down 1 input.pad.y down 0 1 Bool true false 1 false fixed 0 0
54 0x211F 8479 input.pad.y.hold 1 input.pad.y hold 0 1 Int64 true false 1 false fixed 0 0
55 0x2120 8480 input.pad.l.pressed 1 input.pad.l pressed 0 1 Bool true false 1 false fixed 0 0
56 0x2121 8481 input.pad.l.released 1 input.pad.l released 0 1 Bool true false 1 false fixed 0 0
57 0x2122 8482 input.pad.l.down 1 input.pad.l down 0 1 Bool true false 1 false fixed 0 0
58 0x2123 8483 input.pad.l.hold 1 input.pad.l hold 0 1 Int64 true false 1 false fixed 0 0
59 0x2124 8484 input.pad.r.pressed 1 input.pad.r pressed 0 1 Bool true false 1 false fixed 0 0
60 0x2125 8485 input.pad.r.released 1 input.pad.r released 0 1 Bool true false 1 false fixed 0 0
61 0x2126 8486 input.pad.r.down 1 input.pad.r down 0 1 Bool true false 1 false fixed 0 0
62 0x2127 8487 input.pad.r.hold 1 input.pad.r hold 0 1 Int64 true false 1 false fixed 0 0
63 0x2128 8488 input.pad.start.pressed 1 input.pad.start pressed 0 1 Bool true false 1 false fixed 0 0
64 0x2129 8489 input.pad.start.released 1 input.pad.start released 0 1 Bool true false 1 false fixed 0 0
65 0x212A 8490 input.pad.start.down 1 input.pad.start down 0 1 Bool true false 1 false fixed 0 0
66 0x212B 8491 input.pad.start.hold 1 input.pad.start hold 0 1 Int64 true false 1 false fixed 0 0
67 0x212C 8492 input.pad.select.pressed 1 input.pad.select pressed 0 1 Bool true false 1 false fixed 0 0
68 0x212D 8493 input.pad.select.released 1 input.pad.select released 0 1 Bool true false 1 false fixed 0 0
69 0x212E 8494 input.pad.select.down 1 input.pad.select down 0 1 Bool true false 1 false fixed 0 0
70 0x212F 8495 input.pad.select.hold 1 input.pad.select hold 0 1 Int64 true false 1 false fixed 0 0
71 0x2130 8496 input.touch.button.pressed 1 input.touch.button pressed 0 1 Bool true false 1 false fixed 0 0
72 0x2131 8497 input.touch.button.released 1 input.touch.button released 0 1 Bool true false 1 false fixed 0 0
73 0x2132 8498 input.touch.button.down 1 input.touch.button down 0 1 Bool true false 1 false fixed 0 0
74 0x2133 8499 input.touch.button.hold 1 input.touch.button hold 0 1 Int64 true false 1 false fixed 0 0
75 0x2134 8500 input.touch.x 1 input.touch x 0 1 Int64 true false 1 false fixed 0 0
76 0x2135 8501 input.touch.y 1 input.touch y 0 1 Int64 true false 1 false fixed 0 0
77 0x3000 12288 math.i32.min 1 math.i32 min 2 1 Int32|Int32 Int32 true false a|b 2 false fixed 0 0
78 0x3001 12289 math.i32.max 1 math.i32 max 2 1 Int32|Int32 Int32 true false a|b 2 false fixed 0 0
79 0x3002 12290 math.i32.clamp 1 math.i32 clamp 3 1 Int32|Int32|Int32 Int32 true false value|min|max 4 false fixed 0 0
80 0x3003 12291 math.i32.abs 1 math.i32 abs 1 1 Int32 Int32 true false value 2 false fixed 0 0
81 0x3004 12292 math.i64.min 1 math.i64 min 2 1 Int64|Int64 Int64 true false a|b 2 false fixed 0 0
82 0x3005 12293 math.i64.max 1 math.i64 max 2 1 Int64|Int64 Int64 true false a|b 2 false fixed 0 0
83 0x3006 12294 math.i64.clamp 1 math.i64 clamp 3 1 Int64|Int64|Int64 Int64 true false value|min|max 4 false fixed 0 0
84 0x3007 12295 math.i64.abs 1 math.i64 abs 1 1 Int64 Int64 true false value 2 false fixed 0 0
85 0x3008 12296 mathf.min 1 mathf min 2 1 Float|Float Float true false a|b 2 false fixed 0 0
86 0x3009 12297 mathf.max 1 mathf max 2 1 Float|Float Float true false a|b 2 false fixed 0 0
87 0x300A 12298 mathf.clamp 1 mathf clamp 3 1 Float|Float|Float Float true false value|min|max 4 false fixed 0 0
88 0x300B 12299 mathf.abs 1 mathf abs 1 1 Float Float true false value 2 false fixed 0 0
89 0x300C 12300 mathf.floor 1 mathf floor 1 1 Float Float true false value 4 false fixed 0 0
90 0x300D 12301 mathf.ceil 1 mathf ceil 1 1 Float Float true false value 4 false fixed 0 0
91 0x300E 12302 mathf.trunc 1 mathf trunc 1 1 Float Float true false value 4 false fixed 0 0
92 0x300F 12303 mathf.round 1 mathf round 1 1 Float Float true false value 4 false fixed 0 0
93 0x3010 12304 mathf.sqrt 1 mathf sqrt 1 1 Float Float true false value 16 false fixed 0 0
94 0x3011 12305 mathf.sin 1 mathf sin 1 1 Float Float true false angle 32 false fixed 0 0
95 0x3012 12306 mathf.cos 1 mathf cos 1 1 Float Float true false angle 32 false fixed 0 0
96 0x3013 12307 mathf.atan2 1 mathf atan2 2 1 Float|Float Float true false y|x 48 false fixed 0 0
97 0x3014 12308 math.i32.to_i64 1 math.i32 to_i64 1 1 Int32 Int64 true false value 2 false fixed 0 0
98 0x3015 12309 math.i64.to_i32 1 math.i64 to_i32 1 1 Int64 Int32 true false value 2 false fixed 0 0
99 0x3016 12310 math.i32.to_float 1 math.i32 to_float 1 1 Int32 Float true false value 2 false fixed 0 0
100 0x3017 12311 math.i64.to_float 1 math.i64 to_float 1 1 Int64 Float true false value 2 false fixed 0 0
101 0x3018 12312 mathf.to_i32 1 mathf to_i32 1 1 Float Int32 true false value 2 false fixed 0 0
102 0x3019 12313 mathf.to_i64 1 mathf to_i64 1 1 Float Int64 true false value 2 false fixed 0 0
103 0x4000 16384 random.new 1 random new 1 1 Int64 builtin:Random true true seed 32 true fixed 0 0
104 0x4001 16385 random.next 1 random next 1 1 builtin:Random Int64 true false rng 8 true fixed 0 0
105 0x4002 16386 random.nextf 1 random nextf 1 1 builtin:Random Float true false rng 12 true fixed 0 0
106 0x4003 16387 random.range 1 random range 3 1 builtin:Random|Int64|Int64 Int64 true false rng|min|max 4 true random_rejection_v1 8 64
+12 -2
View File
@@ -107,8 +107,14 @@ Example:
- Rows must remain unique by both `(canonical_name, canonical_version)` and `final_id_hex` / `final_id_dec`.
- Rows must remain deterministically ordered by final ID.
- parameter_names uses ordered | separated names for flattened argument slots.
- cost_cycles is the total call cost; mathematical attempts charge upfront
including failure, with no additional generic INTRINSIC cycle.
- cost_model is fixed or random_rejection_v1. cost_cycles is the full fixed
cost or the variable base. attempt_cost_cycles/max_attempts are zero for
fixed entries; random.range publishes base 4, attempt 8, maximum 64.
- Mathematical and random attempts charge upfront, including failure, without
an additional generic INTRINSIC cycle. Random draws retain attempt costs.
- mutates_guest_state distinguishes reproducible stateful calls from pure
computation. It is true for all random entries; may_allocate is true only
for random.new. Consumers must preserve stateful calls and source order.
- Both [INTRINSICS.csv](INTRINSICS.csv) and
[BUILTIN_CONSTANTS.csv](BUILTIN_CONSTANTS.csv) are generated from runtime
descriptors. Float constants publish bits rather than decimal approximations.
@@ -179,3 +185,7 @@ image/verifier must reject these instructions until typed-image integration is p
#### Registry-backed collections
STRUCT_NEW (0x00A0), STRUCT_GET (0x00A1), STRUCT_SET (0x00A2), ARRAY_NEW (0x00A3), ARRAY_LEN (0x00A4), ARRAY_GET (0x00A5) and ARRAY_SET (0x00A6) require a validated Registry. Their exact immediates, full group effects, attempt costs and failure ordering are normative in the [typed collection instruction table](../specs/runtime/02-vm-instruction-set.md#typed-collection-instructions). These operations have no implicit conversion or safepoint. See the [producer handoff](collection-producer-handoff.md) for emission oracles.
## VM-owned random core
See the [random contract](../specs/runtime/02e-vm-owned-random-core.md) for Random BuiltinId 0x0016, ObjectKind tag 9, intrinsics 0x4000–0x4003, atomic state mutation, bounded 4+8*N costs and rejection-limit trap 0x00000015. Random is managed by the VM heap and existing GC, without host entropy or PBX changes.
+111
View File
@@ -0,0 +1,111 @@
{
"date": "2026-10-09",
"target": "aarch64-apple-darwin",
"profiles": [
"debug",
"release"
],
"features": "default workspace features; fpmath soft-float",
"rustc_vv": "rustc 1.98.1 (48a229cea 2026-09-01)\nbinary: rustc\ncommit-hash: 48a229ceaefd4985c50990b14116b6d856af0985\ncommit-date: 2026-09-01\nhost: aarch64-apple-darwin\nrelease: 1.98.1\nLLVM version: 22.1.8",
"lockfile_sha256": "9d2098de05ba9a1568c49f98eb144c317e62b2da57dcab4a76286d7c26d072cd",
"intrinsic_catalog_sha256": "0c1bb78a9b81d1e3480ef5713f3d70f0b06772a7dfab2fd00c1f0a6364f98daa",
"constant_catalog_sha256": "e407e4718127aa7ef7b1097b5b4b67d86dd979235e73a551a7c36b628cddc039",
"fixture_sha256": "0bee1cd0366f1716687aee8c7ac39dd495da5fe2908cce37b1443cb04fac542f",
"oracle_sha256": "0cf29cd24ba08c3fc0162e8e2a38829355bdbeda8ca8ffbfee5925180822164a",
"source_manifest_sha256": "68015d159ce1bd3d14281023c942be232037946ed273e39b6ad393a452762748",
"source_manifest_format": "sorted path + NUL + lowercase SHA-256 + newline; bytecode/vm src Rust files",
"source_files": {
"crates/console/prometeu-bytecode/src/abi.rs": "c4dcaee79b1b30f553fa7a660f8bc9280ec18d57793eb9ba173d2bea94647b95",
"crates/console/prometeu-bytecode/src/assembler.rs": "a687a32a7701602208a28b6e69c4179c54fdcea2d16c0c968d5cbd3a52481715",
"crates/console/prometeu-bytecode/src/decoder.rs": "032e9e7606b68c4d722518e7d4e97eac7fa5feecc78453a41ee8e2e14f8b87d9",
"crates/console/prometeu-bytecode/src/disassembler.rs": "07790f3d023fbe5a57efb2bde9a8a9d4c560b88f10a104c345b8f90bfba02f80",
"crates/console/prometeu-bytecode/src/isa/core.rs": "e5842ac00c1db20fa0e5504e2b10dd01ad86226884f08de50f87f1deefa7223a",
"crates/console/prometeu-bytecode/src/isa/mod.rs": "ed1bb37ae8a434bb93c0f84aef72c69520a147ad040935c3b416c64f73e7f19a",
"crates/console/prometeu-bytecode/src/lib.rs": "f1709d9533721d1334dfeb986645a493dab26b2ed42b3b7721c4fc8ead0646b8",
"crates/console/prometeu-bytecode/src/load_limits.rs": "94a2977adcfb7c12004baeae1ec96525f84d1a7f44d54b973f5b825a76212689",
"crates/console/prometeu-bytecode/src/model.rs": "86884b5fbfa5a520fcea4af6397b210d117a2b0d8ad92d625e6e73c627fdd6e3",
"crates/console/prometeu-bytecode/src/opcode.rs": "eddaffc44562afe78545119e852e2ecc82010efb60a6ae6e39a6c2bc52a0c3da",
"crates/console/prometeu-bytecode/src/opcode_spec.rs": "124ac435f3aa2c428b130c963fb1692c785183fd3b63c1ae5186307a66b1b2b5",
"crates/console/prometeu-bytecode/src/program_image.rs": "ea752b0430963be3d53e41941116a686494dce78644c5a7119e25b6db1b813b2",
"crates/console/prometeu-bytecode/src/registry.rs": "8e9173c9ea500f84da0518669472f62354bd013f684db52ca5d590e22cbdeb4e",
"crates/console/prometeu-bytecode/src/registry_codec/payloads.rs": "457db2f3470e3c746698c2c73cd2d8387918a01daf64377832b2928fb4f05e1e",
"crates/console/prometeu-bytecode/src/registry_codec/writer.rs": "97a1f19dbc335e86c2d93ca6c5115b4845dc2a23fcf7ef16748a840d03e164b6",
"crates/console/prometeu-bytecode/src/registry_codec.rs": "c9dd8c9e6568b355ac1a172ed92c9bef4d61afb18a5dde95d016c028ad688bd2",
"crates/console/prometeu-bytecode/src/registry_instruction.rs": "48e2d1a25a30bdc4ef4842855fdd0fbc38525257375ba36f489485e88b611004",
"crates/console/prometeu-bytecode/src/resource_failure.rs": "64e63da70bb7be5b4472edbe3e8e66c8b856db6fc41dfa5f2571c3535325c07b",
"crates/console/prometeu-bytecode/src/value.rs": "374d4ea2d7e319cc48d2034553ad3b9866bfce2ff24b4fc0805fa8908f1db314",
"crates/console/prometeu-vm/src/builtins.rs": "2373d9088df250eada8867c0afb33a7aac87cf7036c0dac94641c610d1cd596a",
"crates/console/prometeu-vm/src/call_frame.rs": "e89e0a549529236358374697fecc2688db3f7ab84644e7cb0226ce80206d4e66",
"crates/console/prometeu-vm/src/catalog.rs": "165413fc127760110fc33c1989c7e56984ddf463587980510160f12c6a812dab",
"crates/console/prometeu-vm/src/heap/dynamic_box.rs": "3dae99eba1ca5045fff733f38d80cd4297521d11d0fd1c58d2767e6c5c1286e9",
"crates/console/prometeu-vm/src/heap/dynamic_tests.rs": "bb7e8ed7f33d376e160b3aa7933a53e90d8d601dcde283323cb3e9aff9cf1106",
"crates/console/prometeu-vm/src/heap/random.rs": "c3d5061dcdd6d85af5e8519f21ccbd7d95d2bd54d26a077612f52ecf801fccc6",
"crates/console/prometeu-vm/src/heap.rs": "a57326be640966bd771fba36c8aa8422700ec0a0043491da46cde17d302f3a89",
"crates/console/prometeu-vm/src/input_intrinsics.rs": "4cb62267df510c02ecea74ac9e02ffb3927201054ca0c8d1cee8c879de621d95",
"crates/console/prometeu-vm/src/lib.rs": "1091dc5b97ca0221471d2f1772560f6eb8834b190604aaeead96c7937e1f89d4",
"crates/console/prometeu-vm/src/local_addressing.rs": "d74965bda1e26a5712257dfc498a3a5a262430464398561923ced9aed3e117c0",
"crates/console/prometeu-vm/src/math_intrinsics.rs": "9b13b627023a73568aa7efe407e4706fdeacb3fed60a152a76a3970d6a103723",
"crates/console/prometeu-vm/src/numeric.rs": "9e1eaf35137a89160ae09fe11634645c242f97f332c946bebc0da9fd0b533146",
"crates/console/prometeu-vm/src/object.rs": "80a138583f3de3cb262df8fd02d690931fb6bfb30316a90be7835f429dda859b",
"crates/console/prometeu-vm/src/program_image/tests.rs": "2c7f6b50d611f995a97cd3993f779ac5c0ae014f9f4108413dde152a4f9bd3c3",
"crates/console/prometeu-vm/src/program_image.rs": "a6bcced8241557586eb7bf5c6922f4222590cc32563032427ae810fd400dd663",
"crates/console/prometeu-vm/src/random.rs": "48e46d50f0665c85bb899d7324783cb1b5121378cb21f06059f2c2617e6d9e16",
"crates/console/prometeu-vm/src/random_intrinsics.rs": "abfb9d4d3e3d39085b5470b6ffcf5400c73002b050244842dda48aaf445b5b23",
"crates/console/prometeu-vm/src/registry_verifier/heights.rs": "789da044dc5b860027d302d927eb7a460ea1218d0167dffda8c097d9655910f6",
"crates/console/prometeu-vm/src/registry_verifier/tests.rs": "dde3a6a1d06c4402c93b154c4a050880a45363d0493b16af561261c03b0ba1b4",
"crates/console/prometeu-vm/src/registry_verifier/types/tests.rs": "48b5ac47156bbf24988ebc9b3ca8f59df76193231975de6cdb318a682ff68788",
"crates/console/prometeu-vm/src/registry_verifier/types.rs": "904811508ff69631855b01f43a396ec2d558b501469c84786aea56d610c995f7",
"crates/console/prometeu-vm/src/registry_verifier.rs": "985446f71017625266483be539514f8a74c61ffcf3a21e5676bd67620ae3575f",
"crates/console/prometeu-vm/src/resource_budget.rs": "bab06fb8384410d43f32f4f4d6162351b50fded755794ca69b58ac6d5c921efb",
"crates/console/prometeu-vm/src/roots.rs": "c5a26c3cf9c7655c6d3861c17412d1fa9c7738e16e18079224ad44c954660a2c",
"crates/console/prometeu-vm/src/string_ledger/tests.rs": "4c5b0d68a984f662a7aaec50f5c09075a08b991b182d2dbeb4302ef02baf4fda",
"crates/console/prometeu-vm/src/string_ledger.rs": "a16c944bb119aeb806f5765c450fa56b87c1c38568ed23c4cb0d9ee5f88f0770",
"crates/console/prometeu-vm/src/typed_storage/allocation.rs": "44db682ac5ca42f63552910e9c13ea1e8db1a3bcf1428fd0b9d0c6969bc985a1",
"crates/console/prometeu-vm/src/typed_storage/ownership_tests.rs": "c0b7c152984de0e8a150614e9d3d19ba89994ef0ed84be5345db1f890afeb8de",
"crates/console/prometeu-vm/src/typed_storage/tests.rs": "95d017485f4d62c1ad5196a0ae6dfdb816d673934e06dae5d328102121b21265",
"crates/console/prometeu-vm/src/typed_storage.rs": "8df8460a390b5fa06c41c176dc3f9c50fc9e0f7fd5136ed7a2f5b8dd1ba7125f",
"crates/console/prometeu-vm/src/value_contract/reference_tests.rs": "070dc83827cab60e753bcf68d06932d15cfa13ef8f586ce7f7a080ea67e47120",
"crates/console/prometeu-vm/src/value_contract.rs": "0214312fbba372a086bff2a14faa6ac03487c23c62dce5ca25315c0d7e560e1f",
"crates/console/prometeu-vm/src/verifier.rs": "73afffa659f46e8f35532aae015769e7eedb4bdbfd1fc9897b42b217d92aa546",
"crates/console/prometeu-vm/src/virtual_machine/callable.rs": "0e6ada8736039157a4bc90a8a70a127f1c61a325fca1b67c3c40b9fb10db5da0",
"crates/console/prometeu-vm/src/virtual_machine/callable_tests.rs": "0dcbd0513dac25fb6577be089f97d84a2c07bcf68c17bf8b4da695d5800648f4",
"crates/console/prometeu-vm/src/virtual_machine/collections.rs": "d83f753801d5f8ac228de96aedb09a200d52937e5f9dd1cc92ddcfcd9e2b10db",
"crates/console/prometeu-vm/src/virtual_machine/collections_tests.rs": "c6e8a3d0a43894f28fab8f5c3705c6030bb11ddbf80761dca44af88f7d127c47",
"crates/console/prometeu-vm/src/virtual_machine/control.rs": "70a769ae28fb985b3db95e635f1f0281f2b162d5a0f2eca39708b5e023538dd6",
"crates/console/prometeu-vm/src/virtual_machine/dynamic.rs": "898cd1bf0d882704451fba240a95eb00fd2d12369436a802d93661d4ed7f960f",
"crates/console/prometeu-vm/src/virtual_machine/gc.rs": "5bb11a32bffa112ffa5ae9e8dbb9204a62db9fd6a9e4662141c1989e9aadbb76",
"crates/console/prometeu-vm/src/virtual_machine/loader.rs": "9f3b87d886562fef2b18625a96e9b1219587232dfd2dc39615ae854b5b91dd1c",
"crates/console/prometeu-vm/src/virtual_machine/random.rs": "136cdbe46a687a7b755d559a2842d44f494cf76e8a34427eeb48494820935a42",
"crates/console/prometeu-vm/src/virtual_machine/reference.rs": "00da14fac117a307ebd030c846932e94acc503fe14b65c1a4613f82e7614718b",
"crates/console/prometeu-vm/src/virtual_machine/runtime.rs": "5547a6b0d7ab0f8c76837f4c281c8577e63d36fce667c90c256bee410b634a58",
"crates/console/prometeu-vm/src/virtual_machine/stack.rs": "778c641b4bb6dd883affaa8567a97effe7b737215654f6af3f928a4d3e05cb03",
"crates/console/prometeu-vm/src/virtual_machine/strings.rs": "82088a668f71089e2ef92c83023891b289881984642ad85a5f9c5f4c9f38e7e9",
"crates/console/prometeu-vm/src/virtual_machine/typed.rs": "06818c09e28c6d3b750fc592b22e3e943098f4448972f2eaab5c0d011d204572",
"crates/console/prometeu-vm/src/virtual_machine/typed_tests.rs": "84dc60e3c8fb25a60c0a22390195494077450ae2cb2172aa920afc2b63e16490",
"crates/console/prometeu-vm/src/virtual_machine.rs": "4a610d40415279056e7ce64672c9b67a7fba09313afa40cd98a25a2aa72f12c0",
"crates/console/prometeu-vm/src/vm_init_error.rs": "4704ca4bafe3cd760ab1e8f44d6616f6b377d0a264b65f0c8f6142ea07eec24e"
},
"results": {
"bytecode_vm_debug": {
"passed": 400,
"ignored": 3
},
"bytecode_vm_release": {
"passed": 401,
"ignored": 3
},
"workspace_debug": {
"passed": 938,
"ignored": 9
},
"final_random_guest_debug": 13,
"final_random_guest_release": 13,
"private_random_debug_release": 11
},
"unexecuted_comparisons": [
"x86_64 hosts",
"Linux",
"Windows",
"other targets"
]
}
+79
View File
@@ -0,0 +1,79 @@
# Random qualification
Executed on 2026-10-09, target `aarch64-apple-darwin`, default features, with
fpmath 0.1.1 soft-float. Toolchain: rustc 1.98.1 (48a229cea, 2026-09-01),
LLVM 22.1.8. Exact rustc -Vv, source/lockfile/catalog/fixture fingerprints and
per-file source hashes are in [RANDOM_QUALIFICATION.json](RANDOM_QUALIFICATION.json).
This record qualifies only the executed local target/profiles.
## Executed checks
| Check | Result |
| --- | --- |
| cargo test --locked -p prometeu-bytecode -p prometeu-vm | 400 passed, 3 existing ignored |
| cargo test --locked -p prometeu-bytecode -p prometeu-vm --release | 401 passed, 3 existing ignored |
| cargo test --locked --workspace | 938 passed, 9 existing ignored |
| Final random_contract guest suite, debug / release | 13 passed / 13 passed |
| Private engine/VM random tests, debug / release | 11 passed / 11 passed |
| cargo fmt --all -- --check | Passed |
| Generated intrinsic CSV and constant CSV comparison | Exact metadata parity; constants unchanged |
| Coverage source ownership audit | All source files have exactly one owner |
| git diff --check and changed-doc link/workflow-reference checks | Passed |
The complete runs preceded the final additional guest handoff assertion; the
final targeted guest runs cover all 13 assertions in both profiles. No
production source changed between these checks. The ignored tests are existing
repository tests, not unexecuted random acceptance cases.
## Independent oracle and state behavior
[Fixture provenance](../../crates/console/prometeu-vm/tests/fixtures/random-oracle.md)
pins pcg-cpp revision 428802d1a5634f96bcd0705fab379ff0113bcf13 and the six
canonical seed=42 words. A separate test-only Python mathematical model produces
48 words, signed outputs and Float bits for seeds 0, 1, 42, -1 and Int64 MIN/MAX.
Guest tests replay both integer and Float output streams and mixed operations.
The Float grid endpoint checks include +0 and the greatest value below 1.
Tests cover alias/separate-object state, direct Dynamic with exact types/typed
null, locals/globals/fields/arrays/captures/parameters/results, reachable GC
roots, reclamation, stale generations and existing session reset/import rules.
Native snapshots are not guest roots; raw handle copies are not a supported
cross-session import API. Opaque payload access and Struct/Trait misuse are
rejected by the existing admission/runtime type boundaries.
## Bounded work, faults and resources
Real PCG output exercises a rejected word followed by acceptance, charging
20 cycles and committing as one instruction. Private synthetic words exercise
the production bounded loop/transaction: immediate/multiple rejection, acceptance
on attempt 64 and 64 rejections. The cap costs 516 cycles and preserves public
state and operands; the next normal draw still returns the first canonical word.
Tests do not alter production PRNG selection or wait for a rare random event.
Fault matrices cover argument carriers before receiver checks, null/invalid/
wrong-kind handles, numeric bounds, stack height and GuestBytes/HandleSlots/
AuxiliaryBytes/TemporaryBytes refusals. Snapshots prove no operand/state changes,
no provisional charge leaks and no partial handle publication. Billing remains
observable; zero budget does nothing, positive budget allows whole-instruction
overshoot, and faults precede BudgetExhausted without successful-step credit.
Generated metadata exposes guest mutation and variable costs. No RNG execution
uses HostContext, syscalls, host entropy/time/address initialization, FFI,
bigint runtime arithmetic or a parallel catalog. PBX v1 remains unchanged;
unreachable unknown IDs reject with InvalidCode/NativeId and Unknown analysis
retains full runtime checks.
## Pending comparisons and consumers
Linux, Windows, x86_64 and other target comparisons have not been executed.
For each advertised target, run the pinned guest and private fixture suites in
debug/release and record toolchain/features/source/catalog fingerprints plus
bits/faults/cycles. Do not infer qualification from this local result.
CPU benchmarks were not run and do not set virtual costs.
Frontend emission/optimization and reference-game workload integration remain
separate consumer deliveries. Their concrete acceptance tests are in the
[random producer handoff](random-producer-handoff.md). Statistical quality,
sequence conformance and game readiness are separate evidence; none is a
cryptographic guarantee. The normative contract is the
[random spec](../specs/runtime/02e-vm-owned-random-core.md).
+73
View File
@@ -0,0 +1,73 @@
# Random producer handoff
The runtime implements [Random v1](../specs/runtime/02e-vm-owned-random-core.md).
PBS namespace projection/lowering and reference-game integration remain pending
consumer work. No host entropy, syscall or firmware provider is required.
Use the generated [intrinsic catalog](INTRINSICS.csv); never copy its IDs or
cost/effect rules into an independent algorithm implementation.
## Types and emission
Declare program TypeId 0 as BuiltinId 0x0011 (Int64), TypeId 1 as BuiltinId
0x0016 (Random), and TypeId 2 as BuiltinId 0x0012 (Float). TypeIds are local
program identities, not builtin IDs. Random uses one nullable reference slot.
This function has no parameters, one local slot and results [Int64, Float,
Int64]. Its intrinsic IDs are decimal 16384 through 16387 (hex 0x4000–0x4003),
all version 1. Operands are ordered seed; rng; rng; and rng/min/max respectively.
```text
PUSH_I64 42
INTRINSIC 16384
SET_LOCAL 0
GET_LOCAL 0
INTRINSIC 16385
GET_LOCAL 0
INTRINSIC 16386
GET_LOCAL 0
PUSH_I64 -7
PUSH_I64 -6
INTRINSIC 16387
RET
```
The complete function costs 82 virtual cycles: 32+8+12+12 for the four calls,
three PUSH_I64 at 2 each, three GET_LOCAL at 2 each, SET_LOCAL at 2 and RET at 4.
Its ordered results are Int64 bits 0x86B1DA1D72062B68, Float bits
0x3FB304AA46C98538 and Int64 -7. The unit interval consumes the third word;
a subsequent next returns bits 0xF9090E529A7DAE00. Actual producer emission is
exercised by the VM random contract tests through the official PBX v1 writer
and loader, not direct host callbacks.
## Storage and Dynamic
Emit ordinary SET/GET_LOCAL and SET/GET_GLOBAL for handle aliases; typed
Struct fields and Array elements declare the Random TypeId and use existing
collection instructions. Captures and parameter/result groups use that same
one-slot type. NEW cannot create Random; allocate with random.new first.
DYN_PACK 1 followed by DYN_UNPACK 1 preserves the same generator without a
multislot box. Typed null preserves tag 1 and extracts only to that exact type.
No Struct or Trait adaptation is implied by physical HeapRef representation.
## Consumer acceptance tests
Frontend delivery must import Random and all four exact v1 signatures, preserve
source evaluation order for positional/named arguments, retain aliases, and
emit correct ordered carriers. All random entries are deterministic and
mutates_guest_state=true. Only new may_allocate=true. These calls cannot be
compile-time evaluated, folded, eliminated or reordered based on seeds/literals
or the deterministic flag. Range metadata publishes base 4, attempt 8 and
maximum 64, not a fixed total of 4. Test generated PBX against the sequence and
fault/cycle traces above, including mixed next/nextf/range and duplicated handles.
Reference-game delivery must use explicit seeds and replay equal ordered
inputs to compare result bits, fault identities and cycles. Keep generators
separate when independent state is required; copying handles does not fork a
stream. Test min>=max -> NUMERIC_DOMAIN at cost 4 with retained operands/state;
null receiver -> NULL_REFERENCE; incorrect carriers -> TYPE. Failed attempted
calls retain their charged cycles. No PickRandom or helper surface is exposed.
Additional target qualification must run the pinned fixture suite in debug
and release on each advertised target, recording target/toolchain/features,
lockfile, source/catalog fingerprints and result bits/faults/cycles. The
[current qualification record](RANDOM_QUALIFICATION.md) identifies executed
local evidence; unexecuted comparisons are pending tests, not portability claims.
@@ -157,3 +157,9 @@ External compiler acceptance requires these exact bytes and signatures, Fn
pass/return/storage, shared cells, named-argument evaluation order, nested sync
continuation and structured failure tests. The runtime's binary/behavioral oracles
are available; no external implementation is claimed.
## Random reference consumer
The runtime supports Random BuiltinId 0x0016 and the four VM-owned random
intrinsics. The [random handoff](random-producer-handoff.md) supplies PBX
emission, effects, variable costs and pending frontend/game acceptance tests.
@@ -10,7 +10,7 @@
]
},
"system/runtime": {
"baseline_percent": 76.5,
"baseline_percent": 76.19,
"paths": [
"crates/console/prometeu-system/src/services/vm_runtime"
]
@@ -58,19 +58,19 @@
]
},
"vm/core": {
"baseline_percent": 89.12,
"baseline_percent": 84.29,
"paths": [
"crates/console/prometeu-vm/src/"
]
},
"bytecode": {
"baseline_percent": 93.23,
"baseline_percent": 88.26,
"paths": [
"crates/console/prometeu-bytecode/src/"
]
},
"hal/core": {
"baseline_percent": 88.56,
"baseline_percent": 83.56,
"paths": [
"crates/console/prometeu-hal/src/"
],
@@ -83,7 +83,7 @@
]
},
"drivers/core": {
"baseline_percent": 84.51,
"baseline_percent": 79.51,
"paths": [
"crates/console/prometeu-drivers/src/"
],
@@ -92,7 +92,7 @@
]
},
"system/core": {
"baseline_percent": 92.71,
"baseline_percent": 87.71,
"paths": [
"crates/console/prometeu-system/src/"
],
@@ -107,7 +107,7 @@
]
},
"tooling": {
"baseline_percent": 64.75,
"baseline_percent": 59.75,
"paths": [
"crates/tools/prometeu-cli/src/",
"crates/tools/pbxgen-dummy-boy/src/",
@@ -115,7 +115,7 @@
]
},
"dev/test-support": {
"baseline_percent": 85.96,
"baseline_percent": 80.96,
"paths": [
"crates/dev/prometeu-test-support/src/",
"crates/dev/prometeu-layer-tests/src/",