3 ms·
Love this, and I'm glad the conclusion made exactly the point I was about to bring up in my comment: > If Rust had guaranteed that the memory layout of an enum
by brundolf 4y ago
Love this, and I'm glad the conclusion made exactly the point I was about to bring up in my comment:
> If Rust had guaranteed that the memory layout of an enum is always a tag followed by a union then it wouldn’t be possible to make this optimization without breaking somebody’s code. Instead, the compiler retains the freedom to optimize the layout of your types, and your code will automatically be more memory efficient, simply by updating to a newer version of the compiler.
Having things be lower-level/more-explicit/more-exposed-details is often seen as a win for optimization at the cost of ergonomics. But it's not even always a win for optimization. What it really means is putting more things in the hands of developers, instead of the compiler/runtime, which may be good or it may be bad.
One of the most brilliant things about Rust is exactly where it's chosen to draw the contours of that delicate line between explicitness and opaqueness