Giter Site home page Giter Site logo

Handle closures about humpty_dumpty HOT 10 OPEN

manishearth avatar manishearth commented on September 26, 2024
Handle closures

from humpty_dumpty.

Comments (10)

Manishearth avatar Manishearth commented on September 26, 2024

I believe the ctxt has some data on closure capture clauses in a map.

from humpty_dumpty.

Manishearth avatar Manishearth commented on September 26, 2024

http://doc.rust-lang.org/rustc/middle/ty/type.UpvarCaptureMap.html, I think?

from humpty_dumpty.

Munksgaard avatar Munksgaard commented on September 26, 2024

http://doc.rust-lang.org/rustc/middle/ty/fn.closure_upvars.html, maybe?

from humpty_dumpty.

Manishearth avatar Manishearth commented on September 26, 2024

Oh, forgot that middle::ty has a helper funciton for everything you'll ever need ;)

from humpty_dumpty.

Munksgaard avatar Munksgaard commented on September 26, 2024

It occured to me that you could actually just check the def_map to see whether or not something is an upvar. The result is b1782ad. However, I realized that we actually have a bigger problem: we cannot guarantee that a closure will ever be run!

Consider the following code, which is basically just a stripped version of the test from b1782ad:

let x = Foo;
let cl = || {
    close(x);
};

cl is a closure that has captured x and will correctly close it, but only if it is actually run. I don't think we can actually tell whether or not that is the case.

from humpty_dumpty.

Manishearth avatar Manishearth commented on September 26, 2024

There's also an upvar capture map somewhere in the tcx.

We should assume that closures that capture droppy things by move will be run once.

from humpty_dumpty.

Munksgaard avatar Munksgaard commented on September 26, 2024

I don't like that assumption, but I'm also not sure that there's actually anything else we can do.

from humpty_dumpty.

Manishearth avatar Manishearth commented on September 26, 2024

I think it's reasonable.

Note that a closure capturing by move will be FnOnce unless it's capturing by move via move || (in which case it may or may not be. So those closures are run either zero times or once.

Since we don't know when it's going to happen, we assume that "once" is bad.

Alternatively we can track the closure dependency and when it gets run but that sounds complicated.

from humpty_dumpty.

Munksgaard avatar Munksgaard commented on September 26, 2024

What do you mean "once" is bad?

But yes, it would be very nasty to track the closure.

from humpty_dumpty.

Manishearth avatar Manishearth commented on September 26, 2024

@Munksgaard I mean that we disallow closures of this form.

Instantiating a closure that takes an upvar by-move is a move. This is similar to let x = foo(chan) in an abstract sense.

from humpty_dumpty.

Related Issues (12)

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.