refactor(compiler)!: migrate SDK to minimal storage ISA
Replace retired guards and publication opcodes with SDK checks, neutral TRAP and sequential List/Linked mutations with explicit failure phases. Preserve snapshot cursors and import schema 2 metadata with the delivered provider pin. Include common/source/installed conformance, debug and release evidence, synchronized specs and the consolidated lesson. Runtime checkout remains unchanged.
This commit is contained in:
@@ -226,71 +226,81 @@ The full harness also requires these fixtures. The driver uses an external
|
||||
runtime checkout without editing its sources or changing PBX, ISA or quotas.
|
||||
|
||||
|
||||
## SDK List, shared Cursor and generic storage
|
||||
## Minimal storage ISA, SDK collections and phase-aware refusals
|
||||
|
||||
Generate the source corpus and the language-neutral storage fixtures, then run:
|
||||
Generate common/source fixtures and the real installed-JAR examples, then run:
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-compiler:prometeu-build-pipeline:test :prometeu-architecture-tests:test :prometeu-app:installedKnowledgeTest
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime --list-cursor-only
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-conformance python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-conformance python3 tools/pbx-conformance/run.py --runtime ../runtime --release
|
||||
```
|
||||
|
||||
The full harness also requires this corpus. Missing ordinary, optimized, quota,
|
||||
GC, import/reexport or installed-JAR fixtures fail explicitly. Two synthetic
|
||||
common-IR programs execute INDEX_GUARD, ARRAY_CHECK_LENGTH, ARRAY_COPY and
|
||||
STORAGE_PUBLISH through ordinary and optimized producer paths without PBS types.
|
||||
List source cases cover every mutator, exact growth, logical versus physical
|
||||
bounds, int/long arguments (including named application), holes, aliases,
|
||||
vec2/pixel/tuple/Fn/contract/reference groups and every state of a Cursor that remains on its last node.
|
||||
An independent producer distinguishes some(none) from an empty Cursor.
|
||||
Focused `--list-cursor-only` and `--linked-only` modes include mandatory neutral
|
||||
storage/copy/terminal/admission fixtures as well as their collection corpus. The
|
||||
complete run requires both. No runtime source, manifest, lockfile or target
|
||||
artifact is modified: the Cargo harness and target live outside that checkout.
|
||||
|
||||
Four source-generated mutation fixtures expose explicit before/completed markers.
|
||||
The harness lowers GuestBytes, HandleSlots, AuxiliaryBytes and TemporaryBytes from
|
||||
measured setup/success peaks. After each refused attempt it independently observes
|
||||
all List fields and complete backing groups, including reference generations and
|
||||
presence tags. Coverage gates require refusals in no-growth publication scratch,
|
||||
removeAt optional return allocation, candidate allocation, node construction and
|
||||
operand/frame preparation. Read-only resource diagnostics use non-owning storage
|
||||
observations outside guest execution; no observation introduces a GC root or write.
|
||||
The selected provider supports ARRAY_LEN and ARRAY_COPY, ordinary typed stores
|
||||
and terminal TRAP. Four dead-code fixtures prove that 0xA7/0xA8/0xAA/0xAB reject
|
||||
at real instruction positions; corresponding Int32-immediate fixtures must load.
|
||||
All producer-opcode checks decode instruction boundaries rather than scanning
|
||||
raw PBX bytes. Neutral ordinary/optimized programs qualify stores and copy without
|
||||
PBS types. A store followed by TRAP_EXPLICIT proves that terminal failure retains
|
||||
previous effects and source spans survive lowering/optimization.
|
||||
|
||||
The controlled safepoint fixture expects 1,200 nodes/objects initially, one after
|
||||
traversal, one after repeated next on the final node, and zero after releasing the
|
||||
Cursor. It also requires no live source/snapshot array. Shared payload fields stay
|
||||
observable; prefix roots and the final payload obey normal reachability and GC.
|
||||
The installed fixture is compiled by the isolated installDist JVM using the actual
|
||||
packaged spec/example/SDK, then loaded and executed by this production VM harness.
|
||||
Eleven paired neutral copy cases independently check scalar/vec2/String groups,
|
||||
snapshot overlap, empty ranges, bad ranges/receivers, negative/above-u32 counts
|
||||
and fault precedence. At the actual copy PC, zero budget executes nothing;
|
||||
positive budget admits a complete attempt with overshoot. N=10/W=1 costs 24,
|
||||
including receiver/range/scratch refusal; W=2 costs 44. Invalid or empty counts
|
||||
cost base 4 as defined by the provider. Refusals preserve the five operands and
|
||||
previous storage, release scratch and do not count a successful step. Native
|
||||
String owners release with the session. Checked cost-overflow defenses requiring
|
||||
synthetic internal widths are provider evidence, not an assertion that admitted
|
||||
consumer layouts can attain those widths.
|
||||
|
||||
Evidence prints compiler/provider source hashes, exact provider revision and dirty
|
||||
state, toolchain, platform/profile, capabilities, every default VM ceiling and each
|
||||
explicitly lowered refusal limit. Development runs against a dirty provider are
|
||||
identified as such; final catalog verification requires its clean selected commit.
|
||||
List source fixtures cover every mutator, exact growth, logical versus physical
|
||||
bounds, int/long and named evaluation, holes, aliases and complete native/tuple/
|
||||
Fn/contract/reference groups. Linked fixtures cover empty/single/multiple states,
|
||||
reciprocal links, nearest-end lookup, complete values and both snapshot orders.
|
||||
Logical SDK refusals now produce TRAP_EXPLICIT; physical instructions retain
|
||||
their own faults. No missing ordinary or optimized fixture is silently skipped.
|
||||
|
||||
Four List and ten Linked source-generated mutation boundaries have normal and
|
||||
optimized variants. GuestBytes, HandleSlots, AuxiliaryBytes and TemporaryBytes
|
||||
ceilings are lowered from measured setup/success peaks. Non-owning diagnostic
|
||||
observations inspect the original collection objects independently of guest code.
|
||||
Every instruction prefix is compared with the corresponding successful prefix.
|
||||
A refused instruction preserves its own observable entry state. Before visible
|
||||
mutation the entire old collection must remain unchanged; after mutation the
|
||||
previous successful writes remain, without a whole-method rollback or safe-reuse
|
||||
claim. Successful single-instruction-budget traversal also qualifies suspension
|
||||
and resumption in the middle of a source method. Snapshot capture failures must
|
||||
always preserve their source and expose no partial result.
|
||||
|
||||
## SDK Linked and multi-object publication
|
||||
No-growth insertion prepares a one-slot private array before shifting and copies
|
||||
that complete stored group into place; candidate/optional/result and operand/
|
||||
frame preparation remain charged. ARRAY_COPY scratch remains a mandatory observed
|
||||
refusal. Linked prepares nodes/results before its sequential link updates. The
|
||||
corpus retains explicit coverage requirements for these resource refusal paths;
|
||||
it does not rename old publication guarantees as new evidence.
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-compiler:prometeu-build-pipeline:test :prometeu-architecture-tests:test :prometeu-app:installedKnowledgeTest
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime --linked-only
|
||||
```
|
||||
Normal GC safepoints qualify removed nodes and payloads, collection clear,
|
||||
snapshot independence, consumed-prefix reclamation and sticky final values.
|
||||
The Cursor fixture requires 1,200 -> 1 -> 1 -> 0 snapshot nodes/payloads, with no
|
||||
live source/snapshot array. Linked captures must not retain editable source nodes.
|
||||
The actual installed SDK/spec/example is compiled outside the checkout and its
|
||||
PBX is loaded/executed by the production VM; import/reexport fixtures also run.
|
||||
|
||||
The full harness requires this corpus too. Ordinary and optimized source programs
|
||||
exercise the complete Linked API, both snapshot orders, empty/single/multiple
|
||||
states, reciprocal links, identities and full native/tuple/contract/Fn groups,
|
||||
logical and long bounds, contextual construction and source/named evaluation.
|
||||
Neutral common-IR fixtures execute FIELDS_PUBLISH without PBS or collection types.
|
||||
Catalog schema 2 is imported with all 25 fields, per-entry nullable masks,
|
||||
explicit invocation/scratch/context profiles and cost parameters. Ordinary parity
|
||||
and rejection tests need no runtime checkout. Explicit exporter verification uses
|
||||
`tools/runtime-catalog/verify.py` and the selected clean SHA/digests. Nullable
|
||||
hash.string metadata is qualified independently of older non-nullable String
|
||||
entries; importing it does not deliver PBS hashing facades or Set/Map.
|
||||
|
||||
Ten explicit mutation boundaries qualify every mutation and both captures. The
|
||||
harness lowers resource ceilings around measured setup/success peaks and compares
|
||||
all prior Linked roots, optional-link carriers, nodes and complete groups after
|
||||
each refusal. Node allocation, optional removed-value preparation, snapshot-node
|
||||
allocation and frame/operand preparation must all produce observed refusals.
|
||||
Publication itself uses no allocation or scratch; provider tests prove it succeeds
|
||||
at already exhausted allocation ceilings and rejects late invalid groups before
|
||||
any write, including for null destinations and aliased targets.
|
||||
|
||||
Normal GC safepoints qualify removal/clear without snapshots (1,200 → 1,197 → 0
|
||||
nodes and payloads), and snapshot traversal (1,200 → 1 → 1 → 0). Fixtures introduce
|
||||
ordinary garbage pressure so every asserted round performs an actual collection.
|
||||
Snapshots retain no editable Linked nodes. Source imports/reexports and a separately
|
||||
compiled installed-JAR example must execute; its forward/reverse traversals retain
|
||||
final values 22/20 after later replacement and clear. Missing fixtures are failures.
|
||||
Evidence prints consumer/provider source hashes, selected revision and clean state,
|
||||
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.
|
||||
|
||||
+150
-24
@@ -283,7 +283,7 @@ fn main() {
|
||||
fn verify_catalog_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let mut random_cycles = None;
|
||||
for name in ["catalog-random-off", "catalog-random-on", "catalog-constants", "catalog-vec2-zero", "catalog-input", "catalog-string"] {
|
||||
for name in ["catalog-random-off", "catalog-random-on", "catalog-constants", "catalog-vec2-zero", "catalog-input", "catalog-string", "catalog-null-hash", "catalog-null-hash-optimized"] {
|
||||
let bytes = std::fs::read(root.join(format!("{name}.pbx"))).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
.unwrap_or_else(|error| panic!("{name}: {error:?}"));
|
||||
@@ -309,6 +309,10 @@ fn verify_catalog_fixtures(root: &std::path::Path) {
|
||||
assert_eq!(vm.operand_stack_top(2), vec![Value::Float(0.0), Value::Float(0.0)]);
|
||||
} else if name == "catalog-string" {
|
||||
assert_eq!(vm.operand_stack_top(1), vec![Value::Int64(0xAABBCCDD)]);
|
||||
} else if name.starts_with("catalog-null-hash") {
|
||||
assert_eq!(vm.operand_stack_top(1),vec![Value::Int64(0)],"provider null hash vector");
|
||||
use prometeu_bytecode::isa::core::CoreOpCode as Op;
|
||||
assert_eq!(report.cycles_used,Op::PushConst.cycles()+8+Op::Halt.cycles());
|
||||
} else {
|
||||
let mut constants: Vec<_> = prometeu_vm::builtin_constant_catalog().collect();
|
||||
constants.sort_by_key(|constant| constant.key.key());
|
||||
@@ -1040,12 +1044,12 @@ fn verify_pbs_random_fixtures(root: &std::path::Path) {
|
||||
|
||||
fn verify_pbs_list_cursor_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits,RuntimeResource}};
|
||||
use prometeu_bytecode::{TRAP_OOB,TRAP_RESOURCE_LIMIT};
|
||||
use prometeu_bytecode::TRAP_EXPLICIT;
|
||||
let successful=["basic","construction","capacity","holes","structural-growth","cursor-empty","cursor-single",
|
||||
"cursor-many","snapshot","false-present","shared-optional","identity","tuple","nested-array","function","evaluation","vec2","pixel","contract"];
|
||||
let faults=[("fault-read",TRAP_OOB),("fault-write",TRAP_OOB),("fault-negative",TRAP_OOB),
|
||||
("fault-insert",TRAP_OOB),("fault-length",TRAP_OOB),("fault-overflow",TRAP_RESOURCE_LIMIT),
|
||||
("fault-long-index",TRAP_OOB),("fault-constructor",TRAP_OOB)];
|
||||
let faults=[("fault-read",TRAP_EXPLICIT),("fault-write",TRAP_EXPLICIT),("fault-negative",TRAP_EXPLICIT),
|
||||
("fault-insert",TRAP_EXPLICIT),("fault-length",TRAP_EXPLICIT),("fault-overflow",TRAP_EXPLICIT),
|
||||
("fault-long-index",TRAP_EXPLICIT),("fault-constructor",TRAP_EXPLICIT)];
|
||||
let cases=successful.into_iter().map(|n|(n,None)).chain(faults.into_iter().map(|(n,c)|(n,Some(c))))
|
||||
.flat_map(|(name,fault)|[(name.to_string(),fault),(format!("{name}-optimized"),fault)]);
|
||||
for (name,fault) in cases {
|
||||
@@ -1087,14 +1091,50 @@ fn list_storage(vm:&VirtualMachine,image:&ValidatedProgramImage)->(prometeu_vm::
|
||||
(object,array)
|
||||
}
|
||||
|
||||
// Non-owning diagnostic snapshots observe only objects reachable before the operation.
|
||||
// Compare every instruction prefix against a successful execution, so a refused
|
||||
// instruction preserves its own entry state without inventing method rollback.
|
||||
type ObservedStorage = Vec<prometeu_vm::resource_diagnostics::StorageObject>;
|
||||
type MutationPrefix = (usize, ObservedStorage);
|
||||
fn observe_originals(vm:&VirtualMachine, original:&ObservedStorage)->ObservedStorage {
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
original.iter().filter_map(|old|objects.iter().find(|now|now.reference==old.reference).cloned()).collect()
|
||||
}
|
||||
fn trace_collection_attempt(vm:&mut VirtualMachine, original:&ObservedStorage, stop_pc:usize)
|
||||
->(prometeu_vm::BudgetReport, Vec<MutationPrefix>, bool) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let mut prefixes=Vec::new(); let mut mutated=false;
|
||||
for _ in 0..200_000 {
|
||||
let before=observe_originals(vm,original);
|
||||
mutated|=before!=*original;
|
||||
prefixes.push((vm.pc(),before.clone()));
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
let after=observe_originals(vm,original);
|
||||
if matches!(report.reason,End::Trap(_)) {
|
||||
assert_eq!(after,before,"refused instruction preserves its own observable entry state");
|
||||
}
|
||||
mutated|=after!=*original;
|
||||
if vm.pc()==stop_pc || !matches!(report.reason,End::BudgetExhausted) {return (report,prefixes,mutated);}
|
||||
}
|
||||
panic!("collection operation did not reach its completion marker");
|
||||
}
|
||||
fn assert_mutation_prefix(actual:&[MutationPrefix], successful:&[MutationPrefix]) {
|
||||
assert!(actual.len()<=successful.len(),"refusal must be a successful instruction prefix");
|
||||
for (index,(left,right)) in actual.iter().zip(successful).enumerate() {
|
||||
assert_eq!(left,right,"observable effects differ at source-operation instruction {index}");
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_list_cursor_refusals(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits,RuntimeResource as Q}};
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
use prometeu_bytecode::{decode_next,TRAP_RESOURCE_LIMIT};
|
||||
use prometeu_bytecode::isa::core::CoreOpCode as Op;
|
||||
let mut publication_scratch=false;let mut return_carrier=false;let mut nodes=false;let mut candidate=false;let mut operand_preparation=false;
|
||||
let mut copy_scratch=false;let mut return_carrier=false;let mut nodes=false;let mut candidate=false;let mut operand_preparation=false;
|
||||
for name in ["insert","remove","growth","cursor"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-list-refusal-{name}.pbx"))).expect("mandatory refusal fixture");
|
||||
for suffix in ["","-optimized"] {
|
||||
println!("PHASE CORPUS list {name}{suffix}");
|
||||
let bytes=std::fs::read(root.join(format!("pbs-list-refusal-{name}{suffix}.pbx"))).expect("mandatory refusal 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();
|
||||
@@ -1113,7 +1153,9 @@ fn verify_list_cursor_refusals(root:&std::path::Path) {
|
||||
assert!(matches!(baseline.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));
|
||||
let before=baseline.resource_snapshot();let original=list_storage(&baseline,&image);
|
||||
baseline.remove_breakpoint(before_pc);
|
||||
assert!(matches!(baseline.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));
|
||||
let watched=vec![original.0.clone(),original.1.clone()];
|
||||
let (completed_report,successful_prefix,_)=trace_collection_attempt(&mut baseline,&watched,after_pc);
|
||||
assert!(matches!(completed_report.reason,End::BudgetExhausted|End::Breakpoint) && baseline.pc()==after_pc,"operation completion: {completed_report:?}");
|
||||
let completed=baseline.resource_snapshot();let changed=list_storage(&baseline,&image);
|
||||
let expected_size=match name {"insert"|"growth"=>129,"remove"=>127,_=>128};
|
||||
assert_eq!(changed.0.groups[1],[V::Int64(expected_size)],"{name} logical size after success");
|
||||
@@ -1135,12 +1177,16 @@ fn verify_list_cursor_refusals(root:&std::path::Path) {
|
||||
assert!(matches!(setup.reason,End::Breakpoint),"{name} setup at {q:?}={limit}: {setup:?}");
|
||||
let state=list_storage(&vm,&image);
|
||||
vm.remove_breakpoint(before_pc);
|
||||
let report=vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
let watched=vec![state.0.clone(),state.1.clone()];
|
||||
let (report,prefix,mutated)=trace_collection_attempt(&mut vm,&watched,after_pc);
|
||||
assert_mutation_prefix(&prefix,&successful_prefix);
|
||||
if let End::Trap(info)=report.reason {
|
||||
assert_eq!(info.code,TRAP_RESOURCE_LIMIT,"{name} at {q:?}={limit}: {info:?}");
|
||||
assert_eq!(list_storage(&vm,&image),state,"{name}: no partial slots/backing/size at {q:?}={limit}");
|
||||
if !mutated || name=="cursor" {
|
||||
assert_eq!(list_storage(&vm,&image),state,"{name}: failure before mutation preserves slots/backing/size");
|
||||
}
|
||||
let instruction=decode_next(info.pc as usize,image.code()).unwrap();
|
||||
publication_scratch|=q==Q::TemporaryBytes&&instruction.opcode==Op::StoragePublish;
|
||||
copy_scratch|=q==Q::TemporaryBytes&&instruction.opcode==Op::ArrayCopy;
|
||||
operand_preparation|=q==Q::AuxiliaryBytes;
|
||||
candidate|=name=="growth"&&instruction.opcode==Op::ArrayNew;
|
||||
if instruction.opcode==Op::StructNew {
|
||||
@@ -1155,15 +1201,16 @@ fn verify_list_cursor_refusals(root:&std::path::Path) {
|
||||
}
|
||||
}
|
||||
refusals+=1;
|
||||
println!("PBS LIST ATOMIC REFUSAL {name} resource={q:?} limit={limit} opcode={:?}",instruction.opcode);
|
||||
} else {assert!(matches!(report.reason,End::Breakpoint),"{name}: {report:?}");}
|
||||
println!("PBS LIST PHASE REFUSAL {name} mutated={mutated} resource={q:?} limit={limit} opcode={:?}",instruction.opcode);
|
||||
} else {assert!(matches!(report.reason,End::BudgetExhausted|End::Breakpoint) && vm.pc()==after_pc,"{name}: {report:?}");}
|
||||
drop(vm);
|
||||
for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes] {assert_eq!(observer.used(resource),0);}
|
||||
}
|
||||
}
|
||||
assert!(refusals>0,"{name}: mandatory source refusals executed");
|
||||
}
|
||||
assert!(publication_scratch,"no-growth publication scratch refusal");
|
||||
}
|
||||
assert!(copy_scratch,"no-growth copy scratch refusal");
|
||||
assert!(return_carrier,"removeAt optional return allocation refusal");
|
||||
assert!(candidate,"growth candidate allocation refusal");
|
||||
assert!(nodes,"snapshot node allocation refusal");
|
||||
@@ -1197,8 +1244,64 @@ fn verify_collection_cursor_gc(root:&std::path::Path,collection:&str) {
|
||||
assert!(matches!(report.reason,End::Halted|End::EndOfRom));assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)]);
|
||||
}
|
||||
|
||||
fn verify_copy_attempts(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_OOB,TRAP_NULL_REFERENCE,TRAP_RESOURCE_LIMIT};
|
||||
for base in ["scalar","vec2","string","zero","bad-range","bad-empty-range","null-source","null-zero","negative-count","huge-count","fault-order"] {
|
||||
for optimized in [false,true] {
|
||||
let name=format!("common-copy-{base}{}",if optimized{"-optimized"}else{""});
|
||||
let bytes=std::fs::read(root.join(format!("{name}.pbx"))).expect("mandatory copy oracle");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut pc=0;let mut copies=Vec::new();
|
||||
while pc<image.code().len() {
|
||||
let instruction=decode_next(pc,image.code()).unwrap();
|
||||
assert!(![0xa7,0xa8,0xaa,0xab].contains(&(instruction.opcode as u16)));
|
||||
if instruction.opcode==Op::ArrayCopy {copies.push(pc);} pc=instruction.next_pc;
|
||||
}
|
||||
assert_eq!(copies.len(),1);let copy_pc=copies[0];
|
||||
let prepare=|limits| {
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),limits);vm.prepare_boot_call().unwrap();vm.insert_breakpoint(copy_pc);
|
||||
assert!(matches!(vm.run_budget(1_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));vm
|
||||
};
|
||||
let mut vm=prepare(RuntimeLimits::default());let observer=vm.resource_observer();
|
||||
let before=vm.heap().diagnostic_typed_storage();let operands=vm.operand_stack_top(5).to_vec();
|
||||
let scratch_floor=vm.resource_snapshot().budget.peaks[Q::TemporaryBytes as usize];
|
||||
let zero=vm.run_budget(0,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert_eq!((zero.cycles_used,zero.steps_executed,vm.pc()),(0,0,copy_pc));
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
let cycles=if base=="vec2"{44}else if ["zero","bad-empty-range","null-zero","negative-count","huge-count","fault-order"].contains(&base){4}else{24};
|
||||
assert_eq!(report.cycles_used,cycles,"{name}: precharged cost");
|
||||
let fault=if base.starts_with("null-")||base=="fault-order"{Some(TRAP_NULL_REFERENCE)}
|
||||
else if ["bad-range","bad-empty-range","negative-count","huge-count"].contains(&base){Some(TRAP_OOB)}else{None};
|
||||
if let Some(code)=fault {
|
||||
let End::Trap(info)=report.reason else {panic!("{name}: {report:?}")};
|
||||
assert_eq!(info.code,code);assert_eq!(report.steps_executed,0);
|
||||
assert_eq!(vm.operand_stack_top(5),operands);assert_eq!(vm.heap().diagnostic_typed_storage(),before);
|
||||
} else {
|
||||
assert!(matches!(report.reason,End::BudgetExhausted));assert_eq!(report.steps_executed,1);
|
||||
let mut expected=before.clone();
|
||||
if base!="zero" {for i in 0..10 {expected[0].groups[i+2]=before[0].groups[i].clone();}}
|
||||
assert_eq!(vm.heap().diagnostic_typed_storage(),expected,"{name}: snapshot overlap and complete native groups");
|
||||
}
|
||||
assert_eq!(observer.used(Q::TemporaryBytes),0,"copy releases provisional scratch");
|
||||
drop(vm);for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations] {assert_eq!(observer.used(resource),0);}
|
||||
if base=="scalar" {
|
||||
let mut refused=prepare(RuntimeLimits::default().lowered(Q::TemporaryBytes,scratch_floor).unwrap());
|
||||
let before=refused.heap().diagnostic_typed_storage();let operands=refused.operand_stack_top(5).to_vec();
|
||||
let report=refused.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason,End::Trap(ref info) if info.code==TRAP_RESOURCE_LIMIT),"scratch refusal: {report:?}");
|
||||
assert_eq!((report.cycles_used,report.steps_executed),(24,0));
|
||||
assert_eq!(refused.heap().diagnostic_typed_storage(),before);assert_eq!(refused.operand_stack_top(5),operands);
|
||||
assert_eq!(refused.resource_observer().used(Q::TemporaryBytes),0);
|
||||
}
|
||||
println!("COMMON COPY COST/FAULT/GROUP PASS {name} cycles={cycles}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_common_storage_fixtures(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::RuntimeLimits};
|
||||
verify_copy_attempts(root);
|
||||
for name in ["common-storage","common-storage-optimized","common-fields","common-fields-optimized"] {
|
||||
let bytes=std::fs::read(root.join(format!("{name}.pbx"))).expect("mandatory non-PBS storage fixture");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
@@ -1207,7 +1310,23 @@ fn verify_common_storage_fixtures(root:&std::path::Path) {
|
||||
assert!(matches!(report.reason,End::Halted|End::EndOfRom),"{name}: {report:?}");
|
||||
assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)]);
|
||||
println!("COMMON STORAGE SOURCE/LOAD/EXEC PASS {name}");
|
||||
} for opcode in [0xa7,0xa8,0xaa,0xab] {
|
||||
let bytes=std::fs::read(root.join(format!("retired-storage-{opcode:x}.pbx"))).expect("mandatory dead-opcode refusal");
|
||||
assert!(ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).is_err());
|
||||
let data=std::fs::read(root.join(format!("storage-immediate-{opcode:x}.pbx"))).unwrap();
|
||||
assert!(ValidatedProgramImage::load(&data,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).is_ok());
|
||||
}
|
||||
for suffix in ["","-optimized"] {
|
||||
let bytes=std::fs::read(root.join(format!("common-partial-fault{suffix}.pbx"))).unwrap();
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image,RuntimeLimits::default());vm.prepare_boot_call().unwrap();
|
||||
let report=vm.run_budget(100_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason,End::Trap(ref info) if info.code==prometeu_bytecode::TRAP_EXPLICIT));
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
assert_eq!(vm.heap().diagnostic_typed_storage()[0].groups[1],[V::Int32(20)],"terminal fault does not undo prior store");
|
||||
println!("COMMON PARTIAL FAULT PASS {suffix}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn verify_list_cursor_distribution(root:&std::path::Path) { verify_collection_distribution(root,"list",22); }
|
||||
@@ -1243,11 +1362,11 @@ fn verify_collection_distribution(root:&std::path::Path,collection:&str,last:i32
|
||||
|
||||
fn verify_pbs_linked_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits,RuntimeResource}};
|
||||
use prometeu_bytecode::TRAP_OOB;
|
||||
use prometeu_bytecode::TRAP_EXPLICIT;
|
||||
let successful=["basic","links","construction","long-size","empty-cursor","empty-reverseCursor",
|
||||
"single-cursor","single-reverseCursor","snapshot","false-present","optional-field","identity","tuple","nested-array","function","evaluation","vec2","pixel","contract"];
|
||||
let faults=[("fault-read",TRAP_OOB),("fault-write",TRAP_OOB),("fault-negative",TRAP_OOB),
|
||||
("fault-insert",TRAP_OOB),("fault-remove",TRAP_OOB),("fault-overflow",TRAP_OOB),("fault-long-index",TRAP_OOB)];
|
||||
let faults=[("fault-read",TRAP_EXPLICIT),("fault-write",TRAP_EXPLICIT),("fault-negative",TRAP_EXPLICIT),
|
||||
("fault-insert",TRAP_EXPLICIT),("fault-remove",TRAP_EXPLICIT),("fault-overflow",TRAP_EXPLICIT),("fault-long-index",TRAP_EXPLICIT)];
|
||||
let cases=successful.into_iter().map(|n|(n,None)).chain(faults.into_iter().map(|(n,c)|(n,Some(c))))
|
||||
.flat_map(|(name,fault)|[(name.to_string(),fault),(format!("{name}-optimized"),fault)]);
|
||||
for (name,fault) in cases {
|
||||
@@ -1301,7 +1420,9 @@ fn verify_linked_refusals(root:&std::path::Path) {
|
||||
use prometeu_bytecode::isa::core::CoreOpCode as Op;
|
||||
let mut node_allocation=false;let mut optional_return=false;let mut snapshot_allocation=false;let mut preparation=false;
|
||||
for name in ["insert","add","addFirst","remove","removeFirst","removeLast","replace","clear","cursor","reverseCursor"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-linked-refusal-{name}.pbx"))).expect("mandatory Linked refusal fixture");
|
||||
for suffix in ["","-optimized"] {
|
||||
println!("PHASE CORPUS linked {name}{suffix}");
|
||||
let bytes=std::fs::read(root.join(format!("pbs-linked-refusal-{name}{suffix}.pbx"))).expect("mandatory Linked refusal 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();
|
||||
@@ -1318,7 +1439,8 @@ fn verify_linked_refusals(root:&std::path::Path) {
|
||||
assert!(matches!(baseline.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));
|
||||
let before=baseline.resource_snapshot();let original=linked_state(&baseline,&image);
|
||||
baseline.remove_breakpoint(before_pc);
|
||||
assert!(matches!(baseline.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));
|
||||
let (completed_report,successful_prefix,_)=trace_collection_attempt(&mut baseline,&original,after_pc);
|
||||
assert!(matches!(completed_report.reason,End::BudgetExhausted|End::Breakpoint) && baseline.pc()==after_pc,"operation completion: {completed_report:?}");
|
||||
let after=baseline.resource_snapshot();let changed=linked_state(&baseline,&image);
|
||||
let owner=changed.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("linked<int>")).unwrap();
|
||||
let expected=match name {"insert"|"add"|"addFirst"=>33,"remove"|"removeFirst"|"removeLast"=>31,"clear"=>0,_=>32};
|
||||
@@ -1334,10 +1456,13 @@ fn verify_linked_refusals(root:&std::path::Path) {
|
||||
let setup=vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(setup.reason,End::Breakpoint),"{name} setup {q:?}={limit}: {setup:?}");
|
||||
let old=linked_state(&vm,&image);vm.remove_breakpoint(before_pc);
|
||||
let report=vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
let (report,prefix,mutated)=trace_collection_attempt(&mut vm,&old,after_pc);
|
||||
assert_mutation_prefix(&prefix,&successful_prefix);
|
||||
if let End::Trap(info)=report.reason {
|
||||
assert_eq!(info.code,TRAP_RESOURCE_LIMIT,"{name} {q:?}={limit}: {info:?}");
|
||||
assert_eq!(linked_state(&vm,&image),old,"{name}: all original fields, groups and reciprocal links at {q:?}={limit}");
|
||||
if !mutated || name=="cursor" || name=="reverseCursor" {
|
||||
assert_eq!(linked_state(&vm,&image),old,"{name}: failure before mutation preserves original topology");
|
||||
}
|
||||
let instruction=decode_next(info.pc as usize,image.code()).unwrap();
|
||||
preparation|=q==Q::AuxiliaryBytes;
|
||||
if instruction.opcode==Op::StructNew {
|
||||
@@ -1351,12 +1476,13 @@ fn verify_linked_refusals(root:&std::path::Path) {
|
||||
}
|
||||
}
|
||||
}
|
||||
refused+=1;println!("PBS LINKED ATOMIC REFUSAL {name} resource={q:?} limit={limit} opcode={:?}",instruction.opcode);
|
||||
} else {assert!(matches!(report.reason,End::Breakpoint),"{name}: {report:?}");}
|
||||
refused+=1;println!("PBS LINKED PHASE REFUSAL {name} mutated={mutated} resource={q:?} limit={limit} opcode={:?}",instruction.opcode);
|
||||
} else {assert!(matches!(report.reason,End::BudgetExhausted|End::Breakpoint) && vm.pc()==after_pc,"{name}: {report:?}");}
|
||||
drop(vm);for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes] {assert_eq!(observer.used(resource),0);}
|
||||
}
|
||||
}
|
||||
assert!(refused>0,"{name}: whole-source-operation refusals required");
|
||||
assert!(refused>0,"{name}: source-operation phase refusals required");
|
||||
}
|
||||
}
|
||||
assert!(node_allocation,"new Linked node refusal");assert!(optional_return,"optional removed-value refusal");
|
||||
assert!(snapshot_allocation,"snapshot node refusal");assert!(preparation,"frame/operand preparation refusal");
|
||||
|
||||
@@ -35,7 +35,7 @@ print("runtime working tree", subprocess.check_output(["git","-C",str(runtime),"
|
||||
for source in [pathlib.Path("prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsListCursorTest.java"),
|
||||
pathlib.Path("prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsLinkedTest.java"),
|
||||
pathlib.Path("prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/collections/main.pbs"),
|
||||
runtime / "crates/console/prometeu-vm/src/virtual_machine/storage_publication.rs"]:
|
||||
runtime / "crates/console/prometeu-vm/src/virtual_machine/array_copy.rs"]:
|
||||
print("sha256",source,hashlib.sha256(source.read_bytes()).hexdigest(),flush=True)
|
||||
print("platform", platform.platform(), "limits=default capabilities=NONE", flush=True)
|
||||
print("profile", "release" if args.release else "dev", "features=resource-diagnostics", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user