feat(pbs): add Set and reusable identity hashing
This commit is contained in:
@@ -15,7 +15,7 @@ The Java tests generate PBX in the build-pipeline module's
|
||||
`build/registry-conformance`. `run.py` creates a temporary Cargo project, copies
|
||||
the runtime lockfile and references its bytecode/hal/vm/system crates by path.
|
||||
It never modifies the runtime checkout. Add `--online` for an uncached machine;
|
||||
by default Cargo uses only cached dependencies. Java 25, Rust and the runtime
|
||||
by default Cargo uses only cached dependencies. Java 21, Rust and the runtime
|
||||
checkout's dependencies are required.
|
||||
|
||||
The output identifies runtime revision, OS/architecture and load configuration.
|
||||
@@ -304,3 +304,60 @@ Evidence prints consumer/provider source hashes, selected revision and clean sta
|
||||
toolchain/platform/profile, lockfile/catalog hashes, capabilities, default ceilings
|
||||
and lowered refusal limits. Keep new qualification separate from historical List/
|
||||
Linked evidence; prior successful providers are not relabeled as the new target.
|
||||
|
||||
## PBS hashing, Identity and Set
|
||||
|
||||
`IdentityHashingPipelineTest` qualifies neutral 0x97/0x98 production, complete
|
||||
concrete/Trait groups and both optimizer paths. It also emits malformed-category,
|
||||
right-TypeId, unknown-TypeId, dead-code, partial-group and truncated fixtures.
|
||||
Unknown global inputs in two neutral cases reach production runtime validation:
|
||||
an absent/different left cannot hide the invalid complete right view. Refusal
|
||||
retains all three input slots, charges seven cycles and executes zero successful
|
||||
query steps; zero budget executes nothing.
|
||||
|
||||
`PbsIdentityHashingTest` selects all 30 scalar/String rows from the unchanged
|
||||
118-row independent provider C XXH64 oracle. Both producer paths preserve exact
|
||||
signed digest bits and attempted costs. Separate source fixtures qualify Struct,
|
||||
Array, Fn, Random, complete contracts, mutation, aliases and discarded scalar and
|
||||
reference results. The reference-query source gate ran before Set algorithm work.
|
||||
The consumer oracle copy is checked against the selected provider on every
|
||||
explicit harness invocation. Ordinary Gradle compilation uses local resources.
|
||||
|
||||
`PbsSetTest` exercises the complete source API, contextual/default/explicit
|
||||
construction, optional/default diagnostics, nominal origin, shared complete values,
|
||||
content opt-in, collisions, exact growth arithmetic, callbacks, aliases and Cursor.
|
||||
Counter strategies demonstrate that rehash and capture do not call hash/equals.
|
||||
SDK aliases, generic-function reexports and installed examples compile through
|
||||
actual workspace builders; installed compilation uses only installDist JARs in an
|
||||
external directory and writes mandatory PBX fixtures for runtime execution.
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-compiler:prometeu-build-pipeline:test --tests '*IdentityHashingPipelineTest'
|
||||
./gradlew :prometeu-architecture-tests:test --tests '*PbsIdentityHashingTest' --tests '*PbsSetTest'
|
||||
./gradlew :prometeu-app:installedKnowledgeTest
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-target python3 tools/pbx-conformance/run.py --runtime ../runtime --identity-hashing-only
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-target python3 tools/pbx-conformance/run.py --runtime ../runtime --set-only
|
||||
```
|
||||
|
||||
The Set quota corpus measures old/candidate coexistence and compares every
|
||||
original-object instruction prefix with a successful run. It treats guard writes
|
||||
separately from structural writes. Natural quota cases cover insertion, growth,
|
||||
duplicate inclusion, removal, clear and capture with no claim that all failures
|
||||
preserve the entire Set or that every theoretical failure boundary occurs at the
|
||||
sampled limits. Current natural runs refuse before structural mutation; this is
|
||||
reported explicitly by their summaries.
|
||||
|
||||
A **separate test-only instrumented source fixture** inserts a controlled Array
|
||||
allocation after the real candidate-table store and before size assignment. A
|
||||
lowered guest quota refuses that probe. The old size six, new table capacity 16,
|
||||
seven reachable nodes and active guard remain, while the refused instruction
|
||||
preserves its own entry state. This demonstrates the post-publication failure
|
||||
boundary; it is not a production SDK allocation, callback, algorithm or claim about
|
||||
natural refusal frequency. Its ordinary/optimized fixtures are named
|
||||
`pbs-set-injected-refusal-growth*` and are generated from an in-memory SDK copy.
|
||||
|
||||
Real safepoints qualify source Set node/candidate release, removal/clear, snapshot
|
||||
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.
|
||||
|
||||
@@ -41,6 +41,8 @@ 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 == "--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; }
|
||||
if std::env::args().any(|arg| arg == "--list-cursor-only") { verify_common_storage_fixtures(&root); verify_pbs_list_cursor_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--generic-contracts-only") { verify_pbs_generic_contract_fixtures(&root); return; }
|
||||
@@ -49,6 +51,7 @@ fn main() {
|
||||
verify_pbs_math_fixtures(&root);
|
||||
if std::env::args().any(|arg| arg == "--math-only") { return; }
|
||||
verify_pbs_random_fixtures(&root);
|
||||
verify_identity_hashing_fixtures(&root);
|
||||
verify_catalog_fixtures(&root);
|
||||
verify_pbs_fixtures(&root);
|
||||
verify_pbs_structured_fixtures(&root);
|
||||
@@ -57,6 +60,7 @@ fn main() {
|
||||
verify_common_storage_fixtures(&root);
|
||||
verify_pbs_list_cursor_fixtures(&root);
|
||||
verify_pbs_linked_fixtures(&root);
|
||||
verify_pbs_set_fixtures(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
verify_pbs_closure_frames(&root);
|
||||
for name in [
|
||||
@@ -497,7 +501,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-") || 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-") || 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)
|
||||
@@ -1236,8 +1240,9 @@ fn verify_collection_cursor_gc(root:&std::path::Path,collection:&str) {
|
||||
let named=|name:&str|objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some(name)).collect::<Vec<_>>();
|
||||
assert_eq!(named("_SnapshotNode<Item>").len(),nodes,"prefix nodes round {round}");
|
||||
if collection=="linked" {assert!(named("_LinkedNode<Item>").is_empty(),"snapshot does not retain original Linked nodes");}
|
||||
if collection=="set" {assert!(named("_SetNode<Item>").is_empty(),"snapshot does not retain original Set nodes");}
|
||||
let values=named("Item");assert_eq!(values.len(),items,"captured object roots round {round}");
|
||||
if items==1 {assert_eq!(values[0].groups[0],[V::Int32(1199)],"sticky last payload remains live");}
|
||||
if items==1 && collection!="set" {assert_eq!(values[0].groups[0],[V::Int32(1199)],"sticky last payload remains live");}
|
||||
println!("PBS {} CURSOR GC PASS round={round} nodes={nodes} items={items} collected={}",collection.to_uppercase(),snapshot.gc.reclaimed);
|
||||
}
|
||||
let report=vm.run_budget(100_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
@@ -1355,7 +1360,9 @@ fn verify_collection_distribution(root:&std::path::Path,collection:&str,last:i32
|
||||
}
|
||||
retained.sort_unstable();
|
||||
let expected=if collection=="linked"&&name=="installed" {vec![20,22]} else {vec![last]};
|
||||
assert_eq!(retained,expected,"{collection} {name}: complete traversal retains each final value");
|
||||
if collection=="set" {
|
||||
assert_eq!(retained.len(),1);assert!([20,22].contains(&retained[0]),"Set has no order guarantee");
|
||||
}else{assert_eq!(retained,expected,"{collection} {name}: complete traversal retains each final value");}
|
||||
println!("PBS {} DISTRIBUTION LOAD/EXEC PASS {name}",collection.to_uppercase());
|
||||
}
|
||||
}
|
||||
@@ -1509,3 +1516,316 @@ fn verify_linked_collection_gc(root:&std::path::Path) {
|
||||
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_identity_hashing_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
use prometeu_bytecode::{isa::core::CoreOpCode as Op,registry::TypeId};
|
||||
let corpus=std::fs::read_to_string(root.join("hash-vectors.tsv")).expect("mandatory hashing oracle manifest");
|
||||
let mut originals=std::collections::BTreeMap::new();let mut count=0;
|
||||
for row in corpus.lines() {
|
||||
let parts:Vec<_>=row.split_whitespace().collect();let name=parts[0];
|
||||
let expected=u64::from_str_radix(parts[1],16).unwrap() as i64;
|
||||
let id:u32=parts[2].parse().unwrap();let cost:u64=parts[3].parse().unwrap();
|
||||
let bytes=std::fs::read(root.join(format!("{name}.pbx"))).unwrap();
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let code=image.code().to_vec();let mut vm=VirtualMachine::from_image(image,Default::default());
|
||||
vm.prepare_boot_call().unwrap();let mut total=0;let mut calls=0;
|
||||
loop {
|
||||
let pc=vm.pc();let op=Op::try_from(u16::from_le_bytes(code[pc..pc+2].try_into().unwrap())).unwrap();
|
||||
let charge=if op==Op::Intrinsic {
|
||||
assert_eq!(u32::from_le_bytes(code[pc+2..pc+6].try_into().unwrap()),id,"{name}");
|
||||
let before=vm.operand_stack_top(1).to_vec();let zero=vm.run_budget(0,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert_eq!((vm.pc(),zero.cycles_used,zero.steps_executed),(pc,0,0));
|
||||
assert_eq!(vm.operand_stack_top(1),before);calls+=1;cost
|
||||
}else{op.cycles()};
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert_eq!(report.cycles_used,charge,"{name} at {pc}");total+=charge;
|
||||
if matches!(report.reason,End::EndOfRom|End::Halted){break;}
|
||||
assert!(matches!(report.reason,End::BudgetExhausted),"{name}: {report:?}");
|
||||
assert!(total<100_000);
|
||||
}
|
||||
assert_eq!(calls,1,"{name}");assert_eq!(vm.operand_stack_top(1),vec![Value::Int64(expected)],"{name}");
|
||||
if let Some(base)=name.strip_suffix("-optimized") {assert_eq!(originals.get(base),Some(&total),"{name}: optimizer charging");}
|
||||
else{originals.insert(name.to_string(),total);}
|
||||
println!("HASH ORACLE/COST/FUEL PASS {name} result={expected} cycles={total}");count+=1;
|
||||
}
|
||||
assert_eq!(count,60,"all 30 source scalar/String vectors in both optimizer paths");
|
||||
for prefix in ["common-identity","pbs-hash-object","pbs-hash-contract","pbs-hash-array","pbs-hash-function","pbs-hash-random","pbs-hash-discard","pbs-hash-discard-reference"] {
|
||||
for suffix in ["","-optimized"] {
|
||||
let name=format!("{prefix}{suffix}");let bytes=std::fs::read(root.join(format!("{name}.pbx"))).expect("mandatory identity fixture");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap_or_else(|e|panic!("{name}: {e:?}"));
|
||||
let code=image.code().to_vec();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 mut steps=0;let mut queries=0;
|
||||
loop {
|
||||
let pc=vm.pc();let op=Op::try_from(u16::from_le_bytes(code[pc..pc+2].try_into().unwrap())).unwrap();
|
||||
let width=|at:usize|registry.type_layout(TypeId(u32::from_le_bytes(code[at..at+4].try_into().unwrap()))).unwrap().storage.slots as u64;
|
||||
let charge=match op {Op::RefIdentityHash=>Some(8+width(pc+2)),Op::RefIdentityEq=>Some(4+width(pc+2)+width(pc+6)),_=>None};
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
if let Some(charge)=charge {queries+=1;assert_eq!(report.cycles_used,charge,"{name}: typed query charge");}
|
||||
if matches!(report.reason,End::EndOfRom|End::Halted){break;}
|
||||
assert!(matches!(report.reason,End::BudgetExhausted),"{name}: {report:?}");steps+=1;assert!(steps<100_000);
|
||||
}
|
||||
if prefix=="pbs-hash-discard-reference"{assert_eq!(queries,2,"unused reference queries retain charged work");}
|
||||
let expected=if prefix=="common-identity"{Value::Boolean(true)}else{Value::Int32(42)};
|
||||
assert_eq!(vm.operand_stack_top(1),vec![expected],"{name}");drop(vm);
|
||||
for resource in [prometeu_vm::resource_budget::RuntimeResource::GuestBytes,prometeu_vm::resource_budget::RuntimeResource::HandleSlots,prometeu_vm::resource_budget::RuntimeResource::StringBytes] {
|
||||
assert_eq!(observer.used(resource),0,"{name}: owner release");
|
||||
}
|
||||
println!("IDENTITY COMPLETE GROUP/ALIAS/COST PASS {name}");
|
||||
}
|
||||
}
|
||||
verify_identity_negative_fixtures(root);
|
||||
|
||||
}
|
||||
|
||||
|
||||
fn verify_pbs_set_fixtures(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::RuntimeResource as Q};
|
||||
let successes=["basic","construction","arithmetic","scalars","objects","collisions","content","tuple",
|
||||
"cursor-empty","cursor-single","snapshot","callback-reads","references","random","vec2","pixel","evaluation","contract-snapshot","string-snapshot","false-snapshot"];
|
||||
let faults=[("fault-callback-1",prometeu_bytecode::TRAP_EXPLICIT),("fault-callback-2",prometeu_bytecode::TRAP_EXPLICIT),
|
||||
("fault-callback-3",prometeu_bytecode::TRAP_EXPLICIT),("fault-callback-4",prometeu_bytecode::TRAP_EXPLICIT),
|
||||
("fault-callback-5",prometeu_bytecode::TRAP_DIV_ZERO),("fault-overflow",prometeu_bytecode::TRAP_EXPLICIT)];
|
||||
for (base,fault) in successes.into_iter().map(|n|(n,None)).chain(faults.into_iter().map(|(n,f)|(n,Some(f)))) {
|
||||
for suffix in ["","-optimized"] {
|
||||
let name=format!("{base}{suffix}");let bytes=std::fs::read(root.join(format!("pbs-set-{name}.pbx"))).unwrap_or_else(|e|panic!("mandatory Set {name}: {e}"));
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap_or_else(|e|panic!("Set {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(10_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") {
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
let set=objects.iter().find(|o|registry.declarations().types[o.type_id.0 as usize].name.as_deref()==Some("set<int>")).expect("faulted Set retained");
|
||||
assert_eq!(set.groups[0],vec![V::Null],"{name}: unpublished buckets");
|
||||
assert_eq!(set.groups[1],vec![V::Int64(0)],"{name}: old size");
|
||||
assert_eq!(set.groups[3],vec![V::Boolean(true)],"{name}: guard is not cleaned after fault");
|
||||
}
|
||||
}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 resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations] {
|
||||
assert_eq!(observer.used(resource),0,"{name}: final resource release {resource:?}");
|
||||
}
|
||||
println!("SET SOURCE/LOAD/EXEC/GUARD PASS {name}");
|
||||
}
|
||||
}
|
||||
verify_set_refusals(root);
|
||||
verify_set_postpublication_injection(root);
|
||||
verify_collection_cursor_gc(root,"set");
|
||||
verify_set_collection_gc(root);
|
||||
verify_collection_distribution(root,"set",0);
|
||||
verify_installed_hash(root);
|
||||
|
||||
}
|
||||
|
||||
|
||||
fn set_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("set<int>")).expect("source Set");
|
||||
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 Set 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 set_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("set<int>") {
|
||||
object.groups[3]=vec![prometeu_vm::resource_diagnostics::StorageValue::Boolean(false)];
|
||||
}
|
||||
}
|
||||
state
|
||||
}
|
||||
fn validate_set(vm:&VirtualMachine,image:&ValidatedProgramImage,expected:i64)->usize {
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
let state=set_state(vm,image);
|
||||
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("set<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("_SetNode<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[2][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_set_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","duplicate","remove","clear","cursor"] {
|
||||
for suffix in ["","-optimized"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-set-refusal-{name}{suffix}.pbx"))).expect("mandatory Set 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=set_state(&baseline,&image);let size=if name=="growth"{6}else{5};
|
||||
assert_eq!(validate_set(&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("_SetNode<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),"Set {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_set(&baseline,&image,expected);
|
||||
assert_eq!(capacity,if name=="growth"{16}else if name=="clear"{0}else{8});
|
||||
if name=="growth"{assert!(max_nodes>=13,"six old + six copied + inserted");assert!(max_tables>=2);}
|
||||
if name=="duplicate"||name=="cursor"{assert_eq!(set_state(&baseline,&image),old);}
|
||||
println!("SET 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),"Set setup {name} {resource:?}={limit}");
|
||||
let original=set_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,"Set {name} {resource:?}={limit}: {info:?}");
|
||||
let touched=prefix.iter().any(|(_,state)|set_without_guard(state.clone(),&image)!=set_without_guard(original.clone(),&image));
|
||||
if !touched {assert_eq!(set_without_guard(observe_originals(&vm,&original),&image),set_without_guard(original.clone(),&image));}
|
||||
if name=="cursor"{assert_eq!(set_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("_SetNode<int>");snapshot_refusal|=named==Some("_SnapshotNode<int>");
|
||||
}
|
||||
refusals+=1;println!("SET 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,"Set {name}: resource refusal evidence");
|
||||
println!("SET 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_set_collection_gc(root:&std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let bytes=std::fs::read(root.join("pbs-set-gc-collection.pbx")).expect("mandatory Set 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,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),"Set 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 ["_SetNode<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,count,"Set GC {round}: {name}");
|
||||
}
|
||||
println!("SET COLLECTION/OLD-CANDIDATE GC PASS 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_set_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-set-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=set_state(&vm,&image);
|
||||
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("set<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("_SetNode<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!("SET 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_identity_negative_fixtures(root:&std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
use prometeu_bytecode::{decode_next,isa::core::CoreOpCode as Op};
|
||||
for base in ["bad-category","bad-right","dead-bad-category","bad-typeid"] {
|
||||
for suffix in ["","-optimized"] {
|
||||
let name=format!("common-identity-{base}{suffix}");let bytes=std::fs::read(root.join(format!("{name}.pbx"))).unwrap();
|
||||
assert!(ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).is_err(),"{name}");
|
||||
println!("IDENTITY NEUTRAL ADMISSION REJECT PASS {name}");
|
||||
}
|
||||
}
|
||||
for base in ["partial","truncated"] {
|
||||
let bytes=std::fs::read(root.join(format!("common-identity-{base}.pbx"))).unwrap();
|
||||
assert!(ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).is_err());
|
||||
println!("IDENTITY PARTIAL/TRUNCATED ADMISSION REJECT PASS {base}");
|
||||
}
|
||||
for base in ["null-views","right-after-null","right-after-distinct"] {
|
||||
let bytes=std::fs::read(root.join(format!("common-identity-{base}.pbx"))).unwrap();
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap_or_else(|e|panic!("{base}: {e:?}"));
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();
|
||||
loop {
|
||||
let instruction=decode_next(vm.pc(),image.code()).unwrap();
|
||||
if instruction.opcode==Op::RefIdentityEq {
|
||||
let operands=vm.operand_stack_top(3).to_vec();
|
||||
let zero=vm.run_budget(0,&mut NoNative,&mut HostContext::new(None)).unwrap();assert_eq!((zero.cycles_used,zero.steps_executed),(0,0));
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();assert_eq!(report.cycles_used,7);
|
||||
if base=="null-views" {
|
||||
assert!(matches!(report.reason,End::BudgetExhausted));assert_eq!(vm.operand_stack_top(1),vec![Value::Boolean(true)]);
|
||||
}else {
|
||||
let End::Trap(info)=report.reason else{panic!("{base}: right validation was skipped: {report:?}")};
|
||||
assert_eq!(info.code,prometeu_bytecode::TRAP_TYPE);assert_eq!(report.steps_executed,0);assert_eq!(vm.operand_stack_top(3),operands);
|
||||
}
|
||||
println!("IDENTITY COMPLETE RIGHT/NULL/FUEL/COST PASS {base}");break;
|
||||
}
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::BudgetExhausted));
|
||||
}
|
||||
}
|
||||
}
|
||||
fn verify_installed_hash(root:&std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let bytes=std::fs::read(root.join("pbs-hash-installed.pbx")).expect("mandatory installed hashing example");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image,Default::default());vm.prepare_boot_call().unwrap();
|
||||
let report=vm.run_budget(1_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason,End::FrameSync|End::Halted|End::EndOfRom),"installed hashing: {report:?}");
|
||||
println!("HASH INSTALLED JAR/SDK/EXAMPLE LOAD/EXEC PASS");
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ parser.add_argument("--runtime", type=pathlib.Path, default=pathlib.Path("../run
|
||||
parser.add_argument("--fixtures", type=pathlib.Path, default=pathlib.Path("prometeu-compiler/prometeu-build-pipeline/build/registry-conformance"))
|
||||
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("--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")
|
||||
parser.add_argument("--generic-contracts-only", action="store_true", help="Run the mandatory generic-contract source corpus only")
|
||||
@@ -25,6 +27,10 @@ if not args.math_only:
|
||||
consumer_vectors = pathlib.Path("prometeu-architecture-tests/src/test/resources/random/random-conformance.tsv")
|
||||
if provider_vectors.read_bytes() != consumer_vectors.read_bytes():
|
||||
raise SystemExit("Random oracle differs from the selected provider; update provenance and requalify")
|
||||
provider_hash_vectors = runtime / "crates/console/prometeu-vm/tests/fixtures/hash-conformance.tsv"
|
||||
consumer_hash_vectors = pathlib.Path("prometeu-architecture-tests/src/test/resources/hash/hash-conformance.tsv")
|
||||
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("prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsRuntimeRandomTest.java"),
|
||||
@@ -52,4 +58,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"), *(["--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"), *(["--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)
|
||||
|
||||
Reference in New Issue
Block a user