Skip to content

One-shot closures. #7244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 29, 2013
Merged

One-shot closures. #7244

merged 6 commits into from
Jun 29, 2013

Conversation

bblum
Copy link
Contributor

@bblum bblum commented Jun 19, 2013

@graydon suggested that once closures not be part of the language for 1.0, but that they might be hidden behind a -Z compile flag as an "experimental feature" in case people decide they need them.

Regardless of whether -Z once-fns is set, this PR will parse the once keyword and will prevent closures labelled with it from being called more than once. It will also permit moving out of captured vars in heap closures, just to let the runtime writers stop using Cell sooner. Setting -Z once-fns only toggles whether the move-out-from-capture privilege is also given for stack closures.

r? @nikomatsakis

@mstewartgallus
Copy link
Contributor

Great! I've been needing one shot closures for a very long time. After this lands can we start putting one shot closures in some of the standard libraries? For example, it really hurts that extra::arc::RWARC::write doesn't take a once function.

@brson
Copy link
Contributor

brson commented Jun 24, 2013

@sstewartgallus No, we can't use them in public interfaces, since they are not on by default.

bors added a commit that referenced this pull request Jun 29, 2013
@graydon suggested that once closures not be part of the language for 1.0, but that they might be hidden behind a -Z compile flag as an "experimental feature" in case people decide they need them.

Regardless of whether ```-Z once-fns``` is set, this PR will parse the ```once``` keyword and will prevent closures labelled with it from being called more than once. It will also permit moving out of captured vars in heap closures, just to let the runtime writers stop using ```Cell``` sooner. Setting ```-Z once-fns``` only toggles whether the move-out-from-capture privilege is also given for stack closures.

r? @nikomatsakis
@bors bors closed this Jun 29, 2013
@bors bors merged commit e0788c7 into rust-lang:master Jun 29, 2013
@bblum bblum deleted the once branch July 2, 2013 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants