feat(pbs): add array-backed Stack and circular Queue
This commit is contained in:
@@ -397,3 +397,24 @@ prefix reclamation and sticky final retention. Set GC tests do not assume an
|
||||
iteration order. Add `--release` to qualify the Rust release profile independently
|
||||
of the two producer variants; omit focused flags for the complete mandatory corpus.
|
||||
All harness builds remain outside the runtime checkout, which is consumed unchanged.
|
||||
|
||||
## PBS Stack and Queue qualification
|
||||
|
||||
The mandatory Stack/Queue corpus is included in every complete run. A focused
|
||||
run uses `python3 tools/pbx-conformance/run.py --runtime ../runtime --stack-queue-only`;
|
||||
add `--release` for the optimized runtime profile. Both source producer paths are
|
||||
mandatory in each profile. Generate fixtures with the architecture tests and
|
||||
`:prometeu-app:installedKnowledgeTest` before executing the runner.
|
||||
|
||||
`stack_queue.rs` validates dense/circular storage, inactive-slot cleanup, exact
|
||||
capacity/growth, wrapped growth, complete payloads, once/named evaluation, snapshot
|
||||
orders/states, imports and actual installed-JAR examples. Lowered quota runs compare
|
||||
complete original-object instruction prefixes to a successful run and distinguish
|
||||
preservation before mutation from retained writes afterward. Separate test-only
|
||||
growth probes demonstrate an installed candidate with old size after a later fault;
|
||||
these probes are not shipped or counted as natural refusal frequencies.
|
||||
|
||||
GC fixtures require actual advancing collection counters. Snapshots release source
|
||||
backings and observe 1,200 → 1 → 1 → 0 nodes/payloads. Collection fixtures observe
|
||||
64 → 61 → 0 → 1 → 0 payloads and only one retained backing until its final owner
|
||||
is dropped. Temporary Cargo projects/targets stay outside the runtime checkout.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use prometeu_bytecode::Value;
|
||||
mod stack_queue;
|
||||
use prometeu_bytecode::load_limits::{LoadBudget, LoadLimits};
|
||||
use prometeu_hal::syscalls::caps;
|
||||
use prometeu_vm::{
|
||||
@@ -41,6 +42,7 @@ fn main() {
|
||||
for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations,Q::IndividualStringBytes,Q::CallDepth] {
|
||||
println!("DEFAULT VM LIMIT {resource:?}={}",limits.get(resource));
|
||||
}
|
||||
if std::env::args().any(|arg| arg == "--stack-queue-only") { stack_queue::verify(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--map-only") { verify_pbs_map_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--set-only") { verify_pbs_set_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--identity-hashing-only") { verify_identity_hashing_fixtures(&root); return; }
|
||||
@@ -63,6 +65,7 @@ fn main() {
|
||||
verify_pbs_linked_fixtures(&root);
|
||||
verify_pbs_set_fixtures(&root);
|
||||
verify_pbs_map_fixtures(&root);
|
||||
stack_queue::verify(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
verify_pbs_closure_frames(&root);
|
||||
for name in [
|
||||
@@ -503,7 +506,7 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
for entry in std::fs::read_dir(root).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let name = path.file_stem().unwrap().to_str().unwrap();
|
||||
if name.starts_with("pbs-random-") || name.starts_with("pbs-math-") || name.starts_with("pbs-structured-") || name.starts_with("pbs-generic-contract-") || name.starts_with("pbs-generic-struct-") || name.starts_with("pbs-list-") || name.starts_with("pbs-linked-") || name.starts_with("pbs-hash-") || name.starts_with("pbs-set-") || name.starts_with("pbs-map-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
if name.starts_with("pbs-random-") || name.starts_with("pbs-math-") || name.starts_with("pbs-structured-") || name.starts_with("pbs-generic-contract-") || name.starts_with("pbs-generic-struct-") || name.starts_with("pbs-list-") || name.starts_with("pbs-linked-") || name.starts_with("pbs-hash-") || name.starts_with("pbs-set-") || name.starts_with("pbs-map-") || name.starts_with("pbs-stack-") || name.starts_with("pbs-queue-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
count += 1;
|
||||
let bytes = std::fs::read(&path).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
|
||||
@@ -14,6 +14,7 @@ parser.add_argument("--online", action="store_true", help="Allow Cargo to fetch
|
||||
parser.add_argument("--release", action="store_true", help="Execute an optimized runtime harness")
|
||||
parser.add_argument("--set-only", action="store_true", help="Run mandatory PBS Set corpus")
|
||||
parser.add_argument("--map-only", action="store_true", help="Run mandatory PBS Map/Keyval corpus")
|
||||
parser.add_argument("--stack-queue-only", action="store_true", help="Run mandatory PBS Stack/Queue corpus")
|
||||
parser.add_argument("--identity-hashing-only", action="store_true", help="Run mandatory neutral and PBS identity/hash corpus")
|
||||
parser.add_argument("--math-only", action="store_true", help="Run the complete PBS math corpus only")
|
||||
parser.add_argument("--random-only", action="store_true", help="Run the complete PBS Random corpus only")
|
||||
@@ -34,6 +35,8 @@ if provider_hash_vectors.read_bytes() != consumer_hash_vectors.read_bytes():
|
||||
raise SystemExit("Hash oracle differs from selected provider")
|
||||
print(subprocess.check_output(["rustc", "-Vv"], text=True).strip(), flush=True)
|
||||
for source in [pathlib.Path(__file__), pathlib.Path(__file__).with_name("main.rs"),
|
||||
pathlib.Path(__file__).with_name("stack_queue.rs"),
|
||||
pathlib.Path("prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsStackQueueTest.java"),
|
||||
pathlib.Path("prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsRuntimeRandomTest.java"),
|
||||
pathlib.Path("prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/random/main.pbs")]:
|
||||
print("sha256", source, hashlib.sha256(source.read_bytes()).hexdigest(), flush=True)
|
||||
@@ -59,4 +62,5 @@ with tempfile.TemporaryDirectory(prefix="pbx-conformance-") as directory:
|
||||
(root / "Cargo.lock").write_text((runtime / "Cargo.lock").read_text())
|
||||
(root / "src").mkdir()
|
||||
(root / "src/main.rs").write_text(pathlib.Path(__file__).with_name("main.rs").read_text())
|
||||
subprocess.run(["cargo", "run", *(["--release"] if args.release else []), *([] if args.online else ["--offline"]), "--manifest-path", str(root / "Cargo.toml"), "--", str(args.fixtures.resolve()), str(runtime / "devtools/headless-protocol/response.schema.json"), *(["--map-only"] if args.map_only else []), *(["--set-only"] if args.set_only else []), *(["--identity-hashing-only"] if args.identity_hashing_only else []), *(["--math-only"] if args.math_only else []), *(["--random-only"] if args.random_only else []), *(["--generic-contracts-only"] if args.generic_contracts_only else []), *(["--generic-structs-only"] if args.generic_structs_only else []), *(["--list-cursor-only"] if args.list_cursor_only else []), *(["--linked-only"] if args.linked_only else [])], check=True)
|
||||
(root / "src/stack_queue.rs").write_text(pathlib.Path(__file__).with_name("stack_queue.rs").read_text())
|
||||
subprocess.run(["cargo", "run", *(["--release"] if args.release else []), *([] if args.online else ["--offline"]), "--manifest-path", str(root / "Cargo.toml"), "--", str(args.fixtures.resolve()), str(runtime / "devtools/headless-protocol/response.schema.json"), *(["--stack-queue-only"] if args.stack_queue_only else []), *(["--map-only"] if args.map_only else []), *(["--set-only"] if args.set_only else []), *(["--identity-hashing-only"] if args.identity_hashing_only else []), *(["--math-only"] if args.math_only else []), *(["--random-only"] if args.random_only else []), *(["--generic-contracts-only"] if args.generic_contracts_only else []), *(["--generic-structs-only"] if args.generic_structs_only else []), *(["--list-cursor-only"] if args.list_cursor_only else []), *(["--linked-only"] if args.linked_only else [])], check=True)
|
||||
|
||||
@@ -0,0 +1,570 @@
|
||||
//! Real PBS Stack/Queue qualification against the unchanged production provider.
|
||||
use super::*;
|
||||
use prometeu_bytecode::{TRAP_RESOURCE_LIMIT, decode_next, isa::core::CoreOpCode as Op};
|
||||
use prometeu_vm::{
|
||||
LogicalFrameEndingReason as End,
|
||||
resource_budget::{RuntimeLimits, RuntimeResource as Q},
|
||||
resource_diagnostics::{StorageObject, StorageValue as V},
|
||||
};
|
||||
|
||||
fn load(
|
||||
root: &std::path::Path,
|
||||
collection: &str,
|
||||
name: &str,
|
||||
suffix: &str,
|
||||
) -> std::sync::Arc<ValidatedProgramImage> {
|
||||
let path = root.join(format!("pbs-{collection}-{name}{suffix}.pbx"));
|
||||
let bytes =
|
||||
std::fs::read(&path).unwrap_or_else(|e| panic!("mandatory {}: {e}", path.display()));
|
||||
ValidatedProgramImage::load(
|
||||
&bytes,
|
||||
&mut LoadBudget::new(LoadLimits::default()),
|
||||
caps::NONE,
|
||||
)
|
||||
.unwrap_or_else(|e| panic!("{}: {e:?}", path.display()))
|
||||
}
|
||||
fn state(
|
||||
vm: &VirtualMachine,
|
||||
image: &ValidatedProgramImage,
|
||||
collection: &str,
|
||||
) -> Vec<StorageObject> {
|
||||
let objects = vm.heap().diagnostic_typed_storage();
|
||||
let name = format!("{collection}<int>");
|
||||
let owner = objects
|
||||
.iter()
|
||||
.find(|o| {
|
||||
image.registry().declarations().types[o.type_id.0 as usize]
|
||||
.name
|
||||
.as_deref()
|
||||
== Some(&name)
|
||||
})
|
||||
.expect("owner")
|
||||
.clone();
|
||||
let V::Reference(storage) = owner.groups[0][0] else {
|
||||
panic!("backing reference")
|
||||
};
|
||||
let backing = objects
|
||||
.iter()
|
||||
.find(|o| o.reference == storage)
|
||||
.expect("backing")
|
||||
.clone();
|
||||
vec![owner, backing]
|
||||
}
|
||||
fn integer(group: &[V]) -> i64 {
|
||||
let [V::Int64(value)] = group else {
|
||||
panic!("long field {group:?}")
|
||||
};
|
||||
*value
|
||||
}
|
||||
fn validate(
|
||||
vm: &VirtualMachine,
|
||||
image: &ValidatedProgramImage,
|
||||
collection: &str,
|
||||
expected: &[i32],
|
||||
capacity: usize,
|
||||
start: usize,
|
||||
) {
|
||||
let objects = state(vm, image, collection);
|
||||
let owner = &objects[0];
|
||||
let backing = &objects[1];
|
||||
assert_eq!(backing.groups.len(), capacity);
|
||||
assert_eq!(
|
||||
integer(&owner.groups[if collection == "stack" { 1 } else { 2 }]),
|
||||
expected.len() as i64
|
||||
);
|
||||
if collection == "queue" {
|
||||
assert_eq!(integer(&owner.groups[1]), start as i64);
|
||||
}
|
||||
let mut occupied = std::collections::BTreeSet::new();
|
||||
for (offset, expected) in expected.iter().enumerate() {
|
||||
let index = (start + offset) % capacity;
|
||||
occupied.insert(index);
|
||||
let [V::Int64(_), V::Int32(value)] = backing.groups[index].as_slice() else {
|
||||
panic!("present complete int group")
|
||||
};
|
||||
assert_eq!(value, expected);
|
||||
}
|
||||
for (index, group) in backing.groups.iter().enumerate() {
|
||||
if !occupied.contains(&index) {
|
||||
assert_eq!(*group, vec![V::Null, V::Null], "inactive slot {index}");
|
||||
}
|
||||
}
|
||||
}
|
||||
fn release(vm: VirtualMachine) {
|
||||
let observer = vm.resource_observer();
|
||||
drop(vm);
|
||||
for q in [
|
||||
Q::GuestBytes,
|
||||
Q::HandleSlots,
|
||||
Q::AuxiliaryBytes,
|
||||
Q::TemporaryBytes,
|
||||
Q::StringBytes,
|
||||
Q::StringAllocations,
|
||||
] {
|
||||
assert_eq!(observer.used(q), 0, "last owner release {q:?}");
|
||||
}
|
||||
}
|
||||
pub(super) fn verify(root: &std::path::Path) {
|
||||
let successes = [
|
||||
"basic",
|
||||
"capacity",
|
||||
"arithmetic",
|
||||
"cursor-empty",
|
||||
"cursor-single",
|
||||
"snapshot",
|
||||
"cursor-order",
|
||||
"groups",
|
||||
"references",
|
||||
"native",
|
||||
"evaluation",
|
||||
];
|
||||
let mut cases = 0;
|
||||
for collection in ["stack", "queue"] {
|
||||
for (name, fault) in successes
|
||||
.into_iter()
|
||||
.map(|n| (n, None))
|
||||
.chain(
|
||||
["fault-negative", "fault-too-large", "fault-required"]
|
||||
.into_iter()
|
||||
.map(|n| (n, Some(prometeu_bytecode::TRAP_EXPLICIT))),
|
||||
)
|
||||
.chain((collection == "queue").then_some(("wrap", None)))
|
||||
{
|
||||
for suffix in ["", "-optimized"] {
|
||||
let image = load(root, collection, name, suffix);
|
||||
let mut vm = VirtualMachine::from_image(image, Default::default());
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let report = vm
|
||||
.run_budget(20_000_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
if let Some(expected) = fault {
|
||||
let End::Trap(info) = report.reason else {
|
||||
panic!("{collection}/{name}{suffix}: {report:?}")
|
||||
};
|
||||
assert_eq!(info.code, expected);
|
||||
} else {
|
||||
assert!(
|
||||
matches!(report.reason, End::Halted | End::EndOfRom),
|
||||
"{collection}/{name}{suffix}: {report:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
vm.operand_stack_top(1),
|
||||
vec![Value::Int32(42)],
|
||||
"{collection}/{name}{suffix}"
|
||||
);
|
||||
}
|
||||
release(vm);
|
||||
cases += 1;
|
||||
println!("STACK QUEUE SOURCE PASS {collection}/{name}{suffix}");
|
||||
}
|
||||
}
|
||||
refusals(root, collection);
|
||||
postwrite_probe(root, collection);
|
||||
gc(root, collection);
|
||||
}
|
||||
distribution(root);
|
||||
println!("STACK QUEUE MANDATORY BEHAVIOR CASES {cases}");
|
||||
}
|
||||
fn marker(image: &ValidatedProgramImage, value: i32) -> usize {
|
||||
let mut pc = 0;
|
||||
let mut found = Vec::new();
|
||||
while pc < image.code().len() {
|
||||
let i = decode_next(pc, image.code()).unwrap();
|
||||
if i.opcode == Op::PushI32 && i.imm_i32().unwrap() == value {
|
||||
found.push(pc);
|
||||
}
|
||||
pc = i.next_pc;
|
||||
}
|
||||
assert_eq!(found.len(), 1);
|
||||
found[0]
|
||||
}
|
||||
fn refusals(root: &std::path::Path, collection: &str) {
|
||||
let mut total = 0;
|
||||
let mut after_writes = 0;
|
||||
let mut backing_refusal = false;
|
||||
let mut snapshot_refusal = false;
|
||||
for name in [
|
||||
"insert", "growth", "zero", "remove", "clear", "peek", "cursor", "empty",
|
||||
]
|
||||
.into_iter()
|
||||
.chain((collection == "queue").then_some("wrapped"))
|
||||
{
|
||||
for suffix in ["", "-optimized"] {
|
||||
let image = load(root, collection, &format!("refusal-{name}"), suffix);
|
||||
let before_pc = marker(&image, 314160);
|
||||
let after_pc = marker(&image, 314161);
|
||||
let prepare = |limits| {
|
||||
let mut vm = VirtualMachine::from_image(image.clone(), limits);
|
||||
vm.prepare_boot_call().unwrap();
|
||||
vm.insert_breakpoint(before_pc);
|
||||
vm.insert_breakpoint(after_pc);
|
||||
vm
|
||||
};
|
||||
let mut baseline = prepare(RuntimeLimits::default());
|
||||
assert!(matches!(
|
||||
baseline
|
||||
.run_budget(20_000_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap()
|
||||
.reason,
|
||||
End::Breakpoint
|
||||
));
|
||||
let initial: Vec<i32> = if name == "zero" || name == "empty" {
|
||||
vec![]
|
||||
} else if name == "wrapped" {
|
||||
vec![2, 3, 4, 5]
|
||||
} else {
|
||||
vec![0, 1, 2, 3]
|
||||
};
|
||||
let old_capacity = if name == "zero" || name == "empty" {
|
||||
0
|
||||
} else if name == "growth" || name == "wrapped" {
|
||||
4
|
||||
} else {
|
||||
8
|
||||
};
|
||||
validate(
|
||||
&baseline,
|
||||
&image,
|
||||
collection,
|
||||
&initial,
|
||||
old_capacity,
|
||||
if name == "wrapped" { 2 } else { 0 },
|
||||
);
|
||||
let old = state(&baseline, &image, collection);
|
||||
let before = baseline.resource_snapshot();
|
||||
baseline.remove_breakpoint(before_pc);
|
||||
let mut successful = Vec::new();
|
||||
let mut max_arrays = 0;
|
||||
loop {
|
||||
max_arrays = max_arrays.max(
|
||||
baseline
|
||||
.heap()
|
||||
.diagnostic_typed_storage()
|
||||
.iter()
|
||||
.filter(|o| {
|
||||
matches!(
|
||||
image.registry().declarations().types[o.type_id.0 as usize].kind,
|
||||
prometeu_bytecode::registry::TypeKind::Array(_)
|
||||
)
|
||||
})
|
||||
.count(),
|
||||
);
|
||||
successful.push((baseline.pc(), observe_originals(&baseline, &old)));
|
||||
let report = baseline
|
||||
.run_budget(1, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
if baseline.pc() == after_pc {
|
||||
break;
|
||||
}
|
||||
assert!(
|
||||
matches!(report.reason, End::BudgetExhausted),
|
||||
"{collection}/{name}: {report:?}"
|
||||
);
|
||||
assert!(successful.len() < 200_000);
|
||||
}
|
||||
let after = baseline.resource_snapshot();
|
||||
let mut expected = initial.clone();
|
||||
match name {
|
||||
"insert" | "growth" | "zero" | "wrapped" => expected.push(42),
|
||||
"remove" => {
|
||||
if collection == "stack" {
|
||||
expected.pop();
|
||||
} else {
|
||||
expected.remove(0);
|
||||
}
|
||||
}
|
||||
"clear" => expected.clear(),
|
||||
_ => (),
|
||||
}
|
||||
let capacity = match name {
|
||||
"zero" => 1,
|
||||
"growth" | "wrapped" => 6,
|
||||
_ => old_capacity,
|
||||
};
|
||||
validate(
|
||||
&baseline,
|
||||
&image,
|
||||
collection,
|
||||
&expected,
|
||||
capacity,
|
||||
if collection == "queue" && name == "remove" {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
},
|
||||
);
|
||||
if ["growth", "zero", "wrapped"].contains(&name) {
|
||||
assert!(max_arrays >= 2, "old/candidate coexistence");
|
||||
} else {
|
||||
assert_eq!(
|
||||
max_arrays, 1,
|
||||
"ordinary update/capture never reconstructs backing"
|
||||
);
|
||||
}
|
||||
if ["peek", "cursor", "empty"].contains(&name) {
|
||||
assert_eq!(state(&baseline, &image, collection), old);
|
||||
}
|
||||
println!(
|
||||
"STACK QUEUE PEAK {collection}/{name}{suffix} arrays={max_arrays} before={:?} after={:?}",
|
||||
before.budget.peaks, after.budget.peaks
|
||||
);
|
||||
let mut count = 0;
|
||||
let mut partial = 0;
|
||||
for q in [
|
||||
Q::GuestBytes,
|
||||
Q::HandleSlots,
|
||||
Q::AuxiliaryBytes,
|
||||
Q::TemporaryBytes,
|
||||
Q::CallDepth,
|
||||
] {
|
||||
let lower = before.budget.peaks[q as usize];
|
||||
let upper = after.budget.peaks[q as usize];
|
||||
if lower >= upper {
|
||||
continue;
|
||||
}
|
||||
let mut limits = vec![lower, lower + (upper - lower) / 2, upper - 1];
|
||||
if q == Q::HandleSlots {
|
||||
limits.extend(lower..upper.min(lower + 24));
|
||||
}
|
||||
limits.sort_unstable();
|
||||
limits.dedup();
|
||||
for limit in limits {
|
||||
let mut vm = prepare(RuntimeLimits::default().lowered(q, limit).unwrap());
|
||||
assert!(
|
||||
matches!(
|
||||
vm.run_budget(20_000_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap()
|
||||
.reason,
|
||||
End::Breakpoint
|
||||
),
|
||||
"{collection}/{name}/{q:?}={limit} setup"
|
||||
);
|
||||
let original = state(&vm, &image, collection);
|
||||
vm.remove_breakpoint(before_pc);
|
||||
let (report, prefix, mutated) =
|
||||
trace_collection_attempt(&mut vm, &original, after_pc);
|
||||
assert_mutation_prefix(&prefix, &successful);
|
||||
if let End::Trap(info) = report.reason {
|
||||
assert_eq!(info.code, TRAP_RESOURCE_LIMIT);
|
||||
let current = observe_originals(&vm, &original);
|
||||
if !mutated {
|
||||
assert_eq!(
|
||||
current, original,
|
||||
"before first write preserves full original state"
|
||||
);
|
||||
}
|
||||
if ["peek", "cursor", "empty"].contains(&name) {
|
||||
assert_eq!(current, original);
|
||||
}
|
||||
let instruction = decode_next(info.pc as usize, image.code()).unwrap();
|
||||
backing_refusal |= instruction.opcode == Op::ArrayNew;
|
||||
if instruction.opcode == Op::StructNew {
|
||||
snapshot_refusal |= image.registry().declarations().types
|
||||
[instruction.imm_u32().unwrap() as usize]
|
||||
.name
|
||||
.as_deref()
|
||||
== Some("_SnapshotNode<int>");
|
||||
}
|
||||
count += 1;
|
||||
partial += usize::from(mutated);
|
||||
println!(
|
||||
"STACK QUEUE REFUSAL {collection}/{name}{suffix} mutated={mutated} resource={q:?} limit={limit} opcode={:?}",
|
||||
instruction.opcode
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
matches!(report.reason, End::BudgetExhausted | End::Breakpoint)
|
||||
&& vm.pc() == after_pc
|
||||
);
|
||||
}
|
||||
release(vm);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
count > 0,
|
||||
"{collection}/{name}: operation-specific natural refusal required"
|
||||
);
|
||||
total += count;
|
||||
after_writes += partial;
|
||||
println!(
|
||||
"STACK QUEUE PHASE SUMMARY {collection}/{name}{suffix} refusals={count} after_write={partial}"
|
||||
);
|
||||
}
|
||||
}
|
||||
assert!(
|
||||
backing_refusal && snapshot_refusal,
|
||||
"backing and snapshot preparation refusals required"
|
||||
);
|
||||
println!("STACK QUEUE NATURAL REFUSALS {collection} total={total} after_write={after_writes}");
|
||||
}
|
||||
fn postwrite_probe(root: &std::path::Path, collection: &str) {
|
||||
// Separate test-only instrumentation: not natural failure frequency evidence.
|
||||
for suffix in ["", "-optimized"] {
|
||||
let image = load(root, collection, "injected-growth", suffix);
|
||||
let mut vm = VirtualMachine::from_image(
|
||||
image.clone(),
|
||||
RuntimeLimits::default()
|
||||
.lowered(Q::GuestBytes, 500_000)
|
||||
.unwrap(),
|
||||
);
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let mut found = false;
|
||||
for _ in 0..100_000 {
|
||||
let instruction = decode_next(vm.pc(), image.code()).unwrap();
|
||||
if instruction.opcode == Op::ArrayNew
|
||||
&& vm.operand_stack_top(1) == vec![Value::Int64(1_000_000)]
|
||||
{
|
||||
let original = vm.heap().diagnostic_typed_storage();
|
||||
let objects = state(&vm, &image, collection);
|
||||
assert_eq!(
|
||||
integer(&objects[0].groups[if collection == "stack" { 1 } else { 2 }]),
|
||||
2
|
||||
);
|
||||
assert_eq!(objects[1].groups.len(), 3);
|
||||
assert!(matches!(
|
||||
objects[1].groups[2].as_slice(),
|
||||
[V::Int64(_), V::Int32(42)]
|
||||
));
|
||||
let operands = vm.operand_stack_top(1).to_vec();
|
||||
let report = vm
|
||||
.run_budget(1, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
let End::Trap(info) = report.reason else {
|
||||
panic!("post-write probe: {report:?}")
|
||||
};
|
||||
assert_eq!(info.code, TRAP_RESOURCE_LIMIT);
|
||||
assert_eq!(vm.heap().diagnostic_typed_storage(), original);
|
||||
assert_eq!(vm.operand_stack_top(1), operands);
|
||||
println!(
|
||||
"STACK QUEUE TEST-ONLY POST-WRITE PASS {collection}{suffix}: backing=3 old size=2 appended=42 retained"
|
||||
);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
let report = vm
|
||||
.run_budget(1, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
assert!(matches!(report.reason, End::BudgetExhausted));
|
||||
}
|
||||
assert!(found);
|
||||
release(vm);
|
||||
}
|
||||
}
|
||||
fn gc(root: &std::path::Path, collection: &str) {
|
||||
for suffix in ["", "-optimized"] {
|
||||
for (name, counts) in [
|
||||
("gc-snapshot", vec![1200, 1, 1, 0]),
|
||||
("gc-collection", vec![64, 61, 0, 1, 0]),
|
||||
] {
|
||||
let image = load(root, collection, name, suffix);
|
||||
let mut vm = VirtualMachine::from_image(image.clone(), Default::default());
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let mut previous = 0;
|
||||
for (round, count) in counts.into_iter().enumerate() {
|
||||
let report = vm
|
||||
.run_budget(100_000_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(report.reason, End::FrameSync),
|
||||
"{collection}/{name}/{round}: {report:?}"
|
||||
);
|
||||
let collections = vm.resource_snapshot().gc.collections;
|
||||
assert!(
|
||||
collections > previous,
|
||||
"actual collection, not only safepoint"
|
||||
);
|
||||
previous = collections;
|
||||
let objects = vm.heap().diagnostic_typed_storage();
|
||||
let named = |n: &str| {
|
||||
objects
|
||||
.iter()
|
||||
.filter(|o| {
|
||||
image.registry().declarations().types[o.type_id.0 as usize]
|
||||
.name
|
||||
.as_deref()
|
||||
== Some(n)
|
||||
})
|
||||
.count()
|
||||
};
|
||||
assert_eq!(
|
||||
named("Item"),
|
||||
count,
|
||||
"{collection}/{name}/{round}: payload roots"
|
||||
);
|
||||
let arrays = objects
|
||||
.iter()
|
||||
.filter(|o| {
|
||||
matches!(
|
||||
image.registry().declarations().types[o.type_id.0 as usize].kind,
|
||||
prometeu_bytecode::registry::TypeKind::Array(_)
|
||||
)
|
||||
})
|
||||
.count();
|
||||
if name == "gc-snapshot" {
|
||||
assert_eq!(named("_SnapshotNode<Item>"), count);
|
||||
assert_eq!(arrays, 0, "snapshot retains no source backing");
|
||||
} else {
|
||||
assert_eq!(
|
||||
arrays,
|
||||
usize::from(round < 4),
|
||||
"only retained backing, no replaced arrays"
|
||||
);
|
||||
assert_eq!(named("_SnapshotNode<Item>"), 0);
|
||||
}
|
||||
println!(
|
||||
"STACK QUEUE GC PASS {collection}/{name}{suffix} round={round} items={count} arrays={arrays}"
|
||||
);
|
||||
}
|
||||
let report = vm
|
||||
.run_budget(100_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom));
|
||||
assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(42)]);
|
||||
release(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn distribution(root: &std::path::Path) {
|
||||
for name in ["imports", "installed"] {
|
||||
let image = load(root, "stack-queue", name, "");
|
||||
let mut vm = VirtualMachine::from_image(image.clone(), Default::default());
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let report = vm
|
||||
.run_budget(2_000_000, &mut NoNative, &mut HostContext::new(None))
|
||||
.unwrap();
|
||||
assert!(
|
||||
matches!(report.reason, End::FrameSync | End::Halted | End::EndOfRom),
|
||||
"{name}: {report:?}"
|
||||
);
|
||||
let objects = vm.heap().diagnostic_typed_storage();
|
||||
let get = |reference| objects.iter().find(|o| o.reference == reference).unwrap();
|
||||
let mut lasts = Vec::new();
|
||||
for cursor in objects.iter().filter(|o| {
|
||||
image.registry().declarations().types[o.type_id.0 as usize]
|
||||
.name
|
||||
.as_deref()
|
||||
== Some("_SnapshotCursor<int>")
|
||||
}) {
|
||||
let V::Reference(carrier) = cursor.groups[0][0] else {
|
||||
panic!("current carrier")
|
||||
};
|
||||
let V::Reference(node) = get(carrier).groups[0][0] else {
|
||||
panic!("node")
|
||||
};
|
||||
let node = get(node);
|
||||
assert_eq!(node.groups[1], vec![V::Null], "completed traversal");
|
||||
let V::Int32(value) = node.groups[0][0] else {
|
||||
panic!("value")
|
||||
};
|
||||
lasts.push(value);
|
||||
}
|
||||
lasts.sort_unstable();
|
||||
assert_eq!(
|
||||
lasts,
|
||||
vec![20, 22],
|
||||
"both order-sensitive snapshots traversed"
|
||||
);
|
||||
release(vm);
|
||||
println!("STACK QUEUE DISTRIBUTION PASS {name}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user