Split IR Expr into ExprKind

This commit is contained in:
2026-04-24 21:33:47 -06:00
parent 8a81636490
commit 81d43d2e13

View File

@@ -117,6 +117,9 @@ pub struct Assumption<T: ProgramInfo> {
#[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))]
#[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))]
pub struct RuleBody<T: ProgramInfo> {
/// Metadata for this rule body.
pub meta: T::RuleBodyMeta,
/// The type of each variable.
///
/// Also defines the upper bound on valid variable indices.
@@ -125,11 +128,41 @@ pub struct RuleBody<T: ProgramInfo> {
/// Maps relation indices to the IDs of loaded relations.
pub loaded: Vec<T::RelationLabel>,
/// The inner logic for this rule.
pub logic: T::RuleBodyLogic,
/// This rule body's expression body.
pub body: Expr<T>,
}
/// Metadata for this rule body.
pub meta: T::RuleBodyMeta,
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive_where(PartialOrd, Ord; T: OrdProgramInfo)]
#[derive_where(Hash; T: HashProgramInfo)]
#[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))]
#[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))]
pub struct Expr<T: ProgramInfo> {
pub meta: T::ExprMeta,
pub kind: ExprKind<T>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive_where(PartialOrd, Ord; T: OrdProgramInfo)]
#[derive_where(Hash; T: HashProgramInfo)]
#[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))]
#[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))]
pub enum ExprKind<T: ProgramInfo> {
Variable(u32),
Value(Value),
Load {
relation: u32,
query: Vec<QueryTerm>,
},
UnaryOp {
op: UnaryOpKind,
term: Arc<Expr<T>>,
},
BinaryOp {
op: BinaryOpKind,
lhs: Arc<Expr<T>>,
rhs: Arc<Expr<T>>,
},
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -154,27 +187,6 @@ pub enum AssumptionWeight {
Soft(u32),
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum Expr {
Variable(u32),
Value(Value),
Load {
relation: u32,
query: Vec<QueryTerm>,
},
UnaryOp {
op: UnaryOpKind,
term: Arc<Expr>,
},
BinaryOp {
op: BinaryOpKind,
lhs: Arc<Expr>,
rhs: Arc<Expr>,
},
}
/// Redundant operations (Sub, Neq, Gt, Ge) are not included.
// TODO: more docs
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -320,8 +332,8 @@ pub trait ProgramInfo: Info {
/// Metadata for a rule body.
type RuleBodyMeta: Info;
/// The type containing the rule body's logic.
type RuleBodyLogic: Info;
/// Metadata for each expression tree node.
type ExprMeta: Info;
}
/// A blanket trait bounding all associated types in [ProgramInfo].
@@ -338,7 +350,7 @@ macro_rules! def_bound_info {
AssumptionMeta: $bounds,
RuleMeta: $bounds,
RuleBodyMeta: $bounds,
RuleBodyLogic: $bounds,
ExprMeta: $bounds,
>
{
}
@@ -350,7 +362,7 @@ macro_rules! def_bound_info {
AssumptionMeta: $bounds,
RuleMeta: $bounds,
RuleBodyMeta: $bounds,
RuleBodyLogic: $bounds,
ExprMeta: $bounds,
>
{
}