Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rust-lang/polonius
Defines the Rust borrow checker.
https://github.com/rust-lang/polonius
Last synced: 13 days ago
JSON representation
Defines the Rust borrow checker.
- Host: GitHub
- URL: https://github.com/rust-lang/polonius
- Owner: rust-lang
- License: apache-2.0
- Created: 2018-05-01T15:40:59.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-16T01:48:09.000Z (about 1 year ago)
- Last Synced: 2024-05-22T11:22:12.484Z (6 months ago)
- Language: Rust
- Size: 335 MB
- Stars: 1,259
- Watchers: 67
- Forks: 72
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
This is a core library that models the borrow check. It implements the analysis
described in this [blogpost][post] and in this [talk]. Details are [in the Polonius book][book].[post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/
[talk]: https://youtu.be/_agDeiWek8w
[book]: https://rust-lang.github.io/polonius/### Why the name "Polonius"?
The name comes from the famous quote ["Neither a borrower nor a lender
be"][nblnb], which comes from the character Polonius in Shakespeare's
*Hamlet*.[nblnb]: https://literarydevices.net/neither-a-borrower-nor-a-lender-be/
### 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:```bash
> 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][post]. 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:
```bash
> ls -F nll-facts
{{impl}}-maybe_next/ main/
```You can then run on these directories.