Skip to content

Commit

Permalink
add a book
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Aug 30, 2019
1 parent ce3a5c1 commit 65c9346
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
5 changes: 5 additions & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[book]
authors = ["Polonius authors"]
multilingual = false
src = "src"
title = "Polonius"
9 changes: 9 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Summary

- [What is Polonius?](./what_is_polonius.md)
- [Current status and roadmap](./current_status.md)
- [Getting started](./getting_started.md)
- [Generating inputs from rustc](./generate_inputs.md)
- [Rules](./rules.md)
- [Initialization](./rules/initialization.md)
- [See also](./see_also.md)
26 changes: 26 additions & 0 deletions book/src/current_status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Current status

Polonius has been provisionally integrated into rustc. You can run a nightly
rustc with the `-Zpolonius` flag to try it out. However, it is not really
ready for widespread use.

Our current roadmap is as follows:

- **Complete the analysis:** Polonius represents only a portion of the full
borrow checker analysis. We would like to move as much as possible from the
handwritten Rust code in rustc into the datalog-based approach of polonius.
- **Optimize:** Naively implementing the polonius rules can be quite
slow, so it's important that we optimize the rules and produce a
more optimized version. This will also likely require some special
case optimizations to help with specific cases, such as large static
constants.

After those two steps are done, and presuming all goes well, we expect
to replace the existing rustc borrow checker with the polonius
crate. The crate will continue to exist.

## Want to help?

Check out the [polonius working group][wg] of the compiler team.

[wg]; https://rust-lang.github.io/compiler-team/working-groups/polonius/
24 changes: 24 additions & 0 deletions book/src/generate_inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.
27 changes: 27 additions & 0 deletions book/src/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

[post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/
4 changes: 4 additions & 0 deletions book/src/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rules

These chapters document and explain the Polonius rules, primarily in
datalog form.
1 change: 1 addition & 0 deletions book/src/rules/initialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Initialization
10 changes: 10 additions & 0 deletions book/src/see_also.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See also

There have been a number of blog posts related to Polonius as it evolves:

- http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/
- ... TODO add the rest ...

The academic work "Oxide" is partially inspired by Polonius:

- [Oxide](https://aaronweiss.us/pubs/draft19-oxide.pdf)
14 changes: 14 additions & 0 deletions book/src/what_is_polonius.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# What is polonius?

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

[post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/

## Why the name "Polonius"?

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

[nblnb]: https://literarydevices.net/neither-a-borrower-nor-a-lender-be/

0 comments on commit 65c9346

Please sign in to comment.