✓
Passing This code compiles and runs correctly.
Code
// TEST: std/trellis — enforce a tree-shape law over a CONFORMING program.
//
// A trellis DESCRIBES VALID SHAPES OF THE AST: its branches are regex
// patterns (the branch name IS the pattern, byte-for-byte — same surface as
// std/regex:match) over SERIALIZED ANCESTRY PATHS of the program's flow
// trees. Path alphabet (proposed ruling): event names and branch labels as
// segments, `/` as separator, bindings/args excluded — patterns describe
// shape, not data. Example path for the flow below:
//
// std/kernel:init/kernel/std/kernel:self
//
// Each path is matched against the trellis arms, first match wins (regex
// dispatch semantics, FULL match). An arm constructing `=> ok` accepts the
// path; `=> error "msg"` rejects it with a located, koru-level diagnostic.
// Paths matching no arm are unconstrained (placement-constraint semantics;
// closedness is spelled with a catch-all error arm).
//
// `enforce` makes the trellis a program-wide LAW, checked at comptime in
// Stage C, BEFORE kernel transforms consume the tree. The check dissolves —
// zero runtime cost. This generalizes the hand-rolled denylist walker in
// koru_std/kernel.kz (validateKernelSubtree) into a declarative allowlist,
// and is the categorization substrate for variant selection (gpu-legal,
// simd-fusable, ...).
//
// This program CONFORMS: self sits under init through the kernel branch.
// Expected: compiles, runs, prints the doubled masses.
~import std/trellis
~import std/kernel
~import std/io
~std/trellis:define("kernel-shape")
| `std/kernel:init/kernel/.*` _ => ok
| `.*std/kernel:pairwise` _ => error "std/kernel:pairwise found outside std/kernel:init"
| `.*std/kernel:self` _ => error "std/kernel:self found outside std/kernel:init"
~std/trellis:enforce("kernel-shape")
~std/kernel:shape(Body) {
mass: f64,
}
~std/kernel:init(Body) {
{ mass: 1.0 },
{ mass: 2.0 },
}
| kernel k |> std/kernel:self { k.mass *= 2.0 }
| computed c |> std/io:print.blk {
mass[0]={{ c[0].mass:f }} mass[1]={{ c[1].mass:f }}
}
Actual
mass[0]=2 mass[1]=4
Expected output
mass[0]=2 mass[1]=4
Flows
flow ~define click a branch to expand · @labels scroll to their anchor
define (expr: "kernel-shape")
flow ~enforce click a branch to expand · @labels scroll to their anchor
enforce (expr: "kernel-shape")
flow ~shape click a branch to expand · @labels scroll to their anchor
shape (expr: Body, source: mass: f64,)
flow ~init click a branch to expand · @labels scroll to their anchor
init (expr: Body, source: { mass: 1.0 },
{ mass: 2.0 },)
Test Configuration
MUST_RUN