Skip to content

Commit e695b62

Browse files
committed
update NLL after refactorings
1 parent e30bc0f commit e695b62

File tree

5 files changed

+41
-48
lines changed

5 files changed

+41
-48
lines changed

src/borrow_check.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ enforcing a number of properties:
1111
- That you can't mutate a place while it is immutably borrowed.
1212
- etc
1313

14-
At the time of this writing, the code is in a state of transition. The
15-
"main" borrow checker still works by processing [the HIR](hir.html),
16-
but that is being phased out in favor of the MIR-based borrow checker.
17-
Accordingly, this documentation focuses on the new, MIR-based borrow
18-
checker.
19-
20-
Doing borrow checking on MIR has several advantages:
14+
The borrow checker operates on the MIR. An older implementation operated on the
15+
HIR. Doing borrow checking on MIR has several advantages:
2116

2217
- The MIR is *far* less complex than the HIR; the radical desugaring
2318
helps prevent bugs in the borrow checker. (If you're curious, you
@@ -42,15 +37,15 @@ the [`mir_borrowck`] query.
4237
we will modify this copy in place to modify the types and things to
4338
include references to the new regions that we are computing.
4439
- We then invoke [`replace_regions_in_mir`] to modify our local MIR.
45-
Among other things, this function will replace all of the [regions](./appendix/glossary.html) in
46-
the MIR with fresh [inference variables](./appendix/glossary.html).
40+
Among other things, this function will replace all of the [regions](./appendix/glossary.md) in
41+
the MIR with fresh [inference variables](./appendix/glossary.md).
4742
- Next, we perform a number of
48-
[dataflow analyses](./appendix/background.html#dataflow) that
43+
[dataflow analyses](./appendix/background.md#dataflow) that
4944
compute what data is moved and when.
50-
- We then do a [second type check](borrow_check/type_check.html) across the MIR:
45+
- We then do a [second type check](borrow_check/type_check.md) across the MIR:
5146
the purpose of this type check is to determine all of the constraints between
5247
different regions.
53-
- Next, we do [region inference](borrow_check/region_inference.html), which computes
48+
- Next, we do [region inference](borrow_check/region_inference.md), which computes
5449
the values of each region — basically, the points in the control-flow graph where
5550
each lifetime must be valid according to the constraints we collected.
5651
- At this point, we can compute the "borrows in scope" at each point.

src/borrow_check/region_inference.md

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Region inference (NLL)
22

3-
The MIR-based region checking code is located in
4-
[the `rustc_mir::borrow_check::nll` module][nll]. (NLL, of course,
5-
stands for "non-lexical lifetimes", a term that will hopefully be
6-
deprecated once they become the standard kind of lifetime.)
3+
The MIR-based region checking code is located in [the `rustc_mir::borrow_check`
4+
module][nll].
75

8-
[nll]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/index.html
6+
[nll]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/index.html
97

108
The MIR-based region analysis consists of two major functions:
119

@@ -36,12 +34,12 @@ The MIR-based region analysis consists of two major functions:
3634
- The [NLL RFC] also includes fairly thorough (and hopefully readable)
3735
coverage.
3836

39-
[cp]: ./region_inference/constraint_propagation.html
40-
[fvb]: ../appendix/background.html#free-vs-bound
37+
[cp]: ./region_inference/constraint_propagation.md
38+
[fvb]: ../appendix/background.md#free-vs-bound
4139
[`replace_regions_in_mir`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/fn.replace_regions_in_mir.html
4240
[`compute_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/fn.compute_regions.html
43-
[`RegionInferenceContext`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html
44-
[`solve`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.solve
41+
[`RegionInferenceContext`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html
42+
[`solve`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.solve
4543
[NLL RFC]: https://rust-lang.github.io/rfcs/2094-nll.html
4644
[MIR type checker]: ./type_check.md
4745

@@ -68,7 +66,7 @@ the moment.
6866

6967
TODO: write about _how_ these regions are computed.
7068

71-
[`UniversalRegions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/universal_regions/struct.UniversalRegions.html
69+
[`UniversalRegions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/universal_regions/struct.UniversalRegions.html
7270

7371
<a name="region-variables"></a>
7472

@@ -84,7 +82,7 @@ maintain a set storing what elements are present in its value (to make this
8482
efficient, we give each kind of element an index, the `RegionElementIndex`, and
8583
use sparse bitsets).
8684

87-
[ri]: https://github.com/rust-lang/rust/tree/master/src/librustc_mir/borrow_check/nll/region_infer/
85+
[ri]: https://github.com/rust-lang/rust/tree/master/src/librustc_mir/borrow_check/region_infer/
8886

8987
The kinds of region elements are as follows:
9088

@@ -115,7 +113,7 @@ common sorts of constraints are:
115113
2. Liveness constraints. Each region needs to be live at points where it can be
116114
used. These constraints are collected by [`generate_constraints`].
117115

118-
[`generate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/constraint_generation/fn.generate_constraints.html
116+
[`generate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/constraint_generation/fn.generate_constraints.html
119117

120118
## Inference Overview
121119

@@ -219,12 +217,12 @@ Here are some of the fields of the struct:
219217
- [`closure_bounds_mapping`]: used for propagating region constraints from
220218
closures back out to the creator of the closure.
221219

222-
[`constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.constraints
223-
[`liveness_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.liveness_constraints
224-
[`universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.universal_regions
225-
[`universal_region_relations`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.universal_region_relations
226-
[`type_tests`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.type_tests
227-
[`closure_bounds_mapping`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.closure_bounds_mapping
220+
[`constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.constraints
221+
[`liveness_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.liveness_constraints
222+
[`universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.universal_regions
223+
[`universal_region_relations`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.universal_region_relations
224+
[`type_tests`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.type_tests
225+
[`closure_bounds_mapping`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.closure_bounds_mapping
228226

229227
TODO: should we discuss any of the others fields? What about the SCCs?
230228

@@ -233,6 +231,6 @@ inference. This is done by calling the [`solve`] method on the context. This
233231
is where we call [`propagate_constraints`] and then check the resulting type
234232
tests and universal regions, as discussed above.
235233

236-
[`propagate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.propagate_constraints
237-
[`check_type_tests`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.check_type_tests
238-
[`check_universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.check_universal_regions
234+
[`propagate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.propagate_constraints
235+
[`check_type_tests`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.check_type_tests
236+
[`check_universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.check_universal_regions

src/borrow_check/region_inference/constraint_propagation.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on one at a time (each of them is fairly independent from the others):
1010
- outlives constraints (`R1: R2`), which arise from subtyping;
1111
- [member constraints][m_c] (`member R_m of [R_c...]`), which arise from impl Trait.
1212

13-
[`propagate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.propagate_constraints
13+
[`propagate_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.propagate_constraints
1414
[m_c]: ./member_constraints.md
1515

1616
In this chapter, we'll explain the "heart" of constraint propagation,
@@ -68,8 +68,8 @@ though; instead, we store a (sparse) bitset per region variable (of
6868
type [`LivenessValues`]). This way we only need a single bit for each
6969
liveness constraint.
7070

71-
[`liveness_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.liveness_constraints
72-
[`LivenessValues`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/values/struct.LivenessValues.html
71+
[`liveness_constraints`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.liveness_constraints
72+
[`LivenessValues`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/values/struct.LivenessValues.html
7373

7474
One thing that is worth mentioning: All lifetime parameters are always
7575
considered to be live over the entire function body. This is because
@@ -112,9 +112,9 @@ induces an edge `'a -> 'b`. This conversion happens in the
112112
[`RegionInferenceContext::new`] function that creates the inference
113113
context.
114114

115-
[`ConstraintSet`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/constraints/struct.OutlivesConstraintSet.html
116-
[graph-fn]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/constraints/struct.OutlivesConstraintSet.html#method.graph
117-
[`RegionInferenceContext::new`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.new
115+
[`ConstraintSet`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/constraints/struct.OutlivesConstraintSet.html
116+
[graph-fn]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/constraints/struct.OutlivesConstraintSet.html#method.graph
117+
[`RegionInferenceContext::new`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.new
118118

119119
When using a graph representation, we can detect regions that must be equal
120120
by looking for cycles. That is, if you have a constraint like
@@ -146,8 +146,8 @@ of fields are defined in terms of SCCs. For example, the
146146
of a specific region `'a` then, we first figure out the SCC that the
147147
region is a part of, and then find the value of that SCC.
148148

149-
[`constraint_sccs`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.constraint_sccs
150-
[`scc_values`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#structfield.scc_values
149+
[`constraint_sccs`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.constraint_sccs
150+
[`scc_values`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#structfield.scc_values
151151

152152
When we compute SCCs, we not only figure out which regions are a
153153
member of each SCC, we also figure out the edges between them. So for example

src/borrow_check/region_inference/lifetime_parameters.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ relationships to one another. So if you have e.g. `where 'a: 'b`, then
2929
the [`UniversalRegionRelations`] struct would track that `'a: 'b` is
3030
known to hold (which could be tested with the [`outlives`] function.
3131

32-
[`UniversalRegions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/universal_regions/struct.UniversalRegions.html
33-
[`UniversalRegionRelations`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/type_check/free_region_relations/struct.UniversalRegionRelations.html
34-
[`outlives`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/type_check/free_region_relations/struct.UniversalRegionRelations.html#method.outlives
32+
[`UniversalRegions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/universal_regions/struct.UniversalRegions.html
33+
[`UniversalRegionRelations`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/type_check/free_region_relations/struct.UniversalRegionRelations.html
34+
[`outlives`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/type_check/free_region_relations/struct.UniversalRegionRelations.html#method.outlives
3535

3636
## Everything is a region variable
3737

@@ -56,7 +56,7 @@ type). These subdivisions are not important for the topics discussed
5656
here, but become important when we consider [closure constraint
5757
propagation](./closure_constraints.html), so we discuss them there.
5858

59-
[`RegionClassification`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/universal_regions/enum.RegionClassification.html#variant.Local
59+
[`RegionClassification`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/universal_regions/enum.RegionClassification.html#variant.Local
6060

6161
## Universal lifetimes as the elements of a region's value
6262

@@ -86,7 +86,7 @@ liveness constraint (i.e., `'a` must extend until the end of
8686
itself). In the code, these liveness constraints are setup in
8787
[`init_free_and_bound_regions`].
8888

89-
[`init_free_and_bound_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.init_free_and_bound_regions
89+
[`init_free_and_bound_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.init_free_and_bound_regions
9090

9191
## Propagating outlives constraints for universal regions
9292

@@ -122,4 +122,4 @@ not, as in our example, that is an error. This check is done in the
122122
universal regions, inspects their final value, and tests against the
123123
declared [`UniversalRegionRelations`].
124124

125-
[`check_universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/region_infer/struct.RegionInferenceContext.html#method.check_universal_regions
125+
[`check_universal_regions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/region_infer/struct.RegionInferenceContext.html#method.check_universal_regions

src/borrow_check/type_check.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The MIR type-check
22

33
A key component of the borrow check is the
4-
[MIR type-check](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/nll/type_check/index.html).
4+
[MIR type-check](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/type_check/index.html).
55
This check walks the MIR and does a complete "type check" -- the same
66
kind you might find in any other language. In the process of doing
77
this type-check, we also uncover the region constraints that apply to

0 commit comments

Comments
 (0)