3 ms·
Sure. But a naive compiler whose only purpose is to stomp out a poorly optimized executable can safely ignore that annotation, right?
by EdSchouten 5y ago
Sure. But a naive compiler whose only purpose is to stomp out a poorly optimized executable can safely ignore that annotation, right?
- richardwhiuk 5y agoNo, because checking that it is exhaustive is required by the language definition. It's not just not optimized, it's wrong.
- kevincox 5y agoYes, that annotation doesn't affect the codegen of a correct program (optimizations aside).
- tialaramex 5y agoYou could instead require everything to be treated as non-exhaustive in your cheap compiler. This means it would reject correct Rust code that explicitly handles each of the five PlatonicSolids differently, because that code lacks a way to handle a sixth (non-existent) PlatonicSolid. You can't just go "Eh, shrug emoji" without deciding what happens when you don't match. Suppose you silently treat the first (or last) handled case as the default, so I can write code that only handles Cubes and unlike the real Rust compiler your naive compiler spits out a program. But wait, now what happens for a Tetrahedron? I defined Cubes to have a 32-bit floating point size, but for whatever reason Tetrahedrons have a 16-bit integer length instead. Does your compiler just try to treat the 16-bit integer as a 32-bit floating point number since it assumes this was a Cube?