On 08.06.2018 01:14, Steven Schveighoffer wrote:

No matter what is inside fn, it will return S.init, if it returns. The question to answer is, can we assume all functions don't enter infinite loops, and if we can assume this, then why couldn't the compiler simply replace a call to fn with S.init?

And the case FeepingCreature gives is pretty compelling, because it's a real example, not a toy example.

-Steve

FeepingCreature's example does not really qualify as a do-nothing loop, because the loop produces a value that you (presumably) later access.

In any case, I don't think the right answer is to make programs that enter infinite loops that do nothing undefined behavior (like in C++), but they should possibly be allowed to be removed, though it can be surprising, see: https://blog.regehr.org/archives/140 (However, the "Fermat" example is a bit contrived, because presumably one would also want to print the specific counterexample, breaking the "optimization".)

Reply via email to