An Option? Have a slice!
summary
Adds Option::as_slice and Option::as_mut_slice to libcore (stabilized in 1.75) by trying four implementations and finally landing a compiler intrinsic sim_option_payload_ptr that emits a MIR place projection to get the Some field. Resulting slice creation compiles to a no-op (or a single setE for niche-optimized types), avoids heap allocation and per-iteration branching, is const-evaluable, and spurred the offset_of macro to gain inner-variant support shortly afterward.
AI-written summary · about
chapters (7)
- 0:00Option and Vec problem
- 3:36Slice method for Option needed
- 8:13Memory layout and niche optimization
- 13:12MaybeUninit layout challenges
- 15:23Compiler intrinsic design
- 20:36Rust implementation stabilized
- 22:46Option::as_slice impact
related talks
06mA tour of the compiler guided by bitvec
01h 23mC++23 Standard Library Preview
05mMaking optional optional
01h 05mC++11 in the Wild: Techniques from a Real Codebase
01h 01mEmbracing (and also Destroying) Variant Types Safely
01h 21mGazing Beyond Reflection for C++26
54mC++26: an overview
09mstd::optional and the m word
