Skip to content

Commit 8eac2db

Browse files
committed
Do not simplify If::cond expressions
1 parent 329b215 commit 8eac2db

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/transform/src/analysis/equivalences.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl EquivalenceClasses {
244244
stable = self.minimize_once(columns);
245245
}
246246

247-
// TODO: remove these measures once we are more confidence about idempotence.
247+
// TODO: remove these measures once we are more confident about idempotence.
248248
let prev = self.clone();
249249
self.minimize_once(columns);
250250
assert_eq!(self, &prev);
@@ -340,9 +340,7 @@ impl EquivalenceClasses {
340340
}
341341
});
342342
for expr in class.iter() {
343-
// If Eq(x, y) must be true, we can introduce classes `[x, y]` and `[false, IsNull(x), IsNull(y)]`.
344-
// This substitution replaces a complex expression with several smaller expressions, and cannot
345-
// cycle if we follow that practice.
343+
// If TRUE == NOT(X) then FALSE == X is a simpler form.
346344
if let MirScalarExpr::CallUnary {
347345
func: mz_expr::UnaryFunc::Not(_),
348346
expr: e,
@@ -366,9 +364,7 @@ impl EquivalenceClasses {
366364
}
367365
if class.iter().any(|c| c.is_literal_false()) {
368366
for expr in class.iter() {
369-
// If Eq(x, y) must be true, we can introduce classes `[x, y]` and `[false, IsNull(x), IsNull(y)]`.
370-
// This substitution replaces a complex expression with several smaller expressions, and cannot
371-
// cycle if we follow that practice.
367+
// If FALSE == NOT(X) then TRUE == X is a simpler form.
372368
if let MirScalarExpr::CallUnary {
373369
func: mz_expr::UnaryFunc::Not(_),
374370
expr: e,
@@ -556,8 +552,9 @@ impl EquivalenceClasses {
556552
simplified = self.reduce_expr(expr) || simplified;
557553
}
558554
}
559-
MirScalarExpr::If { cond, then, els } => {
560-
simplified = self.reduce_expr(cond) || simplified;
555+
MirScalarExpr::If { cond: _, then, els } => {
556+
// Do not simplify `cond`, as we cannot ensure the simplification
557+
// continues to hold as expressions migrate around.
561558
simplified = self.reduce_expr(then) || simplified;
562559
simplified = self.reduce_expr(els) || simplified;
563560
}

0 commit comments

Comments
 (0)