feat(pbs): add service constants and runtime math integration
This commit is contained in:
@@ -131,3 +131,32 @@ threshold collections, retained closure/object reachability after frame one,
|
||||
and reclamation after release. The remaining root is the global array.
|
||||
PBS publishes FRAME_ROOT and the existing guarded wrapper returns normally.
|
||||
No sync syntax, new frame integration, suspension or coroutine is introduced.
|
||||
|
||||
## PBS service constants and runtime math
|
||||
|
||||
`PbsRuntimeMathTest` produces 261 independent numeric cases in both ordinary and
|
||||
optimized bytecode (522 mandatory executions per runtime profile), covering all
|
||||
26 math/mathf signatures. The checked-in corpus preserves 240 provider scalar
|
||||
fixture rows and exact contract examples (duplicates removed); provenance is in
|
||||
`prometeu-architecture-tests/src/test/resources/math/provenance.txt`.
|
||||
|
||||
The harness verifies exact bits/faults, selected intrinsic identity and one
|
||||
retained call per case. Single-step charging is compared with the provider's
|
||||
opcode costs and independent fixture call cost; full-budget charging must equal
|
||||
their sum, and optimization must preserve total cycles. Additional cases exercise
|
||||
pi/tau, literal sin, ordinary int/long service constants, constant dependencies,
|
||||
and real module imports with service aliases. The installed example also imports
|
||||
both SDK services, so installedKnowledgeTest covers their packaged resources.
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-architecture-tests:test --tests '*PbsRuntimeMathTest'
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime --math-only
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime --math-only --release
|
||||
```
|
||||
|
||||
Omit `--math-only` for the full existing corpus. `--release` selects the optimized
|
||||
Rust runtime harness; it is independent of the PBS optimizer variants included in
|
||||
every run. Optional `CARGO_TARGET_DIR` can retain build artifacts outside the
|
||||
runtime checkout. Each invocation prints runtime revision, platform, profile,
|
||||
features, lockfile and provider catalog/oracle hashes. Local evidence qualifies
|
||||
macOS/arm64 only; macOS/x86_64 and Linux/x86_64 remain pending.
|
||||
|
||||
@@ -36,6 +36,8 @@ impl NativeInterface for NoNative {
|
||||
|
||||
fn main() {
|
||||
let root = std::path::PathBuf::from(std::env::args().nth(1).expect("fixture directory"));
|
||||
verify_pbs_math_fixtures(&root);
|
||||
if std::env::args().any(|arg| arg == "--math-only") { return; }
|
||||
verify_catalog_fixtures(&root);
|
||||
verify_pbs_fixtures(&root);
|
||||
verify_pbs_structured_fixtures(&root);
|
||||
@@ -475,7 +477,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-structured-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
if name.starts_with("pbs-math-") || 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)
|
||||
@@ -630,3 +632,97 @@ fn verify_pbs_closure_frames(root: &std::path::Path) {
|
||||
}
|
||||
println!("PBS CLOSURE FRAME LIFECYCLE/RETENTION/GC PASS");
|
||||
}
|
||||
|
||||
// The expected results/call costs are independent provider fixtures. Step costs
|
||||
// use the published opcode contract, not observed timings or compiler estimates.
|
||||
fn verify_pbs_math_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
use prometeu_bytecode::isa::core::CoreOpCode as OpCode;
|
||||
let corpus = std::fs::read_to_string(root.join("math-vectors.tsv")).expect("mandatory math corpus");
|
||||
let mut covered = std::collections::BTreeSet::new();
|
||||
let mut count = 0;
|
||||
let mut original_cycles = std::collections::BTreeMap::new();
|
||||
let mut names = std::collections::BTreeSet::new();
|
||||
for line in corpus.lines() {
|
||||
let parts: Vec<_> = line.split_whitespace().collect();
|
||||
let name = parts[0];
|
||||
assert!(names.insert(parts[0]), "duplicate math fixture");
|
||||
let id = u32::from_str_radix(parts[1], 16).unwrap();
|
||||
let expected = parts[parts.len()-2];
|
||||
let cost: u64 = parts.last().unwrap().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;
|
||||
let ending = loop {
|
||||
let pc = vm.pc();
|
||||
let opcode = OpCode::try_from(u16::from_le_bytes(code[pc..pc+2].try_into().unwrap())).unwrap();
|
||||
let cycles = if opcode == OpCode::Intrinsic {
|
||||
let actual = u32::from_le_bytes(code[pc+2..pc+6].try_into().unwrap());
|
||||
assert_eq!(actual, id, "{name}: wrong overload or unexpected conversion");
|
||||
calls += 1;
|
||||
cost
|
||||
} else { opcode.cycles() };
|
||||
let report = vm.run_budget(1, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert_eq!(report.cycles_used, cycles, "{name}: cycle charge at {pc}, {opcode:?}");
|
||||
total += cycles;
|
||||
if matches!(report.reason, End::Halted | End::EndOfRom | End::Trap(_)) { break report.reason; }
|
||||
assert!(total < 10000, "{name}: nonterminating source fixture");
|
||||
};
|
||||
assert_eq!(calls, 1, "{name}: preserve literal calls and no hidden conversions");
|
||||
if let Some(code) = expected.strip_prefix("trap:") {
|
||||
let code = u32::from_str_radix(code,16).unwrap();
|
||||
assert!(matches!(ending, End::Trap(ref trap) if trap.code == code), "{name}: {ending:?}");
|
||||
} else {
|
||||
assert!(matches!(ending, End::Halted | End::EndOfRom), "{name}: {ending:?}");
|
||||
let value = vm.operand_stack_top(1);
|
||||
let actual = match &value[0] {
|
||||
Value::Float(value) => format!("f:{:016x}",value.to_bits()),
|
||||
Value::Int32(value) => format!("i:{value}"),
|
||||
Value::Int64(value) => format!("l:{value}"),
|
||||
value => panic!("{name}: unexpected value {value:?}"),
|
||||
};
|
||||
assert_eq!(actual, expected, "{name}: exact result bits");
|
||||
}
|
||||
// A full-budget execution must charge exactly the independently checked steps.
|
||||
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(10000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert_eq!(report.cycles_used, total, "{name}: aggregate cost");
|
||||
if let Some(original) = name.strip_suffix("-optimized") {
|
||||
assert_eq!(original_cycles.get(original), Some(&total), "{name}: optimization changed cycles");
|
||||
} else { original_cycles.insert(name.to_string(), total); }
|
||||
covered.insert(id);
|
||||
count += 1;
|
||||
}
|
||||
assert_eq!(covered, (0x3000..=0x3019).collect());
|
||||
assert_eq!(count, 522, "mandatory boundary corpus missing");
|
||||
for (name, expected) in [("pi", Value::Float(f64::from_bits(0x400921fb54442d18))),
|
||||
("tau", Value::Float(f64::from_bits(0x401921fb54442d18))),
|
||||
("literal", Value::Float(-0.0)), ("dependency", Value::Int32(42)), ("long", Value::Int64(2147483648)),
|
||||
("service", Value::Int32(42)), ("min", Value::Int64(42))] {
|
||||
let bytes = std::fs::read(root.join(format!("pbs-math-{name}.pbx"))).unwrap();
|
||||
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(10000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
|
||||
let actual = vm.operand_stack_top(1);
|
||||
match (&actual[0], &expected) {
|
||||
(Value::Float(a), Value::Float(b)) => assert_eq!(a.to_bits(), b.to_bits(), "{name}"),
|
||||
_ => assert_eq!(actual, vec![expected]),
|
||||
}
|
||||
if name == "pi" || name == "tau" || name == "service" { assert_eq!(report.cycles_used, 6, "constant load + root RET only"); }
|
||||
}
|
||||
let bytes = std::fs::read(root.join("pbs-math-import.pbx")).expect("real SDK imports fixture");
|
||||
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(10000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "import: {report:?}");
|
||||
println!("PBS MATH PASS: {count} exact bits/faults/cycle vectors; all 26 signatures; service constants");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Build a production-loader harness without writing into the runtime checkout."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import pathlib
|
||||
import platform
|
||||
@@ -10,10 +11,15 @@ parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--runtime", type=pathlib.Path, default=pathlib.Path("../runtime"))
|
||||
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("--math-only", action="store_true", help="Run the complete PBS math corpus only")
|
||||
args = parser.parse_args()
|
||||
runtime = args.runtime.resolve()
|
||||
print("runtime", subprocess.check_output(["git", "-C", str(runtime), "rev-parse", "HEAD"], text=True).strip(), 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)
|
||||
for relative in ["Cargo.lock", "docs/vm-arch/INTRINSICS.csv", "docs/vm-arch/BUILTIN_CONSTANTS.csv", "crates/console/prometeu-vm/tests/fixtures/numeric-conformance.tsv"]:
|
||||
print("sha256", relative, hashlib.sha256((runtime / relative).read_bytes()).hexdigest(), flush=True)
|
||||
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'
|
||||
@@ -25,4 +31,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", *([] if args.online else ["--offline"]), "--manifest-path", str(root / "Cargo.toml"), "--", str(args.fixtures.resolve()), str(runtime / "devtools/headless-protocol/response.schema.json")], 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"), *(["--math-only"] if args.math_only else [])], check=True)
|
||||
|
||||
Reference in New Issue
Block a user