Heapster Rust layout optimization for option-like types #1627
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR changes Heapster's Rust layout engine to handle the option-like type optimization of Rust.
An "option-like" type in Rust is a non-recursive enum with two variants, one of which is empty and one of which is not. The canonical example is
Option<T>
. The field type of the non-empty variant is called the "payload". If the payload of an option-like type has illegal values, called "niches", then Rust optimizes the layout of the option-like type so that the empty variant is represented as a value in one of these niches. So, for example,Option<&T>
is laid out like a&T
but where the null pointer (which is an invalid reference) represents theNone
constructor, whileOption<T>
whenT
is itself an enum withN
constructors is laid out asT
but with an extraN+1
th constructor for `None.This PR also adds a test case, the
list64_tail
function inrust_data.rs
, to test out this option-like type optimization.