From 59a50b32ae85afbe8d52f8206517a3c280c4d8cf Mon Sep 17 00:00:00 2001 From: Marceline Cramer Date: Sun, 26 Apr 2026 15:07:19 -0600 Subject: [PATCH] More generics on expressions --- crates/ir/src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/ir/src/lib.rs b/crates/ir/src/lib.rs index 423ebb9..7f3534c 100644 --- a/crates/ir/src/lib.rs +++ b/crates/ir/src/lib.rs @@ -151,6 +151,7 @@ pub struct Expr { #[cfg_attr(feature = "fuzz", derive_where(Arbitrary; T: ArbitraryProgramInfo))] #[cfg_attr(feature = "serde", derive_where(Deserialize, Serialize; T: SerdeProgramInfo))] pub enum ExprKind { + Extra(T::ExprExtra), Variable(u32), Value(Value), Load { @@ -158,11 +159,11 @@ pub enum ExprKind { query: Vec, }, UnaryOp { - op: UnaryOpKind, + op: T::UnaryOp, term: Arc>, }, BinaryOp { - op: BinaryOpKind, + op: T::BinaryOp, lhs: Arc>, rhs: Arc>, }, @@ -337,6 +338,15 @@ pub trait ProgramInfo { /// Metadata for each expression tree node. type ExprMeta: Info; + + /// The type of binary operators. + type BinaryOp: Info + From + TryInto; + + /// The type of unary operators. + type UnaryOp: Info + From + TryInto; + + /// Extensions to [Expr] past the primitive definitions. + type ExprExtra: Info; } /// A blanket trait bounding all associated types in [ProgramInfo]. @@ -356,6 +366,9 @@ macro_rules! def_bound_info { RuleMeta: $bounds, RuleBodyMeta: $bounds, ExprMeta: $bounds, + BinaryOp: $bounds, + UnaryOp: $bounds, + ExprExtra: $bounds, > { } @@ -368,6 +381,9 @@ macro_rules! def_bound_info { RuleMeta: $bounds, RuleBodyMeta: $bounds, ExprMeta: $bounds, + BinaryOp: $bounds, + UnaryOp: $bounds, + ExprExtra: $bounds, > { }