diff --git a/spec/checker/src/form/bridge.rs b/spec/checker/src/form/bridge.rs index 1d4bc0e0..9e5c55e6 100644 --- a/spec/checker/src/form/bridge.rs +++ b/spec/checker/src/form/bridge.rs @@ -2442,15 +2442,14 @@ impl Built { // test's value (the Iterate passes the test's outputs to the body). self.seed_flow(sc, test_stmts, rest, &[])?; let vars = carried_vars(sc, &[test_stmts, rest]); - let thread = (sc.omega.is_some() || parent_omega.is_some()) - && (self.stmts_need_order(test_stmts) - || self.stmts_need_order(rest) - || sc.omega.is_some()); - // A count Iterate may halt, so it has no applied form unless a region - // actually consumes ω (C7 drops a carried ω that is only passed through). - if !thread { + // A count may halt, so it carries order whenever the enclosing + // region has one. C7 keeps that order when neither region uses it + // (erratum 2026-11-13). The old refusal here blamed that removal. + // It is false when an order is in scope. When none is, the region + // still has no order to carry; that is the message below, not C7. + if sc.omega.is_none() && parent_omega.is_none() { return Err(self.deny( - "bound: a count-bounded Iterate must carry ω, and C7 removes a carried ω that neither region uses, so this pure count loop has no applied form", + "omega: a count-bounded Iterate may halt, and this region has no ω to carry", )); } let mut test = self.open_region(sc, parent_omega, &vars, true)?; @@ -2468,20 +2467,13 @@ impl Built { }; let mut bod = self.open_region(sc, parent_omega, &vars, true)?; let bw = bod.omega; - // A body break that names this loop is the flag. A pure count still - // has no applied form: the flag is a bool and is not a use of ω (O8). + // A body break that names this loop is the flag. The flag is a + // bool and is not a use of ω. The count still carries order, and + // C7 keeps that order when neither region uses it (erratum 2026-11-13). let bflag = self.exec_body(rest, &mut bod, bw, ret_ty, brk)?; if let Some(r) = bod.exit_residual { sc.exit_residual = Some(r); } - if !region_uses_order(&test) && !region_uses_order(&bod) { - // The body may have been read as a flag. A pure count is still - // outside Dom, so that reading is not an admission (O8). - BODY_BREAK.with(|c| c.set(false)); - return Err(self.deny( - "bound: a count-bounded Iterate must carry ω, and C7 removes a carried ω that neither region uses, so this pure count loop has no applied form", - )); - } let test_b = Body { nodes: std::mem::take(&mut test.nodes), out: region_outs(&test, flag, &vars, true, None) @@ -2765,23 +2757,10 @@ impl Built { let mut bod = build_region(mid_body, &parts.flag1, &parts.sets1)?; lose_outputs(sc, &test); lose_outputs(sc, &bod); + // Both regions are given order together when the enclosing region + // has one, so a count does not reach a state where only one region + // carries it. The refusal for a count with no order at all is below. let thread = test.omega.is_some() || bod.omega.is_some() || sc.omega.is_some(); - if thread { - for region in [&mut test, &mut bod] { - if region.omega.is_none() { - let p = sc - .omega - .or(parent_omega) - .ok_or_else(|| self.deny("defect: a loop region has no ω"))?; - // inputs were built without ω; refuse rather than renumber - if !region.caps.is_empty() || !region.nodes.is_empty() { - return Err(self.deny("bound: a count-bounded Iterate must carry ω, and this loop's regions do not both receive it")); - } - region.caps.insert(0, p); - region.omega = Some(Src::In(0)); - } - } - } let omega_used = |region: &Scope| -> bool { let Some(Src::In(0)) = region.omega else { return region.omega.is_some(); @@ -2796,8 +2775,18 @@ impl Built { } touch(®ion.nodes, Src::In(0)) || region.omega != Some(Src::In(0)) }; - if count.is_some() && !omega_used(&test) && !omega_used(&bod) { - return Err(self.deny("bound: a count-bounded Iterate must carry ω, and C7 removes a carried ω that neither region uses, so this pure count loop has no applied form")); + // Both regions may only pass order through. C7 keeps that carried + // order on a count (erratum 2026-11-13), so the old refusal is + // false in that case. A count whose regions were not given an + // order still has none to carry. + if count.is_some() + && !omega_used(&test) + && !omega_used(&bod) + && (test.omega.is_none() || bod.omega.is_none()) + { + return Err(self.deny( + "omega: a count-bounded Iterate may halt, and this region has no ω to carry", + )); } let finish = |region: &mut Scope, sets: &[(u32, Atom)]| -> Result { if let Some(h) = region.env.get(&u32::MAX).copied() { @@ -2839,13 +2828,12 @@ impl Built { out, }) }; - // Recompute outs with a consistent ω bit. + // A count whose regions were given order carries it even when + // neither region uses it (erratum 2026-11-13). A count with no + // order was already refused above. let use_w = test.omega.is_some() && bod.omega.is_some() && (count.is_some() || omega_used(&test) || omega_used(&bod)); - if count.is_some() && !use_w { - return Err(self.deny("bound: a count-bounded Iterate must carry ω, and C7 removes a carried ω that neither region uses, so this pure count loop has no applied form")); - } let mut carried_ty = vec![]; if use_w { carried_ty.push(BTy::Order); @@ -3203,11 +3191,6 @@ fn bool_not(region: &mut Scope, s: Src) -> Src { Src::Out(i, 0) } -fn region_uses_order(region: &Scope) -> bool { - matches!(region.omega, Some(Src::Out(..))) - || region.nodes.iter().any(|n| n.ins.contains(&Src::In(0))) -} - fn region_outs( region: &Scope, flag: Src, diff --git a/spec/checker/src/form/canon.rs b/spec/checker/src/form/canon.rs index de367c2c..bd4bb42c 100644 --- a/spec/checker/src/form/canon.rs +++ b/spec/checker/src/form/canon.rs @@ -313,7 +313,9 @@ fn c7_hook(node: &mut Node, md: &dyn Fn(&Src) -> String) { } /// Remove the carried values of an Iterate that neither region uses and -/// both return unchanged; the Iterate's output for one becomes its initial value. +/// both return unchanged; the Iterate's output for one becomes its initial +/// value. A count-bounded Iterate keeps its carried order (erratum of +/// 2026-11-13): a count may halt, so that order is not an unused carrier. fn c7_carried(b: &Body) -> Body { let mut b = b.clone(); loop { @@ -336,6 +338,11 @@ fn c7_carried(b: &Body) -> Body { { continue; } + // Erratum 2026-11-13: a count may halt, so its carried order + // stays even when both regions only pass it through. + if matches!(&n.attrs, Attr::Count(ts) if ts.get(k) == Some(&BTy::Order)) { + continue; + } let keep = n.regions.iter().any(|r| r.out.get(1 + k) != Some(&Src::In(k as u32)) || uses_input(r, k as u32, Some(1 + k))); if !keep { found = Some((i, k, first)); diff --git a/spec/checker/tests/break_fg8_witness.rs b/spec/checker/tests/break_fg8_witness.rs index 872fb4e3..680cf224 100644 --- a/spec/checker/tests/break_fg8_witness.rs +++ b/spec/checker/tests/break_fg8_witness.rs @@ -1098,7 +1098,10 @@ fn shortcuts_that_admit_the_wrong_program_stay_refused() { assert_eq!(z, Ok(Val::Int(0))); assert_eq!(n4, Ok(Val::Int(1)), "the mutated end stops the next test"); - // A pure count that breaks. The flag is not a use of ω. O8. + // A pure count that breaks. Before the erratum of 2026-11-13 the bridge + // refused this with tag `bound`, because C7 removed the carried order. + // The count now keeps that order. The flag is still not a use of ω. + // The value is the core's value. let ct = build::count_t(); let mut b = FB::new(vec![ct.clone()], ct.clone()); let bound = b.arg(0); @@ -1115,12 +1118,20 @@ fn shortcuts_that_admit_the_wrong_program_stay_refused() { let rv = b.let_(Atom::V(i)); b.ret(rv); let m = module("pure", b.finish()); - let e = refuse(&m); - assert_eq!(e.tag(), "bound", "{}", e.line()); + wf::check(&m).unwrap(); + let f = bridge::construct(&m).unwrap_or_else(|e| panic!("pure count: {}", e.line())); assert!( - !bridge::body_break_rewrite(), - "a refused pure count is not an admission" + f.defs.values().any(|g| g.fns.iter().any(|func| func.body.nodes.iter().any(|n| { + matches!(&n.attrs, fir::Attr::Count(ts) if ts.first() == Some(&fir::BTy::Order)) + }))), + "the pure count dropped its carried order" ); + let (z, _) = core_eval(&m, vec![Val::Int(1)]); + assert_eq!(z, Ok(Val::Int(0))); + let got = feval::apply(&f, &form_key(&f, 1).0, form_key(&f, 1).1, vec![Val::Int(1)]).unwrap(); + assert_eq!(got, vec![Val::Int(0)]); + let (halt, _) = core_eval(&m, vec![Val::Int(0)]); + assert!(halt.is_err(), "bound 0 did not halt: {halt:?}"); // A depth that names nothing. The core rejects it. let mut b = FB::new(vec![], i64ty()); diff --git a/spec/checker/tests/form_bridge.rs b/spec/checker/tests/form_bridge.rs index 000db236..f7dfaa22 100644 --- a/spec/checker/tests/form_bridge.rs +++ b/spec/checker/tests/form_bridge.rs @@ -709,9 +709,32 @@ fn owned_body_break_is_scheduled_once() { assert_eq!(fuel_b, fuel_sb, "O7': fuel differs on the bound path"); } +fn count_carried(f: &fir::Module) -> Vec> { + let mut out = vec![]; + fn walk(b: &fir::Body, out: &mut Vec>) { + for n in &b.nodes { + if let fir::Attr::Count(ts) = &n.attrs { + out.push(ts.clone()); + } + for r in &n.regions { + walk(r, out); + } + } + } + for g in f.defs.values() { + for func in &g.fns { + walk(&func.body, &mut out); + } + } + out +} + #[test] -fn pure_count_break_stays_outside_dom() { - // O8. A break flag is a bool. It does not put a pure count into Dom. +fn pure_count_keeps_carried_order() { + // Erratum of 2026-11-13. Neither region uses ω. The old bridge refused + // with "C7 removes a carried ω that neither region uses". C7 now keeps + // that order, and the count has an applied form. The flag is still a + // bool, not a use of ω. let ct = build::count_t(); let mut b = FB::new(vec![ct.clone()], ct.clone()); let bound = b.arg(0); @@ -720,7 +743,6 @@ fn pure_count_break_stays_outside_dom() { b.loop_(|b| { b.count(cnt, bound)?; let iv = b.let_(Atom::V(i)); - // `int.eq` does not halt, so neither region uses ω. The flag is not a use of ω. let stop = b.int_cmp("int.eq", iv, build::lit(0))?; b.exit_if(stop)?; Ok(()) @@ -730,12 +752,108 @@ fn pure_count_break_stays_outside_dom() { b.ret(r); let m = module("pure", b.finish()); wf::check(&m).unwrap_or_else(|e| panic!("{e}")); - let e = bridge::construct(&m).expect_err("pure count"); - assert_eq!(e.tag(), "bound", "{}", e.line()); + let f = bridge::construct(&m).unwrap_or_else(|e| panic!("{}", e.line())); assert!( - !bridge::body_break_rewrite(), - "a refused pure count is not an admitted break rewrite" + bridge::body_break_rewrite(), + "the body break was not restructured into a flag" ); + let carried = count_carried(&f); + assert!( + carried.iter().any(|ts| ts.first() == Some(&fir::BTy::Order)), + "a count-bounded Iterate dropped its carried order: {carried:?}" + ); + assert!( + flag_is_fresh_false(&f), + "the break path must return a literal false, not a carried bool" + ); + let bytes = fir::encode(&f); + assert!( + matches!(form::check(bytes.as_bytes(), None), form::Outcome::Applied(_)), + "the pure count is not applied" + ); + let s = bridge::schedule(&f).unwrap_or_else(|e| panic!("{}", e.line())); + wf::check(&s).unwrap_or_else(|e| panic!("schedule is not well formed: {e}")); + let back = bridge::construct(&s).unwrap_or_else(|e| panic!("construct of the schedule: {}", e.line())); + assert_eq!(fir::encode(&f), fir::encode(&back), "construct(schedule(F)) is not F"); + // Bound 1: the body breaks on the first iteration, before the next bound check. + agree(&m, &f, &s, vec![Val::Int(1)]); + // Bound 0: the count halts before the body. The flag is not that halt. + agree(&m, &f, &s, vec![Val::Int(0)]); +} + +const NO_ORDER: &str = "omega: a count-bounded Iterate may halt, and this region has no ω to carry"; + +/// A count bound whose trap is the bytes `loop bound` and a `break`, not a +/// `halt`, so the function is not given order. +fn count_without_halt(b: &mut FB, counter: u32, bound: Atom) { + let ct = build::count_t(); + let nv = b.let_(Atom::V(counter)); + let n1 = b.p("int.sadd", vec![ct.clone()], vec![nv, build::lit(1)]).unwrap(); + b.set(counter, n1.clone()); + let over = b.p("int.lt", vec![ct], vec![bound, n1]).unwrap(); + b.open(); + let _ = b.p("bytes.len", vec![], vec![Atom::bytes(b"loop bound")]).unwrap(); + b.brk(0); + let arm = b.close(); + b.push(Stmt::If(over, arm, vec![])); +} + +#[test] +fn a_lowering_count_with_no_order_names_that_refusal() { + // `build_count`. The loop is the lowering's count shape, and nothing in + // the function takes order, so the count cannot carry it. + let ct = build::count_t(); + let mut b = FB::new(vec![ct.clone()], ct.clone()); + let bound = b.arg(0); + let cnt = b.var(ct.clone(), build::lit(0)); + b.loop_(|b| { + count_without_halt(b, cnt, bound); + Ok(()) + }) + .unwrap(); + b.ret(build::lit(0)); + let m = module("bare", b.finish()); + wf::check(&m).unwrap_or_else(|e| panic!("{e}")); + let e = bridge::construct(&m).expect_err("a count with no order"); + assert_eq!(e.reason, NO_ORDER, "{}", e.line()); +} + +#[test] +fn a_schedule_count_with_no_order_names_that_refusal() { + // `loop_stmt`. Two breaks with the same carried store, and a count + // between them. The count's own statements are the bound, not part of + // either region. Nothing takes order. + let ct = build::count_t(); + let mut b = FB::new(vec![ct.clone()], ct.clone()); + let cnt = b.var(ct.clone(), build::lit(0)); + let acc = b.var(ct.clone(), build::lit(0)); + let cmp = |b: &mut FB| -> Atom { + b.p("int.eq", vec![ct.clone()], vec![build::lit(0), build::lit(0)]).unwrap() + }; + let leave = |b: &mut FB, c: Atom| { + b.open(); + let th = b.close(); + b.open(); + b.brk(0); + let el = b.close(); + b.push(Stmt::If(c, th, el)); + }; + b.loop_(|b| { + let c = cmp(b); + b.set(acc, build::lit(0)); + leave(b, c); + count_without_halt(b, cnt, build::lit(2)); + let c = cmp(b); + b.set(acc, build::lit(1)); + leave(b, c); + Ok(()) + }) + .unwrap(); + b.ret(Atom::V(acc)); + let m = module("sched", b.finish()); + wf::check(&m).unwrap_or_else(|e| panic!("{e}")); + let e = bridge::construct(&m).expect_err("a scheduled count with no order"); + assert_eq!(e.reason, NO_ORDER, "{}", e.line()); } #[test] diff --git a/spec/checker/tests/form_bridge_census.txt b/spec/checker/tests/form_bridge_census.txt index f8bf71bb..dca1ef12 100644 --- a/spec/checker/tests/form_bridge_census.txt +++ b/spec/checker/tests/form_bridge_census.txt @@ -41,20 +41,20 @@ whole-with-user 1 whole modules, top 10 by modules unblocked (one tag, or a pair) unblocks set -14 break +15 break 14 round-trip 9 lowering 3 break,exit 2 defect 2 global 1 FG8 -1 bound,break 1 break,catch 1 break,defect +1 catch,global whole modules, every exact set modules set -14 break +15 break 14 round-trip 9 lowering 3 break,exit @@ -64,7 +64,6 @@ modules set 2 defect,exit,loop 2 global 1 FG8 -1 bound,break 1 break,catch 1 break,catch,exit,loop 1 break,defect @@ -133,7 +132,7 @@ module whole roots user global-sites 39_structural_recursion.rce lowering lowering lowering not covered by the lowering: a recursive type 40_extern.rce round-trip clear user 41_arena_bound_wrapping.rce round-trip round-trip user -42_f32.rce bound,break clear user +42_f32.rce break clear user 43_simd_lanes.rce FG8 round-trip user 44_device_region.rce break break user 45_byte_text.rce exit,global round-trip user check 7: global: g3 is not part of the working context ω holds diff --git a/spec/checker/tests/form_c7_order.rs b/spec/checker/tests/form_c7_order.rs new file mode 100644 index 00000000..a45ba994 --- /dev/null +++ b/spec/checker/tests/form_c7_order.rs @@ -0,0 +1,218 @@ +//! C7 on a count-bounded Iterate's carried order. +//! +//! Erratum of 2026-11-13: a count keeps its carried order even when both +//! regions only pass it through. The old rule removed that order. The +//! module it produced does not comply with FG7, because a count may halt +//! and then does not consume and return order. An unused carried value that +//! is not that order is still removed. A measure's unused order is still +//! removed. +use rce_spec_check::form::canon::canonical; +use rce_spec_check::form::ir::{Attr, BTy, Body, Bound, Func, Group, Lit, Module, Node, Src}; +use rce_spec_check::form::{self, Outcome}; +use std::collections::BTreeMap; + +fn lit(t: BTy, v: Lit) -> Node { + Node { attrs: Attr::Lit(t, v), ins: vec![], regions: vec![] } +} + +/// A region that returns true and then each carried input, unchanged. +fn pass(n: u32) -> Body { + Body { + nodes: vec![lit(BTy::Bool, Lit::Bool(true))], + out: std::iter::once(Src::Out(0, 0)).chain((0..n).map(Src::In)).collect(), + } +} + +fn module_of(f: Func) -> Module { + let g = Group { fns: vec![f] }; + let key = rce_spec_check::form::ir::group_key(&g); + Module { + catalogue: rce_spec_check::form::catalogue::key().to_string(), + types: vec![], + regions: vec![], + events: vec![], + errors: vec![], + steps: vec![], + main: None, + caps: vec![], + defs: BTreeMap::from([(key, g)]), + } +} + +fn counts(m: &Module) -> Vec> { + let mut out = vec![]; + fn walk(b: &Body, out: &mut Vec>) { + for n in &b.nodes { + match &n.attrs { + Attr::Count(ts) => out.push(ts.clone()), + Attr::Measure(_, _, ts) => out.push(ts.clone()), + _ => {} + } + for r in &n.regions { + walk(r, out); + } + } + } + for g in m.defs.values() { + for f in &g.fns { + walk(&f.body, &mut out); + } + } + out +} + +fn i100() -> BTy { + BTy::Int(0, 100) +} + +/// Count carrying order and an unused integer. Both regions pass both through. +fn count_with_unused_int() -> Module { + let carried = vec![BTy::Order, i100()]; + let count = Node { + attrs: Attr::Count(carried), + ins: vec![Src::Out(0, 0), Src::In(1), Src::In(0)], + regions: vec![pass(2), pass(2)], + }; + let f = Func { + ins: vec![i100(), BTy::Order], + outs: vec![i100(), BTy::Order], + eff: 1, + bound: Bound::None, + body: Body { + nodes: vec![lit(BTy::u64(), Lit::Int(2)), count], + out: vec![Src::Out(1, 1), Src::Out(1, 0)], + }, + }; + module_of(f) +} + +#[test] +fn a_count_keeps_unused_carried_order_and_drops_another_unused_value() { + let m = count_with_unused_int(); + let (c, first) = canonical(&m).unwrap_or_else(|e| panic!("{}", e.0)); + assert_eq!(first, Some("C7"), "the unused integer was not removed"); + assert_eq!( + counts(&c), + vec![vec![BTy::Order]], + "the old rule removed the carried order as well" + ); + let (again, second) = canonical(&c).unwrap_or_else(|e| panic!("{}", e.0)); + assert_eq!(second, None, "the kept order is not a fixed point"); + assert_eq!(counts(&again), vec![vec![BTy::Order]]); + let bytes = rce_spec_check::form::ir::encode(&c); + match form::check(bytes.as_bytes(), None) { + Outcome::Applied(_) => {} + Outcome::RequiresChange(k) => panic!("the count that keeps order is not applied: {}", k.line()), + } +} + +#[test] +fn a_count_keeps_unused_carried_order_and_drops_an_unused_bool() { + // The same rule as the integer above, for a carried bool. C7 still + // removes a pass-through bool. It keeps the count's order. + let carried = vec![BTy::Order, BTy::Bool]; + let count = Node { + attrs: Attr::Count(carried), + ins: vec![Src::Out(0, 0), Src::In(1), Src::In(0)], + regions: vec![pass(2), pass(2)], + }; + let f = Func { + ins: vec![BTy::Bool, BTy::Order], + outs: vec![BTy::Bool, BTy::Order], + eff: 1, + bound: Bound::None, + body: Body { + nodes: vec![lit(BTy::u64(), Lit::Int(2)), count], + out: vec![Src::Out(1, 1), Src::Out(1, 0)], + }, + }; + let (c, first) = canonical(&module_of(f)).unwrap_or_else(|e| panic!("{}", e.0)); + assert_eq!(first, Some("C7"), "the unused bool was not removed"); + assert_eq!(counts(&c), vec![vec![BTy::Order]], "the count dropped its order: {:?}", counts(&c)); + let bytes = rce_spec_check::form::ir::encode(&c); + match form::check(bytes.as_bytes(), None) { + Outcome::Applied(_) => {} + Outcome::RequiresChange(k) => panic!("the count that keeps order is not applied: {}", k.line()), + } +} + +#[test] +fn the_old_count_without_carried_order_requires_change() { + // The bytes the old C7 produced for a count whose only job for order + // was to carry it: the order is gone, the integer is still carried + // because the body changes it, and the count may still halt. + let wide = BTy::Int(0, 101); + let one = lit(BTy::Int(1, 1), Lit::Int(1)); + let add = Node { + attrs: Attr::Prim("int.add".into(), vec![rce_spec_check::form::ir::TyArg::Body(wide.clone())], None), + ins: vec![Src::In(0), Src::Out(0, 0)], + regions: vec![], + }; + let body = Body { + nodes: vec![one, add, lit(BTy::Bool, Lit::Bool(true))], + out: vec![Src::Out(2, 0), Src::Out(1, 0)], + }; + let count = Node { + attrs: Attr::Count(vec![wide.clone()]), + ins: vec![Src::Out(0, 0), Src::In(0)], + regions: vec![pass(1), body], + }; + let f = Func { + ins: vec![i100(), BTy::Order], + outs: vec![wide, BTy::Order], + eff: 1, + bound: Bound::None, + body: Body { + nodes: vec![lit(BTy::u64(), Lit::Int(2)), count], + out: vec![Src::Out(1, 0), Src::In(1)], + }, + }; + let m = module_of(f); + let (c, _) = canonical(&m).unwrap_or_else(|e| panic!("{}", e.0)); + assert!( + counts(&c).iter().any(|ts| !ts.is_empty() && !ts.contains(&BTy::Order)), + "the stripped count did not stay a count without order: {:?}", + counts(&c) + ); + let bytes = rce_spec_check::form::ir::encode(&c); + match form::check(bytes.as_bytes(), None) { + Outcome::RequiresChange(k) => { + assert_eq!(k.rule, "FG7", "{}", k.line()); + assert!( + k.reason.contains("does not consume and return"), + "{}", + k.line() + ); + } + Outcome::Applied(_) => panic!("a count that lost its carried order was applied"), + } +} + +#[test] +fn a_measure_still_drops_unused_carried_order() { + let span = i100(); + let carried = vec![BTy::Order, span.clone(), span.clone()]; + let measure = Node { + attrs: Attr::Measure(1, 2, carried), + ins: vec![Src::In(2), Src::In(0), Src::In(1)], + regions: vec![pass(3), pass(3)], + }; + let f = Func { + ins: vec![span.clone(), span.clone(), BTy::Order], + outs: vec![span.clone(), span, BTy::Order], + eff: 1, + bound: Bound::None, + body: Body { + nodes: vec![measure], + out: vec![Src::Out(0, 1), Src::Out(0, 2), Src::Out(0, 0)], + }, + }; + let (c, first) = canonical(&module_of(f)).unwrap_or_else(|e| panic!("{}", e.0)); + assert_eq!(first, Some("C7")); + let ts = counts(&c); + assert_eq!(ts.len(), 1, "{ts:?}"); + assert!( + !ts[0].contains(&BTy::Order), + "a measure kept an unused carried order: {ts:?}" + ); +} diff --git a/spec/examples/form/README.md b/spec/examples/form/README.md index a00b50b7..a86e987a 100644 --- a/spec/examples/form/README.md +++ b/spec/examples/form/README.md @@ -27,6 +27,8 @@ canonical rules C1 to C11 and the gate rules FG1 to FG15 of | `types` | a declared record and kind (C8), an option field, a payload, an emitted float | applied | | `group` | `even` and `odd` as one recursive group with declared bounds (C9, FG8) | applied | | `loops` | Iterate with a measure and with a count bound, `list.get` under DF5, `sum.get` under DF4, a memo cell (FG6, FG8) | applied | +| `count-order` | a count-bounded Iterate whose test and body only pass `order` through; C7 keeps that carried order (erratum of 2026-11-13) | applied | +| `count-order-stripped` | the same count with that carried order removed, the bytes the old rule produced | requires change under FG7 | | `counter-c1`, `-c3` … `-c7`, `-c10`, `-c11`, `types-c8`, `group-c9` | each breaks one canonical rule | requires change under FG1 (C1, C10) or FG3 (the others) | | `counter-fg1` … `-fg13`, `types-fg12`, `types-fg14`, `group-fg8`, `counter.wrong-vectors` | each breaks one gate rule | requires change under that rule | | `cycle` | a region whose node reads its own output | requires change under FG4 (below) | diff --git a/spec/examples/form/count-order-stripped.json b/spec/examples/form/count-order-stripped.json new file mode 100644 index 00000000..891b8302 --- /dev/null +++ b/spec/examples/form/count-order-stripped.json @@ -0,0 +1 @@ +{"caps":[],"catalogue":"2db277f8c9f1de15676375642a30c275d75e9d1b9fe48ebcbfcdaae6c0bd0a5a","defs":{"a75a4dd9d94b6e6c8795ea6c4c1d9c168b7ceb1e0741b2b80c84e499d038f414":{"fns":[{"body":{"nodes":[[0,["lit",["int","2","2"],"2"],[],[]],[4,["count",[["int","0","101"]]],[[0,0],[-1,0]],[{"nodes":[[0,["lit",["bool"],true],[],[]]],"out":[[0,0],[-1,0]]},{"nodes":[[0,["lit",["bool"],true],[],[]],[0,["lit",["int","1","1"],"1"],[],[]],[1,["prim","int.add",[["int","0","101"]]],[[-1,0],[1,0]],[]]],"out":[[0,0],[2,0]]}]]],"out":[[1,0],[-1,1]]},"bound":null,"sig":[[["int","0","100"],["order"]],[["int","0","101"],["order"]],1]}]}},"errors":[],"events":[],"format":"rce-form/1","main":null,"regions":[],"steps":[],"types":[]} \ No newline at end of file diff --git a/spec/examples/form/count-order.json b/spec/examples/form/count-order.json new file mode 100644 index 00000000..6b1f2af1 --- /dev/null +++ b/spec/examples/form/count-order.json @@ -0,0 +1 @@ +{"caps":[],"catalogue":"2db277f8c9f1de15676375642a30c275d75e9d1b9fe48ebcbfcdaae6c0bd0a5a","defs":{"89b2ea387760ed2f818a1a98dc97147ef191b9a8d7d31f4b2c91eb08df3206d5":{"fns":[{"body":{"nodes":[[0,["lit",["int","2","2"],"2"],[],[]],[4,["count",[["order"]]],[[0,0],[-1,1]],[{"nodes":[[0,["lit",["bool"],true],[],[]]],"out":[[0,0],[-1,0]]},{"nodes":[[0,["lit",["bool"],true],[],[]]],"out":[[0,0],[-1,0]]}]]],"out":[[-1,0],[1,0]]},"bound":null,"sig":[[["int","0","100"],["order"]],[["int","0","100"],["order"]],1]}]}},"errors":[],"events":[],"format":"rce-form/1","main":null,"regions":[],"steps":[],"types":[]} \ No newline at end of file diff --git a/spec/examples/form/expect.json b/spec/examples/form/expect.json index ea479822..b50cd4dc 100644 --- a/spec/examples/form/expect.json +++ b/spec/examples/form/expect.json @@ -1 +1 @@ -{"fixtures":[{"form":"counter.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"counter-c1.json","names":"C1","outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-c10.json","names":"C10","outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-c11.json","names":"C11","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c3.json","names":"C3","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c4.json","names":"C4","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c5.json","names":"C5","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c6.json","names":"C6","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c7.json","names":"C7","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-fg1.json","names":null,"outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-fg10.json","names":null,"outcome":"requires change","rule":"FG10","vectors":null},{"form":"counter-fg11.json","names":null,"outcome":"requires change","rule":"FG11","vectors":null},{"form":"counter-fg13.json","names":null,"outcome":"requires change","rule":"FG13","vectors":null},{"form":"counter-fg2.json","names":null,"outcome":"requires change","rule":"FG2","vectors":null},{"form":"counter-fg3.json","names":"6.1.1","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-fg4.json","names":null,"outcome":"requires change","rule":"FG4","vectors":null},{"form":"counter-fg5.json","names":null,"outcome":"requires change","rule":"FG5","vectors":null},{"form":"counter-fg6.json","names":null,"outcome":"requires change","rule":"FG6","vectors":null},{"form":"counter-fg7.json","names":null,"outcome":"requires change","rule":"FG7","vectors":null},{"form":"counter-fg8.json","names":null,"outcome":"requires change","rule":"FG8","vectors":null},{"form":"counter.json","names":null,"outcome":"applied","rule":null,"vectors":"counter.vectors.json"},{"form":"counter.json","names":null,"outcome":"requires change","rule":"FG15","vectors":"counter.wrong-vectors.json"},{"form":"cycle.json","names":null,"outcome":"requires change","rule":"FG4","vectors":null},{"form":"group.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"group-c9.json","names":"C9","outcome":"requires change","rule":"FG3","vectors":null},{"form":"group-fg8.json","names":null,"outcome":"requires change","rule":"FG8","vectors":null},{"form":"group.json","names":null,"outcome":"applied","rule":null,"vectors":"group.vectors.json"},{"form":"loops.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"types.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"types-c8.json","names":"C8","outcome":"requires change","rule":"FG3","vectors":null},{"form":"types-fg12.json","names":null,"outcome":"requires change","rule":"FG12","vectors":null},{"form":"types-fg14.json","names":null,"outcome":"requires change","rule":"FG14","vectors":null},{"form":"types.json","names":null,"outcome":"applied","rule":null,"vectors":"types.vectors.json"}],"format":"rce-form-fixtures/1","rules":{"C1":{"applied":"counter","requires_change":"counter-c1"},"C10":{"applied":"counter","requires_change":"counter-c10"},"C11":{"applied":"counter","requires_change":"counter-c11"},"C2":{"applied":"counter","requires_change":null},"C3":{"applied":"counter","requires_change":"counter-c3"},"C4":{"applied":"counter","requires_change":"counter-c4"},"C5":{"applied":"counter","requires_change":"counter-c5"},"C6":{"applied":"counter","requires_change":"counter-c6"},"C7":{"applied":"counter","requires_change":"counter-c7"},"C8":{"applied":"types","requires_change":"types-c8"},"C9":{"applied":"group","requires_change":"group-c9"},"FG1":{"applied":"counter","requires_change":"counter-fg1"},"FG10":{"applied":"types","requires_change":"counter-fg10"},"FG11":{"applied":"types","requires_change":"counter-fg11"},"FG12":{"applied":"types","requires_change":"types-fg12"},"FG13":{"applied":"counter","requires_change":"counter-fg13"},"FG14":{"applied":"types","requires_change":"types-fg14"},"FG15":{"applied":"counter.vectors","requires_change":"counter.wrong-vectors"},"FG2":{"applied":"counter","requires_change":"counter-fg2"},"FG3":{"applied":"counter","requires_change":"counter-fg3"},"FG4":{"applied":"counter","requires_change":"counter-fg4"},"FG5":{"applied":"counter","requires_change":"counter-fg5"},"FG6":{"applied":"loops","requires_change":"counter-fg6"},"FG7":{"applied":"counter","requires_change":"counter-fg7"},"FG8":{"applied":"loops","requires_change":"counter-fg8"},"FG9":{"applied":"loops","requires_change":null}}} \ No newline at end of file +{"fixtures":[{"form":"count-order.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"count-order-stripped.json","names":"does not consume and return","outcome":"requires change","rule":"FG7","vectors":null},{"form":"counter.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"counter-c1.json","names":"C1","outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-c10.json","names":"C10","outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-c11.json","names":"C11","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c3.json","names":"C3","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c4.json","names":"C4","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c5.json","names":"C5","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c6.json","names":"C6","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-c7.json","names":"C7","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-fg1.json","names":null,"outcome":"requires change","rule":"FG1","vectors":null},{"form":"counter-fg10.json","names":null,"outcome":"requires change","rule":"FG10","vectors":null},{"form":"counter-fg11.json","names":null,"outcome":"requires change","rule":"FG11","vectors":null},{"form":"counter-fg13.json","names":null,"outcome":"requires change","rule":"FG13","vectors":null},{"form":"counter-fg2.json","names":null,"outcome":"requires change","rule":"FG2","vectors":null},{"form":"counter-fg3.json","names":"6.1.1","outcome":"requires change","rule":"FG3","vectors":null},{"form":"counter-fg4.json","names":null,"outcome":"requires change","rule":"FG4","vectors":null},{"form":"counter-fg5.json","names":null,"outcome":"requires change","rule":"FG5","vectors":null},{"form":"counter-fg6.json","names":null,"outcome":"requires change","rule":"FG6","vectors":null},{"form":"counter-fg7.json","names":null,"outcome":"requires change","rule":"FG7","vectors":null},{"form":"counter-fg8.json","names":null,"outcome":"requires change","rule":"FG8","vectors":null},{"form":"counter.json","names":null,"outcome":"applied","rule":null,"vectors":"counter.vectors.json"},{"form":"counter.json","names":null,"outcome":"requires change","rule":"FG15","vectors":"counter.wrong-vectors.json"},{"form":"cycle.json","names":null,"outcome":"requires change","rule":"FG4","vectors":null},{"form":"group.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"group-c9.json","names":"C9","outcome":"requires change","rule":"FG3","vectors":null},{"form":"group-fg8.json","names":null,"outcome":"requires change","rule":"FG8","vectors":null},{"form":"group.json","names":null,"outcome":"applied","rule":null,"vectors":"group.vectors.json"},{"form":"loops.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"types.json","names":null,"outcome":"applied","rule":null,"vectors":null},{"form":"types-c8.json","names":"C8","outcome":"requires change","rule":"FG3","vectors":null},{"form":"types-fg12.json","names":null,"outcome":"requires change","rule":"FG12","vectors":null},{"form":"types-fg14.json","names":null,"outcome":"requires change","rule":"FG14","vectors":null},{"form":"types.json","names":null,"outcome":"applied","rule":null,"vectors":"types.vectors.json"}],"format":"rce-form-fixtures/1","rules":{"C1":{"applied":"counter","requires_change":"counter-c1"},"C10":{"applied":"counter","requires_change":"counter-c10"},"C11":{"applied":"counter","requires_change":"counter-c11"},"C2":{"applied":"counter","requires_change":null},"C3":{"applied":"counter","requires_change":"counter-c3"},"C4":{"applied":"counter","requires_change":"counter-c4"},"C5":{"applied":"counter","requires_change":"counter-c5"},"C6":{"applied":"counter","requires_change":"counter-c6"},"C7":{"applied":"counter","requires_change":"counter-c7"},"C8":{"applied":"types","requires_change":"types-c8"},"C9":{"applied":"group","requires_change":"group-c9"},"FG1":{"applied":"counter","requires_change":"counter-fg1"},"FG10":{"applied":"types","requires_change":"counter-fg10"},"FG11":{"applied":"types","requires_change":"counter-fg11"},"FG12":{"applied":"types","requires_change":"types-fg12"},"FG13":{"applied":"counter","requires_change":"counter-fg13"},"FG14":{"applied":"types","requires_change":"types-fg14"},"FG15":{"applied":"counter.vectors","requires_change":"counter.wrong-vectors"},"FG2":{"applied":"counter","requires_change":"counter-fg2"},"FG3":{"applied":"counter","requires_change":"counter-fg3"},"FG4":{"applied":"counter","requires_change":"counter-fg4"},"FG5":{"applied":"counter","requires_change":"counter-fg5"},"FG6":{"applied":"loops","requires_change":"counter-fg6"},"FG7":{"applied":"counter","requires_change":"counter-fg7"},"FG8":{"applied":"loops","requires_change":"counter-fg8"},"FG9":{"applied":"loops","requires_change":null}}} \ No newline at end of file diff --git a/spec/examples/form/make.py b/spec/examples/form/make.py index 0ad3dc0d..e8ae491e 100644 --- a/spec/examples/form/make.py +++ b/spec/examples/form/make.py @@ -591,6 +591,66 @@ def full(a, h): # ---- a region with a cycle, which FG4 keeps before FG9 is reached +def count_order_module(): + """A count whose test and body only pass order through. + + C7 keeps that carried order (erratum of 2026-11-13). The integer input + is not carried: the loop does not mention it, and the function returns it + beside the order the count returns. + """ + i100 = ["int", "0", "100"] + + def counted(r, ins): + i, om = ins + bound = r.lit(lit_int(2), "2") + + def test(t, k): + (tom,) = k + return [t.lit(BOOL, True), tom] + + def body(b, k): + (bom,) = k + return [b.lit(BOOL, True), bom] + + out = r.iterate(["count", [ORDER]], [bound, om], test, body, 1) + return [i, out[0]] + + k, g = group(fn([i100, ORDER], [i100, ORDER], 1, counted)) + return module([(k, g)]) + + +def count_order_stripped_module(): + """A reachable count that does not carry order, which the old C7 left. + + The body returns the integer raised by one, so the count stays reachable + and C7 does not remove that integer. The function is class 1 and takes + order, and the count does not consume it. FG7 keeps that module. C7 does + not put the order back. + """ + i100 = ["int", "0", "100"] + wide = ["int", "0", "101"] + + def counted(r, ins): + i, om = ins + bound = r.lit(lit_int(2), "2") + + def test(t, k): + (ti,) = k + return [t.lit(BOOL, True), ti] + + def body(b, k): + (bi,) = k + one = b.lit(lit_int(1), "1") + stepped = b.prim("int.add", [wide], [bi, one])[0] + return [b.lit(BOOL, True), stepped] + + out = r.iterate(["count", [wide]], [bound, i], test, body, 1) + return [out[0], om] + + k, g = group(fn([i100, ORDER], [wide, ORDER], 1, counted)) + return module([(k, g)]) + + def cycle_module(): m = counter() k_pos = m["steps"][1][2][0] @@ -637,6 +697,8 @@ def fixtures(): yield "group", g, None yield "group.vectors", g, vectors(g, [([(0, [])], [True], "done", [[4]])]) yield "loops", loops_module(), None + yield "count-order", count_order_module(), None + yield "count-order-stripped", count_order_stripped_module(), None for v in ["c3", "c4", "c5", "c6", "c7", "c11", "fg1", "fg2", "fg4", "fg5", "fg6", "fg7", "fg8", "fg10", "fg11", "fg13"]: yield f"counter-{v}", counter(v), None yield "types-c8", types_module("c8"), None @@ -668,6 +730,10 @@ def raw_fixtures(written): "group": ("applied", None, None), "group.vectors": ("applied", None, None), "loops": ("applied", None, None), + # Erratum 2026-11-13: the regions only pass order through, and the count keeps it. + "count-order": ("applied", None, None), + # The bytes the old rule produced: the count no longer carries order, so FG7 keeps it. + "count-order-stripped": ("requires change", "FG7", "does not consume and return"), "counter-c1": ("requires change", "FG1", "C1"), "counter-c10": ("requires change", "FG1", "C10"), "counter-c3": ("requires change", "FG3", "C3"), diff --git a/spec/proposals/LEDGER.md b/spec/proposals/LEDGER.md index ba1227fb..d8b97a4d 100644 --- a/spec/proposals/LEDGER.md +++ b/spec/proposals/LEDGER.md @@ -100,3 +100,4 @@ and the share per reason. | 2026-11-09 | Library functions and unobserved δ stay in the core (book 4.2; rce-form.md FG5; the reference trace, 10.5 and ONE-5): a module of only functions, types, constants and impls denotes that set of functions, and a module with state or an event is a Form module whose regions, δ and initial state exist whether or not an example runs them. `entry` still runs only what the reference trace runs, so it does not call a parameterised function. A generic with no use is not a core function, because the lift monomorphises a generic at a use. The 18 modules that constructed were entry-only cores: the lowered core held only `entry`, and no user code was constructed. That count is not 18 user programs round-tripping. `whole-with-user` was 0. With the definitions kept, whole goes from 18 to 2: 1 entry-only (`09_generics`, still no monomorphic function) and 1 with user code (`35_nested_if`). The syntactic floor stays 5 of 60: `20_strings` leaves it and `35_nested_if` enters it. Nine modules require change in the lowering where the trace alone did not reach the function (`13_spawn_chan`, `14_select`, `15_actor`, `21_maps`, `29_nested_kind`, `34_chan_types`, `37_actor_spawn`, `39_structural_recursion`, `47_select_fair`). The largest remaining whole-module set is global+out, 20. This is not a production compiler | accepted; implemented | A library denotes its functions, and a Form module denotes δ, even when the trace does not run them | `spec/checker/src/one/lower.rs`, `spec/checker/src/one/build.rs`, `spec/checker/tests/one_lower.rs`, `spec/checker/tests/form_bridge_census.txt` | | 2026-11-09 | Output list reads and core `out` on the Form bridge (rce-form.md §5, §13, FG7): a read of the global `outputs` is the output list inside ω. A fresh ω holds that list empty, so the read is `list.new` of bytes. A `list.push` of that list, stored back, appends. A store of `list.new` restores the empty list. A store of the list just read puts the same list back. A branch that changes the list, and a call of a function that reads or stores it, leaves the list unseen, so a later read still requires change. `fuel` and `fuel.limit` stay refused: fuel is charged only by `fuel.tick`, and the fuel limit is not a field of a module. Core `out` of bytes is `emit[text]` on ω. The function's effect class is 2, and a caller of it is class 2. A value that is not bytes still requires the per-type show runtime this slice does not link. `out` leaves every whole-module set. The 20 modules that were exactly global+out are not one set afterwards: 12 are global, and functions that had stopped on the output list now show break, so break+global is 12. The syntactic floor stays 5 of 60. Semantic admission stays 0. Whole stays 2: 1 entry-only (`09_generics`) and 1 with user code (`35_nested_if`). The observation driver still reads `fuel.limit`, so those modules still require change. This is not a production compiler | accepted; implemented | The output list is inside ω, and `out` of bytes is `emit[text]`; the fuel limit is not a field of a module | `spec/checker/src/form/bridge.rs`, `spec/checker/tests/form_bridge.rs`, `spec/checker/tests/form_bridge_census.txt` | | 2026-11-10 | The observation driver's fuel frame on the Form bridge (rce-form.md §5): `fuel.limit` is the limit of a run, per input on a host and per observation in a trace, and it is never a field of a module. The driver reads that global, stores it into `fuel`, runs the observation, then prints `fuel N` from limit minus fuel left. That frame is the runner. A fresh ω already holds the limit, and the fuel line is the runner's step count, so neither read nor the store is a node. A read of `fuel` outside that frame stays refused, because fuel moves only by `fuel.tick`. Constant flags (`const C evaluated`) and the constant's value global are the two halves of a memo cell (rce-form.md §5, §13), not compile-time constants, so they are not folded. Those reads stay refused. Iterator buffers are memo cells of the same kind and stay refused. The exact set global goes from 12 to 2 (`32_comptime_block`, `46_u64`). The syntactic floor stays 5 of 60. Semantic admission stays 0. Whole stays 2: 1 entry-only (`09_generics`) and 1 with user code (`35_nested_if`). A `break` that is not inside a recognised loop is still refused (`Stmt::Break` in `exec_refs`). The law (e = d, `break 0` local, decrement once per block or loop, never per `if`) is already applied inside a loop. A block that is not a loop, the match shape `if tag { } else { break 0 }`, is a gap in the construction. Joining that break with the tail is not shipped: the branch it built did not carry FG8's tag fact. This is not a production compiler | accepted; implemented | The fuel limit is a parameter of the run; the driver's frame is the runner, not a module global | `spec/checker/src/form/bridge.rs`, `spec/checker/tests/form_bridge.rs`, `spec/checker/tests/form_bridge_census.txt` | +| 2026-11-13 | C7 erratum (rce-form.md §6 and §10): a count-bounded Iterate keeps its carried order. Until this date C7 removed every carried value that neither region uses and both return unchanged, and that removal included order. A count may halt, so that order is the chain the bound halt sits on, even when the test and the body only pass it through. A measure's unused order, and every unused carried value that is not that order, are still removed. The four construction sentences that said C7 removes a carried order, so a pure count has no applied form, are withdrawn where that claim is now false. On the 60 examples the only such refusal was `build_count` after both regions had been given order and neither used it, at `rt.big.dec` in `42_f32.rce`. That module's whole set goes from `bound,break` to `break`. The exact set `bound,break` goes from 1 to 0, and `break` from 14 to 15. The other three sentences did not refuse any example. A count with no order in scope still requires change, and the reason no longer names C7. FG7, FG8 and the other gates are unchanged. The syntactic floor stays 5 of 60. Semantic admission stays 0. Whole stays 2. The witness baseline `corpus_baseline_on_50294e05` does not move. This is not a production compiler | accepted (erratum); implemented | A count may halt, and removing the order the regions only pass through takes that halt off the chain FG7 requires | `spec/checker/src/form/canon.rs`, `spec/checker/tests/form_c7_order.rs`, `spec/examples/form/count-order.json`, `spec/checker/tests/form_bridge.rs`, `spec/checker/tests/form_bridge_census.txt` | diff --git a/spec/proposals/break-carried-flag.md b/spec/proposals/break-carried-flag.md index 541b5891..65daee0f 100644 --- a/spec/proposals/break-carried-flag.md +++ b/spec/proposals/break-carried-flag.md @@ -26,7 +26,9 @@ constrains: `spec/lean/RCE/Form.lean`, `spec/lean/RCE/Iter.lean`, ## 1. Terms **Dom** is the set of canonical Forms for which the bridge slice claims -identity. A pure count loop is not in Dom (obligation O8, §3). +identity. A pure count loop is in Dom: the erratum of 2026-11-13 keeps +its carried order (§4.2). The earlier obligation O8 put that loop outside +Dom, because C7 then removed the order. **Syntactic identity** on Dom is `construct(schedule(F)) = F` as canonical bytes. Canonical bytes already apply C7 (capture order by digest, and @@ -53,9 +55,14 @@ node. **A pure count** is a count-bounded Iterate whose test and body do not use ω except by carrying it. FG7 gives every count effect class at least 1, so -the node must consume and return ω. C7 then removes a carried ω that -neither region uses. The slice has no applied form for that loop -(`bound` in the bridge). That is O8: a pure count is outside Dom. +the node must consume and return ω. Until 2026-11-13, C7 then removed that +carried ω, and the slice had no applied form for that loop (`bound` in the +bridge). That was O8. + +**Erratum, 2026-11-13.** C7 now keeps the carried order of a count-bounded +Iterate. A pure count has an applied form: the count carries order, and the +regions may only pass it through. A pass-through bool is still removed. +FG7 is unchanged. See rce-form.md §10. **An exit sum** is a result with one constructor per way a loop ends. The iterator model already has three: `.done`, `.stopped` and `.bound` @@ -115,8 +122,10 @@ region. schedule ∘ construct is already not the identity on the core (§13). The mathground sketch states that identity as obligations O1 to O10. This note does not restate O1 to O7, O9 or O10; their wording is the sketch's. -The obligation this design has to keep visible is O8: a pure count is -outside Dom, because FG7 demands a carried ω and C7 removes it. +The obligation this design kept visible was O8: a pure count was outside +Dom, because FG7 demands a carried ω and, until 2026-11-13, C7 removed it. +The erratum of that date keeps the carried order, so O8 does not hold +after it. The obligations are a plan for a proof. They are not a proof, and this note does not mark them proved. @@ -164,14 +173,17 @@ does not by itself make the measure take ω. A count may halt, so it always takes ω (§6). FG7 checks that a node of class at least 1 consumes and returns ω. The flag is a plain `bool`. It is -not a use of ω. Carrying `go` does not put a pure count into Dom. +not a use of ω. Carrying `go` is not what admits a pure count. The erratum +of 2026-11-13 keeps the carried order, and that is what admits it. C7 keeps a carried value when either region uses it or either region -returns something other than that same input. The break path must return -the literal false, not the incoming `go`. If both regions return `go` -unchanged and neither uses it, C7 removes it and the early exit disappears. -That removal is the same one O8 records for an unused carried ω (constraint -B4, §5). +returns something other than that same input, and it keeps the order of a +count even when both regions only pass that order through. The break path +must return the literal false, not the incoming `go`. If both regions +return `go` unchanged and neither uses it, C7 removes the bool and the +early exit disappears. That removal is the rule for an unused carried +value other than a count's order. It is not O8. O8 recorded a carried +order that C7 used to remove (constraint B4, §5). ω stays linear. Every path of a region that took ω returns it exactly once, including the break path. The flag's own nodes do not read or write ω. If @@ -179,8 +191,8 @@ they did, fuel and the order of effects would change (constraint B3, §5). A count whose regions use ω for a reason other than the unused carrier, and whose body break is the flag above, is the count item 3 can describe. -A pure count stays `bound`, outside Dom, until FG7 or C7 changes. This note -does not propose that change. +A pure count stayed `bound`, outside Dom, until C7 changed. The erratum of +2026-11-13 is that change. This note did not propose it. ## 5. A silent flag rewrite breaks syntactic identity @@ -212,9 +224,10 @@ fuel and the order of operations change. ω orders effects and halts. A flag that touches ω is a different computation, not a spelling of the same one. **B4.** C7 drops `go` when it is only passed through, by the same rule that -drops an unused carried ω. The result is a loop that cannot stop early, the -same way a pure count has no applied form (O8). A pass-through bool is not -an encoding of break. +drops an unused carried value other than the order of a count. The result +is a loop that cannot stop early. A pass-through bool is not an encoding +of break. The erratum of 2026-11-13 keeps a count's carried order and does +not keep a pass-through bool. **B5.** A conditional increment leaves the measure shape. `find_measure` requires `int.lt` (or the `int.le` spelling) of an unchanged index and end, diff --git a/spec/proposals/break-fg8-impl-contract.md b/spec/proposals/break-fg8-impl-contract.md index d2e1dc98..b9c8b729 100644 --- a/spec/proposals/break-fg8-impl-contract.md +++ b/spec/proposals/break-fg8-impl-contract.md @@ -81,11 +81,13 @@ the first Form. **Not a gap, and not to be "fixed" by a new reading of FG8.** A continue path that does not raise the index is not a measure (§6, constraint B5 in -the break note). A pure count still has no applied form: FG7 gives every -count class at least 1, and C7 removes a carried ω that neither region -uses (O8). A guard on one value does not establish a partial operation on -another value, or on a later value of the same variable (§7, DF5). The -tests in section 6 pin these refusals. +the break note). Until 2026-11-13 a pure count had no applied form: FG7 +gives every count class at least 1, and C7 removed a carried ω that neither +region uses (O8). The erratum of that date keeps the carried order, so a +pure count is applied. FG8 is not the rule that changed. A guard on one +value does not establish a partial operation on another value, or on a +later value of the same variable (§7, DF5). The tests in section 6 pin +these refusals, and the pure-count case now pins the kept order. ## 3. Representation of a break @@ -368,11 +370,12 @@ is the smallest core that shows it. The test asserts the refusal that because the flag is false, not because the index moved. 2. **Turn the measure into a count to avoid the check.** A count may halt, - so FG7 requires ω. C7 deletes a carried ω that neither region uses. A - pure count is `bound`, including one whose body breaks (O8). The flag - is a bool and is not a use of ω. Relabeling `mset` as a count either - has no applied form or adds a "loop bound" halt the measure does not - have. Empty input and a one-entry map must not trap with "loop bound". + so FG7 requires ω. Since 2026-11-13 C7 keeps a carried ω that neither + region uses, so a pure count is applied, including one whose body breaks. + The flag is a bool and is not a use of ω. Relabeling `mset` as a count + still adds a "loop bound" halt the measure does not have. Empty input + and a one-entry map must not trap with "loop bound". The witness checks + the value, not a `bound` tag. 3. **Test the flag after the bound.** For a count that does use ω, the schedule tests the flag before raising the counter and before the bound @@ -468,10 +471,12 @@ One change, in the bridge only, after this contract: so `construct(schedule(F))` equals F for `fn table`. That file then sits on the option B row. It is not one of the nine byte mismatches, and it is not covered. `measure_shape` stays. -4. Leave FG8, C7, FG6, FG7, and the pure-count `bound` refusal as they are. - Leave catch, `out`, globals, and a loop that is not a measure or a - count (`rt.f64.parts` in the `fn dot4` closure is "a break outside a - recognised loop") for their own changes. +4. Leave FG8, FG6, and FG7 as they are. The C7 erratum of 2026-11-13 is + already adopted: a pure count keeps its carried order and is not refused + with `bound`. Do not restore that refusal. Leave catch, `out`, globals, + and a loop that is not a measure or a count (`rt.f64.parts` in the + `fn dot4` closure is "a break outside a recognised loop") for their own + changes. `spec/checker/tests/form_bridge.rs` is the other run's file. Extend `break_fg8_witness.rs` rather than editing it. Raise the syntactic floor @@ -541,5 +546,7 @@ What the witnesses check on `410bfd40`: is FG8 at node 3. - `fn main` in `02_hello_main.rce` is refused at `rt.escaped` with `exit: a loop body does not fall through`. The return is not the loop flag. -- The flat body `break 0`, the conditional increment, the mutated end, the - pure count, and a `return` inside a loop stay refused, as section 6 says. +- The flat body `break 0`, the conditional increment, the mutated end, and + a `return` inside a loop stay refused, as section 6 says. A pure count is + applied: C7 keeps its carried order (erratum of 2026-11-13). The flag is + still not a use of ω. diff --git a/spec/proposals/rce-form.md b/spec/proposals/rce-form.md index 59794d2d..02d64f38 100644 --- a/spec/proposals/rce-form.md +++ b/spec/proposals/rce-form.md @@ -230,7 +230,7 @@ A node is `[k, attrs, ins, regions]`. The kind numbers are the kernel's numbers, - **Evaluation order.** A region's nodes are evaluated once each, in index order. The canonical numbering (C5, §10, below) is a topological order, so the order is a function of the graph. - **Calls.** `call` evaluates the callee's body on the arguments. A halt in the callee halts the caller, except under `catch`, which returns the halt as the second variant of its result. On that path `catch` returns the ω that the callee's Halt consumed: fuel and cost spent and outputs gathered before the halt stay, as in the reference, whose `catch` restores none of them. The fuel trap passes through every `catch`, because fuel exhaustion cannot be caught (E1). The core's `catch` catches every halt, the fuel trap included (`one/eval.rs`), so the schedule writes after each `catch` a Branch that halts again when the caught halt is the fuel trap, and the construction reads that pair back as one Form `catch` (§13, below). RCE's own `catch` handles only declared errors (6.2), so the lift of RCE writes after each Form `catch` a Branch on the halt's tag that halts again on a trap text, except the "budget" trap that the `else` of `with budget n … else …` handles (C.5). - **Capabilities.** `cap` is allowed only in the context of `main` and of task bodies (5.11). Its results enter D as `Foreign(f, arguments, result)` and are replayed, never run again (HC-8). -- **Iterate with a count bound.** With bound n and carried values c (ω first): set i = 0; then repeat: run the test region on c, giving (k, c); if k is `false`, output c; else raise i by one, and if i > n, halt with the trap text "loop bound"; run the body region on c, giving (k, c); if k is `false`, output c. This is the order of the reference's loop, which the lowering reproduces in `run_loop` (`one/lower.rs`): the condition is tested, the counter raised, the bound tested, and only then does the body run. So iteration n + 1 traps when it starts, before any of its work, as 6.7 states ("Starting iteration n + 1 is `trap("loop bound")`"). A loop with no condition has a test region that returns `true`; a `break` in the body returns `false`. Because the bound is a source, a bound computed at run time (`while c bound n`, n "comptime-or-runtime") and the default LOOP_LIMIT are the same construct. A count-bounded Iterate may halt, so it always takes ω. +- **Iterate with a count bound.** With bound n and carried values c (ω first): set i = 0; then repeat: run the test region on c, giving (k, c); if k is `false`, output c; else raise i by one, and if i > n, halt with the trap text "loop bound"; run the body region on c, giving (k, c); if k is `false`, output c. This is the order of the reference's loop, which the lowering reproduces in `run_loop` (`one/lower.rs`): the condition is tested, the counter raised, the bound tested, and only then does the body run. So iteration n + 1 traps when it starts, before any of its work, as 6.7 states ("Starting iteration n + 1 is `trap("loop bound")`"). A loop with no condition has a test region that returns `true`; a `break` in the body returns `false`. Because the bound is a source, a bound computed at run time (`while c bound n`, n "comptime-or-runtime") and the default LOOP_LIMIT are the same construct. A count-bounded Iterate may halt, so it always takes ω. C7 keeps that carried order when the test and the body only pass it through (erratum of 2026-11-13, §10). - **Iterate with a measure.** `["measure",[i,j],[τ…]]` is applied only when the gate proves termination by one closed shape: i and j are positions among the carried values; the test region returns carried values i and j unchanged, and its first output is `int.lt` of i and j, or `bool.and` with that `int.lt` as an operand; the body region returns j unchanged and i raised by exactly one whenever it continues. This is the shape of `for` over ranges and lists in the lowering. Such a loop cannot run past its measure, so the Iterate has no run-time check and no trap text. A `for` over a range keeps the reference's check before the loop, as a Branch and a Halt with the trap text "loop bound" when the range holds more than 10 × LOOP_LIMIT items, LOOP_LIMIT being 6.7's default or the module's own value of it (`iter_items` in `interp.rs`). Every other loop carries a count bound, or is step-split (B5, §17, below). - **Halt.** A halt stops the definition. At the top of a step it keeps the event: the whole state stays and λ is `[Kept(X, payload)]` (6.4, 6.5, T8). - **Effect classes.** A function's signature carries one of: 0 total, 1 may halt, 2 emits (step context), 3 host (the context of `main` and of task bodies, where capabilities and foreign calls are allowed). 5.2 gives `fn main` and task functions the same effects, and 5.11 allows foreign calls from both, so one class holds both, and the classes form a chain 0 < 1 < 2 < 3. A function of class 1 or above takes ω as its last input and returns it as its last output; a step body is class 2 by the frame, and `main` and task bodies are class 3. Every node that may halt (a Halt, a count-bounded Iterate, a call or capability that may halt, `fuel.tick`, `cost.charge`) consumes and returns ω. So every halt, fuel exhaustion included, lies on the ω chain, and effects and halts are totally ordered by linearity alone (§8, below). @@ -350,7 +350,9 @@ A type argument ι is a body type, or a frame type for `emit`. A function's `bou - **C4 Sharing.** Two nodes of one region with the same Merkle digest whose inputs and outputs are all plain are one node. A node with an owned input or output is never merged with another: two equal allocations are two values under linearity, and owned twins share a digest, so two nodes that consume twins (two `tup.open` or `sum.get` of equal tuples) also share one, and merging them would leave a twin unused. Such twins are interchangeable, so C5 still numbers them uniquely. - **C5 Numbering.** Nodes are numbered in the first-completion order of an iterative depth-first walk from the region's outputs, in output order, visiting each node's sources in port order. The numbering is topological and is the evaluation order. - **C6 Reachability.** Every node is reachable from its region's outputs. Every node with an effect or that may halt is, because the ω it returns must reach an output. Canonicalisation removes an unreachable node; only a pure, total node can be one, and an owned value it held is dropped, so the removal changes no meaning. -- **C7 Captures and carried values.** A Branch captures exactly the outer sources its arms use, ordered by Merkle digest. An Iterate's carried values keep the lift's order, since loop variables are positional, with ω first when taken; a carried value that neither region uses and both return unchanged is removed. +- **C7 Captures and carried values.** A Branch captures exactly the outer sources its arms use, ordered by Merkle digest. An Iterate's carried values keep the lift's order, since loop variables are positional, with ω first when taken. A carried value that neither region uses and both return unchanged is removed, except the carried order of a count-bounded Iterate, which stays. A count may halt, so that order is the chain the bound halt sits on, even when the test and the body only pass it through. A measure does not halt on a bound, and an unused carried value that is not that order is still removed. + +**Erratum, 2026-11-13.** Until this date the removal in C7 included the carried order of a count-bounded Iterate. FG7 requires every node that may halt to consume and return ω, and a count may halt when the next iteration would pass the bound. Removing an order that the regions only passed through took that halt off the ω chain, so a pure count had no applied form. The rule now keeps that carried order. The rest of C7 is unchanged. - **C8 Types.** Declared types that are structurally equal, recursive ones included, are merged (bisimulation on the type graph); the table is ordered by the digest of each declaration's graph, and indices are renumbered. - **C9 Recursive groups.** Members are ordered by an iterated digest: in round 0 each member is digested with its references inside the group written `["rec","?"]`; in round r + 1 each such reference is replaced by the round-r digest of its target; after as many rounds as there are members, members are sorted by digest, and members with equal final digests are one function (they are bisimilar). So a group's key does not depend on the order in which a module first used its members. - **C10 No unobservable names.** No field holds a name that no program can observe, a comment, a span or layout. Observable names are data (§3).