Comments (10)
I believe the ctxt has some data on closure capture clauses in a map.
from humpty_dumpty.
http://doc.rust-lang.org/rustc/middle/ty/type.UpvarCaptureMap.html, I think?
from humpty_dumpty.
http://doc.rust-lang.org/rustc/middle/ty/fn.closure_upvars.html, maybe?
from humpty_dumpty.
Oh, forgot that middle::ty has a helper funciton for everything you'll ever need ;)
from humpty_dumpty.
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.
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.
I don't like that assumption, but I'm also not sure that there's actually anything else we can do.
from humpty_dumpty.
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.
What do you mean "once" is bad?
But yes, it would be very nasty to track the closure.
from humpty_dumpty.
@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)
- Add more tests
- Properly document what humpty_dumpty can and cant do HOT 1
- Remove "debug" output HOT 1
- Implement ExprWhile checking HOT 1
- handling of for loops doesn't correctly take breaks into account
- Introducing a protected value inside a loop does not always warn
- Incorrent handling of breaks inside match statements HOT 2
- Handle generic functions HOT 6
- Handle return statements HOT 3
- Handle break and continue statements in loops HOT 2
- Find a better way to test humpty HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from humpty_dumpty.