Hacker News new | ask | show | jobs
by paniq303 3020 days ago
unconst can't be the default because there is no way to re-const a value once it's been turned into an unknown. The most "automagic" behavior is to tie branch conditionals to their exit values (there's a helper function called tie-const that does this for the manual case). If the conditional is unknown at compile time, then the continuations that exit the branch will mark their arguments as unknown. That also stops loops from unrolling (they'd typically unroll for i=0, but then stop). But, as I mentioned before, that completely kills constant folding at the exit points, something that is at times desirable.

Another reason loops are unrolling by default is that there are many situations where constexprs have to completely fold at compile time, and you need a guarantee that they do. A common example is handling keyed varargs. You need to be able to iterate through the keys and build local variables from that without any code being generated.

If a compile time unroll takes forever, there's practically no clean way to debug that.