Niko Matsakis
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # RFC 2229 Update [Watch the recording](https://www.youtube.com/watch?v=mJbv4rM9Yt8) The implementation for RFC 2229 has been progressing rapidly but we've encountered some interesting complications, especially around `move` closures (although the problems apply more generally). [More detailed update from the group](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view) ## Implementation status * [x] `![feature(capture_disjoint_fields)` works for simple cases * [ ] "Naive" pass for migrations * [ ] PR open for handling bugs around mutable references and restricting precison * [ ] PRs open for improving diangostics (reporting precise) information back to the user * [ ] Remove old data structures from the compiler ## Questions and conclusions from meeting * Do we need a better syntax for migrations? * Summary from meeting: no, assuming it's not that common * How do we migrate around traits that are not satisfied by the closure anymore? * some sketches below, we can introduce migrations for these if necessary (we should measure) * for `Clone` there may be changes in behavior, not just failure to compile * What should be the correct behavior in case of capture by move? * no concerns raised about the behavior, nor extension to reborrow, for now at least * what are some questions to try to answer * What percentage of closures require `let x = x` and why? * What percentage of closures change size and by how much? ## Rules as implemented today * [Move closures don't capture derefs](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#1-Move-closure-don%E2%80%99t-capture-Derefs) * [By value captures don't capture derefs](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#2-By-value-captures-don%E2%80%99t-capture-Derefs) * [Don't capture anything more precise on top of raw pointers](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#3-Don%E2%80%99t-capture-anything-more-precise-on-top-of-Raw-ptrs) * [Repr packed](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#4-Repr-packed) ## Why move closures don't capture derefs * [Wrong behavior for references](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#Motivation), could fix with [reborrowing captures for move closures](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#5-Reborrowing-capture-possible-extension) * [Performance concerns for box](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#Motivation) ## Migration plan * Behavior changes in the following situation: * a closure would have moved an entire variable (e.g., `x`) but now moves a more specific place (e.g., `x.y`) * and other fields of `x` that are no longer moved have 'significant' destructors (e.g., `x.z`) * In this scenario, the destructor for `x.z` runs when `x` goes out of scope, rather than when the closure is dropped * Proposed fix: * In such cases, we insert (via migraton lint) `let x = x;` into the closure * If there are multiple such variables, we insert `let (a, b, c) = (a, b, c);` * Improving accuracy: * Permit annotation of destructors in the standard library that just free memory. Those destructors are not considered 'significant'. * So e.g. if `x.z` is of type `String`, we would not insert `let x = x;` into the closure. Observations and shortcomings: * `let x = x` looks odd to be the recommended pattern, to be more specific * non-obvious to figure out * not obvious why it is there * `let _ = x` looks similar but is very different :) * could use `drop(x)` in some cases to make a more obvious desugaring * we detect behavioral changes via these rules but it's also possible for closures to change size (sometimes dramatically), and that is not presently detected * Auto traits: [Struct implements a Trait but subfield doesn’t](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#Struct-implements-a-Trait-but-subfield-doesn%E2%80%99t-Migration) * MEETING NOTES: * Could use a diagnostic * Or could have special rules that look for cases where `w.0: !Send` but `w: Send` (also for `Sync` and maybe `Clone`) for the migration lint * See notes about Clone below * [Base of an index projection is always captured](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#Base-of-an-index-projection-is-always-captured) -- partly implementation, partly policy Capturing subpaths can change the semantics of `closure.clone()`: ```rust= struct Foo { x: *mut u32 }; let foo: Foo; let c = move || { // fix is to add `let foo = foo;` let y = foo.x; }; c.clone(); // used to run `Foo::clone()` but now it runs `<*mut u32>::Clone` ``` We could detect cases where clone is implemented manually. With specialization could be true for autotraits, but we don't have that yet. ## Other bugs Notable bugs and limitations: * [Place mentioned in the closure isn't entirely captured](https://hackmd.io/71qq-IOpTNqzMkPpAI1dVg?view#Place-mentioned-in-the-closure-isn%E2%80%99t-entirely-captured) -- see also "captures and matches" below * We may now capture many more paths than we used to, inflating the size of closures * Recommendation: gather data * Note that this is limited to non-move closures, unless we implement the reborrowing rule (which we probably will) ### Captures and matches There are also some cases where the implementation is capturing more than you might think. These occur most notably around patterns, for example in cases like these: ```rust= let _ = x; match x { _ => () } let (_, _) = x; match x { (_, _) => () } ``` We have tried to stick to the rule that "if the borrow checker considers this an access of type X, then the closure captures do too", for the most part. But right now when pattern matching against a place expression (e.g., `x` in the examples above), that place is always captured *at least* by read. This should be fixable with more refactoring, we've deferred the work. Current behavor: * `let _ = <place>` ICEs Behavior we discussed last week: * `let _ = <place>` will trigger a "fake capture" of `<place>`, as will `match` Ultimate behavior: * all of the above would not capture `x`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully