vortex_array/expr/analysis/
immediate_access.rs1use vortex_dtype::FieldName;
5use vortex_dtype::StructFields;
6use vortex_error::VortexExpect;
7use vortex_utils::aliases::hash_set::HashSet;
8
9use crate::expr::Expression;
10use crate::expr::analysis::AnnotationFn;
11use crate::expr::analysis::Annotations;
12use crate::expr::descendent_annotations;
13use crate::expr::exprs::get_item::GetItem;
14use crate::expr::exprs::root::Root;
15use crate::expr::exprs::select::Select;
16
17pub type FieldAccesses<'a> = Annotations<'a, FieldName>;
18
19pub fn annotate_scope_access(scope: &StructFields) -> impl AnnotationFn<Annotation = FieldName> {
21 move |expr: &Expression| {
22 assert!(
23 !expr.is::<Select>(),
24 "cannot analyse select, simplify the expression"
25 );
26
27 if let Some(get_item) = expr.as_opt::<GetItem>() {
28 if get_item.child(0).is::<Root>() {
29 return vec![get_item.data().clone()];
30 }
31 } else if expr.is::<Root>() {
32 return scope.names().iter().cloned().collect();
33 }
34
35 vec![]
36 }
37}
38
39pub fn immediate_scope_accesses<'a>(
47 expr: &'a Expression,
48 scope: &'a StructFields,
49) -> FieldAccesses<'a> {
50 descendent_annotations(expr, annotate_scope_access(scope))
51}
52
53pub fn immediate_scope_access<'a>(
55 expr: &'a Expression,
56 scope: &'a StructFields,
57) -> HashSet<FieldName> {
58 immediate_scope_accesses(expr, scope)
59 .get(expr)
60 .vortex_expect("Expression missing from scope accesses, this is a internal bug")
61 .clone()
62}