GithubHelp home page GithubHelp logo

RFC 2229 about lang-team HOT 6 CLOSED

rust-lang avatar rust-lang commented on May 25, 2024 7
RFC 2229

from lang-team.

Comments (6)

arora-aman avatar arora-aman commented on May 25, 2024 10
  • Feature mostly works and is avaiable under #![feature(capture_disjoint_fields)]
  • We have handled all edge cases we are aware of including patterns, FRU syntax, references in move closures, handling unsafe
  • Migration lint for drop reordering is supported under #[deny(disjoint_capture_drop_reorder)] and is supported using rust fix.
  • On going work to support migration for auto-traits, and diagnostics

from lang-team.

arora-aman avatar arora-aman commented on May 25, 2024

There are some more relaxations to closures that can be made as side effects of work being done for 2229, proposed details can be found here: rust-lang/project-rfc-2229#16

from lang-team.

nikomatsakis avatar nikomatsakis commented on May 25, 2024

Update 2020-10-26:

Uncovered a few interesting things this far. For example, this changes behavior:

let c = || {
    let _ = x;  // today: borrows `x`
};

In the new edition, using the new RFC, x would not be captured.

from lang-team.

arora-aman avatar arora-aman commented on May 25, 2024

The workgroup's focus over the last month has been diagnostics, migrations and getting closer to the edition 21 release.

1. Diangostics

  • Overall improvement to closure diagnostics: we now point to part of the source code responsible for the capture kind associated with the error message.
  • eg:
let mut p = Point { x: 1, y: 2 };
let y = &p.y; 

let mut c = || {  								   
    println!("{:?}", p);  								
    let x = &mut p.x;
};

c(); 
println!("{}", y);

Ouput before change:
image

Output ater change (available on rust nightly):
image


2. Migrations

  • We can now detect if the closure after enabling RFC 2229 will not meet Clone or any of the auto trait bounds and can provide migrations for it. These migrations are supported via rustfix as well.
  • We can annote drop implementations with #[rustc_insignificant_dtor] to avoid migrating in scenarios where drop order doesn't affect semantics of the program. We intend to use this attribute to annotate the stdlib to mark certain type as safe to be Drop reorded. eg: when a string gets dropped it would not affect the behavior of rest of the program.

3. Closure Size

  • We wrote an initial implementation for printing out the closure size before and after the feature. The implementation is somewhat incomplete, but was good enough for us to get some data on cargo and stdlib.

Cargo and all depensices size data: https://docs.google.com/spreadsheets/d/1Irsj5O7HPPfomWat2jPTPdx_KPlsyYo5kRuQpNNuwsQ/edit?usp=sharing

from lang-team.

arora-aman avatar arora-aman commented on May 25, 2024
  • Lots of progress squelching small bugs in the implementation
  • It's now enabled by default in edition 2021
  • We are working to add material to the reference and to create a concise, formal definition of what gets captured and what doesn't (separate from the code)
  • We tested the size of closures and discovered one critical optimization. (Data that was collected is linked here: rust-lang/rust#86701 (comment))
  • After optimization closures appear largely unchanged, but we added a useful flag (-Zprofile-closures) to measure and are going to ask people to do so

from lang-team.

nikomatsakis avatar nikomatsakis commented on May 25, 2024

Stabilized!

from lang-team.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.