Skip to content
0:00 / 0:00

#unsaferust#aliasing#left-right

The Unsafe Chronicles: Exhibit A: Aliasing Boxes

Jon Gjengset

111K subscribers • 38 videos on Hallway

YouTube

Advanced. Deep dive for people who know the field.

28K views5 years ago1 recommendation

Programming languagesSystems programmingRustMemory managementConcurrency and parallelism

Jon Gjengset explores the complexities of unsafe Rust, focusing on the challenges of aliasing boxed values in concurrent data structures.

In this new series we take deep-dives into the world of unsafe Rust. These chronicles aren't necessarily aimed at teaching you how to write unsafe code, but instead try to showcase particular things to keep in mind when it comes to safety in Rust. In particular, in each episode we'll look at a specific (and usually tricky) source of unsoundness, and how to work around it. This particular episode focuses on the journey to aliasing boxed values in the left-right crate (docs.rs/left-right/), which we developed in a previous stream, and was augmented in github.com/jonhoo/rust-evmap/pull/83. left-right wishes to alias types between two different copies of a data structure, but doing so leads down an interesting rabbit hole around the safety of aliasing and casting. About this new series left-right and evmap Expressing the problem in code Why is aliasing a Box not okay? Aliasing Box with MaybeUninit Dropping aliases The cast is unsound Making the cast sound Q&A Unsoundness from non-determinism More Q&A Outroduction Some relevant issues: evmap unsoundness issue: github.com/jonhoo/rust-evmap/issues/74 Aliasing rules for Box{T}: github.com/rust-lang/unsafe-code-guidelines/issues/258 Deterministic layout: github.com/rust-lang/unsafe-code-guidelines/issues/35#issuec… Deterministic Eq+Hash: github.com/jonhoo/rust-evmap/issues/78 You can watch the live version with comments at youtu.be/4LrQidI5z1g

Why it's here

1 person recommends this

What people say. Recommended as an excellent, in-depth look at the subtle traps of writing unsafe Rust and compiler optimizations.

u/kinoshitajonain r/rust • Recommends

On “Avoiding Arcs and Mutexes when sharing data in a multithreaded program”

…ite you in surprising ways. So when writing unsafe Rust, you not only need to know the Rust rules, but also how the Rust compiler optimizes things. You also need to know what optimizations are guaranteed and what are not. You also will probably be way more likely to run into rare compiler bugs! Watch this video to get some in the wild examples: link to this video Also this one is way more in depth with a much more practical example that’s a bit more difficult to wrap your head around. But it does a good job explaining: link to this video…