Skip to content

Commit

Permalink
Removed the -Z once_fns compiler flag and added the new feature direc…
Browse files Browse the repository at this point in the history
…tive of the same name to replace it.

Changed the frame_address intrinsic to no longer be a once fn.
This removes the dependency on once_fns from std.
  • Loading branch information
csainty committed Oct 17, 2013
1 parent 1f279bf commit 88ab38c
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 40 deletions.
4 changes: 4 additions & 0 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,10 @@ The currently implemented features of the compiler are:
For now this style of variant is hidden behind a feature
flag.

* `once_fns` - Onceness guarantees a closure is only executed once. Defining a
closure as `once` is unlikely to be supported going forward. So
they are hidden behind this feature until they are to be removed.

If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about #[feature] directives which enabled
the new feature (because the directive is no longer necessary). However, if
Expand Down
17 changes: 6 additions & 11 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -74,12 +74,11 @@ pub static statik: uint = 1 << 21;
pub static print_link_args: uint = 1 << 22;
pub static no_debug_borrows: uint = 1 << 23;
pub static lint_llvm: uint = 1 << 24;
pub static once_fns: uint = 1 << 25;
pub static print_llvm_passes: uint = 1 << 26;
pub static no_vectorize_loops: uint = 1 << 27;
pub static no_vectorize_slp: uint = 1 << 28;
pub static no_prepopulate_passes: uint = 1 << 29;
pub static use_softfp: uint = 1 << 30;
pub static print_llvm_passes: uint = 1 << 25;
pub static no_vectorize_loops: uint = 1 << 26;
pub static no_vectorize_slp: uint = 1 << 27;
pub static no_prepopulate_passes: uint = 1 << 28;
pub static use_softfp: uint = 1 << 29;

pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
~[("verbose", "in general, enable more debug printouts", verbose),
Expand Down Expand Up @@ -118,9 +117,6 @@ pub fn debugging_opts_map() -> ~[(&'static str, &'static str, uint)] {
("lint-llvm",
"Run the LLVM lint pass on the pre-optimization IR",
lint_llvm),
("once-fns",
"Allow 'once fn' closures to deinitialize captured variables",
once_fns),
("print-llvm-passes",
"Prints the llvm optimization passes being run",
print_llvm_passes),
Expand Down Expand Up @@ -326,7 +322,6 @@ impl Session_ {
pub fn debug_borrows(&self) -> bool {
self.opts.optimize == No && !self.debugging_opt(no_debug_borrows)
}
pub fn once_fns(&self) -> bool { self.debugging_opt(once_fns) }
pub fn print_llvm_passes(&self) -> bool {
self.debugging_opt(print_llvm_passes)
}
Expand Down
15 changes: 15 additions & 0 deletions src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("globs", Active),
("macro_rules", Active),
("struct_variant", Active),
("once_fns", Active),

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

visit::walk_item(self, i, ());
}

fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
match t.node {
ast::ty_closure(closure) if closure.onceness == ast::Once => {
self.gate_feature("once_fns", t.span,
"once functions are \
experimental and likely to be removed");

},
_ => {}
}

visit::walk_ty(self, t, ());
}
}

pub fn check_crate(sess: Session, crate: &ast::Crate) {
Expand Down
20 changes: 4 additions & 16 deletions src/librustc/middle/borrowck/gather_loans/gather_moves.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -102,25 +102,13 @@ fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
match cmt.cat {
mc::cat_deref(_, _, mc::region_ptr(*)) |
mc::cat_deref(_, _, mc::gc_ptr(*)) |
mc::cat_deref(_, _, mc::unsafe_ptr(*)) => {
bccx.span_err(
cmt0.span,
format!("cannot move out of {}",
bccx.cmt_to_str(cmt)));
false
}

// These are separate from the above cases for a better error message.
mc::cat_deref(_, _, mc::unsafe_ptr(*)) |
mc::cat_stack_upvar(*) |
mc::cat_copied_upvar(mc::CopiedUpvar { onceness: ast::Many, _ }) => {
let once_hint = if bccx.tcx.sess.once_fns() {
" (unless the destination closure type is `once fn')"
} else {
""
};
bccx.span_err(
cmt0.span,
format!("cannot move out of {}{}", bccx.cmt_to_str(cmt), once_hint));
format!("cannot move out of {}",
bccx.cmt_to_str(cmt)));
false
}

Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand Down Expand Up @@ -508,12 +508,10 @@ impl mem_categorization_ctxt {
let var_is_refd = match (closure_ty.sigil, closure_ty.onceness) {
// Many-shot stack closures can never move out.
(ast::BorrowedSigil, ast::Many) => true,
// 1-shot stack closures can move out with "-Z once-fns".
(ast::BorrowedSigil, ast::Once)
if self.tcx.sess.once_fns() => false,
(ast::BorrowedSigil, ast::Once) => true,
// 1-shot stack closures can move out.
(ast::BorrowedSigil, ast::Once) => false,
// Heap closures always capture by copy/move, and can
// move out iff they are once.
// move out if they are once.
(ast::OwnedSigil, _) |
(ast::ManagedSigil, _) => false,

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3645,7 +3645,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy {
purity: ast::impure_fn,
sigil: ast::BorrowedSigil,
onceness: ast::Once,
onceness: ast::Many,
region: ty::re_bound(ty::br_anon(0)),
bounds: ty::EmptyBuiltinBounds(),
sig: ty::FnSig {
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/unstable/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ extern "rust-intrinsic" {

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

pub fn frame_address(f: &once fn(*u8));
#[cfg(not(stage0))]
pub fn frame_address(f: &fn(*u8));

/// Get the address of the `__morestack` stack growth function.
pub fn morestack_addr() -> *();
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/once-cant-call-twice-on-heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.

#[feature(once_fns)];
extern mod extra;
use extra::arc;
use std::util;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/once-cant-call-twice-on-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.

// compile-flags:-Z once-fns
#[feature(once_fns)];
extern mod extra;
use extra::arc;
use std::util;
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/once-fn-subtyping.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[feature(once_fns)];
fn main() {
let f: &once fn() = ||();
let g: &fn() = f; //~ ERROR mismatched types
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/intrinsic-frame-address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -12,7 +12,7 @@

mod rusti {
extern "rust-intrinsic" {
pub fn frame_address(f: &once fn(*u8));
pub fn frame_address(f: &fn(*u8));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/once-move-out-on-heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// xfail-fast

#[feature(once_fns)];
extern mod extra;
use extra::arc;
use std::util;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/once-move-out-on-stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// xfail-fast

// compile-flags:-Z once-fns
#[feature(once_fns)];
extern mod extra;
use extra::arc;
use std::util;
Expand Down

5 comments on commit 88ab38c

@bors
Copy link
Contributor

@bors bors commented on 88ab38c Oct 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at csainty@88ab38c

@bors
Copy link
Contributor

@bors bors commented on 88ab38c Oct 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging csainty/rust/issue-9755-once-fns-feature-directive = 88ab38c into auto

@bors
Copy link
Contributor

@bors bors commented on 88ab38c Oct 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

csainty/rust/issue-9755-once-fns-feature-directive = 88ab38c merged ok, testing candidate = 00adcf0

@bors
Copy link
Contributor

@bors bors commented on 88ab38c Oct 17, 2013

@bors
Copy link
Contributor

@bors bors commented on 88ab38c Oct 17, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 00adcf0

Please sign in to comment.