Skip to content
0:00 / 0:00

#polonius#borrowchecker#non-lexicallifetimes

Polonius: Either Borrower or Lender Be, but Responsibly - Niko Matsakis

Rust Belt Rust Conference

4.8K subscribers • 4 videos on Hallway

YouTube
  • Recommended by 4 people: 4 in engineering communities.
  • A classic. People kept recommending it from 2020 to 2023.
  • Presented by Niko Matsakis, co-designer of Rust

Advanced. Deep dive for people who know the field.

20K views6 years ago4 recommendations

Systems programmingProgramming languagesRustCompilers and interpretersMemory management

Niko Matsakis explains Polonius, a new formulation of the Rust borrow checker that tracks origins instead of lifetimes to accept more safe programs.

Rust 2018 brought with it “non-lexical lifetimes” (NLL), a big overhaul of how the borrow checker worked that allowed it to accept a lot more programs. And yet, we’re still not accepting the full range of programs that was envisioned by the original NLL RFC – this is both for performance reasons and because the formulation didn’t turn out to be as flexible as originally thought. Polonius is a “reframing” of Rust’s borrow checker. It works quite differently than the original system. Rather than tracking how long each reference is used (its “lifetime”), it tracks where each reference may have come from (its “origin”) – and it does so in a very fine-grained way. As a result, Polonius is able to accept all the programs that the NLL RFC envisioned, and a few more! We also believe it can be made more performant (though that has yet to be fully proven out). This talk will explain how Polonius works in a simple and example-driven style. It will help you to gain a deeper understanding of how Rust’s borrow checker works internally. --- Note from the conference: The slides for this talk were not captured and we've re-recorded them after the fact. Some of the visuals did not work perfectly, and for that we apologize.

Why it's here

4 people recommend this

What people say. Recommended as a great explanation of the limitations of non-lexical lifetimes and how the Polonius borrow checker solves them.

Moments people linked to

u/panstromekin r/rust • Recommends

On “Is the borrow checker wrong here?”

This is "the third" problem that was supposed to be solved by non lexical lifetimes. That turned out to be too difficult in the end, but it should be fixed by switching to Polonius (new borrow checker implementation) in the future. There's a great talk from Niko Matsakis about it where he explains another common instance of this problem (HashMap::get\_or\_insert), see [video
50View on Reddit

u/hniksicin r/rust • Recommends

On “Polonius revisited, part 1: the next generation of the Rust borrow checker”

In addition to the goals put forth by NLL, a Polonius-like borrow checker also provides the ability to reason about self-referential data, as announced here some years ago. The great news is that the post is actually explicit about this: "I’m most excited about Polonius as a stepping stone towards an analysis that can support internal references and self borrows."
35View on Reddit

u/SeriToolsin r/rust • Recommends

On “What's the status of the Polonius borrow checker?”

A nice talk: link to this video

u/olemni7in r/rust • Recommends

On “Confusion around borrow checker analysis of loops”

This sadly is a limitations of the current borrow checker. I can't explain this very well myself, but there is a great talk by Niko Matsakis, which explains this problem and how it may be solved in the somewhat near future: link to this video
8View on Reddit

u/minauteurin r/rust • Mentions

On “Is the borrow checker wrong here?”

> link to this video I get video unavailable ? :( TIL! TY u/CodenameLambda for the knowledge: link to this video works!
7View on Reddit

u/CodenameLambdain r/rust • Mentions

On “Is the borrow checker wrong here?”

I think this might be an issue with what Reddit layout you're using, it doesn't work for me on the old layout either. There's a backslash in there that's not supposed to be there, if you remove that from the original link (not in the address bar of the resulting URL, because YouTube will have already truncated it by then so the `w` in the end would be missing) it works. link to this video ← Hoping putting this link here in old Reddit works
5View on Reddit

u/phazer99in r/rust • Mentions

On “What cons of rust should I know before I begin?”

Mostly it's related to not being able to create a shared reference to something for which there is already mutable reference, although it's perfectly safe to do so (for example, you could determine it's safe using local flow/escape analysis). I believe Polonius will be able to allow some of these cases in the future, but not all.

u/hniksicin r/rust • Mentions

On “Food for thought: Simple Rust a'la Simple Haskell?”

Quite a few, actually. Off the top of my head: * finishing const generics, so that you can use them in const expressions in a natural way (including in associated constants) * getting Polonius out the door, so that perfectly valid code like this finally gets accepted by the borrow checker. (currently in some cases you can only use unsafe to work around the limitation.) * support for self-referential types in Polonius, as promised long ago and rekindled lately (see second paragraph of this post). * associated types and type aliases for impl Trait in return position, so you can implement `IntoIterator` using combinators and lambdas. Currently you have to do it by hand-coding a separate type…
3View on Reddit

u/hniksicin r/rust • Mentions

On “Self-referential types for fun and profit”

Yes, in fact one is linked from the article, but I don't know if it's being actively worked on.
2View on Reddit

u/ArtisticHamsterin r/rust • Mentions

On “How to make this code compile?”

Here's a video with an example almost like this covered: link to this video
2View on Reddit

u/SirKastic23in r/rust • Mentions

On “Hey Rustaceans! Got a question? Ask here (15/2023)!”

…(or that mention this at all). but there's this youtube video i saw that really helped me understand the ownership rules and lifetimes better it's about this project named *polonius*, which aims to be a new, more capable model for the ownership rules. watching this could confuse you, but it has a great explanation of how the current model works: link to this video…