Skip to content
Defines the Rust borrow checker.
Branch: master
Clone or download
nikomatsakis Merge pull request #102 from albins/master
Add a naïve hybrid algorithm
Latest commit 4549e71 Mar 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
inputs Merge pull request #93 from lqd/factchecking Dec 7, 2018
polonius-engine Drop the my_ prefix for region_live_at Mar 14, 2019
polonius-parser Parser: update module generation for 0.16 Dec 7, 2018
src Add a naïve hybrid algorithm. Mar 11, 2019
.gitignore Implement friendly front-end format May 28, 2018
.travis.yml
CODE_OF_CONDUCT.md first commit May 1, 2018
Cargo.lock
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
RELEASES.md
rust-toolchain

README.md

This is a core library that models the borrow check. It implements the analysis described in this blogpost.

Why the name "Polonius"?

The name comes from the famous quote "Neither borrower nor lender be", which comes from the character Polonius in Shakespeare's Hamlet.

Want to run the code?

One of the goals with this repo is to experiment and compare different implementations of the same algorithm. You can run the analysis by using cargo run and you can choose the analysis with -a. So for example to run against an example extract from clap, you might do:

> cargo +nightly run --release -- -a DatafrogOpt inputs/clap-rs/app-parser-{{impl}}-add_defaults/
    Finished release [optimized] target(s) in 0.05 secs
     Running `target/release/borrow-check 'inputs/clap-rs/app-parser-{{impl}}-add_defaults/'`
--------------------------------------------------
Directory: inputs/clap-rs/app-parser-{{impl}}-add_defaults/
Time: 3.856s

You could also try -a Naive to get the naive rules (more readable, slower) -- these are the exact rules described in the blogpost. You can also use -a LocationInsensitive to use a location insensitive analysis (faster, but may yield spurious errors).

By default, cargo run just prints timing. If you also want to see the results, try --show-tuples (which will show errors) and maybe -v (to show more intermediate computations). You can supply --help to get more docs.

How to generate your own inputs

To run the borrow checker on an input, you first need to generate the input facts. For that, you will need to run rustc with the -Znll-facts option:

> rustc -Znll-facts inputs/issue-47680/issue-47680.rs

Or, for generating the input facts of a crate using the #![feature(nll)] flag:

> cargo rustc -- -Znll-facts

This will generate a nll-facts directory with one subdirectory per function:

> ls -F nll-facts
{{impl}}-maybe_next/  main/

You can then run on these directories.

You can’t perform that action at this time.