feat(pbs): add parametric arrays and concrete generic contracts
Support explicit contract type parameters, canonical nominal applications, recursive substitution, concrete implementations and instantiated editor views. Complete parametric Array syntax and contextual construction integration. Preserve type origins across imports and reexports, fix trait argument stack order, and relocate global slots before lifecycle assembly. Publish specs, installed examples and consolidated discussion lessons. Validate frontend, common pipeline, architecture, LSP and installed knowledge gates, plus the full production VM conformance corpus with 14 generic fixtures.
This commit is contained in:
@@ -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' --tests '*PbsStructuredValuesTest' --tests '*PbsClosuresTest'
|
||||
./gradlew :prometeu-architecture-tests:test --tests '*PbsRuntimeAlignmentTest' --tests '*PbsStructuredValuesTest' --tests '*PbsClosuresTest' --tests '*PbsGenericContractsTest'
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||
```
|
||||
|
||||
@@ -196,3 +196,31 @@ claims. Qualify those separately with the provider's `random_contract` suite and
|
||||
`cargo test -p prometeu-vm --lib random` in debug/release. No alternate RNG or
|
||||
public injection hook is used. Installed knowledge validation remains a separate
|
||||
gate for packaged SDK/spec/example resources.
|
||||
|
||||
## PBS generic contracts
|
||||
|
||||
`PbsGenericContractsTest` generates fourteen mandatory source fixtures:
|
||||
`identity`, `manual`, `multiple`, `tuple`, `optional`, `function`, `contract`,
|
||||
`native`, `recursive`, `phantom`, `receiver`, `gc`, `installed` and `imports`.
|
||||
The corpus uses ordinary concrete Trait descriptors on the existing runtime.
|
||||
It checks several applications on one owner, ordered substitution, composed
|
||||
multi-slot values, finite recursion, canonical aliases/reexports and distinct
|
||||
same-named argument declarations. The imported program uses the production
|
||||
workspace builder and lifecycle assembler.
|
||||
|
||||
The generic and handwritten concrete identity fixtures both execute with one
|
||||
heap handle, establishing that contract adaptation needs no generic wrapper.
|
||||
Typed absence and implementation index zero are valid. A mismatched Trait call
|
||||
must be rejected by the verifier or trap with the runtime type check. The GC
|
||||
fixture retains a contract receiver through a closure while at least 1,100
|
||||
discarded objects are reclaimed. Reduced GuestBytes, HandleSlots and loader
|
||||
implementation limits verify refusal and ownership release. Descriptor counts
|
||||
and PBX byte sizes are printed as evidence, without a performance threshold.
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-architecture-tests:test --tests '*PbsGenericContractsTest'
|
||||
python3 tools/pbx-conformance/run.py --runtime ../runtime --generic-contracts-only
|
||||
```
|
||||
|
||||
The full harness also requires these fixtures. The driver uses an external
|
||||
runtime checkout without editing its sources or changing PBX, ISA or quotas.
|
||||
|
||||
@@ -36,6 +36,7 @@ impl NativeInterface for NoNative {
|
||||
|
||||
fn main() {
|
||||
let root = std::path::PathBuf::from(std::env::args().nth(1).expect("fixture directory"));
|
||||
if std::env::args().any(|arg| arg == "--generic-contracts-only") { verify_pbs_generic_contract_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--random-only") { verify_pbs_random_fixtures(&root); return; }
|
||||
verify_pbs_math_fixtures(&root);
|
||||
if std::env::args().any(|arg| arg == "--math-only") { return; }
|
||||
@@ -43,6 +44,7 @@ fn main() {
|
||||
verify_catalog_fixtures(&root);
|
||||
verify_pbs_fixtures(&root);
|
||||
verify_pbs_structured_fixtures(&root);
|
||||
verify_pbs_generic_contract_fixtures(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
verify_pbs_closure_frames(&root);
|
||||
for name in [
|
||||
@@ -479,7 +481,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-") || 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-") || 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)
|
||||
@@ -547,7 +549,7 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
|
||||
fn verify_pbs_structured_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let success = ["closure-import", "closure-installed", "closure-groups", "closure-isolation", "closure-fields", "closure-functions", "closure-snapshot", "closure-objects", "closure-nested", "array-cycle", "array-nested", "optional-flow", "struct-contract", "service-contract",
|
||||
let success = ["closure-import", "closure-installed", "closure-groups", "closure-isolation", "closure-fields", "closure-functions", "closure-snapshot", "closure-objects", "closure-nested", "array-cycle", "array-nested", "array-parametric", "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"]) {
|
||||
@@ -590,6 +592,111 @@ fn verify_pbs_structured_fixtures(root: &std::path::Path) {
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_pbs_generic_contract_fixtures(root: &std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End, resource_budget::{RuntimeLimits, RuntimeResource}};
|
||||
use prometeu_bytecode::{registry::{TypeId, TypeKind}, isa::core::CoreOpCode};
|
||||
let mut reference_heap = None;
|
||||
for name in ["identity", "manual", "multiple", "tuple", "optional", "function", "contract", "native", "recursive", "phantom", "receiver", "gc", "installed", "imports"] {
|
||||
let bytes = std::fs::read(root.join(format!("pbs-generic-contract-{name}.pbx")))
|
||||
.unwrap_or_else(|error| panic!("missing mandatory generic-contract fixture {name}: {error}"));
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
.unwrap_or_else(|error| panic!("generic contract {name}: {error:?}"));
|
||||
let declarations = image.registry().declarations();
|
||||
let traits: Vec<_> = declarations.types.iter().enumerate().filter(|(_, t)| matches!(t.kind, TypeKind::Trait(_))).collect();
|
||||
assert!(!traits.is_empty(), "{name}: source must emit concrete traits");
|
||||
for (index, _) in &traits {
|
||||
assert_eq!(image.registry().type_layout(TypeId(*index as u32)).unwrap().storage.default_values(), &[Value::Null, Value::Null], "{name}: absent concrete trait");
|
||||
}
|
||||
assert!(!declarations.implementations.is_empty());
|
||||
// The first dense implementation is valid; zero must never act as an absence sentinel.
|
||||
assert_eq!(image.registry().implementation(declarations.implementations[0].owner, declarations.implementations[0].trait_id).unwrap().0, 0);
|
||||
if name == "multiple" || name == "phantom" {
|
||||
assert_eq!(traits.len(), 2);
|
||||
assert_eq!(declarations.implementations.len(), 2);
|
||||
assert_eq!(declarations.implementations[0].owner, declarations.implementations[1].owner);
|
||||
assert_ne!(declarations.implementations[0].trait_id, declarations.implementations[1].trait_id);
|
||||
}
|
||||
if name == "imports" { assert_eq!(traits.len(), 3); assert_eq!(declarations.implementations.len(), 3); }
|
||||
if name == "phantom" {
|
||||
let mut code = image.code().to_vec();
|
||||
let mut pc = 0;
|
||||
let mut changed = false;
|
||||
while pc < code.len() {
|
||||
let instruction = prometeu_bytecode::decode_next(pc, &code).unwrap();
|
||||
if instruction.opcode == CoreOpCode::CallTrait {
|
||||
let (original, _) = instruction.imm_u32x2().unwrap();
|
||||
let other = traits.iter().map(|(index, _)| *index as u32).find(|id| *id != original).unwrap();
|
||||
code[pc+2..pc+6].copy_from_slice(&other.to_le_bytes());
|
||||
changed = true; break;
|
||||
}
|
||||
pc = instruction.next_pc;
|
||||
}
|
||||
assert!(changed);
|
||||
let corrupt = replace(&bytes, 2, &code);
|
||||
match ValidatedProgramImage::load(&corrupt, &mut LoadBudget::new(LoadLimits::default()), caps::NONE) {
|
||||
Err(error) => record_fault(root, "generic-contract-wrong-view", error),
|
||||
Ok(image) => {
|
||||
// Unknown receiver facts may defer rejection to the mandatory runtime check.
|
||||
let mut invalid = VirtualMachine::from_image(image, RuntimeLimits::default());
|
||||
invalid.prepare_boot_call().unwrap();
|
||||
let report = invalid.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_TYPE), "mismatched concrete view: {report:?}");
|
||||
}
|
||||
}
|
||||
println!("PBS GENERIC WRONG-VIEW REJECTION PASS");
|
||||
}
|
||||
println!("PBS GENERIC METADATA {name}: types={} implementations={} bytes={}", declarations.types.len(), declarations.implementations.len(), bytes.len());
|
||||
let limits = if name == "identity" || name == "manual" {
|
||||
RuntimeLimits::default().lowered(RuntimeResource::HandleSlots, 1).unwrap()
|
||||
} else { RuntimeLimits::default() };
|
||||
let mut vm = VirtualMachine::from_image(image, limits);
|
||||
let observer = vm.resource_observer();
|
||||
vm.prepare_boot_call().unwrap();
|
||||
let mut report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
if name == "gc" {
|
||||
assert!(matches!(report.reason, End::FrameSync), "{name}: {report:?}");
|
||||
let gc = vm.resource_snapshot().gc;
|
||||
assert!(gc.collections >= 1 && gc.reclaimed >= 1100, "{gc:?}");
|
||||
report = vm.run_budget(100_000, &mut NoNative, &mut HostContext::new(None)).unwrap();
|
||||
}
|
||||
if name == "imports" {
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
|
||||
} else {
|
||||
assert!(matches!(report.reason, End::Halted | End::EndOfRom), "{name}: {report:?}");
|
||||
assert_eq!(vm.operand_stack_top(1), vec![Value::Int32(42)], "{name}");
|
||||
}
|
||||
if name == "identity" || name == "manual" {
|
||||
assert_eq!(vm.heap().len(), 1, "no generic argument box or view wrapper");
|
||||
let heap = observer.used(RuntimeResource::GuestBytes);
|
||||
if let Some(reference) = reference_heap { assert_eq!(heap, reference, "generic and manual contract heap footprints"); }
|
||||
reference_heap = Some(heap);
|
||||
}
|
||||
drop(vm);
|
||||
for resource in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots, RuntimeResource::AuxiliaryBytes,
|
||||
RuntimeResource::TemporaryBytes, RuntimeResource::StringBytes, RuntimeResource::StringAllocations] {
|
||||
assert_eq!(observer.used(resource), 0, "{name}: release {resource:?}");
|
||||
}
|
||||
if name == "identity" || name == "receiver" {
|
||||
for (resource, limit) in [(RuntimeResource::GuestBytes, 0), (RuntimeResource::GuestBytes, 1), (RuntimeResource::GuestBytes, 2), (RuntimeResource::HandleSlots, 0)] {
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE).unwrap();
|
||||
let mut refused = VirtualMachine::from_image(image, RuntimeLimits::default().lowered(resource, limit).unwrap());
|
||||
let observed = refused.resource_observer();
|
||||
refused.prepare_boot_call().unwrap();
|
||||
let report = refused.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:?}: {report:?}");
|
||||
assert_eq!(refused.heap().len(), 0, "refusal cannot publish partial objects");
|
||||
assert!(observed.used(resource) <= limit);
|
||||
drop(refused);
|
||||
for domain in [RuntimeResource::GuestBytes, RuntimeResource::HandleSlots, RuntimeResource::AuxiliaryBytes, RuntimeResource::TemporaryBytes] {
|
||||
assert_eq!(observed.used(domain), 0);
|
||||
}
|
||||
}
|
||||
reject(root, &format!("generic-contract-{name}-load-quota"), &bytes, LoadLimits { implementations: 0, ..LoadLimits::default() });
|
||||
}
|
||||
println!("PBS GENERIC 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 ["closure-objects", "array-cycle", "tuple-storage", "struct-contract"] {
|
||||
|
||||
@@ -14,6 +14,7 @@ parser.add_argument("--online", action="store_true", help="Allow Cargo to fetch
|
||||
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")
|
||||
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")
|
||||
args = parser.parse_args()
|
||||
runtime = args.runtime.resolve()
|
||||
if not args.math_only:
|
||||
@@ -42,4 +43,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 [])], 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 []), *(["--random-only"] if args.random_only else []), *(["--generic-contracts-only"] if args.generic_contracts_only else [])], check=True)
|
||||
|
||||
Reference in New Issue
Block a user