Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions vortex-array/src/expr/analysis/fallible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ pub fn label_is_fallible(expr: &Expression) -> BooleanLabels<'_> {
expr,
|expr| match expr {
Expression::Scalar { scalar_fn, .. } => scalar_fn.signature().is_fallible(),
// The scope itself cannot fail.
Expression::Root => false,
Expression::HigherOrder { .. } => true,
Expression::Lambda(_) => true,
Expression::Root | Expression::Variable(_) => false,
},
|acc, &child| acc | child,
)
Expand Down
40 changes: 39 additions & 1 deletion vortex-array/src/expr/analysis/immediate_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ pub fn make_bound_free_field_annotator(
) -> impl AnnotationFn<BoundExpression, Annotation = FieldName> {
move |expr: &BoundExpression| {
let Some(scalar_fn) = expr.as_scalar() else {
return scope.names().iter().cloned().collect();
return if expr.is_root() {
scope.names().iter().cloned().collect()
} else {
vec![]
};
};

if let Some(selection) = scalar_fn.as_opt::<Select>() {
Expand All @@ -87,3 +91,37 @@ pub fn make_bound_free_field_annotator(
vec![]
}
}

#[cfg(test)]
mod tests {
use vortex_error::VortexResult;

use super::*;
use crate::dtype::DType;
use crate::dtype::Nullability;
use crate::dtype::PType;
use crate::expr::Scope;
use crate::expr::Variable;
use crate::expr::test_harness::struct_dtype;
use crate::expr::var;

#[test]
fn a_bound_variable_accesses_no_root_fields() -> VortexResult<()> {
let scope_dtype = struct_dtype();
let fields = scope_dtype
.as_struct_fields_opt()
.vortex_expect("test scope is a struct");

let bound = var("x").bind_scope(&Scope::new(scope_dtype.clone()).with_bindings([(
Variable::new("x"),
DType::Primitive(PType::I32, Nullability::NonNullable),
)])?)?;

let annotator = make_bound_free_field_annotator(fields);
assert!(
annotator(&bound).is_empty(),
"a variable should read no root fields"
);
Ok(())
}
}
6 changes: 4 additions & 2 deletions vortex-array/src/expr/analysis/strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ pub fn label_strict(expr: &Expression) -> BooleanLabels<'_> {
expr,
|expr| match expr {
Expression::Scalar { scalar_fn, .. } => scalar_fn.signature().is_strict(),
// Vacuously strict.
Expression::Root => true,
Expression::HigherOrder { .. } => false,
Expression::Lambda(_) => false,
// Vacuously strict: nullary, so no argument can be null.
Expression::Root | Expression::Variable { .. } => true,
},
|acc, &child| acc & child,
)
Expand Down
Loading