pinned-aliasable
Unboxed aliasable values based on Pin
.
In Rust, it is currently impossible to soundly create unboxed self-referencing, or
externally-referenced, types - see this
document for details.
However, futures generated by async blocks need to be self-referencing, and this makes them
technically unsound. So to avoid
miscompilations, Rust has inserted a temporary loophole: No unique references to !Unpin
types
will actually be annotated with noalias
, preventing the compiler from making optimizations
based on the pointed-to types being not self-referential.
This is a huge hack. Not all self-referential types are !Unpin
, and some !Unpin
types would
actually work with noalias
. Ultimately, the solution will be to provide an Aliasable<T>
type
in libcore that prevents any parent containers from being annotated with noalias
, but
unfortunately that doesn't exist yet.
As a workaround, this crate provides an Aliasable<T>
type that doesn't cause miscompilations
today by being !Unpin
, and is future-compatible with the hypothetical Aliasable
type in
libcore. Additionally, to avoid Miri giving errors, it is substituted for a boxed value when
run using it. When Aliasable
is finally added to the language itself, I will release a new
version of this crate based on it and yank all previous versions.
Examples
A pair type:
use Pin;
use Cell;
use Aliasable;
use pin_project;
use pin_mut;
pin_project!
License: MIT