diff --git a/crates/ir/src/lib.rs b/crates/ir/src/lib.rs index 9915bb9..af0bc72 100644 --- a/crates/ir/src/lib.rs +++ b/crates/ir/src/lib.rs @@ -117,6 +117,9 @@ pub struct Assumption { #[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))] #[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))] pub struct RuleBody { + /// 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 { /// Maps relation indices to the IDs of loaded relations. pub loaded: Vec, - /// The inner logic for this rule. - pub logic: T::RuleBodyLogic, + /// This rule body's expression body. + pub body: Expr, +} - /// 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 { + pub meta: T::ExprMeta, + pub kind: ExprKind, +} + +#[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 { + Variable(u32), + Value(Value), + Load { + relation: u32, + query: Vec, + }, + UnaryOp { + op: UnaryOpKind, + term: Arc>, + }, + BinaryOp { + op: BinaryOpKind, + lhs: Arc>, + rhs: Arc>, + }, } #[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, - }, - UnaryOp { - op: UnaryOpKind, - term: Arc, - }, - BinaryOp { - op: BinaryOpKind, - lhs: Arc, - rhs: Arc, - }, -} - /// 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, > { }