Re:Rust and Nix = easier Unix systems programming
by arielb1 on Thursday April 14, 2016 @05:45AM
(#11495333)
We do have a planned optimization that would fold the tags for cases like `Option<ForkResult>` to give a word pair, which should be returned in %eax:%edx (or %rax:%rdx).
Re:Rust and Nix = easier Unix systems programming
by Jweb_Guru on Thursday April 14, 2016 @10:01AM
(#11496738)
Really? That's exciting. Missed enum layout optimizations are one of my few issues with Rust right now.
Re:Rust and Nix = easier Unix systems programming
by pcwalton on Thursday April 14, 2016 @12:38PM
(#11498179)
But if the wrappers get inlined (which they should be) then SROA kicks in and promotes the tags to SSA values, where other optimizations such as SCCP can eliminate them. Optimizing compilers are awesome :)
There is a slight bit of stack overhead: Option<ForkResult> is at least {tag:u8, {tag:u8, pid:i32}}, and due to alignment constraints it's actually {tag: u32, {tag: u32, pid: i32 }}). A nonzero wrapper[0] would allow folding either ForkResult or Option into a 0-valued pid_t and remove one level of tagging: http://is.gd/yxStW1
Beyond that you'd need generalised enum folding in order to fold two tags into the underlying value (you'd denote that pid_t is nonzero and nonnegative for instance)
[0] which is unstable, so not really an option