We have a bunch of tests in our test suite that compare the result of a compile-time evaluation (so a constant) against a runtime evaluation. The problem is that @Wesley Wiser is making our const propagator way too smart for its own good. It will at some point be able to optimize the right hand side of a
C == foo(42) comparison to a constant, and then optimize away the entire comparison. Now we can easily prevent this by wrapping the
foo(42) in a call to
test::black_box, but then the call will still get optimized, so we wrap the
42, too and then we end up with
b(foo(b(42))), which isn't too bad, but its very error-prone.
In order to make these tests a little saner, we could create a
rustc_* attribute that makes const prop not run for the entire crate or maybe just function or even specific statements in the function.
A PR where this came up: https://github.com/rust-lang/rust/pull/61658
would it be possible to write a macro for this end?
non_eval!(foo(42)) expanded to
maybe, but I still fear we'll end up missing edge cases
like we'll have to think about all cases
the attribute system will "just work"