3 ms·
Structured control flow is a thing to help people understand code. The compiler's job is to emit instructions that do precisely the things the code says to do,
by ncmncm 5y ago
Structured control flow is a thing to help people understand code.
The compiler's job is to emit instructions that do precisely the things the code says to do, as efficiently as possible. There is no need for chips to understand the purpose of the code; they just need to do what it says. They don't get confused.
- mhh__ 5y agoChips don't need to know but knowing information about loops is really important, so some structure or metadata can go a very long way.
- chrisseaton 5y ago> as efficiently as possible Which requires a high-level understanding of the program and its control flow.
- WalterBright 5y ago> Which requires a high-level understanding of the program and its control flow. The `for` loop construct does not offer the compiler any more understanding of the code than one made from `goto`s. They contain the same information, and are interchangeable. The latter, however, is more amenable to applying mathematical algorithms to. The former is more amenable to human understanding.
- chrisseaton 5y agoWhy is unstructured control-flow better for applying algorithms than structured control flow? That seems counter-intuitive to me. With structured control-flow I can do things like reason about the level of nesting of the loop that I'm in. I can peel a loop iteration by literally saying 'take this loop here - copy the body of it out'. For context here's the kind of structure we use https://chrisseaton.com/truffleruby/basic-graal-graphs/#loops https://chrisseaton.com/truffleruby/basic-graal-graphs/#loop....