feat(pbs): implement typed arrays, optional binding and contract execution

This commit is contained in:
2026-10-16 16:21:33 +01:00
parent c4e1b9055d
commit 39df63581c
51 changed files with 1902 additions and 68 deletions
+26 -1
View File
@@ -7,7 +7,7 @@ From the Studio root:
```sh
./gradlew :prometeu-compiler:prometeu-build-pipeline:test --tests '*LinkedRegistryTest' --tests '*PbxRegistryConformanceTest' --tests '*TypedCommonPipelineTest' --tests '*RuntimeCatalogPipelineTest'
./gradlew :prometeu-architecture-tests:test --tests '*PbsRuntimeAlignmentTest'
./gradlew :prometeu-architecture-tests:test --tests '*PbsRuntimeAlignmentTest' --tests '*PbsStructuredValuesTest'
python3 tools/pbx-conformance/run.py --runtime ../runtime
```
@@ -87,3 +87,28 @@ missing PBS fixtures. Integer arithmetic wrapping is distinct from checked
Int64-to-Int32 narrowing and Float numeric-range faults. The full installed
knowledge gate remains separate and mandatory for SDK resource/producer
integration.
## PBS typed arrays, optional and Struct/contract execution
`PbsStructuredValuesTest` generates 27 mandatory `pbs-structured-*` fixtures.
They cover contextual arrays, nested levels, vacancy/zero, clear/length, aliasing,
int/long bounds, single evaluation, lazy optional fallback, inferred/explicit
optional tuples, native vec2 groups, fields and constructors, overloads and Self,
contract elements/dispatch, imported services/structs/contracts, global file-init,
and the installed example. The runtime harness names every required fixture;
a missing file is an error.
Eighteen additional runs lower GuestBytes or HandleSlots to 0, 1 or 2. They assert
resource faults, bounded accounting, no object publication at zero quota, and
release of session ownership. The integer-storage fixture succeeds with one
handle total, proving that its three integers do not allocate individual boxes.
String session accounting is checked after each structured execution.
The GC fixture compiles all allocations, roots and post-collection reads from PBS.
A test-only driver hook replaces one isolated marker assignment with FRAME_SYNC
and NOPs without changing code offsets; it does not add PBS sync syntax. At the
real runtime safepoint, at least 1,100 discarded objects are reclaimed while
nested references, tuples and strings remain readable. `resource-diagnostics`
is enabled solely for observation. Default production ceilings and GC threshold
are unchanged outside the explicitly lowered quota runs. This is semantic and
resource conformance, not a performance benchmark or installed game qualification.
+74 -1
View File
@@ -38,6 +38,8 @@ fn main() {
let root = std::path::PathBuf::from(std::env::args().nth(1).expect("fixture directory"));
verify_catalog_fixtures(&root);
verify_pbs_fixtures(&root);
verify_pbs_structured_fixtures(&root);
verify_pbs_resource_refusals(&root);
for name in [
"minimal",
"jump-end",
@@ -472,7 +474,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-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
if name.starts_with("pbs-structured-") || !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)
@@ -537,3 +539,74 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
println!("PBS Registry defaults PASS: all eight existing value types");
assert_eq!(count, 114, "The complete PBS qualification corpus must be present");
}
fn verify_pbs_structured_fixtures(root: &std::path::Path) {
use prometeu_vm::LogicalFrameEndingReason as End;
let success = ["array-cycle", "array-nested", "optional-flow", "struct-contract", "service-contract",
"optional-tuple", "tuple-storage", "optional-intrinsics", "optional-lazy", "array-context",
"binding-scope", "overloads", "single-evaluation", "long-boundaries", "gc-roots", "native-groups", "contract-elements", "imports", "global-array", "installed-example", "return-overloads", "inferred-optional-tuple", "inline-integers"];
for name in success.into_iter().chain(["negative-index", "past-end", "negative-length", "large-length"]) {
let bytes = std::fs::read(root.join(format!("pbs-structured-{name}.pbx")))
.unwrap_or_else(|e| panic!("missing mandatory PBS structured fixture {name}: {e}"));
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
.unwrap_or_else(|e| panic!("{name}: {e:?}"));
let limits = if name == "inline-integers" {
prometeu_vm::resource_budget::RuntimeLimits::default()
.lowered(prometeu_vm::resource_budget::RuntimeResource::HandleSlots, 1).unwrap()
} else { Default::default() };
let mut vm = VirtualMachine::from_image(image, limits);
vm.prepare_boot_call().unwrap();
let mut report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
if name == "gc-roots" {
assert!(matches!(report.reason, End::FrameSync), "{report:?}");
let snapshot = vm.resource_snapshot();
assert_eq!(snapshot.gc.collections, 1);
assert!(snapshot.gc.reclaimed >= 1100, "{:?}", snapshot.gc);
report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
}
match name {
"negative-index" | "past-end" | "negative-length" => assert!(matches!(report.reason,
End::Trap(ref fault) if fault.code == prometeu_bytecode::TRAP_OOB), "{name}: {report:?}"),
"large-length" => assert!(matches!(report.reason,
End::Trap(ref fault) if fault.code == prometeu_bytecode::TRAP_RESOURCE_LIMIT), "{name}: {report:?}"),
_ => {
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(42)], "{name}");
}
}
if name == "inline-integers" { assert_eq!(vm.heap().len(), 1, "single-slot integers must not allocate boxes"); }
let ownership = vm.resource_observer();
drop(vm);
for resource in [prometeu_vm::resource_budget::RuntimeResource::StringBytes,
prometeu_vm::resource_budget::RuntimeResource::StringAllocations] {
assert_eq!(ownership.used(resource), 0, "{name}: string ownership released");
}
println!("PBS STRUCTURED SOURCE/LOAD/EXEC PASS {name}");
}
}
fn verify_pbs_resource_refusals(root: &std::path::Path) {
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits, RuntimeResource}};
for name in ["array-cycle", "tuple-storage", "struct-contract"] {
for resource in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots] {
for limit in [0, 1, 2] {
let bytes = std::fs::read(root.join(format!("pbs-structured-{name}.pbx"))).unwrap();
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE).unwrap();
let limits = RuntimeLimits::default().lowered(resource, limit).unwrap();
let mut vm = VirtualMachine::from_image(image, limits);
let observer = vm.resource_observer();
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 fault) if fault.code == prometeu_bytecode::TRAP_RESOURCE_LIMIT), "{name}/{resource:?}/{limit}: {report:?}");
assert!(observer.used(resource) <= limit);
if limit == 0 { assert_eq!(vm.heap().len(), 0, "no partially published object"); }
drop(vm);
for domain in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots,
RuntimeResource::AuxiliaryBytes, RuntimeResource::TemporaryBytes] {
assert_eq!(observer.used(domain), 0, "{name}: session ownership released after refusal: {domain:?}");
}
println!("PBS QUOTA/OWNERSHIP PASS {name}/{resource:?}/{limit}");
}
}
}
}
+2 -1
View File
@@ -18,7 +18,8 @@ with tempfile.TemporaryDirectory(prefix="pbx-conformance-") as directory:
root = pathlib.Path(directory)
manifest = '[package]\nname="studio-pbx-conformance"\nversion="0.1.0"\nedition="2024"\n[dependencies]\n'
for crate in ["prometeu-bytecode", "prometeu-hal", "prometeu-vm", "prometeu-system"]:
manifest += f'{crate}={{path={json.dumps(str(runtime / "crates/console" / crate))}}}\n'
features = ',features=["resource-diagnostics"]' if crate == "prometeu-vm" else ''
manifest += f'{crate}={{path={json.dumps(str(runtime / "crates/console" / crate))}{features}}}\n'
manifest += 'serde_json="1.0.149"\njsonschema={version="0.33",default-features=false}\n'
(root / "Cargo.toml").write_text(manifest)
(root / "Cargo.lock").write_text((runtime / "Cargo.lock").read_text())