Rust: Tracking issue for RFC 2229, "Closures Capture Disjoint Fields"

Created on 19 Aug 2018  路  13Comments  路  Source: rust-lang/rust

This is a tracking issue for the RFC "Closures Capture Disjoint Fields" (rust-lang/rfcs#2229).

Status

This is under active development by the wg-rfc-2229 compiler-team working group. You can follow along in #t-compiler/wg-rfc-2229 stream of the rust-lang Zulip.

Implementation plan and status

  • [x] https://github.com/rust-lang/rust/issues/56905 refactor the compiler to be less reliant on freevars, which are tied to the variables, and instead to use a map produced by the type-checker
  • [x] Rename upvars query to upvars_mentioned https://github.com/rust-lang/rust/pull/72544
  • [x] Rename upvars_list to closure_captures https://github.com/rust-lang/rust/pull/72591
  • [ ] Refactor uses of the upvars_mentioned query to extract information from the typeck tables (https://github.com/sexxi-goose/rust/issues/4)
  • [ ] Refactor hir::Place to include full detail on projections
  • [ ] Refactor hir::Place to separate out the hir_id and Span (that is a PlaceReference)
  • [ ] Change closure captures to use a hir::Place instead of just an upvar
  • [ ] Update the closure analysis to compute minimal hir::Place captures

At this point, the implementation will capture paths and not just variables, but this will be a breaking change. Remaining work would be to:

  • [ ] analyze the size of the closures that result
  • [ ] write a lint that detects when destructors might run at different times and report a warning, including some idea of heuristics for things we don't care about
  • [ ] use that to analyze impact on the ecosystem and to prepare a "transition lint"

Links, see also

  • rust-lang/compiler-team#292, a Major Change Proposal outlining an initial plan

Unresolved questions:

  • [ ] How to optimize pointers. Can borrows that all reference parts of the same object be stored as a single pointer? How should this optimization be implemented (e.g. a special repr, refinement typing)?
  • [ ] How to signal that a function is pure. Is this even needed/wanted? Any other places where the language could benefit?
  • [ ] Should Box be special?
  • [ ] Drop order can change as a result of this RFC, is this a real stability problem? How should this be resolved?


This issue has been assigned to @arora-aman via this comment.


A-closures B-RFC-approved C-tracking-issue T-lang

Most helpful comment

I'm not really aware of any particular interaction between this feature and self-referential types. Am I missing something?

All 13 comments

IIRC, this needs to wait for the new MIR (NLL) borrow-checker to replace the old one.
cc @rust-lang/wg-compiler-nll

I would love to follow this through and give the code a shot, but it's probably too big of a first contribution to the compiler. Maybe I'll take a swing at some starter issues and then come back if no one else has gotten it done.

@eddyb Yes, this definitely should be built on NLL.

@blitzerr could you please provide a status update on this? it looks like the related issues (#57482 and #60205) had some work done, but they look stuck now. Anything that needs help with? Not sure if I can do anything, but I can try :)

Concern: How does this feature interact with self-referential struct?

@lzutao Rust has no native support for self referential types, so you will just have to be careful with the unsafe code you write.

I know. But with polonius, there might be support for self-referential types in the future. So for future design space we need to care about how to interact this feature with self-referential types.

This is the first I've heard of Polonius having anything to do with self-referential types, despite having read all the blog posts and docs behind your link. Is this interaction spelled out somewhere?

@Ixrec I do recall that there was a presentation from Niko that says it could maybe help with self-referential structs somehow, but he did preface it by saying that it's purely speculative: https://youtu.be/_agDeiWek8w?t=1900.

I'm not really aware of any particular interaction between this feature and self-referential types. Am I missing something?

@rustbot assign arora-aman

Error: Parsing assign command in comment failed: ...'arora-aman' | error: user should start with @ at >| ''...

Please let @rust-lang/release know if you're having trouble with this bot.

@rustbot assign @arora-aman

@rustbot claim

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikomatsakis picture nikomatsakis  路  331Comments

Leo1003 picture Leo1003  路  898Comments

Mark-Simulacrum picture Mark-Simulacrum  路  681Comments

nikomatsakis picture nikomatsakis  路  236Comments

nikomatsakis picture nikomatsakis  路  268Comments