Remove arg vectors from main functions. Stop supporting them.

This commit is contained in:
Brian Anderson 2012-10-03 19:16:27 -07:00
parent e3f458e639
commit edc317b821
45 changed files with 95 additions and 101 deletions

View File

@ -1889,7 +1889,8 @@ Commands:
set-method Change the method for a source.");
}
fn main(argv: ~[~str]) {
fn main() {
let argv = os::args();
let o = build_cargo_options(argv);
if vec::len(o.free) < 2u {

View File

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

View File

@ -19,7 +19,6 @@ if not src_dir:
run_pass = os.path.join(src_dir, "src", "test", "run-pass")
run_pass = os.path.abspath(run_pass)
stage2_tests = []
take_args = {}
for t in os.listdir(run_pass):
if t.endswith(".rs") and not (
@ -30,8 +29,6 @@ for t in os.listdir(run_pass):
"xfail-fast" in s or
"xfail-win32" in s):
stage2_tests.append(t)
if "fn main(args:" in s or "fn main(++args:" in s:
take_args[t] = True
f.close()
stage2_tests.sort()
@ -64,9 +61,6 @@ for t in stage2_tests:
p = os.path.join("test", "run-pass", t)
p = p.replace("\\", "\\\\")
d.write(" out.write_str(~\"run-pass [stage2]: %s\\n\");\n" % p)
if t in take_args:
d.write(" t_%d::main(~[~\"arg0\"]);\n" % i)
else:
d.write(" t_%d::main();\n" % i)
d.write(" t_%d::main();\n" % i)
i += 1
d.write("}\n")

View File

@ -599,7 +599,8 @@ fn check_variants(files: &[Path], cx: context) {
}
}
fn main(args: ~[~str]) {
fn main() {
let args = os::args();
if vec::len(args) != 2u {
error!("usage: %s <testdir>", args[0]);
return;

View File

@ -277,7 +277,8 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
}
}
fn main(args: ~[~str]) {
fn main() {
let args = os::args();
do monitor |demitter| {
run_compiler(args, demitter);
}

View File

@ -415,34 +415,12 @@ fn mk_test_wrapper(cx: test_ctxt,
}
fn mk_main(cx: test_ctxt) -> @ast::item {
let str_pt = path_node(~[cx.sess.ident_of(~"str")]);
let str_ty_inner = @{id: cx.sess.next_node_id(),
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
span: dummy_sp()};
let str_ty = @{id: cx.sess.next_node_id(),
node: ast::ty_uniq({ty: str_ty_inner, mutbl: ast::m_imm}),
span: dummy_sp()};
let args_mt = {ty: str_ty, mutbl: ast::m_imm};
let args_ty_inner = @{id: cx.sess.next_node_id(),
node: ast::ty_vec(args_mt),
span: dummy_sp()};
let args_ty = {id: cx.sess.next_node_id(),
node: ast::ty_uniq({ty: args_ty_inner, mutbl: ast::m_imm}),
span: dummy_sp()};
let args_arg: ast::arg =
{mode: ast::expl(ast::by_val),
ty: @args_ty,
ident: cx.sess.ident_of(~"args"),
id: cx.sess.next_node_id()};
let ret_ty = {id: cx.sess.next_node_id(),
node: ast::ty_nil,
span: dummy_sp()};
let decl: ast::fn_decl =
{inputs: ~[args_arg],
{inputs: ~[],
output: @ret_ty,
cf: ast::return_val};
@ -465,9 +443,11 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
}
fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
// Get the args passed to main so we can pass the to test_main
let args_path = path_node(~[cx.sess.ident_of(~"args")]);
// Call os::args to generate the vector of test_descs
let args_path = path_node(~[
cx.sess.ident_of(~"os"),
cx.sess.ident_of(~"args")
]);
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
@ -475,6 +455,12 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
node: args_path_expr_, span: dummy_sp()};
let args_call_expr_ = ast::expr_call(@args_path_expr, ~[], false);
let args_call_expr: ast::expr =
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
node: args_call_expr_, span: dummy_sp()};
// Call __test::test to generate the vector of test_descs
let test_path = path_node(~[cx.sess.ident_of(~"tests")]);
@ -503,7 +489,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
let test_main_call_expr_: ast::expr_ =
ast::expr_call(@test_main_path_expr,
~[@args_path_expr, @test_call_expr], false);
~[@args_call_expr, @test_call_expr], false);
let test_main_call_expr: ast::expr =
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),

View File

@ -1953,32 +1953,23 @@ fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path,
ast_map::path_to_str(path, ccx.sess.parse_sess.interner));
let is_main = is_main_name(path) && !ccx.sess.building_library;
if is_main { create_main_wrapper(ccx, sp, llfn, node_type); }
if is_main { create_main_wrapper(ccx, sp, llfn); }
llfn
}
// Create a _rust_main(args: ~[str]) function which will be called from the
// runtime rust_start function
fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
main_node_type: ty::t) {
fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef) {
if ccx.main_fn != None::<ValueRef> {
ccx.sess.span_fatal(sp, ~"multiple 'main' functions");
}
let main_takes_argv =
// invariant!
match ty::get(main_node_type).sty {
ty::ty_fn(ref fn_ty) => fn_ty.sig.inputs.len() != 0u,
_ => ccx.sess.span_fatal(sp, ~"main has a non-function type")
};
let llfn = create_main(ccx, main_llfn, main_takes_argv);
let llfn = create_main(ccx, main_llfn);
ccx.main_fn = Some(llfn);
create_entry_fn(ccx, llfn);
fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef,
takes_argv: bool) -> ValueRef {
fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef) -> ValueRef {
let unit_ty = ty::mk_estr(ccx.tcx, ty::vstore_uniq);
let vecarg_ty: ty::arg =
{mode: ast::expl(ast::by_val),
@ -1998,9 +1989,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint);
let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint);
let mut args = ~[lloutputarg, llenvarg];
if takes_argv {
args.push(llvm::LLVMGetParam(llfdecl, 2 as c_uint));
}
Call(bcx, main_llfn, args);
build_return(bcx);

View File

@ -301,14 +301,12 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
}
let mut ok = ty::type_is_nil(fn_ty.sig.output);
let num_args = vec::len(fn_ty.sig.inputs);
ok &= num_args == 0u || num_args == 1u &&
arg_is_argv_ty(tcx, fn_ty.sig.inputs[0]);
ok &= num_args == 0u;
if !ok {
tcx.sess.span_err(
main_span,
fmt!("Wrong type in main function: found `%s`, \
expected `extern fn(++v: ~[~str]) -> ()` \
or `extern fn() -> ()`",
expected `fn() -> ()`",
ty_to_str(tcx, main_t)));
}
}

View File

@ -3,7 +3,8 @@ use doc::Item;
use pass::Pass;
use config::Config;
fn main(args: ~[~str]) {
fn main() {
let args = os::args();
if args.contains(&~"-h") || args.contains(&~"--help") {
config::usage();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -288,7 +288,8 @@ mod map_reduce {
}
}
fn main(++argv: ~[~str]) {
fn main() {
let argv = os::args();
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(++v: ~[~str])
// error-pattern:expected `fn()
fn main(x: int) { }

View File

@ -1,5 +0,0 @@
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 +0,0 @@
fn main(++args: ~[~str]) { log(debug, args[0]); }

View File

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