tavianator/bfs

Confusing warnings due to optimization

tavianator opened this issue · 2 comments

Example 1

$ bfs -type f -type d
bfs: warning: bfs -type f -type d
bfs: warning:             ~~~~~~~
bfs: warning: This expression is always false.

This part is good, but...

bfs: warning: bfs -type f -type d
bfs: warning:     ~~~~~~~
bfs: warning: The result of this expression is ignored.

Why? Well, the optimizer sees bfs -type f -false at this point. Maybe this warning should only be printed if the -false was not the result of other optimizations (but how to track that?).

Example 2

$ bfs -not \( -type b -print \) -not \( -type c -print \)
bfs: warning: bfs -not ( -type b -print ) -not ( -type c -print )
bfs: warning:     ~~~~   ~~~~~~~~~~~~~~          ~~~~~~~~~~~~~~
bfs: warning: The result of this expression is ignored.

Here we De Morgan'd the expression into -not \( -type b -print -o -type c -print \), and we warn when stripping the unnecessary root -not. We picked the first -not as the span pretty arbitrarily. I'm not convinced this is a very useful warning even in the best case, actually:

$ bfs -not -print
bfs: warning: bfs -not -print
bfs: warning:     ~~~~~~~~~~~
bfs: warning: The result of this expression is ignored.

Example 3

Expression reordering leads to surprises:

$ bfs -not -type f -and -type p
bfs: warning: bfs -not -type f -and -type p
bfs: warning:          ~~~~~~~
bfs: warning: This expression is always false.

Example 4

"Unreachable" flags?

$ bfs -quit -O3
bfs: warning: bfs -quit -O3
bfs: warning:           ~~~
bfs: warning: This expression is unreachable.