7 points birdculture 56 minutes ago 4 comments
Hizonner 7 minutes ago | parent
The compiler is allowed to transform your code if it can prove that the result would interact with the outside world in exactly the same way as your original code would, right? You can optimize on "I already checked the value of X" if you can prove that nothing could have changed X.
Well, it sounds like a lot of compilers are making unjustified assumptions about what the outside world is allowed to affect or observe. Maybe with the encouragement of specs, maybe not.
wat10000 2 minutes ago | parent
Sort of. Its idea of “the outside world” is very restrictive. Simple example: write into a pointer, then free it. From the compiler’s perspective, this write can’t be observed and can be removed. It’s not legal to read memory after it’s been freed, so there’s no legal side effect from that write. But in reality, we can use a dangling pointer or a debugger and read bat memory just fine.
kelnos 2 minutes ago | parent
[delayed]
fithisux 4 minutes ago | parent
Compiler does what I tell it. Not the other way around.