Skip to content

Commit 7ccbae9

Browse files
committed
u
Signed-off-by: Joe Isaacs <[email protected]>
1 parent 56a05f4 commit 7ccbae9

File tree

4 files changed

+46
-117
lines changed

4 files changed

+46
-117
lines changed

vortex-array/src/expr/exprs/get_item/transform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mod tests {
6969

7070
// Create: get_item("x", lit(42)) - not a pack child
7171
let lit_expr = lit(42);
72-
let get_item_expr = get_item("x", lit_expr.clone());
72+
let get_item_expr = get_item("x", lit_expr);
7373

7474
let dtype = DType::Primitive(PType::I32, NonNullable);
7575
let ctx = SimpleRewriteContext { dtype: &dtype };

vortex-array/src/expr/session/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::expr::exprs::pack::Pack;
2323
use crate::expr::exprs::root::Root;
2424
use crate::expr::exprs::select::Select;
2525
use crate::expr::exprs::select::transform::RemoveSelectRule;
26+
use crate::expr::transform::TypedRewriteContext;
2627
use crate::expr::transform::rules::{ParentReduceRule, ReduceRule, RewriteContext};
2728
use crate::expr::{ExprVTable, VTable};
2829

@@ -62,7 +63,7 @@ impl ExprSession {
6263
where
6364
V: VTable,
6465
R: 'static,
65-
for<'a> R: ReduceRule<V, &'a dyn crate::expr::transform::TypedRewriteContext>,
66+
for<'a> R: ReduceRule<V, &'a dyn TypedRewriteContext>,
6667
{
6768
self.rewrite_rules.register_typed_reduce_rule(vtable, rule);
6869
}
@@ -93,7 +94,7 @@ impl ExprSession {
9394
where
9495
V: VTable,
9596
R: 'static,
96-
for<'a> R: ParentReduceRule<V, &'a dyn crate::expr::transform::TypedRewriteContext>,
97+
for<'a> R: ParentReduceRule<V, &'a dyn TypedRewriteContext>,
9798
{
9899
self.rewrite_rules.register_typed_parent_rule(vtable, rule);
99100
}

vortex-array/src/expr/session/rewrite.rs

Lines changed: 36 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,34 @@ pub(crate) trait DynTypedReduceRule: Send + Sync {
2828
) -> VortexResult<Option<Expression>>;
2929
}
3030

31-
/// Concrete wrapper that implements DynReduceRule for rules with `&dyn RewriteContext` context.
32-
struct ReduceRuleAdapter<V, R>
33-
where
34-
V: VTable,
35-
for<'a> R: ReduceRule<V, &'a dyn RewriteContext>,
36-
{
31+
/// Type-erased wrapper for ParentReduceRule that allows dynamic dispatch.
32+
pub(crate) trait DynParentReduceRule: Send + Sync {
33+
fn reduce_parent_dyn(
34+
&self,
35+
expr: &Expression,
36+
parent: &Expression,
37+
child_idx: usize,
38+
ctx: &dyn RewriteContext,
39+
) -> VortexResult<Option<Expression>>;
40+
}
41+
42+
pub(crate) trait DynTypedParentReduceRule: Send + Sync {
43+
fn reduce_parent_dyn_typed(
44+
&self,
45+
expr: &Expression,
46+
parent: &Expression,
47+
child_idx: usize,
48+
ctx: &dyn TypedRewriteContext,
49+
) -> VortexResult<Option<Expression>>;
50+
}
51+
52+
/// Universal adapter for both ReduceRule and ParentReduceRule with any context type.
53+
struct RuleAdapter<V: VTable, R> {
3754
rule: R,
3855
_phantom: PhantomData<V>,
3956
}
4057

41-
impl<V, R> ReduceRuleAdapter<V, R>
42-
where
43-
V: VTable,
44-
for<'a> R: ReduceRule<V, &'a dyn RewriteContext>,
45-
{
58+
impl<V: VTable, R> RuleAdapter<V, R> {
4659
fn new(rule: R) -> Self {
4760
Self {
4861
rule,
@@ -51,7 +64,8 @@ where
5164
}
5265
}
5366

54-
impl<V, R> DynReduceRule for ReduceRuleAdapter<V, R>
67+
// Implement DynReduceRule for any ReduceRule with RewriteContext
68+
impl<V, R> DynReduceRule for RuleAdapter<V, R>
5569
where
5670
V: VTable,
5771
for<'a> R: ReduceRule<V, &'a dyn RewriteContext>,
@@ -68,30 +82,8 @@ where
6882
}
6983
}
7084

71-
/// Concrete wrapper that implements DynReduceRule for rules with `&dyn TypedRewriteContext` context.
72-
struct TypedReduceRuleAdapter<V, R>
73-
where
74-
V: VTable,
75-
for<'a> R: ReduceRule<V, &'a dyn TypedRewriteContext>,
76-
{
77-
rule: R,
78-
_phantom: PhantomData<V>,
79-
}
80-
81-
impl<V, R> TypedReduceRuleAdapter<V, R>
82-
where
83-
V: VTable,
84-
for<'a> R: ReduceRule<V, &'a dyn TypedRewriteContext>,
85-
{
86-
fn new(rule: R) -> Self {
87-
Self {
88-
rule,
89-
_phantom: PhantomData,
90-
}
91-
}
92-
}
93-
94-
impl<V, R> DynTypedReduceRule for TypedReduceRuleAdapter<V, R>
85+
// Implement DynTypedReduceRule for any ReduceRule with TypedRewriteContext
86+
impl<V, R> DynTypedReduceRule for RuleAdapter<V, R>
9587
where
9688
V: VTable,
9789
for<'a> R: ReduceRule<V, &'a dyn TypedRewriteContext>,
@@ -108,41 +100,8 @@ where
108100
}
109101
}
110102

111-
/// Type-erased wrapper for ParentReduceRule that allows dynamic dispatch.
112-
pub(crate) trait DynParentReduceRule: Send + Sync {
113-
fn reduce_parent_dyn(
114-
&self,
115-
expr: &Expression,
116-
parent: &Expression,
117-
child_idx: usize,
118-
ctx: &dyn RewriteContext,
119-
) -> VortexResult<Option<Expression>>;
120-
}
121-
122-
/// Concrete wrapper that implements DynParentReduceRule for a specific VTable type.
123-
struct ParentReduceRuleAdapter<V, R>
124-
where
125-
V: VTable,
126-
for<'a> R: ParentReduceRule<V, &'a dyn RewriteContext>,
127-
{
128-
rule: R,
129-
_phantom: PhantomData<V>,
130-
}
131-
132-
impl<V, R> ParentReduceRuleAdapter<V, R>
133-
where
134-
V: VTable,
135-
for<'a> R: ParentReduceRule<V, &'a dyn RewriteContext>,
136-
{
137-
fn new(rule: R) -> Self {
138-
Self {
139-
rule,
140-
_phantom: PhantomData,
141-
}
142-
}
143-
}
144-
145-
impl<V, R> DynParentReduceRule for ParentReduceRuleAdapter<V, R>
103+
// Implement DynParentReduceRule for any ParentReduceRule with RewriteContext
104+
impl<V, R> DynParentReduceRule for RuleAdapter<V, R>
146105
where
147106
V: VTable,
148107
for<'a> R: ParentReduceRule<V, &'a dyn RewriteContext>,
@@ -161,39 +120,8 @@ where
161120
}
162121
}
163122

164-
pub(crate) trait DynTypedParentReduceRule: Send + Sync {
165-
fn reduce_parent_dyn_typed(
166-
&self,
167-
expr: &Expression,
168-
parent: &Expression,
169-
child_idx: usize,
170-
ctx: &dyn TypedRewriteContext,
171-
) -> VortexResult<Option<Expression>>;
172-
}
173-
174-
struct TypedParentReduceRuleAdapter<V: VTable, R>
175-
where
176-
V: VTable,
177-
for<'a> R: ParentReduceRule<V, &'a dyn TypedRewriteContext>,
178-
{
179-
rule: R,
180-
_phantom: PhantomData<V>,
181-
}
182-
183-
impl<V, R> TypedParentReduceRuleAdapter<V, R>
184-
where
185-
V: VTable,
186-
for<'a> R: ParentReduceRule<V, &'a dyn TypedRewriteContext>,
187-
{
188-
fn new(rule: R) -> Self {
189-
Self {
190-
rule,
191-
_phantom: PhantomData,
192-
}
193-
}
194-
}
195-
196-
impl<V, R> DynTypedParentReduceRule for TypedParentReduceRuleAdapter<V, R>
123+
// Implement DynTypedParentReduceRule for any ParentReduceRule with TypedRewriteContext
124+
impl<V, R> DynTypedParentReduceRule for RuleAdapter<V, R>
197125
where
198126
V: VTable,
199127
for<'a> R: ParentReduceRule<V, &'a dyn TypedRewriteContext>,
@@ -252,7 +180,7 @@ impl RewriteRuleRegistry {
252180
for<'a> R: ReduceRule<V, &'a dyn TypedRewriteContext>,
253181
{
254182
let id = vtable.id();
255-
let adapter = TypedReduceRuleAdapter::new(rule);
183+
let adapter = RuleAdapter::new(rule);
256184
self.typed_reduce_rules
257185
.entry(id)
258186
.or_default()
@@ -268,7 +196,7 @@ impl RewriteRuleRegistry {
268196
for<'a> R: ReduceRule<V, &'a dyn RewriteContext>,
269197
{
270198
let id = vtable.id();
271-
let adapter = ReduceRuleAdapter::new(rule);
199+
let adapter = RuleAdapter::new(rule);
272200
self.reduce_rules
273201
.entry(id)
274202
.or_default()
@@ -282,7 +210,7 @@ impl RewriteRuleRegistry {
282210
for<'a> R: ParentReduceRule<V, &'a dyn RewriteContext>,
283211
{
284212
let id = vtable.id();
285-
let adapter = ParentReduceRuleAdapter::new(rule);
213+
let adapter = RuleAdapter::new(rule);
286214
self.parent_rules
287215
.entry(id)
288216
.or_default()
@@ -297,7 +225,7 @@ impl RewriteRuleRegistry {
297225
for<'a> R: ParentReduceRule<V, &'a dyn TypedRewriteContext>,
298226
{
299227
let id = vtable.id();
300-
let adapter = TypedParentReduceRuleAdapter::new(rule);
228+
let adapter = RuleAdapter::new(rule);
301229
self.typed_parent_rules
302230
.entry(id)
303231
.or_default()

vortex-array/src/expr/transform/simplify.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod tests {
110110
// Test: 0 + x should simplify to x
111111
let x = col("x");
112112
let zero = lit(0);
113-
let expr = checked_add(zero.clone(), x.clone());
113+
let expr = checked_add(zero, x.clone());
114114

115115
let result = simplify(expr, &session).unwrap();
116116

@@ -125,8 +125,8 @@ mod tests {
125125
// Test: 0 + (0 + x) should simplify to 0 + x, then to x
126126
let x = col("x");
127127
let zero = lit(0);
128-
let zero_plus_x = checked_add(zero.clone(), x.clone());
129-
let expr = checked_add(zero.clone(), zero_plus_x);
128+
let zero_plus_x = checked_add(lit(0), x.clone());
129+
let expr = checked_add(zero, zero_plus_x);
130130

131131
let result = simplify(expr, &session).unwrap();
132132

@@ -141,7 +141,7 @@ mod tests {
141141
// Test: x + 0 should simplify to x
142142
let x = col("x");
143143
let zero = lit(0);
144-
let expr = checked_add(x.clone(), zero.clone());
144+
let expr = checked_add(x.clone(), zero);
145145

146146
let result = simplify(expr, &session).unwrap();
147147

@@ -156,8 +156,8 @@ mod tests {
156156
// Test: (0 + x) + 0 should simplify to x
157157
let x = col("x");
158158
let zero = lit(0);
159-
let zero_plus_x = checked_add(zero.clone(), x.clone());
160-
let expr = checked_add(zero_plus_x, zero.clone());
159+
let zero_plus_x = checked_add(lit(0), x.clone());
160+
let expr = checked_add(zero_plus_x, zero);
161161

162162
let result = simplify(expr, &session).unwrap();
163163

0 commit comments

Comments
 (0)