use + mode for (almost) everything when not using legacy modes

This commit is contained in:
Niko Matsakis 2012-09-20 15:59:09 -07:00
parent 37aee97e4b
commit 267ab11cca
58 changed files with 133 additions and 68 deletions

View File

@ -19,6 +19,8 @@
#[no_core];
#[legacy_exports];
#[legacy_modes];
#[allow(vecs_implicitly_copyable,
non_implicitly_copyable_typarams)];
#[allow(non_camel_case_types)];

View File

@ -12,7 +12,7 @@ use common::mode_pretty;
use common::mode;
use util::logv;
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let config = parse_config(args);
log_config(config);
run_tests(config);

View File

@ -256,16 +256,31 @@ fn entangle_buffer<T: Send, Tstart: Send>(
(SendPacketBuffered(p), RecvPacketBuffered(p))
}
#[cfg(stage0)]
#[abi = "rust-intrinsic"]
#[doc(hidden)]
extern mod rusti {
#[legacy_exports];
fn atomic_xchg(dst: &mut int, src: int) -> int;
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
fn atomic_xchg(dst: &mut int, ++src: int) -> int;
fn atomic_xchg_acq(dst: &mut int, ++src: int) -> int;
fn atomic_xchg_rel(dst: &mut int, ++src: int) -> int;
fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;
fn atomic_xadd_acq(dst: &mut int, ++src: int) -> int;
fn atomic_xsub_rel(dst: &mut int, ++src: int) -> int;
}
#[cfg(stage1)]
#[cfg(stage2)]
#[abi = "rust-intrinsic"]
#[doc(hidden)]
extern mod rusti {
#[legacy_exports];
fn atomic_xchg(dst: &mut int, +src: int) -> int;
fn atomic_xchg_acq(dst: &mut int, +src: int) -> int;
fn atomic_xchg_rel(dst: &mut int, +src: int) -> int;
fn atomic_xadd_acq(dst: &mut int, +src: int) -> int;
fn atomic_xsub_rel(dst: &mut int, +src: int) -> int;
}
// If I call the rusti versions directly from a polymorphic function,

View File

@ -240,7 +240,7 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
}
vec::raw::form_slice(ptr::offset(p, i),
len - i, f)
len - i, f)
}
}
}

View File

@ -1723,7 +1723,7 @@ mod raw {
* not bytes).
*/
#[inline(always)]
unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(&&v: &[T]) -> U) -> U {
unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(v: &[T]) -> U) -> U {
let pair = (p, len * sys::size_of::<T>());
let v : *(&blk/[T]) =
::cast::reinterpret_cast(&ptr::addr_of(pair));

View File

@ -116,6 +116,6 @@ mod intrinsic {
extern mod rusti {
#[legacy_exports];
fn get_tydesc<T>() -> *();
fn visit_tydesc(td: *TyDesc, &&tv: TyVisitor);
fn visit_tydesc(++td: *TyDesc, &&tv: TyVisitor);
}
}

View File

@ -133,6 +133,7 @@ export type_is_numeric;
export type_is_pod;
export type_is_scalar;
export type_is_immediate;
export type_is_borrowed;
export type_is_sequence;
export type_is_signed;
export type_is_structural;
@ -1090,13 +1091,21 @@ pure fn mach_sty(cfg: @session::config, t: t) -> sty {
}
fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode {
return if ty::type_is_immediate(ty) {
ast::by_val
} else if tcx.legacy_modes || type_is_fn(ty) {
// ^^^^^^^^^^^^^^
return if type_is_fn(ty) {
// ^^^^^^^^^^^^^^
// FIXME(#2202) --- We retain by-ref by default to workaround a memory
// leak that otherwise results when @fn is upcast to &fn.
ast::by_ref
} else if tcx.legacy_modes {
if type_is_borrowed(ty) {
// the old mode default was ++ for things like &ptr, but to be
// forward-compatible with non-legacy, we should use +
ast::by_copy
} else if ty::type_is_immediate(ty) {
ast::by_val
} else {
ast::by_ref
}
} else {
ast::by_copy
};
@ -1107,6 +1116,18 @@ fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode {
_ => false
}
}
fn type_is_borrowed(ty: t) -> bool {
match ty::get(ty).sty {
ty::ty_rptr(*) => true,
ty_evec(_, vstore_slice(_)) => true,
ty_estr(vstore_slice(_)) => true,
// technically, we prob ought to include
// &fn(), but that is treated specially due to #2202
_ => false
}
}
}
// Returns the narrowest lifetime enclosing the evaluation of the expression
@ -1575,7 +1596,6 @@ fn type_is_immediate(ty: t) -> bool {
type_is_unique(ty) || type_is_region_ptr(ty);
}
fn type_needs_drop(cx: ctxt, ty: t) -> bool {
match cx.needs_drop_cache.find(ty) {
Some(result) => return result,

View File

@ -256,7 +256,14 @@ fn require_same_types(
}
}
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
match ty::resolved_mode(tcx, a.mode) {
ast::by_val => { /*ok*/ }
_ => {
return false;
}
}
match ty::get(a.ty).sty {
ty::ty_evec(mt, vstore_uniq) => {
if mt.mutbl != ast::m_imm { return false; }
@ -300,7 +307,7 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
tcx.sess.span_err(
main_span,
fmt!("Wrong type in main function: found `%s`, \
expected `extern fn(~[str]) -> ()` \
expected `extern fn(++v: ~[~str]) -> ()` \
or `extern fn() -> ()`",
ty_to_str(tcx, main_t)));
}

View File

@ -2609,10 +2609,10 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
~"atomic_xchg" | ~"atomic_xadd" | ~"atomic_xsub" |
~"atomic_xchg_acq" | ~"atomic_xadd_acq" | ~"atomic_xsub_acq" |
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => {
(0u, ~[arg(ast::by_val,
(0u, ~[arg(ast::by_copy,
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)),
ty::mk_int(tcx))),
arg(ast::by_val, ty::mk_int(tcx))],
arg(ast::by_copy, ty::mk_int(tcx))],
ty::mk_int(tcx))
}

View File

@ -142,7 +142,7 @@ fn empty_results() -> Results {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let num_keys = {
if args.len() == 2 {
uint::from_str(args[1]).get()

View File

@ -8,7 +8,7 @@ use std::map::{Map, HashMap};
use io::{Reader, ReaderUtil};
fn main(argv: ~[~str]) {
fn main(++argv: ~[~str]) {
#macro[
[#bench[id],
maybe_run_test(argv, #stringify(id), id)

View File

@ -1,4 +1,4 @@
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"10000000"]
} else if args.len() <= 1u {

View File

@ -20,7 +20,7 @@ fn collect_dvec(num: uint) -> ~[uint] {
return dvec::unwrap(move result);
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"50000000"]
} else if args.len() <= 1u {

View File

@ -384,7 +384,7 @@ fn validate(edges: ~[(node_id, node_id)],
true
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"15", ~"48"]
} else if args.len() <= 1u {

View File

@ -90,7 +90,7 @@ fn run(args: &[~str]) {
assert result == num_bytes * size;
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"1000000", ~"10000"]
} else if args.len() <= 1u {

View File

@ -87,7 +87,7 @@ fn run(args: &[~str]) {
assert result == num_bytes * size;
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"1000000", ~"8"]
} else if args.len() <= 1u {

View File

@ -56,7 +56,7 @@ fn thread_ring(i: uint,
};
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100", ~"10000"]
} else if args.len() <= 1u {

View File

@ -52,7 +52,7 @@ fn thread_ring(i: uint,
};
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100", ~"10000"]
} else if args.len() <= 1u {

View File

@ -56,7 +56,7 @@ fn thread_ring(i: uint,
};
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100", ~"10000"]
} else if args.len() <= 1u {

View File

@ -21,7 +21,7 @@ fn thread_ring(i: uint,
};
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100", ~"10000"]
} else if args.len() <= 1u {

View File

@ -57,7 +57,7 @@ fn run(args: ~[~str]) {
io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"1000000", ~"10000"]
} else if args.len() <= 1u {

View File

@ -12,7 +12,7 @@ fn ack(m: int, n: int) -> int {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"12"]
} else if args.len() <= 1u {

View File

@ -25,7 +25,7 @@ fn bottom_up_tree(arena: &r/arena::Arena,
return arena.alloc(|| nil);
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"17"]
} else if args.len() <= 1u {

View File

@ -178,7 +178,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
io::println(show_number(creatures_met));
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"200000"]
} else if args.len() <= 1u {

View File

@ -5,7 +5,7 @@ fn fannkuch(n: int) -> int {
fn perm1init(i: uint) -> int { return i as int; }
let perm = vec::to_mut(vec::from_elem(n as uint, 0));
let perm1 = vec::to_mut(vec::from_fn(n as uint, perm1init));
let perm1 = vec::to_mut(vec::from_fn(n as uint, |i| perm1init(i)));
let count = vec::to_mut(vec::from_elem(n as uint, 0));
let mut f = 0;
let mut i = 0;
@ -56,7 +56,7 @@ fn fannkuch(n: int) -> int {
return flips;
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"10"]
} else if args.len() <= 1u {

View File

@ -70,7 +70,7 @@ fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) unsa
fn acid(ch: char, prob: u32) -> aminoacids { return {ch: ch, prob: prob}; }
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
// alioth tests k-nucleotide with this data at 25,000,000
~[~"", ~"5000000"]

View File

@ -8,7 +8,7 @@ fn fib(n: int) -> int {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"40"]
} else if args.len() <= 1u {

View File

@ -128,7 +128,7 @@ fn make_sequence_processor(sz: uint, from_parent: pipes::Port<~[u8]>,
}
// given a FASTA file on stdin, process sequence THREE
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
// FIXME: Using this compile-time env variable is a crummy way to
// get to this massive data set, but #include_bin chokes on it (#2598)

View File

@ -125,7 +125,7 @@ fn make_sequence_processor(sz: uint, from_parent: comm::Port<~[u8]>,
}
// given a FASTA file on stdin, process sequence THREE
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let rdr = if os::getenv(~"RUST_BENCH").is_some() {
// FIXME: Using this compile-time env variable is a crummy way to
// get to this massive data set, but #include_bin chokes on it (#2598)

View File

@ -151,7 +151,7 @@ fn writer(path: ~str, writech: comm::Chan<comm::Chan<line>>, size: uint)
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"4000", ~"10"]
} else {

View File

@ -14,7 +14,7 @@ extern mod libc {
fn sqrt(n: float) -> float;
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"4000000"]
} else if args.len() <= 1u {

View File

@ -81,7 +81,7 @@ fn stress(num_tasks: int) {
for results.each |r| { future::get(r); }
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"20"]
} else if args.len() <= 1u {

View File

@ -40,7 +40,7 @@ fn eval_AtA_times_u(u: ~[const float], AtAu: ~[mut float]) {
eval_At_times_u(v, AtAu);
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"2000"]
} else if args.len() <= 1u {

View File

@ -37,7 +37,7 @@ fn roundtrip(id: int, p: comm::Port<int>, ch: comm::Chan<int>) {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"2000000"]
} else if args.len() <= 1u {

View File

@ -17,7 +17,7 @@ fn check_sequential(min: uint, max: uint, map: SmallIntMap<uint>) {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000", ~"100"]
} else if args.len() <= 1u {

View File

@ -126,7 +126,7 @@ fn write_grid(f: io::Writer, g: grid_t) {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let grid = if vec::len(args) == 1u {
// FIXME create sudoku inline since nested vec consts dont work yet
// (#571)

View File

@ -23,7 +23,7 @@ fn child_generation(gens_left: uint, -c: pipes::Chan<()>) {
}
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000"]
} else if args.len() <= 1u {

View File

@ -37,7 +37,7 @@ fn spawn_supervised_blocking(myname: &str, +f: fn~()) {
assert x == task::Success;
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000"]
} else if args.len() <= 1u {

View File

@ -48,7 +48,7 @@ fn calc(children: uint, parent_ch: comm::Chan<msg>) {
comm::send(parent_ch, done(sum + 1));
}
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"100000"]
} else if args.len() <= 1u {

View File

@ -8,7 +8,7 @@ fn f(&&n: uint) {
fn g() { }
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"400"]
} else if args.len() <= 1u {

View File

@ -289,7 +289,7 @@ mod map_reduce {
}
}
fn main(argv: ~[~str]) {
fn main(++argv: ~[~str]) {
if vec::len(argv) < 2u && !os::getenv(~"RUST_BENCH").is_some() {
let out = io::stdout();

View File

@ -1,3 +1,3 @@
// error-pattern:expected `extern fn(~[str])
// error-pattern:expected `extern fn(++v: ~[~str])
fn main(x: int) { }

View File

@ -18,6 +18,7 @@ fn foo(s: @int) {
}
log(debug, sys::refcount(s));
assert (sys::refcount(s) == count + 1u);
let _ = sys::refcount(s); // don't get bitten by last-use.
}
fn main() {

View File

@ -1,4 +1,4 @@
fn main(args: ~[~str]) {
fn main(++args: ~[~str]) {
let vs: ~[~str] = ~[~"hi", ~"there", ~"this", ~"is", ~"a", ~"vec"];
let vvs: ~[~[~str]] = ~[args, vs];
for vvs.each |vs| { for vs.each |s| { log(debug, *s); } }

View File

@ -1,3 +1,3 @@
fn main(args: ~[~str]) { log(debug, args[0]); }
fn main(++args: ~[~str]) { log(debug, args[0]); }

View File

@ -21,4 +21,4 @@ extern mod libc {
extern mod baz {
#[legacy_exports]; }
fn main(args: ~[~str]) { }
fn main() { }

View File

@ -6,4 +6,4 @@ mod zed {
fn bar() { debug!("bar"); }
}
fn main(args: ~[~str]) { let zed = 42; bar(); }
fn main() { let zed = 42; bar(); }

View File

@ -9,4 +9,4 @@ mod foo {
}
}
fn main(args: ~[~str]) { bar(); }
fn main() { bar(); }

View File

@ -17,4 +17,4 @@ mod bar {
#[legacy_exports]; }
}
}
fn main(args: ~[~str]) { baz(); }
fn main() { baz(); }

View File

@ -14,7 +14,7 @@ fn rendezvous() {
error!("%?", streams[0]);
}
fn main(args: ~[~str]) {
fn main() {
//os::getenv("FOO");
rendezvous();
}
}

View File

@ -1 +1 @@
fn main(args: ~[~str]) { for args.each |s| { log(debug, *s); } }
fn main(++args: ~[~str]) { for args.each |s| { log(debug, *s); } }

View File

@ -0,0 +1,20 @@
struct X {
repr: int
}
fn apply<T>(x: T, f: fn(T)) {
f(x);
}
fn check_int(x: int) {
assert x == 22;
}
fn check_struct(x: X) {
check_int(x.repr);
}
fn main() {
apply(22, check_int);
apply(X {repr: 22}, check_struct);
}

View File

@ -1,8 +1,8 @@
fn main(args: ~[~str]) {
fn main() {
let thing = ~"{{ f }}";
let f = str::find_str(thing, ~"{{");
if f.is_none() {
io::println(~"None!");
}
}
}

View File

@ -5,4 +5,4 @@ mod foo {
fn bar(offset: uint) { }
}
fn main(args: ~[~str]) { foo::bar(0u); }
fn main() { foo::bar(0u); }

View File

@ -1,4 +1,4 @@
fn swap<T>(v: ~[mut T], i: int, j: int) { v[i] <-> v[j]; }
fn swap<T>(v: &[mut T], i: int, j: int) { v[i] <-> v[j]; }
fn main() {
let a: ~[mut int] = ~[mut 0, 1, 2, 3, 4, 5, 6];

View File

@ -6,4 +6,4 @@ fn foo() {
fn baz() { zed(nil); }
}
fn main(args: ~[~str]) { }
fn main() { }

View File

@ -2,4 +2,4 @@
type lteq<T> = extern fn(T) -> bool;
fn main(args: ~[~str]) { }
fn main() { }

View File

@ -2,4 +2,4 @@ fn f(a: *int) -> *int { return a; }
fn g(a: *int) -> *int { let b = f(a); return b; }
fn main(args: ~[~str]) { return; }
fn main() { return; }