Skip to content

Commit 2db4ab1

Browse files
authored
remove SessionVar blanket impl, replace with type impls (#7695)
The blanket impl is a bit of a footgun, replace with impls for each of the session extension types See discussion in #7693 (comment) --------- Signed-off-by: Andrew Duffy <andrew@a10y.dev>
1 parent 269cbeb commit 2db4ab1

15 files changed

Lines changed: 180 additions & 16 deletions

File tree

vortex-array/public-api.lock

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ impl core::fmt::Debug for vortex_array::aggregate_fn::session::AggregateFnSessio
762762

763763
pub fn vortex_array::aggregate_fn::session::AggregateFnSession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
764764

765+
impl vortex_session::SessionVar for vortex_array::aggregate_fn::session::AggregateFnSession
766+
767+
pub fn vortex_array::aggregate_fn::session::AggregateFnSession::as_any(&self) -> &dyn core::any::Any
768+
769+
pub fn vortex_array::aggregate_fn::session::AggregateFnSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
770+
765771
pub trait vortex_array::aggregate_fn::session::AggregateFnSessionExt: vortex_session::SessionExt
766772

767773
pub fn vortex_array::aggregate_fn::session::AggregateFnSessionExt::aggregate_fns(&self) -> vortex_session::Ref<'_, vortex_array::aggregate_fn::session::AggregateFnSession>
@@ -9044,6 +9050,12 @@ impl core::fmt::Debug for vortex_array::dtype::session::DTypeSession
90449050

90459051
pub fn vortex_array::dtype::session::DTypeSession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
90469052

9053+
impl vortex_session::SessionVar for vortex_array::dtype::session::DTypeSession
9054+
9055+
pub fn vortex_array::dtype::session::DTypeSession::as_any(&self) -> &dyn core::any::Any
9056+
9057+
pub fn vortex_array::dtype::session::DTypeSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
9058+
90479059
pub trait vortex_array::dtype::session::DTypeSessionExt: vortex_session::SessionExt
90489060

90499061
pub fn vortex_array::dtype::session::DTypeSessionExt::dtypes(&self) -> vortex_session::Ref<'_, vortex_array::dtype::session::DTypeSession>
@@ -13374,6 +13386,12 @@ impl core::fmt::Debug for vortex_array::memory::MemorySession
1337413386

1337513387
pub fn vortex_array::memory::MemorySession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1337613388

13389+
impl vortex_session::SessionVar for vortex_array::memory::MemorySession
13390+
13391+
pub fn vortex_array::memory::MemorySession::as_any(&self) -> &dyn core::any::Any
13392+
13393+
pub fn vortex_array::memory::MemorySession::as_any_mut(&mut self) -> &mut dyn core::any::Any
13394+
1337713395
pub struct vortex_array::memory::WritableHostBuffer
1337813396

1337913397
impl vortex_array::memory::WritableHostBuffer
@@ -13480,6 +13498,12 @@ impl core::fmt::Debug for vortex_array::optimizer::kernels::ArrayKernels
1348013498

1348113499
pub fn vortex_array::optimizer::kernels::ArrayKernels::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1348213500

13501+
impl vortex_session::SessionVar for vortex_array::optimizer::kernels::ArrayKernels
13502+
13503+
pub fn vortex_array::optimizer::kernels::ArrayKernels::as_any(&self) -> &dyn core::any::Any
13504+
13505+
pub fn vortex_array::optimizer::kernels::ArrayKernels::as_any_mut(&mut self) -> &mut dyn core::any::Any
13506+
1348313507
pub trait vortex_array::optimizer::kernels::ArrayKernelsExt: vortex_session::SessionExt
1348413508

1348513509
pub fn vortex_array::optimizer::kernels::ArrayKernelsExt::kernels(&self) -> vortex_session::Ref<'_, vortex_array::optimizer::kernels::ArrayKernels>
@@ -17602,6 +17626,12 @@ impl core::fmt::Debug for vortex_array::scalar_fn::session::ScalarFnSession
1760217626

1760317627
pub fn vortex_array::scalar_fn::session::ScalarFnSession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1760417628

17629+
impl vortex_session::SessionVar for vortex_array::scalar_fn::session::ScalarFnSession
17630+
17631+
pub fn vortex_array::scalar_fn::session::ScalarFnSession::as_any(&self) -> &dyn core::any::Any
17632+
17633+
pub fn vortex_array::scalar_fn::session::ScalarFnSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
17634+
1760517635
pub trait vortex_array::scalar_fn::session::ScalarFnSessionExt: vortex_session::SessionExt
1760617636

1760717637
pub fn vortex_array::scalar_fn::session::ScalarFnSessionExt::scalar_fns(&self) -> vortex_session::Ref<'_, vortex_array::scalar_fn::session::ScalarFnSession>
@@ -19056,6 +19086,12 @@ impl core::fmt::Debug for vortex_array::session::ArraySession
1905619086

1905719087
pub fn vortex_array::session::ArraySession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
1905819088

19089+
impl vortex_session::SessionVar for vortex_array::session::ArraySession
19090+
19091+
pub fn vortex_array::session::ArraySession::as_any(&self) -> &dyn core::any::Any
19092+
19093+
pub fn vortex_array::session::ArraySession::as_any_mut(&mut self) -> &mut dyn core::any::Any
19094+
1905919095
pub trait vortex_array::session::ArraySessionExt: vortex_session::SessionExt
1906019096

1906119097
pub fn vortex_array::session::ArraySessionExt::array_serialize(&self, array: &vortex_array::ArrayRef) -> vortex_error::VortexResult<core::option::Option<alloc::vec::Vec<u8>>>

vortex-array/src/aggregate_fn/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::any::Any;
45
use std::sync::Arc;
56

67
use parking_lot::RwLock;
78
use vortex_session::Ref;
89
use vortex_session::SessionExt;
10+
use vortex_session::SessionVar;
911
use vortex_session::registry::Registry;
1012
use vortex_utils::aliases::hash_map::HashMap;
1113

@@ -42,6 +44,16 @@ pub struct AggregateFnSession {
4244
pub(super) grouped_kernels: RwLock<HashMap<KernelKey, &'static dyn DynGroupedAggregateKernel>>,
4345
}
4446

47+
impl SessionVar for AggregateFnSession {
48+
fn as_any(&self) -> &dyn Any {
49+
self
50+
}
51+
52+
fn as_any_mut(&mut self) -> &mut dyn Any {
53+
self
54+
}
55+
}
56+
4557
type KernelKey = (ArrayId, Option<AggregateFnId>);
4658

4759
impl Default for AggregateFnSession {

vortex-array/src/dtype/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
//! Module for managing extension dtypes in a Vortex session.
55
6+
use std::any::Any;
67
use std::sync::Arc;
78

89
use vortex_session::Ref;
910
use vortex_session::SessionExt;
11+
use vortex_session::SessionVar;
1012
use vortex_session::registry::Registry;
1113

1214
use crate::dtype::extension::ExtDTypePluginRef;
@@ -39,6 +41,16 @@ impl Default for DTypeSession {
3941
}
4042
}
4143

44+
impl SessionVar for DTypeSession {
45+
fn as_any(&self) -> &dyn Any {
46+
self
47+
}
48+
49+
fn as_any_mut(&mut self) -> &mut dyn Any {
50+
self
51+
}
52+
}
53+
4254
impl DTypeSession {
4355
/// Register an extension DType with the Vortex session.
4456
pub fn register<V: ExtVTable>(&self, vtable: V) {

vortex-array/src/memory.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
//! Session-scoped memory allocation for host-side buffers.
55
6+
use std::any::Any;
67
use std::fmt::Debug;
78
use std::mem::size_of;
89
use std::sync::Arc;
@@ -18,6 +19,7 @@ use vortex_error::vortex_err;
1819
use vortex_session::Ref;
1920
use vortex_session::RefMut;
2021
use vortex_session::SessionExt;
22+
use vortex_session::SessionVar;
2123

2224
/// Mutable host buffer contract used by [`WritableHostBuffer`].
2325
pub trait HostBufferMut: Send + 'static {
@@ -199,6 +201,16 @@ impl Default for MemorySession {
199201
}
200202
}
201203

204+
impl SessionVar for MemorySession {
205+
fn as_any(&self) -> &dyn Any {
206+
self
207+
}
208+
209+
fn as_any_mut(&mut self) -> &mut dyn Any {
210+
self
211+
}
212+
}
213+
202214
/// Extension trait for accessing session-scoped memory configuration.
203215
pub trait MemorySessionExt: SessionExt {
204216
/// Returns the memory session for this execution/session context.

vortex-array/src/optimizer/kernels.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
//! sessions can add it with [`VortexSession::with`](vortex_session::VortexSession::with) or rely
1818
//! on [`ArrayKernelsExt::kernels`] to insert the default value.
1919
20+
use std::any::Any;
2021
use std::hash::BuildHasher;
2122
use std::sync::Arc;
2223
use std::sync::LazyLock;
@@ -25,6 +26,7 @@ use arc_swap::ArcSwap;
2526
use vortex_error::VortexResult;
2627
use vortex_session::Ref;
2728
use vortex_session::SessionExt;
29+
use vortex_session::SessionVar;
2830
use vortex_session::registry::Id;
2931
use vortex_utils::aliases::DefaultHashBuilder;
3032
use vortex_utils::aliases::hash_map::HashMap;
@@ -100,6 +102,16 @@ impl ArrayKernels {
100102
}
101103
}
102104

105+
impl SessionVar for ArrayKernels {
106+
fn as_any(&self) -> &dyn Any {
107+
self
108+
}
109+
110+
fn as_any_mut(&mut self) -> &mut dyn Any {
111+
self
112+
}
113+
}
114+
103115
/// Extension trait for accessing optimizer kernels from a
104116
/// [`VortexSession`](vortex_session::VortexSession).
105117
pub trait ArrayKernelsExt: SessionExt {

vortex-array/src/scalar_fn/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::any::Any;
45
use std::sync::Arc;
56

67
use vortex_session::Ref;
78
use vortex_session::SessionExt;
9+
use vortex_session::SessionVar;
810
use vortex_session::registry::Registry;
911

1012
use crate::scalar_fn::ScalarFnPluginRef;
@@ -74,6 +76,16 @@ impl Default for ScalarFnSession {
7476
}
7577
}
7678

79+
impl SessionVar for ScalarFnSession {
80+
fn as_any(&self) -> &dyn Any {
81+
self
82+
}
83+
84+
fn as_any_mut(&mut self) -> &mut dyn Any {
85+
self
86+
}
87+
}
88+
7789
/// Extension trait for accessing scalar function session data.
7890
pub trait ScalarFnSessionExt: SessionExt {
7991
/// Returns the scalar function vtable registry.

vortex-array/src/session/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::any::Any;
45
use std::sync::Arc;
56

67
use vortex_error::VortexResult;
78
use vortex_error::vortex_bail;
89
use vortex_session::Ref;
910
use vortex_session::SessionExt;
11+
use vortex_session::SessionVar;
1012
use vortex_session::registry::Registry;
1113

1214
use crate::ArrayRef;
@@ -85,6 +87,16 @@ impl Default for ArraySession {
8587
}
8688
}
8789

90+
impl SessionVar for ArraySession {
91+
fn as_any(&self) -> &dyn Any {
92+
self
93+
}
94+
95+
fn as_any_mut(&mut self) -> &mut dyn Any {
96+
self
97+
}
98+
}
99+
88100
/// Session data for Vortex arrays.
89101
pub trait ArraySessionExt: SessionExt {
90102
/// Returns the array encoding registry.

vortex-cuda/src/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::any::Any;
45
use std::fmt::Debug;
56
use std::sync::Arc;
67

@@ -10,6 +11,7 @@ use vortex::array::VortexSessionExecute;
1011
use vortex::error::VortexResult;
1112
use vortex::session::Ref;
1213
use vortex::session::SessionExt;
14+
use vortex::session::SessionVar;
1315
use vortex::utils::aliases::dash_map::DashMap;
1416

1517
use crate::ExportDeviceArray;
@@ -147,6 +149,16 @@ impl Default for CudaSession {
147149
}
148150
}
149151

152+
impl SessionVar for CudaSession {
153+
fn as_any(&self) -> &dyn Any {
154+
self
155+
}
156+
157+
fn as_any_mut(&mut self) -> &mut dyn Any {
158+
self
159+
}
160+
}
161+
150162
/// Extension trait for accessing the CUDA session from a Vortex session.
151163
pub trait CudaSessionExt: SessionExt {
152164
/// Returns the CUDA session.

vortex-file/src/multi/session.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
//! Session extension for multi-file scanning, providing a shared footer cache.
55
6+
use std::any::Any;
67
use std::fmt;
78
use std::fmt::Debug;
89

910
use vortex_session::SessionExt;
11+
use vortex_session::SessionVar;
1012

1113
use crate::footer::Footer;
1214

@@ -61,6 +63,16 @@ impl MultiFileSession {
6163
}
6264
}
6365

66+
impl SessionVar for MultiFileSession {
67+
fn as_any(&self) -> &dyn Any {
68+
self
69+
}
70+
71+
fn as_any_mut(&mut self) -> &mut dyn Any {
72+
self
73+
}
74+
}
75+
6476
/// Extension trait for accessing the [`MultiFileSession`] from a session.
6577
pub(super) trait MultiFileSessionExt: SessionExt {
6678
/// Returns a reference to the [`MultiFileSession`] state.

vortex-io/public-api.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,12 @@ impl core::fmt::Debug for vortex_io::session::RuntimeSession
488488

489489
pub fn vortex_io::session::RuntimeSession::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
490490

491+
impl vortex_session::SessionVar for vortex_io::session::RuntimeSession
492+
493+
pub fn vortex_io::session::RuntimeSession::as_any(&self) -> &dyn core::any::Any
494+
495+
pub fn vortex_io::session::RuntimeSession::as_any_mut(&mut self) -> &mut dyn core::any::Any
496+
491497
pub trait vortex_io::session::RuntimeSessionExt: vortex_session::SessionExt
492498

493499
pub fn vortex_io::session::RuntimeSessionExt::handle(&self) -> vortex_io::runtime::Handle

0 commit comments

Comments
 (0)