feat(pbs): add Map and read-only Keyval associations
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

This commit is contained in:
2026-10-26 20:37:06 +00:00
parent 8105604f92
commit 01a1968689
41 changed files with 4072 additions and 42 deletions
+36
View File
@@ -3,6 +3,42 @@
Owner: compiler/general. This harness uses the production runtime loader and VM;
it does not implement a Java approximation of runtime admission.
## PBS Map and Keyval qualification
Generate the mandatory Map corpus and actual installed-JAR example, then execute
the dedicated verifier in both runtime profiles:
```sh
./gradlew :prometeu-architecture-tests:test --tests '*PbsMapKeyvalTest' :prometeu-app:installedKnowledgeTest --console=plain
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime --map-only
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime --map-only --release
```
Each non-GC source case has ordinary/optimized PBS producer variants, independent
of the Rust dev/release profile. The manifest names every required success/fault,
resource, injection, GC, import and installed fixture; missing files fail. The
full harness includes Map separately from its historical catch-all PBS verifier.
The corpus covers typed non-positional keys; default/explicit Identity; optional
V and previous-value presence; original-key retention under content policies;
read-only Keyval instance identity; collisions/negative full hashes; rehash and
capture callback counters; complete tuple/native/contract groups; evaluation order;
alias reentrancy and permitted callback reads; and the shared snapshot state table.
Resource fixtures compare attempted instruction prefixes with successful
instruction prefixes under lowered production quotas. They separate installed
guard writes from structural mutation and measure old/candidate table/node and
snapshot/keyval peaks. A named test-only allocation after the real candidate-table
store qualifies permitted post-write incomplete invariants; production SDK has no
injected probe. Natural quota refusal counts are reported separately.
Real safepoints check independent key/value roots, obsolete-value release after
replacement, removed-key/value reclamation, Map-node reclamation, captured Keyvals,
consumed Cursor prefixes, retained final current and release after all owners exit.
Imported/reexported and installed examples execute through the production loader
and VM and actually construct the shared entry Cursor. This is local semantic and
resource qualification, not a performance benchmark or a new provider contract.
From the Studio root:
```sh
+241 -1
View File
@@ -41,6 +41,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 == "--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; }
if std::env::args().any(|arg| arg == "--linked-only") { verify_common_storage_fixtures(&root); verify_pbs_linked_fixtures(&root); return; }
@@ -61,6 +62,7 @@ fn main() {
verify_pbs_list_cursor_fixtures(&root);
verify_pbs_linked_fixtures(&root);
verify_pbs_set_fixtures(&root);
verify_pbs_map_fixtures(&root);
verify_pbs_resource_refusals(&root);
verify_pbs_closure_frames(&root);
for name in [
@@ -501,7 +503,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-") || 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-") || 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)
@@ -1829,3 +1831,241 @@ fn verify_installed_hash(root:&std::path::Path) {
assert!(matches!(report.reason,End::FrameSync|End::Halted|End::EndOfRom),"installed hashing: {report:?}");
println!("HASH INSTALLED JAR/SDK/EXAMPLE LOAD/EXEC PASS");
}
fn map_state(vm:&VirtualMachine,image:&ValidatedProgramImage)->ObservedStorage {
use prometeu_vm::resource_diagnostics::StorageValue as V;
let objects=vm.heap().diagnostic_typed_storage();
let owner=objects.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).expect("source Map");
let mut pending=vec![owner.reference];let mut state:ObservedStorage=Vec::new();
while let Some(reference)=pending.pop() {
if state.iter().any(|o|o.reference==reference){continue;}
let object=objects.iter().find(|o|o.reference==reference).expect("live complete Map group");
for value in object.groups.iter().flatten(){if let V::Reference(reference)=value{pending.push(*reference);}}
state.push(object.clone());
}
state.sort_by_key(|o|(o.reference.index,o.reference.generation));state
}
fn map_without_guard(mut state:ObservedStorage,image:&ValidatedProgramImage)->ObservedStorage {
for object in &mut state {
if image.registry().declarations().types[object.type_id.0 as usize].name.as_deref()==Some("map<int, int>") {
object.groups[3]=vec![prometeu_vm::resource_diagnostics::StorageValue::Boolean(false)];
}
}
state
}
fn validate_map(vm:&VirtualMachine,image:&ValidatedProgramImage,expected:i64)->usize {
use prometeu_vm::resource_diagnostics::StorageValue as V;
let state=map_state(vm,image);
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).unwrap();
assert_eq!(owner.groups[1],vec![V::Int64(expected)]);assert_eq!(owner.groups[3],vec![V::Boolean(false)]);
let get=|reference|state.iter().find(|o|o.reference==reference).expect("reachable object");
let V::Reference(carrier)=owner.groups[0][0] else{assert_eq!(expected,0);return 0;};
let V::Reference(table)=get(carrier).groups[0][0] else{panic!("bucket carrier")};
let buckets=get(table);let capacity=buckets.groups.len();let mut nodes=std::collections::HashSet::new();
for (bucket,group) in buckets.groups.iter().enumerate() {
if *group==vec![V::Null,V::Null]{continue;}
let [V::Int64(tag),V::Reference(first)]=group.as_slice() else{panic!("complete bucket group")};
assert_eq!(image.registry().declarations().types[*tag as usize].name.as_deref(),Some("_MapNode<int, int>"));
let mut next=Some(*first);
while let Some(reference)=next {
assert!(nodes.insert(reference),"each node appears once, no cycles");let node=get(reference);
let V::Int64(hash)=node.groups[0][0] else{panic!("cached complete hash")};
assert_eq!(hash.rem_euclid(capacity as i64) as usize,bucket);
next=match node.groups[3][0]{V::Null=>None,V::Reference(carrier)=>{let V::Reference(value)=get(carrier).groups[0][0] else{panic!("next node carrier")};Some(value)},_=>panic!("next group")};
}
}
assert_eq!(nodes.len(),expected as usize);capacity
}
fn verify_map_refusals(root:&std::path::Path) {
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::{RuntimeLimits,RuntimeResource as Q}};
use prometeu_bytecode::{decode_next,isa::core::CoreOpCode as Op,TRAP_RESOURCE_LIMIT};
let mut node_refusal=false;let mut snapshot_refusal=false;let mut table_refusal=false;let mut guard_effect=false;
for name in ["growth","add","replace","put","remove","clear","cursor","read"] {
for suffix in ["","-optimized"] {
let bytes=std::fs::read(root.join(format!("pbs-map-refusal-{name}{suffix}.pbx"))).expect("mandatory Map resource fixture");
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
let marker=|value:i32|{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]};
let before_pc=marker(314160);let after_pc=marker(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 before=baseline.resource_snapshot();let old=map_state(&baseline,&image);let size=if name=="growth"{6}else{5};
assert_eq!(validate_map(&baseline,&image,size),8);baseline.remove_breakpoint(before_pc);
let mut successful=Vec::new();let mut max_nodes=0;let mut max_tables=0;
loop {
let objects=baseline.heap().diagnostic_typed_storage();
max_nodes=max_nodes.max(objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")).count());
max_tables=max_tables.max(objects.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),"Map {name}: {report:?}");assert!(successful.len()<200_000);
}
let after=baseline.resource_snapshot();let expected=match name{"growth"|"add"=>size+1,"remove"=>size-1,"clear"=>0,_=>size};
let capacity=validate_map(&baseline,&image,expected);
assert_eq!(capacity,if name=="growth"{16}else if name=="clear"{0}else{8});
if name=="replace"||name=="put"{let state=map_state(&baseline,&image);assert!(state.iter().any(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")&&o.groups[1]==vec![prometeu_vm::resource_diagnostics::StorageValue::Int32(1)]&&o.groups[2]==vec![prometeu_vm::resource_diagnostics::StorageValue::Int32(42)]));}
if name=="growth"{assert!(max_nodes>=13,"six old + six copied + inserted");assert!(max_tables>=2);}
if name=="read"||name=="cursor"{assert_eq!(map_state(&baseline,&image),old);}
println!("MAP PEAK {name}{suffix} nodes={max_nodes} tables={max_tables} before={:?} after={:?}",before.budget.peaks,after.budget.peaks);
let mut refusals=0;let mut structural_refusals=0;
for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::CallDepth] {
let lower=before.budget.peaks[resource as usize];let upper=after.budget.peaks[resource as usize];if lower>=upper{continue;}
let mut limits=vec![lower,lower+(upper-lower)/4,lower+(upper-lower)/2,upper-1];
if resource==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(resource,limit).unwrap());let observer=vm.resource_observer();
assert!(matches!(vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint),"Map setup {name} {resource:?}={limit}");
let original=map_state(&vm,&image);vm.remove_breakpoint(before_pc);
let (report,prefix,_)=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,"Map {name} {resource:?}={limit}: {info:?}");
let touched=prefix.iter().any(|(_,state)|map_without_guard(state.clone(),&image)!=map_without_guard(original.clone(),&image));
if !touched {assert_eq!(map_without_guard(observe_originals(&vm,&original),&image),map_without_guard(original.clone(),&image));}
if name=="cursor"{assert_eq!(map_state(&vm,&image),original);}
let now=observe_originals(&vm,&original);guard_effect|=!touched&&now!=original;
structural_refusals+=usize::from(touched);
let instruction=decode_next(info.pc as usize,image.code()).unwrap();table_refusal|=name=="growth"&&instruction.opcode==Op::ArrayNew;
if instruction.opcode==Op::StructNew {
let named=image.registry().declarations().types[instruction.imm_u32().unwrap() as usize].name.as_deref();
node_refusal|=named==Some("_MapNode<int, int>");snapshot_refusal|=named==Some("_SnapshotNode<keyval<int, int>>");
}
refusals+=1;println!("MAP PHASE REFUSAL {name}{suffix} structural={touched} resource={resource:?} limit={limit} opcode={:?}",instruction.opcode);
}else{assert!(matches!(report.reason,End::BudgetExhausted|End::Breakpoint)&&vm.pc()==after_pc);}
drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes]{assert_eq!(observer.used(q),0);}
}
}
assert!(refusals>0,"Map {name}: resource refusal evidence");
println!("MAP PHASE SUMMARY {name}{suffix} refusals={refusals} after_structural_write={structural_refusals}");
}
}
assert!(node_refusal&&snapshot_refusal&&table_refusal&&guard_effect,"nodes/snapshot/table/guard refusal evidence required");
}
fn verify_map_collection_gc(root:&std::path::Path) {
for suffix in ["","-optimized"] {verify_map_collection_gc_variant(root,suffix);}
}
fn verify_map_collection_gc_variant(root:&std::path::Path,suffix:&str) {
use prometeu_vm::LogicalFrameEndingReason as End;
let bytes=std::fs::read(root.join(format!("pbs-map-gc-collection{suffix}.pbx"))).expect("mandatory Map collection GC fixture");
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();let mut previous=0;
for (round,count) in [64,64,61,0,0].into_iter().enumerate() {
let report=vm.run_budget(30_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::FrameSync),"Map GC {round}: {report:?}");
let collections=vm.resource_snapshot().gc.collections;assert!(collections>previous);previous=collections;
let objects=vm.heap().diagnostic_typed_storage();
for name in ["_MapNode<Item, Item>","Item"] {
let actual=objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some(name)).count();assert_eq!(actual,if name=="Item"{count*2}else{count},"Map GC {round}: {name}");
}
println!("MAP COLLECTION/OLD-CANDIDATE GC PASS {suffix} round={round} live_nodes={count}");
}
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)]);
}
// Controlled test-only source instrumentation, never a production SDK algorithm.
// A quota probe is inserted after the real candidate-table store and before size.
// Natural production-quota coverage and its refusal frequencies remain separate.
fn verify_map_postpublication_injection(root:&std::path::Path) {
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::{RuntimeLimits,RuntimeResource as Q},resource_diagnostics::StorageValue as V};
use prometeu_bytecode::{decode_next,isa::core::CoreOpCode as Op,TRAP_RESOURCE_LIMIT};
for suffix in ["","-optimized"] {
let bytes=std::fs::read(root.join(format!("pbs-map-injected-refusal-growth{suffix}.pbx"))).expect("explicit test-only post-publication injection");
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
let limits=RuntimeLimits::default().lowered(Q::GuestBytes,500_000).unwrap();
let mut vm=VirtualMachine::from_image(image.clone(),limits);let observer=vm.resource_observer();vm.prepare_boot_call().unwrap();
let mut found=false;
for _ in 0..200_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 state=map_state(&vm,&image);
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).unwrap();
assert_eq!(owner.groups[1],vec![V::Int64(6)]);assert_eq!(owner.groups[3],vec![V::Boolean(true)]);
assert_eq!(state.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")).count(),7);
assert!(state.iter().any(|o|matches!(image.registry().declarations().types[o.type_id.0 as usize].kind,prometeu_bytecode::registry::TypeKind::Array(_))&&o.groups.len()==16));
let input=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-publication injection: {report:?}")};assert_eq!(info.code,TRAP_RESOURCE_LIMIT);
assert_eq!(vm.heap().diagnostic_typed_storage(),original,"refused probe preserves its entry state, retaining earlier table publication");
assert_eq!(vm.operand_stack_top(1),input);
println!("MAP TEST-ONLY POST-PUBLICATION QUOTA INJECTION PASS {suffix}: new table=16 nodes=7 old size=6 guard=true");found=true;break;
}
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::BudgetExhausted),"before injection: {report:?}");
}
assert!(found);drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes]{assert_eq!(observer.used(q),0);}
}
}
fn verify_pbs_map_fixtures(root:&std::path::Path) {
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::RuntimeResource as Q};
let successes=["basic","optional","scalars","objects","references","content","collisions","arithmetic",
"tuple","native","pixel","random","cursor-empty","cursor-single","snapshot","evaluation","callback-reads"];
let faults=(1..=7).map(|n|(format!("fault-callback-{n}"),if n==7{prometeu_bytecode::TRAP_DIV_ZERO}else{prometeu_bytecode::TRAP_EXPLICIT}))
.chain((1..=7).map(|n|(format!("fault-equals-{n}"),if n==7{prometeu_bytecode::TRAP_DIV_ZERO}else{prometeu_bytecode::TRAP_EXPLICIT})))
.chain(std::iter::once(("fault-overflow".to_string(),prometeu_bytecode::TRAP_EXPLICIT)));
let mut count=0;
for (base,fault) in successes.into_iter().map(|n|(n.to_string(),None)).chain(faults.map(|(n,f)|(n,Some(f)))) {
for suffix in ["","-optimized"] {
let name=format!("{base}{suffix}");let bytes=std::fs::read(root.join(format!("pbs-map-{name}.pbx"))).unwrap_or_else(|e|panic!("mandatory Map {name}: {e}"));
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap_or_else(|e|panic!("Map {name}: {e:?}"));
let registry=image.registry().clone();let mut vm=VirtualMachine::from_image(image,Default::default());let observer=vm.resource_observer();
vm.prepare_boot_call().unwrap();let report=vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
if let Some(code)=fault {
let End::Trap(info)=report.reason else{panic!("{name}: {report:?}")};assert_eq!(info.code,code,"{name}: {info:?}");
if base.starts_with("fault-callback")||base.starts_with("fault-equals") {
use prometeu_vm::resource_diagnostics::StorageValue as V;
let objects=vm.heap().diagnostic_typed_storage();
let owner=objects.iter().find(|o|registry.declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).expect("faulted Map retained");
let populated=base.starts_with("fault-equals");
assert_eq!(owner.groups[1],vec![V::Int64(if populated{1}else{0})]);assert_eq!(owner.groups[3],vec![V::Boolean(true)]);
if populated{assert!(objects.iter().any(|o|registry.declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")&&o.groups[1]==vec![V::Int32(0)]&&o.groups[2]==vec![V::Int32(20)]));}
else{assert_eq!(owner.groups[0],vec![V::Null]);}
}
} else {assert!(matches!(report.reason,End::Halted|End::EndOfRom),"{name}: {report:?}");assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)],"{name}");}
drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations]{assert_eq!(observer.used(q),0,"{name}: owner release {q:?}");}
count+=1;println!("MAP SOURCE/LOAD/EXEC/GUARD PASS {name}");
}
}
println!("MAP MANDATORY SOURCE CASES {count}");
verify_map_refusals(root);verify_map_postpublication_injection(root);verify_map_cursor_gc(root);verify_map_collection_gc(root);verify_map_distribution(root);
}
fn verify_map_cursor_gc(root:&std::path::Path) {
for suffix in ["","-optimized"] {verify_map_cursor_gc_variant(root,suffix);}
}
fn verify_map_cursor_gc_variant(root:&std::path::Path,suffix:&str) {
use prometeu_vm::LogicalFrameEndingReason as End;
let bytes=std::fs::read(root.join(format!("pbs-map-gc{suffix}.pbx"))).expect("mandatory Map snapshot GC fixture");
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();let mut previous=0;
for (round,count) in [1200,1,1,0].into_iter().enumerate() {
let report=vm.run_budget(100_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::FrameSync),"Map cursor GC {round}: {report:?}");
let snapshot=vm.resource_snapshot();assert!(snapshot.gc.collections>previous);previous=snapshot.gc.collections;
let objects=vm.heap().diagnostic_typed_storage();
assert!(!objects.iter().any(|o|matches!(image.registry().declarations().types[o.type_id.0 as usize].kind,prometeu_bytecode::registry::TypeKind::Array(_))),"snapshot retains no Map table");
for (name,expected) in [("_SnapshotNode<keyval<Item, Item>>",count),("keyval<Item, Item>",count),("Item",count*2),("_MapNode<Item, Item>",0)] {
assert_eq!(objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some(name)).count(),expected,"Map cursor GC {round}: {name}");
}
println!("MAP CURSOR/KEYVAL/KEY/VALUE GC PASS {suffix} round={round} nodes={count} items={}",count*2);
}
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)]);
}
fn verify_map_distribution(root:&std::path::Path) {
use prometeu_vm::{LogicalFrameEndingReason as End,resource_diagnostics::StorageValue as V};
for name in ["imports","installed"] {
let bytes=std::fs::read(root.join(format!("pbs-map-{name}.pbx"))).expect("mandatory Map workspace/installed example");
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
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),"Map distribution {name}: {report:?}");
let objects=vm.heap().diagnostic_typed_storage();
let cursors=objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_SnapshotCursor<keyval<str, optional int>>")).collect::<Vec<_>>();
assert!(!cursors.is_empty(),"installed/imported Map actually constructs the common entry Cursor");
let get=|r|objects.iter().find(|o|o.reference==r).unwrap();
for cursor in cursors {
let V::Reference(carrier)=cursor.groups[0][0] else{panic!("current carrier")};let V::Reference(node)=get(carrier).groups[0][0] else{panic!("node")};
assert_eq!(get(node).groups[1],vec![V::Null],"complete traversal retains sticky final node");
let V::Reference(entry)=get(node).groups[0][0] else{panic!("captured keyval")};
assert_eq!(image.registry().declarations().types[get(entry).type_id.0 as usize].name.as_deref(),Some("keyval<str, optional int>"));
}
println!("MAP DISTRIBUTION SOURCE/LOAD/EXEC PASS {name}");
}
}
+2 -1
View File
@@ -13,6 +13,7 @@ parser.add_argument("--fixtures", type=pathlib.Path, default=pathlib.Path("prome
parser.add_argument("--online", action="store_true", help="Allow Cargo to fetch uncached dependencies")
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("--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")
@@ -58,4 +59,4 @@ 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"), *(["--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)
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)