by tialaramex · 3y ago · 0 comments
As written this can't work, but once the compiler understands what's going on it seems fine.
In Rust I'd imagine this as a method on MaybeUninit<T> the type which might be a T but maybe not yet. It's possible we can just assume_init() today where T is something like a byte but if it's unclear, a method which expresses our intent to get an unspecified value is better than just saying well, maybe you can assume_init() but we're not sure if that means what you intended.
I'd be fine if it was named freeze, labelled unsafe and specifically called out in Safety as requiring that all bit patterns for T are valid representations of T which I think meets the requirement, but it sounds like this can't be done (easily?) without help from LLVM
I imagine the details are tricky (my understanding is that "freeze" took a long time to land in LLVM), but that there's no fundamental reason it can't be done. But I also imagine there are a lot higher priorities; the use case in this blog is pretty niche.
There's more discussion in this thread: [2]
[1]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
[2]: https://internals.rust-lang.org/t/freeze-maybeuninit-t-maybe...
Reading for after work thanks for links