From 1f738e1a628b5bb6d22bd0d33461cee61855220b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 16:42:09 +0000 Subject: [PATCH 1/3] lance-graph-r2il: FoldDialect::call is inherent; the ogar_loco::Dialect impl is an adapter Executing an R2IL call no longer needs ogar_loco's interpreter trait in scope. The Dialect impl forwards to the inherent call and is behind the default loco-dialect feature, so ogar_loco::Interpreter can still drive the dialect. Callers that imported Dialect only to reach call drop the import. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF --- crates/egglog-r2il-probe/src/lower.rs | 1 - crates/lance-graph-nal/src/nal.rs | 2 +- crates/lance-graph-r2il/Cargo.toml | 6 +++++ crates/lance-graph-r2il/src/lib.rs | 28 ++++++++++++++++++++---- crates/lance-graph-r2il/src/procs.rs | 2 +- crates/lance-graph-r2il/tests/dialect.rs | 2 +- crates/lance-graph-r2il/tests/procs.rs | 1 - 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/crates/egglog-r2il-probe/src/lower.rs b/crates/egglog-r2il-probe/src/lower.rs index 645649422..cc3bf444b 100644 --- a/crates/egglog-r2il-probe/src/lower.rs +++ b/crates/egglog-r2il-probe/src/lower.rs @@ -14,7 +14,6 @@ use lance_graph_contract::set_rules::Arith; use lance_graph_mask_risc::{Foreign, Planes}; use lance_graph_r2il::{FoldDialect, FoldError, INT_MULT, Val}; -use ogar_loco::Dialect; use crate::term::Tm; use crate::{Compiled, LowerRefusal}; diff --git a/crates/lance-graph-nal/src/nal.rs b/crates/lance-graph-nal/src/nal.rs index 624d094e8..a8e9abdf5 100644 --- a/crates/lance-graph-nal/src/nal.rs +++ b/crates/lance-graph-nal/src/nal.rs @@ -18,7 +18,7 @@ use lance_graph_mask_risc::{ CompiledProgram, CrossPowerSums, Foreign, Lowering, Out, Planes, Pred, Program, Scratch, Value, }; use lance_graph_r2il::{procs, FoldDialect, FoldError, Val, INT_S_LESS, LOAD, POP_COUNT}; -use ogar_loco::{Dialect, FnIndex}; +use ogar_loco::FnIndex; use crate::{ evidence, Aperture, Bound, NalError, Statement, HORIZON, LANE_C, LANE_EVIDENCE, LANE_F, LANE_W, diff --git a/crates/lance-graph-r2il/Cargo.toml b/crates/lance-graph-r2il/Cargo.toml index 5cc17c151..614270963 100644 --- a/crates/lance-graph-r2il/Cargo.toml +++ b/crates/lance-graph-r2il/Cargo.toml @@ -8,6 +8,12 @@ description = "The fold reading of R2IL executed over mask-risc: FoldDialect, an # A workspace member: the root `Cargo.toml` patches the contract and ndarray # git coordinates to their local paths, so there is one of each. +[features] +# The `ogar_loco::Dialect` adapter, so `ogar_loco::Interpreter` can drive the +# dialect. Execution never needs it: `FoldDialect::call` is inherent. +default = ["loco-dialect"] +loco-dialect = [] + [dependencies] # The only bulk execution engine. lance-graph-mask-risc = { path = "../lance-graph-mask-risc" } diff --git a/crates/lance-graph-r2il/src/lib.rs b/crates/lance-graph-r2il/src/lib.rs index 89560df35..09ae91f6a 100644 --- a/crates/lance-graph-r2il/src/lib.rs +++ b/crates/lance-graph-r2il/src/lib.rs @@ -1,8 +1,10 @@ //! `lance-graph-r2il` — the fold reading of R2IL, executed over mask-risc. //! -//! [`FoldDialect`] is an [`ogar_loco::Dialect`] that interprets R2IL calls -//! (`ogar_r2il`'s opcode table, R2IL band `0x90..=0xE1` plus the fold band -//! `0xE2..=0xED`) over borrowed column planes. Predicate calls build +//! [`FoldDialect`] interprets R2IL calls through its inherent +//! [`FoldDialect::call`]; with the default `loco-dialect` feature it is also an +//! `ogar_loco::Dialect`, so `ogar_loco::Interpreter` can drive it. Each call is +//! an opcode of `ogar_r2il`'s table (R2IL band `0x90..=0xE1` plus the fold +//! band `0xE2..=0xED`), executed over borrowed column planes. Predicate calls build //! [`MaskOp`]s; at every scalar-producing fold (`SUM`, `POP_COUNT`, //! `GROUP_SUM`, `KEEP`) the accumulated ops are finalized into one //! mask-risc [`Program`] and run with [`execute_into`]. mask-risc is the only @@ -110,7 +112,9 @@ use lance_graph_mask_risc::{ FuseError, GroupKey, LaneKind, MaskOp, Operand, Out, Planes, Pred, Program, Scratch, Terminal, Value, }; -use ogar_loco::{Dialect, FnIndex}; +#[cfg(feature = "loco-dialect")] +use ogar_loco::Dialect; +use ogar_loco::FnIndex; use ogar_r2il::{ALL, ANY, GROUP_SUM, KEEP, KEY_RUNS, MAX, MIN, R2IL_BASE, RANGE, SUM, VIA}; // ── R2IL-band opcodes this dialect wires, by their VERIFIED ordinals ─────── @@ -739,6 +743,10 @@ fn is_mask(v: Val) -> bool { matches!(v, Val::Slot { .. } | Val::Address(Addr::Plane(_))) } +/// Lets `ogar_loco::Interpreter` drive this dialect. Execution itself is the +/// inherent [`FoldDialect::call`]; this impl only forwards to it and adds the +/// interpreter's branching hooks. +#[cfg(feature = "loco-dialect")] impl Dialect for FoldDialect<'_> { type Value = Val; type Error = FoldError; @@ -768,6 +776,18 @@ impl Dialect for FoldDialect<'_> { /// for the exhaustive list of which of the twelve fold-band opcodes and /// which R2IL-band opcodes each arm below covers. fn call(&mut self, f: FnIndex, v: [u8; 3], stack: &mut Vec) -> Result<(), FoldError> { + FoldDialect::call(self, f, v, stack) + } +} + + +impl FoldDialect<'_> { + /// Execute one R2IL call: pop its operands off the stack, + /// push its result. The whole dispatch table this crate wires — see the + /// crate doc's § "Implemented, and refused by name" + /// for the exhaustive list of which of the twelve fold-band opcodes and + /// which R2IL-band opcodes each arm below covers. + pub fn call(&mut self, f: FnIndex, v: [u8; 3], stack: &mut Vec) -> Result<(), FoldError> { match f { FnIndex::NUMBER => { stack.push(Val::Scalar(i64::from(v[0]))); diff --git a/crates/lance-graph-r2il/src/procs.rs b/crates/lance-graph-r2il/src/procs.rs index 5089fc041..4062b77fc 100644 --- a/crates/lance-graph-r2il/src/procs.rs +++ b/crates/lance-graph-r2il/src/procs.rs @@ -12,7 +12,7 @@ //! address on top of the stack. Lane arguments are indexes into //! [`Planes::lanes`](lance_graph_mask_risc::Planes::lanes). -use ogar_loco::{Dialect, FnIndex}; +use ogar_loco::FnIndex; use ogar_r2il::{ALL, ANY, GROUP_SUM, KEEP, KEY_RUNS, MAX, MIN, SUM}; use crate::{ diff --git a/crates/lance-graph-r2il/tests/dialect.rs b/crates/lance-graph-r2il/tests/dialect.rs index 996e4438a..6c697c96c 100644 --- a/crates/lance-graph-r2il/tests/dialect.rs +++ b/crates/lance-graph-r2il/tests/dialect.rs @@ -11,7 +11,7 @@ use lance_graph_r2il::{ Addr, FoldDialect, FoldError, Val, INT_ADD, INT_AND, INT_EQUAL, INT_LESS, INT_LESS_EQUAL, INT_MULT, INT_NOT, INT_OR, INT_SUB, INT_S_DIV, INT_S_LESS, INT_XOR, LOAD, MAX_SLOTS, POP_COUNT, }; -use ogar_loco::{Dialect, FnIndex}; +use ogar_loco::FnIndex; use ogar_r2il::{ R2ILFn, ALL, ANY, BLEND, GROUP_SUM, KEEP, KEY_RUNS, R2IL_BASE, RANGE, SCATTER_OR, SUM, VIA, }; diff --git a/crates/lance-graph-r2il/tests/procs.rs b/crates/lance-graph-r2il/tests/procs.rs index ec51e3767..a19249f44 100644 --- a/crates/lance-graph-r2il/tests/procs.rs +++ b/crates/lance-graph-r2il/tests/procs.rs @@ -15,7 +15,6 @@ use lance_graph_r2il::{ BoolMode, FoldDialect, FoldError, Val, INT_ADD, INT_AND, INT_MULT, INT_NOT, INT_OR, INT_S_DIV, INT_XOR, POP_COUNT, }; -use ogar_loco::Dialect; use ogar_r2il::KEEP; const N: usize = 1_000; From fbe2faecbe994c947bb59dc37be9068b9d02ca02 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 17:51:07 +0000 Subject: [PATCH 2/3] lance-graph-r2il: gate the Dialect-trait test on loco-dialect; fmt The truthy test calls the ogar_loco::Dialect method, so it imports the trait and runs only with the loco-dialect feature (default). Tests pass with and without the feature; clippy -D warnings is clean in both. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF --- crates/lance-graph-r2il/src/lib.rs | 1 - crates/lance-graph-r2il/tests/dialect.rs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/lance-graph-r2il/src/lib.rs b/crates/lance-graph-r2il/src/lib.rs index 09ae91f6a..d68c04bd0 100644 --- a/crates/lance-graph-r2il/src/lib.rs +++ b/crates/lance-graph-r2il/src/lib.rs @@ -780,7 +780,6 @@ impl Dialect for FoldDialect<'_> { } } - impl FoldDialect<'_> { /// Execute one R2IL call: pop its operands off the stack, /// push its result. The whole dispatch table this crate wires — see the diff --git a/crates/lance-graph-r2il/tests/dialect.rs b/crates/lance-graph-r2il/tests/dialect.rs index 6c697c96c..04d2a2ad1 100644 --- a/crates/lance-graph-r2il/tests/dialect.rs +++ b/crates/lance-graph-r2il/tests/dialect.rs @@ -11,6 +11,8 @@ use lance_graph_r2il::{ Addr, FoldDialect, FoldError, Val, INT_ADD, INT_AND, INT_EQUAL, INT_LESS, INT_LESS_EQUAL, INT_MULT, INT_NOT, INT_OR, INT_SUB, INT_S_DIV, INT_S_LESS, INT_XOR, LOAD, MAX_SLOTS, POP_COUNT, }; +#[cfg(feature = "loco-dialect")] +use ogar_loco::Dialect; use ogar_loco::FnIndex; use ogar_r2il::{ R2ILFn, ALL, ANY, BLEND, GROUP_SUM, KEEP, KEY_RUNS, R2IL_BASE, RANGE, SCATTER_OR, SUM, VIA, @@ -213,6 +215,7 @@ fn every_named_refusal_is_still_produced() { /// FAILS IF: branching on a population stops being recorded, or branching /// on a scalar starts being recorded. +#[cfg(feature = "loco-dialect")] #[test] fn branching_on_a_population_poisons_and_a_scalar_does_not() { let values = lane(); From ba74ecc0cabf4c4a3dc07150476dfb6972e3ba9d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 18:19:27 +0000 Subject: [PATCH 3/3] Drop ogar_loco::Dialect imports made unused by the inherent FoldDialect::call math-polyfill-probe (lib, native, examples/layers, tests/polyfill), lance-graph-relalg (lower), lance-graph-onnx (examples/alias_cost, tests/conformance) and r2il-mask-abi-probe (tests/row_bridge) called FoldDialect::call through the trait; the inherent method now resolves first, so the import fails -D warnings. clippy --all-targets -D warnings is clean on all seven crates that touch FoldDialect. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XAqKMNZqKXSaeb9g2ypywF --- crates/lance-graph-onnx/examples/alias_cost.rs | 1 - crates/lance-graph-onnx/tests/conformance.rs | 1 - crates/lance-graph-relalg/src/lower.rs | 2 +- crates/math-polyfill-probe/examples/layers.rs | 1 - crates/math-polyfill-probe/src/lib.rs | 1 - crates/math-polyfill-probe/src/native.rs | 1 - crates/math-polyfill-probe/tests/polyfill.rs | 1 - crates/r2il-mask-abi-probe/tests/row_bridge.rs | 4 +--- 8 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/lance-graph-onnx/examples/alias_cost.rs b/crates/lance-graph-onnx/examples/alias_cost.rs index 4bf04ea14..61cf72968 100644 --- a/crates/lance-graph-onnx/examples/alias_cost.rs +++ b/crates/lance-graph-onnx/examples/alias_cost.rs @@ -23,7 +23,6 @@ use lance_graph_mask_risc::{Foreign, LaneRef, Planes}; use lance_graph_onnx as onnx; use lance_graph_r2il::{FoldDialect, Val, INT_S_LESS, LOAD}; use ndarray::Array1; -use ogar_loco::Dialect; struct Counting; static ALLOCS: AtomicUsize = AtomicUsize::new(0); diff --git a/crates/lance-graph-onnx/tests/conformance.rs b/crates/lance-graph-onnx/tests/conformance.rs index 2bc6b0162..fd336f355 100644 --- a/crates/lance-graph-onnx/tests/conformance.rs +++ b/crates/lance-graph-onnx/tests/conformance.rs @@ -463,7 +463,6 @@ fn composite_matches_the_oracle_mask_risc_r2il_and_relalg() { // The r2il fold reading: t < x, then SUM. let mut d = FoldDialect::new(&planes, &Foreign::NONE); let mut stack = vec![Val::Scalar(i64::from(t)), Val::Scalar(0)]; - use ogar_loco::Dialect as _; d.call(LOAD, [1, 0, 0], &mut stack).unwrap(); d.call(INT_S_LESS, [0; 3], &mut stack).unwrap(); lance_graph_r2il::procs::sum(&mut d, &mut stack, 0).unwrap(); diff --git a/crates/lance-graph-relalg/src/lower.rs b/crates/lance-graph-relalg/src/lower.rs index cf3309b2e..8af05ff74 100644 --- a/crates/lance-graph-relalg/src/lower.rs +++ b/crates/lance-graph-relalg/src/lower.rs @@ -6,7 +6,7 @@ use lance_graph_mask_risc::{Foreign, Planes, Program}; use lance_graph_r2il::{ FoldDialect, FoldError, Val, INT_AND, INT_EQUAL, INT_NOT, INT_OR, INT_S_LESS, LOAD, POP_COUNT, }; -use ogar_loco::{Dialect, FnIndex}; +use ogar_loco::FnIndex; use ogar_r2il::{KEEP, MAX, MIN, RANGE, SUM}; use crate::ir::{Atom, Cmp, Measure, Query, Rel}; diff --git a/crates/math-polyfill-probe/examples/layers.rs b/crates/math-polyfill-probe/examples/layers.rs index 348e39bee..53c32328c 100644 --- a/crates/math-polyfill-probe/examples/layers.rs +++ b/crates/math-polyfill-probe/examples/layers.rs @@ -29,7 +29,6 @@ use lance_graph_mask_risc::ir::{CompiledProgram, MaskOp, Operand, Pred, Program, use lance_graph_mask_risc::{words_for, Foreign, LaneRef, Out, Planes, Value}; use lance_graph_r2il::procs; use lance_graph_r2il::{FoldDialect, FoldError, Val, INT_S_LESS, LOAD}; -use ogar_loco::Dialect; struct Counting; static ALLOCS: AtomicUsize = AtomicUsize::new(0); diff --git a/crates/math-polyfill-probe/src/lib.rs b/crates/math-polyfill-probe/src/lib.rs index 56a415ba2..688b0c528 100644 --- a/crates/math-polyfill-probe/src/lib.rs +++ b/crates/math-polyfill-probe/src/lib.rs @@ -33,7 +33,6 @@ pub mod onnx_compat; use lance_graph_r2il::procs::{and_cmp_i32, count, is_not_null, sum, Order}; use lance_graph_r2il::{FoldDialect, FoldError, Val, INT_MULT, INT_SUB}; -use ogar_loco::Dialect; /// Lane and plane indexes the expression reads. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/crates/math-polyfill-probe/src/native.rs b/crates/math-polyfill-probe/src/native.rs index 49128a57f..bd0b4414e 100644 --- a/crates/math-polyfill-probe/src/native.rs +++ b/crates/math-polyfill-probe/src/native.rs @@ -11,7 +11,6 @@ use lance_graph_r2il::procs::{is_not_null, sum}; use lance_graph_r2il::{FoldDialect, FoldError, Val, INT_AND, INT_NOT, INT_S_LESS, LOAD}; -use ogar_loco::Dialect; /// `LOAD` space of an `I32` lane, as `FoldDialect` reads it. const SPACE_I32: u8 = 1; diff --git a/crates/math-polyfill-probe/tests/polyfill.rs b/crates/math-polyfill-probe/tests/polyfill.rs index 34ce4c412..cceda66d4 100644 --- a/crates/math-polyfill-probe/tests/polyfill.rs +++ b/crates/math-polyfill-probe/tests/polyfill.rs @@ -8,7 +8,6 @@ use lance_graph_r2il::{ }; use lance_graph_relalg::{run, Answer, Cmp, Measure, Query, Rel}; use math_polyfill_probe::{eval, oracle, Expr, Layout}; -use ogar_loco::Dialect; const L: Layout = Layout { x: 0, diff --git a/crates/r2il-mask-abi-probe/tests/row_bridge.rs b/crates/r2il-mask-abi-probe/tests/row_bridge.rs index 567499a7a..fbb16a0b1 100644 --- a/crates/r2il-mask-abi-probe/tests/row_bridge.rs +++ b/crates/r2il-mask-abi-probe/tests/row_bridge.rs @@ -265,9 +265,7 @@ use lance_graph_r2il::{ LOAD, MAX_SLOTS, POP_COUNT, }; use ogar_loco::vocabulary::conformance::validate; -use ogar_loco::{ - Call, Dialect, FnIndex, FunctionBody, Interpreter, LaneShape, Program as LocoProgram, -}; +use ogar_loco::{Call, FnIndex, FunctionBody, Interpreter, LaneShape, Program as LocoProgram}; use ogar_r2il::{R2ILVocabulary, GROUP_SUM, KEEP, RANGE, SUM, VIA}; // ── allocation counter — THREAD-LOCAL, not global ──────────────────────────