Skip to content

Commit a5f0591

Browse files
committed
add general documentation on the polonius module
this describes the rough algorithm using the localized constraint graph
1 parent b70a915 commit a5f0591

File tree

1 file changed

+35
-0
lines changed
  • compiler/rustc_borrowck/src/polonius

1 file changed

+35
-0
lines changed

compiler/rustc_borrowck/src/polonius/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
//! Polonius analysis and support code:
2+
//! - dedicated constraints
3+
//! - conversion from NLL constraints
4+
//! - debugging utilities
5+
//! - etc.
6+
//!
7+
//! The current implementation models the flow-sensitive borrow-checking concerns as a graph
8+
//! containing both information about regions and information about the control flow.
9+
//!
10+
//! Loan propagation is seen as a reachability problem (with some subtleties) between where the loan
11+
//! is introduced and a given point.
12+
//!
13+
//! Constraints arising from type-checking allow loans to flow from region to region at the same CFG
14+
//! point. Constraints arising from liveness allow loans to flow within from point to point, between
15+
//! live regions at these points.
16+
//!
17+
//! Edges can be bidirectional to encode invariant relationships, and loans can flow "back in time"
18+
//! to traverse these constraints arising earlier in the CFG.
19+
//!
20+
//! When incorporating kills in the traversal, the loans reaching a given point are considered live.
21+
//!
22+
//! After this, the usual NLL process happens. These live loans are fed into a dataflow analysis
23+
//! combining them with the points where loans go out of NLL scope (the frontier where they stop
24+
//! propagating to a live region), to yield the "loans in scope" or "active loans", at a given
25+
//! point.
26+
//!
27+
//! Illegal accesses are still computed by checking whether one of these resulting loans is
28+
//! invalidated.
29+
//!
30+
//! More information on this simple approach can be found in the following links, and in the future
31+
//! in the rustc dev guide:
32+
//! - <https://smallcultfollowing.com/babysteps/blog/2023/09/22/polonius-part-1/>
33+
//! - <https://smallcultfollowing.com/babysteps/blog/2023/09/29/polonius-part-2/>
34+
//!
35+
136
mod constraints;
237
pub(crate) use constraints::*;
338

0 commit comments

Comments
 (0)