Skip to content

Commit 00adcf0

Browse files
committed
auto merge of #9863 : csainty/rust/issue-9755-once-fns-feature-directive, r=alexcrichton
Hello, First time rust contributor here, please let me know if I need to sort out the contribution agreement for this. I picked issue #9755 to dip my toe in the water, this pull request isn't quite complete though as I have not updated the documentation. The reason for this is that I haven't tracked down why this feature is gated so I don't feel I can write a justification of the same quality as the other features have been documented. If someone would like to explain or point me at a mail thread I am happy to update with this change. Hopefully I have understood the process of converting the old flag into a directive correctly. Also just to call out what I am sure if a known quirk when adding feature directives, you can't build this code unless you have a snapshot of the compiler which knows about the feature directive. Chicken and the egg. I split the change into two commits, the first should be able to build a snapshot that can compile the second.
2 parents 88acb73 + 88ab38c commit 00adcf0

13 files changed

+44
-40
lines changed

doc/rust.md

+4
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,10 @@ The currently implemented features of the compiler are:
20672067
For now this style of variant is hidden behind a feature
20682068
flag.
20692069

2070+
* `once_fns` - Onceness guarantees a closure is only executed once. Defining a
2071+
closure as `once` is unlikely to be supported going forward. So
2072+
they are hidden behind this feature until they are to be removed.
2073+
20702074
If a feature is promoted to a language feature, then all existing programs will
20712075
start to receive compilation warnings about #[feature] directives which enabled
20722076
the new feature (because the directive is no longer necessary). However, if

src/librustc/driver/session.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -74,12 +74,11 @@ pub static statik: uint = 1 << 21;
7474
pub static print_link_args: uint = 1 << 22;
7575
pub static no_debug_borrows: uint = 1 << 23;
7676
pub static lint_llvm: uint = 1 << 24;
77-
pub static once_fns: uint = 1 << 25;
78-
pub static print_llvm_passes: uint = 1 << 26;
79-
pub static no_vectorize_loops: uint = 1 << 27;
80-
pub static no_vectorize_slp: uint = 1 << 28;
81-
pub static no_prepopulate_passes: uint = 1 << 29;
82-
pub static use_softfp: uint = 1 << 30;
77+
pub static print_llvm_passes: uint = 1 << 25;
78+
pub static no_vectorize_loops: uint = 1 << 26;
79+
pub static no_vectorize_slp: uint = 1 << 27;
80+
pub static no_prepopulate_passes: uint = 1 << 28;
81+
pub static use_softfp: uint = 1 << 29;
8382

8483
pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
8584
~[("verbose", "in general, enable more debug printouts", verbose),
@@ -118,9 +117,6 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
118117
("lint-llvm",
119118
"Run the LLVM lint pass on the pre-optimization IR",
120119
lint_llvm),
121-
("once-fns",
122-
"Allow 'once fn' closures to deinitialize captured variables",
123-
once_fns),
124120
("print-llvm-passes",
125121
"Prints the llvm optimization passes being run",
126122
print_llvm_passes),
@@ -326,7 +322,6 @@ impl Session_ {
326322
pub fn debug_borrows(&self) -> bool {
327323
self.opts.optimize == No && !self.debugging_opt(no_debug_borrows)
328324
}
329-
pub fn once_fns(&self) -> bool { self.debugging_opt(once_fns) }
330325
pub fn print_llvm_passes(&self) -> bool {
331326
self.debugging_opt(print_llvm_passes)
332327
}

src/librustc/front/feature_gate.rs

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
3333
("globs", Active),
3434
("macro_rules", Active),
3535
("struct_variant", Active),
36+
("once_fns", Active),
3637

3738
// These are used to test this portion of the compiler, they don't actually
3839
// mean anything
@@ -126,6 +127,20 @@ impl Visitor<()> for Context {
126127

127128
visit::walk_item(self, i, ());
128129
}
130+
131+
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
132+
match t.node {
133+
ast::ty_closure(closure) if closure.onceness == ast::Once => {
134+
self.gate_feature("once_fns", t.span,
135+
"once functions are \
136+
experimental and likely to be removed");
137+
138+
},
139+
_ => {}
140+
}
141+
142+
visit::walk_ty(self, t, ());
143+
}
129144
}
130145

131146
pub fn check_crate(sess: Session, crate: &ast::Crate) {

src/librustc/middle/borrowck/gather_loans/gather_moves.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -102,25 +102,13 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
102102
match cmt.cat {
103103
mc::cat_deref(_, _, mc::region_ptr(*)) |
104104
mc::cat_deref(_, _, mc::gc_ptr(*)) |
105-
mc::cat_deref(_, _, mc::unsafe_ptr(*)) => {
106-
bccx.span_err(
107-
cmt0.span,
108-
format!("cannot move out of {}",
109-
bccx.cmt_to_str(cmt)));
110-
false
111-
}
112-
113-
// These are separate from the above cases for a better error message.
105+
mc::cat_deref(_, _, mc::unsafe_ptr(*)) |
114106
mc::cat_stack_upvar(*) |
115107
mc::cat_copied_upvar(mc::CopiedUpvar { onceness: ast::Many, _ }) => {
116-
let once_hint = if bccx.tcx.sess.once_fns() {
117-
" (unless the destination closure type is `once fn')"
118-
} else {
119-
""
120-
};
121108
bccx.span_err(
122109
cmt0.span,
123-
format!("cannot move out of {}{}", bccx.cmt_to_str(cmt), once_hint));
110+
format!("cannot move out of {}",
111+
bccx.cmt_to_str(cmt)));
124112
false
125113
}
126114

src/librustc/middle/mem_categorization.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -508,12 +508,10 @@ impl mem_categorization_ctxt {
508508
let var_is_refd = match (closure_ty.sigil, closure_ty.onceness) {
509509
// Many-shot stack closures can never move out.
510510
(ast::BorrowedSigil, ast::Many) => true,
511-
// 1-shot stack closures can move out with "-Z once-fns".
512-
(ast::BorrowedSigil, ast::Once)
513-
if self.tcx.sess.once_fns() => false,
514-
(ast::BorrowedSigil, ast::Once) => true,
511+
// 1-shot stack closures can move out.
512+
(ast::BorrowedSigil, ast::Once) => false,
515513
// Heap closures always capture by copy/move, and can
516-
// move out iff they are once.
514+
// move out if they are once.
517515
(ast::OwnedSigil, _) |
518516
(ast::ManagedSigil, _) => false,
519517

src/librustc/middle/typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3645,7 +3645,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
36453645
let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy {
36463646
purity: ast::impure_fn,
36473647
sigil: ast::BorrowedSigil,
3648-
onceness: ast::Once,
3648+
onceness: ast::Many,
36493649
region: ty::re_bound(ty::br_anon(0)),
36503650
bounds: ty::EmptyBuiltinBounds(),
36513651
sig: ty::FnSig {

src/libstd/unstable/intrinsics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ extern "rust-intrinsic" {
331331

332332
pub fn visit_tydesc(td: *TyDesc, tv: &mut TyVisitor);
333333

334-
pub fn frame_address(f: &once fn(*u8));
334+
#[cfg(not(stage0))]
335+
pub fn frame_address(f: &fn(*u8));
335336

336337
/// Get the address of the `__morestack` stack growth function.
337338
pub fn morestack_addr() -> *();

src/test/compile-fail/once-cant-call-twice-on-heap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Testing guarantees provided by once functions.
1212
// This program would segfault if it were legal.
1313

14+
#[feature(once_fns)];
1415
extern mod extra;
1516
use extra::arc;
1617
use std::util;

src/test/compile-fail/once-cant-call-twice-on-stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Testing guarantees provided by once functions.
1212
// This program would segfault if it were legal.
1313

14-
// compile-flags:-Z once-fns
14+
#[feature(once_fns)];
1515
extern mod extra;
1616
use extra::arc;
1717
use std::util;

src/test/compile-fail/once-fn-subtyping.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(once_fns)];
1112
fn main() {
1213
let f: &once fn() = ||();
1314
let g: &fn() = f; //~ ERROR mismatched types

src/test/run-pass/intrinsic-frame-address.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -12,7 +12,7 @@
1212

1313
mod rusti {
1414
extern "rust-intrinsic" {
15-
pub fn frame_address(f: &once fn(*u8));
15+
pub fn frame_address(f: &fn(*u8));
1616
}
1717
}
1818

src/test/run-pass/once-move-out-on-heap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// xfail-fast
1414

15+
#[feature(once_fns)];
1516
extern mod extra;
1617
use extra::arc;
1718
use std::util;

src/test/run-pass/once-move-out-on-stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// xfail-fast
1414

15-
// compile-flags:-Z once-fns
15+
#[feature(once_fns)];
1616
extern mod extra;
1717
use extra::arc;
1818
use std::util;

0 commit comments

Comments
 (0)