vortex_expr/transform/
immediate_access.rs1use vortex_dtype::{FieldName, StructFields};
5use vortex_error::VortexExpect;
6use vortex_utils::aliases::hash_set::HashSet;
7
8use crate::transform::annotations::{AnnotationFn, Annotations, descendent_annotations};
9use crate::{ExprRef, GetItemVTable, SelectVTable, is_root};
10
11pub type FieldAccesses<'a> = Annotations<'a, FieldName>;
12
13pub fn annotate_scope_access(scope: &StructFields) -> impl AnnotationFn<Annotation = FieldName> {
15 move |expr: &ExprRef| {
16 assert!(
17 !expr.is::<SelectVTable>(),
18 "cannot analyse select, simplify the expression"
19 );
20
21 if let Some(get_item) = expr.as_opt::<GetItemVTable>() {
22 if is_root(get_item.child()) {
23 return vec![get_item.field().clone()];
24 }
25 } else if is_root(expr) {
26 return scope.names().iter().cloned().collect();
27 }
28
29 vec![]
30 }
31}
32
33pub fn immediate_scope_accesses<'a>(
41 expr: &'a ExprRef,
42 scope: &'a StructFields,
43) -> FieldAccesses<'a> {
44 descendent_annotations(expr, annotate_scope_access(scope))
45}
46
47pub fn immediate_scope_access<'a>(
49 expr: &'a ExprRef,
50 scope: &'a StructFields,
51) -> HashSet<FieldName> {
52 immediate_scope_accesses(expr, scope)
53 .get(expr)
54 .vortex_expect("Expression missing from scope accesses, this is a internal bug")
55 .clone()
56}