Defines the Rust borrow checker.
Clone or download
nikomatsakis Merge pull request #79 from lqd/crate-in-paths
Remove crate_in_paths feature as it has been stabilized in 1.30
Latest commit 83bb2cd Oct 24, 2018

README.md

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

How to use

First off, you must use the nightly channel. To build, do something like this:

cargo +nightly build --release

You can try it on one our input tests like so:

cargo +nightly run --release -- inputs/issue-47680/nll-facts/main

This will generate a bunch of output tuples:

# borrow_live_at

"Mid(bb3[2])"   "bw0"
"Mid(bb3[2])"   "bw2"
"Mid(bb10[2])"  "bw0"
...

To generate a graphviz file with the CFG enriched with input and output tuples at each point, do:

cargo +nightly run --release -- --graphviz_file=graph.dot inputs/issue-47680/nll-facts/main

Want to see something slow?

One of the goals with this repo is to experiment and compare different implementations of the same algorithm. The repo includes one particularly egregious case where we currently perform poorly, and you can test it against it like so:

> cargo +nightly run --release -- inputs/clap-rs/app-parser-{{impl}}-add_defaults/ | head
    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: 113.316s

(You can see it is pretty dang slow on my machine!)

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.