Skip to content

Commit e47dbc0

Browse files
authored
Remove VTable downcasting (#2469)
No need, since we're already in an `impl for E`
1 parent ed56a02 commit e47dbc0

18 files changed

+41
-116
lines changed

vortex-array/src/compute/between.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ where
5252
.downcast_ref::<E::Array>()
5353
.vortex_expect("Failed to downcast array");
5454
let vtable = arr.vtable();
55-
let encoding = vtable
56-
.as_any()
57-
.downcast_ref::<E>()
58-
.vortex_expect("Failed to downcast encoding");
59-
BetweenFn::between(encoding, array_ref, lower, upper, options)
55+
BetweenFn::between(self, array_ref, lower, upper, options)
6056
}
6157
}
6258

vortex-array/src/compute/binary_numeric.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ where
3131
.downcast_ref::<E::Array>()
3232
.vortex_expect("Failed to downcast array");
3333
let vtable = lhs.vtable();
34-
let encoding = vtable
35-
.as_any()
36-
.downcast_ref::<E>()
37-
.vortex_expect("Failed to downcast encoding");
38-
BinaryNumericFn::binary_numeric(encoding, array_ref, rhs, op)
34+
35+
BinaryNumericFn::binary_numeric(self, array_ref, rhs, op)
3936
}
4037
}
4138

vortex-array/src/compute/boolean.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ where
4545
.downcast_ref::<E::Array>()
4646
.vortex_expect("Failed to downcast array");
4747
let vtable = lhs.vtable();
48-
let encoding = vtable
49-
.as_any()
50-
.downcast_ref::<E>()
51-
.vortex_expect("Failed to downcast encoding");
52-
BinaryBooleanFn::binary_boolean(encoding, array_ref, rhs, op)
48+
49+
BinaryBooleanFn::binary_boolean(self, array_ref, rhs, op)
5350
}
5451
}
5552

vortex-array/src/compute/cast.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ where
1818
.downcast_ref::<E::Array>()
1919
.vortex_expect("Failed to downcast array");
2020
let vtable = array.vtable();
21-
let encoding = vtable
22-
.as_any()
23-
.downcast_ref::<E>()
24-
.vortex_expect("Failed to downcast encoding");
25-
CastFn::cast(encoding, array_ref, dtype)
21+
22+
CastFn::cast(self, array_ref, dtype)
2623
}
2724
}
2825

vortex-array/src/compute/compare.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ where
9898
.downcast_ref::<E::Array>()
9999
.vortex_expect("Failed to downcast array");
100100
let vtable = lhs.vtable();
101-
let encoding = vtable
102-
.as_any()
103-
.downcast_ref::<E>()
104-
.vortex_expect("Failed to downcast encoding");
105-
CompareFn::compare(encoding, array_ref, rhs, operator)
101+
102+
CompareFn::compare(self, array_ref, rhs, operator)
106103
}
107104
}
108105

vortex-array/src/compute/fill_forward.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ where
2222
.downcast_ref::<E::Array>()
2323
.vortex_expect("Failed to downcast array");
2424
let vtable = array.vtable();
25-
let encoding_ref = vtable
26-
.as_any()
27-
.downcast_ref::<E>()
28-
.vortex_expect("Failed to downcast encoding");
29-
FillForwardFn::fill_forward(encoding_ref, array_ref)
25+
FillForwardFn::fill_forward(self, array_ref)
3026
}
3127
}
3228

vortex-array/src/compute/fill_null.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ where
2121
.downcast_ref::<E::Array>()
2222
.vortex_expect("Failed to downcast array");
2323
let vtable = array.vtable();
24-
let encoding = vtable
25-
.as_any()
26-
.downcast_ref::<E>()
27-
.vortex_expect("Failed to downcast encoding");
28-
FillNullFn::fill_null(encoding, array_ref, fill_value)
24+
25+
FillNullFn::fill_null(self, array_ref, fill_value)
2926
}
3027
}
3128

vortex-array/src/compute/filter.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ where
2929
.downcast_ref::<E::Array>()
3030
.vortex_expect("Failed to downcast array");
3131
let vtable = array.vtable();
32-
let encoding = vtable
33-
.as_any()
34-
.downcast_ref::<E>()
35-
.vortex_expect("Failed to downcast encoding");
36-
FilterFn::filter(encoding, array_ref, mask)
32+
33+
FilterFn::filter(self, array_ref, mask)
3734
}
3835
}
3936

vortex-array/src/compute/invert.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ where
1919
.downcast_ref::<E::Array>()
2020
.vortex_expect("Failed to downcast array");
2121
let vtable = array.vtable();
22-
let encoding = vtable
23-
.as_any()
24-
.downcast_ref::<E>()
25-
.vortex_expect("Failed to downcast encoding");
26-
InvertFn::invert(encoding, array_ref)
22+
23+
InvertFn::invert(self, array_ref)
2724
}
2825
}
2926

vortex-array/src/compute/like.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ where
2626
) -> VortexResult<Option<ArrayRef>> {
2727
let encoding = array.vtable();
2828
LikeFn::like(
29-
encoding
30-
.as_any()
31-
.downcast_ref::<E>()
32-
.ok_or_else(|| vortex_err!("Mismatched encoding"))?,
29+
self,
3330
array
3431
.as_any()
3532
.downcast_ref()

vortex-array/src/compute/mask.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ where
2424
.downcast_ref::<E::Array>()
2525
.vortex_expect("Failed to downcast array");
2626
let vtable = array.vtable();
27-
let encoding = vtable
28-
.as_any()
29-
.downcast_ref::<E>()
30-
.vortex_expect("Failed to downcast encoding");
31-
MaskFn::mask(encoding, array_ref, mask)
27+
28+
MaskFn::mask(self, array_ref, mask)
3229
}
3330
}
3431

vortex-array/src/compute/min_max.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ where
2626
.downcast_ref::<E::Array>()
2727
.vortex_expect("Failed to downcast array");
2828
let vtable = array.vtable();
29-
let encoding = vtable
30-
.as_any()
31-
.downcast_ref::<E>()
32-
.vortex_expect("Failed to downcast encoding");
33-
MinMaxFn::min_max(encoding, array_ref)
29+
30+
MinMaxFn::min_max(self, array_ref)
3431
}
3532
}
3633

vortex-array/src/compute/scalar_at.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ where
2121
.downcast_ref::<E::Array>()
2222
.vortex_expect("Failed to downcast array");
2323
let vtable = array.vtable();
24-
let encoding = vtable
25-
.as_any()
26-
.downcast_ref::<E>()
27-
.vortex_expect("Failed to downcast encoding");
28-
ScalarAtFn::scalar_at(encoding, array_ref, index)
24+
25+
ScalarAtFn::scalar_at(self, array_ref, index)
2926
}
3027
}
3128

vortex-array/src/compute/search_sorted.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,8 @@ where
168168
.downcast_ref::<E::Array>()
169169
.vortex_expect("Failed to downcast array");
170170
let vtable = array.vtable();
171-
let encoding = vtable
172-
.as_any()
173-
.downcast_ref::<E>()
174-
.vortex_expect("Failed to downcast encoding");
175-
SearchSortedFn::search_sorted(encoding, array_ref, value, side)
171+
172+
SearchSortedFn::search_sorted(self, array_ref, value, side)
176173
}
177174

178175
fn search_sorted_many(
@@ -186,11 +183,8 @@ where
186183
.downcast_ref::<E::Array>()
187184
.vortex_expect("Failed to downcast array");
188185
let vtable = array.vtable();
189-
let encoding = vtable
190-
.as_any()
191-
.downcast_ref::<E>()
192-
.vortex_expect("Failed to downcast encoding");
193-
SearchSortedFn::search_sorted_many(encoding, array_ref, values, side)
186+
187+
SearchSortedFn::search_sorted_many(self, array_ref, values, side)
194188
}
195189
}
196190

@@ -209,11 +203,8 @@ where
209203
.downcast_ref::<E::Array>()
210204
.vortex_expect("Failed to downcast array");
211205
let vtable = array.vtable();
212-
let encoding = vtable
213-
.as_any()
214-
.downcast_ref::<E>()
215-
.vortex_expect("Failed to downcast encoding");
216-
SearchSortedUsizeFn::search_sorted_usize(encoding, array_ref, value, side)
206+
207+
SearchSortedUsizeFn::search_sorted_usize(self, array_ref, value, side)
217208
}
218209

219210
fn search_sorted_usize_many(
@@ -227,11 +218,8 @@ where
227218
.downcast_ref::<E::Array>()
228219
.vortex_expect("Failed to downcast array");
229220
let vtable = array.vtable();
230-
let encoding = vtable
231-
.as_any()
232-
.downcast_ref::<E>()
233-
.vortex_expect("Failed to downcast encoding");
234-
SearchSortedUsizeFn::search_sorted_usize_many(encoding, array_ref, values, side)
221+
222+
SearchSortedUsizeFn::search_sorted_usize_many(self, array_ref, values, side)
235223
}
236224
}
237225

vortex-array/src/compute/slice.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ where
2222
.downcast_ref::<E::Array>()
2323
.vortex_expect("Failed to downcast array");
2424
let vtable = array.vtable();
25-
let encoding = vtable
26-
.as_any()
27-
.downcast_ref::<E>()
28-
.vortex_expect("Failed to downcast encoding");
29-
SliceFn::slice(encoding, array_ref, start, stop)
25+
26+
SliceFn::slice(self, array_ref, start, stop)
3027
}
3128
}
3229

vortex-array/src/compute/take.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ where
5050
.downcast_ref::<E::Array>()
5151
.vortex_expect("Failed to downcast array");
5252
let vtable = array.vtable();
53-
let encoding = vtable
54-
.as_any()
55-
.downcast_ref::<E>()
56-
.vortex_expect("Failed to downcast encoding");
57-
TakeFn::take(encoding, array_ref, indices)
53+
54+
TakeFn::take(self, array_ref, indices)
5855
}
5956

6057
fn take_into(
@@ -68,11 +65,8 @@ where
6865
.downcast_ref::<E::Array>()
6966
.vortex_expect("Failed to downcast array");
7067
let vtable = array.vtable();
71-
let encoding = vtable
72-
.as_any()
73-
.downcast_ref::<E>()
74-
.vortex_expect("Failed to downcast encoding");
75-
TakeFn::take_into(encoding, array_ref, indices, builder)
68+
69+
TakeFn::take_into(self, array_ref, indices, builder)
7670
}
7771
}
7872

vortex-array/src/compute/to_arrow.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ where
3232
.downcast_ref::<E::Array>()
3333
.vortex_expect("Failed to downcast array");
3434
let vtable = array.vtable();
35-
let encoding = vtable
36-
.as_any()
37-
.downcast_ref::<E>()
38-
.vortex_expect("Failed to downcast encoding");
39-
ToArrowFn::preferred_arrow_data_type(encoding, array_ref)
35+
36+
ToArrowFn::preferred_arrow_data_type(self, array_ref)
4037
}
4138

4239
fn to_arrow(
@@ -49,11 +46,8 @@ where
4946
.downcast_ref::<E::Array>()
5047
.vortex_expect("Failed to downcast array");
5148
let vtable = array.vtable();
52-
let encoding = vtable
53-
.as_any()
54-
.downcast_ref::<E>()
55-
.vortex_expect("Failed to downcast encoding");
56-
ToArrowFn::to_arrow(encoding, array_ref, data_type)
49+
50+
ToArrowFn::to_arrow(self, array_ref, data_type)
5751
}
5852
}
5953

vortex-array/src/vtable/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ pub trait EncodingVTable:
7070
{
7171
/// Return the ID for this encoding implementation.
7272
fn id(&self) -> EncodingId;
73-
74-
/// Return a reference to this encoding as a `dyn Any` for type erasure.
75-
fn as_any(&self) -> &dyn Any;
7673
}
7774

7875
impl PartialEq for dyn EncodingVTable + '_ {
@@ -105,8 +102,4 @@ impl<
105102
fn id(&self) -> EncodingId {
106103
E::ID
107104
}
108-
109-
fn as_any(&self) -> &dyn Any {
110-
self
111-
}
112105
}

0 commit comments

Comments
 (0)