Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
arora-aman committed Jul 1, 2020
1 parent 9fa3c91 commit 1457ad8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions closure_captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ When we see a closure within the body of the scope, we walk the body of the clos


To begin the analysis we use hints like `mut` for c5, `move` in c6, to guess the initial borrow kind of each capture.
Once the guesses are set, we create an ExprUseVistior that visits each expression within the closure body.
Once the guesses are set, we create an `ExprUseVistior` that visits each expression within the closure body.
ExprUseVisitor calls into MemCategorization which returns the access information about the expression as a `Place`.

ExprUseVisitor delegates the work of marking a Place as consume/borrow to a callback. In our case the `Delegate` trait is implemented
`ExprUseVisitor`(https://github.com/rust-lang/rust/blob/master/src/librustc_typeck/expr_use_visitor.rs) invokes methods on the delegate when it finds a Place being consumed or borrowed. The delegate has the job of deciding what to do with that information. In this case, the delegate is the upvar analysis, which "upgrades" the kind of borrow needed depending on the accesses it sees (all reads == shared borrow, writes == mutable borrow, moves == take ownership).
In our case the `Delegate` trait is implemented
by [`InferBorrowKind`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/upvar/struct.InferBorrowKind.html).
Everytime the delegate is called, it adjusts the current borrow kind of the captured variable.

It's possible that while processing the expressions in ExprUseVisitor on the closure body we see another closure (i.e. nested within the enclosing closure).
Since we walked the body of the closure before we started the analysis, we have already proccessed all nested closures.
Expand Down Expand Up @@ -207,7 +207,7 @@ The flow here would look like:
| | | visit closure c2
| | | | visit body of c2 (does nothing)
| | | | analyze body of c2, producing capture_kinds[c2]
| | analyze body of c1, reading capture_kinds[[c2], producing capture_kinds[c1]
| | analyze body of c1, reading capture_kinds[c2], producing capture_kinds[c1]
```

#### [`Place`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/mem_categorization/struct.Place.html)
Expand Down

0 comments on commit 1457ad8

Please sign in to comment.