Skip to content

Commit

Permalink
use + mode for (almost) everything when not using legacy modes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Sep 25, 2012
1 parent 37aee97 commit 267ab11
Show file tree
Hide file tree
Showing 58 changed files with 133 additions and 68 deletions.
2 changes: 2 additions & 0 deletions src/cargo/cargo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#[no_core];
#[legacy_exports];

#[legacy_modes];

#[allow(vecs_implicitly_copyable,
non_implicitly_copyable_typarams)];
#[allow(non_camel_case_types)];
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 20 additions & 5 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/uint-template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/front/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
30 changes: 25 additions & 5 deletions src/rustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/rustc/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/rustc/middle/typeck/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-uint-to-str.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/core-vec-append.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/graph500-bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-pipes-shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-ring-mutex-arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-ring-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-ring-rw-arcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend-ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/msgsend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-ackermann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-binarytrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-chameneos-redux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/shootout-fannkuchredux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-fasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-fibo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-k-nucleotide-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-k-nucleotide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-mandelbrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-nbody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-pfib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 267ab11

Please sign in to comment.