Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/egglog-r2il-probe/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion crates/lance-graph-nal/src/nal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/lance-graph-onnx/examples/alias_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion crates/lance-graph-onnx/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions crates/lance-graph-r2il/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
27 changes: 23 additions & 4 deletions crates/lance-graph-r2il/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 ───────
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -768,6 +776,17 @@ 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<Val>) -> 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<Val>) -> Result<(), FoldError> {
match f {
FnIndex::NUMBER => {
stack.push(Val::Scalar(i64::from(v[0])));
Expand Down
2 changes: 1 addition & 1 deletion crates/lance-graph-r2il/src/procs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
5 changes: 4 additions & 1 deletion crates/lance-graph-r2il/tests/dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ 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};
#[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,
};
Expand Down Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion crates/lance-graph-r2il/tests/procs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/lance-graph-relalg/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 0 additions & 1 deletion crates/math-polyfill-probe/examples/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion crates/math-polyfill-probe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion crates/math-polyfill-probe/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion crates/math-polyfill-probe/tests/polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions crates/r2il-mask-abi-probe/tests/row_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ──────────────────────────
Expand Down
Loading