Compiler meeting presentation

Short Problem statement

Today closures don’t accept the code snippet below because a closure captures the entire composite type foo rather than just foo.b.

let a = &mut foo.a;
|| &mut foo.b; // Error! cannot borrow `foo`

Steps to get there

  • Step 1 change the type check to actually generate a tuple
Change the definition of closure
struct Closure<'l0...'li, T0...Tj, CK, CS, U0...Uk> {
struct Closure<'l0...'li, T0...Tj, CK, CS, (U0...Uk)> {

// U0, ..., Uk represents the types of each of the upvars captured by the closure.
For details of why we do this, please refer to this.

  • step 2 : Change the assumption that the closure capture is no longer one freevar for one upvar
  • How to do
  • Inspect each caller of with_freevars and change them to use upvar_list as it is here. upvar_list is a new data structure that was added as preparation for this RFC.
  • step 3 In the type checker, analyze the paths that get used and create more refined borrows
  • step 4  Try to optimize the representation of closures to separate logical from actual borrows

Current status

  • We are near the end of step 1. The implementation is done but this is causing some tests to fail. This is being looked at. A PR will appear soon.