Skip to content

Commit 5bd2302

Browse files
selection: routing: promote terminals true and false (not just true) (#508)
Summary: Pull Request resolved: #508 it never came up before due to there being no surface syntax for `False` but terminal promotion should by symmetry be the same for `False` as exists for `True`. Reviewed By: pzhan9 Differential Revision: D78169907 fbshipit-source-id: e15de476a22e155ff1a85b55abefc1221e999fca
1 parent bdccb29 commit 5bd2302

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

ndslice/src/selection.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -892,26 +892,28 @@ impl Selection {
892892
}
893893
}
894894

895-
// "Pads out" a selection so that if `Selection::True` appears before
896-
// the final dimension, it becomes All(All(...(True))), enough to fill
897-
// the remaining dimensions.
898-
pub(crate) fn promote_terminal_true(self, dim: usize, max_dim: usize) -> Selection {
895+
/// Pads out a terminal selection (e.g., `True`, `False`) with
896+
/// `All(...)` to reach `max_dim` dimensions.
897+
pub(crate) fn promote_terminal(self, dim: usize, max_dim: usize) -> Selection {
899898
use crate::selection::dsl::*;
900899

901900
match self {
902901
Selection::True if dim < max_dim => all(true_()),
903-
Selection::All(inner) => all(inner.promote_terminal_true(dim + 1, max_dim)),
904-
Selection::Range(r, inner) => range(r, inner.promote_terminal_true(dim + 1, max_dim)),
902+
Selection::False if dim < max_dim => all(false_()),
903+
904+
Selection::All(inner) => all(inner.promote_terminal(dim + 1, max_dim)),
905+
Selection::Range(r, inner) => range(r, inner.promote_terminal(dim + 1, max_dim)),
905906
Selection::Intersection(a, b) => intersection(
906-
a.promote_terminal_true(dim, max_dim),
907-
b.promote_terminal_true(dim, max_dim),
907+
a.promote_terminal(dim, max_dim),
908+
b.promote_terminal(dim, max_dim),
908909
),
909910
Selection::Union(a, b) => union(
910-
a.promote_terminal_true(dim, max_dim),
911-
b.promote_terminal_true(dim, max_dim),
911+
a.promote_terminal(dim, max_dim),
912+
b.promote_terminal(dim, max_dim),
912913
),
913-
Selection::First(inner) => first(inner.promote_terminal_true(dim + 1, max_dim)),
914-
Selection::Any(inner) => any(inner.promote_terminal_true(dim + 1, max_dim)),
914+
Selection::First(inner) => first(inner.promote_terminal(dim + 1, max_dim)),
915+
Selection::Any(inner) => any(inner.promote_terminal(dim + 1, max_dim)),
916+
915917
other => other,
916918
}
917919
}

ndslice/src/selection/routing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ impl RoutingFrame {
409409
let selection = self
410410
.selection
411411
.clone()
412-
.promote_terminal_true(self.dim, self.slice.num_dim());
412+
.promote_terminal(self.dim, self.slice.num_dim());
413413
match &selection {
414414
Selection::True => ControlFlow::Continue(()),
415415
Selection::False => ControlFlow::Continue(()),
@@ -1644,7 +1644,7 @@ mod tests {
16441644
assert!(step.deliver_here());
16451645
assert_eq!(step.slice.location(&step.here).unwrap(), 42);
16461646

1647-
let selection = all(false_());
1647+
let selection = false_();
16481648
let frame = RoutingFrame::root(selection, slice);
16491649

16501650
let mut steps = vec![];

0 commit comments

Comments
 (0)