Skip to content

Commit edc317b

Browse files
committed
Remove arg vectors from main functions. Stop supporting them.
1 parent e3f458e commit edc317b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+95
-101
lines changed

src/cargo/cargo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,8 @@ Commands:
18891889
set-method Change the method for a source.");
18901890
}
18911891

1892-
fn main(argv: ~[~str]) {
1892+
fn main() {
1893+
let argv = os::args();
18931894
let o = build_cargo_options(argv);
18941895

18951896
if vec::len(o.free) < 2u {

src/compiletest/compiletest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use common::mode_pretty;
1212
use common::mode;
1313
use util::logv;
1414

15-
fn main(++args: ~[~str]) {
15+
fn main() {
16+
let args = os::args();
1617
let config = parse_config(args);
1718
log_config(config);
1819
run_tests(config);

src/etc/combine-tests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def scrub(b):
1919
run_pass = os.path.join(src_dir, "src", "test", "run-pass")
2020
run_pass = os.path.abspath(run_pass)
2121
stage2_tests = []
22-
take_args = {}
2322

2423
for t in os.listdir(run_pass):
2524
if t.endswith(".rs") and not (
@@ -30,8 +29,6 @@ def scrub(b):
3029
"xfail-fast" in s or
3130
"xfail-win32" in s):
3231
stage2_tests.append(t)
33-
if "fn main(args:" in s or "fn main(++args:" in s:
34-
take_args[t] = True
3532
f.close()
3633

3734
stage2_tests.sort()
@@ -64,9 +61,6 @@ def scrub(b):
6461
p = os.path.join("test", "run-pass", t)
6562
p = p.replace("\\", "\\\\")
6663
d.write(" out.write_str(~\"run-pass [stage2]: %s\\n\");\n" % p)
67-
if t in take_args:
68-
d.write(" t_%d::main(~[~\"arg0\"]);\n" % i)
69-
else:
70-
d.write(" t_%d::main();\n" % i)
64+
d.write(" t_%d::main();\n" % i)
7165
i += 1
7266
d.write("}\n")

src/fuzzer/fuzzer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ fn check_variants(files: &[Path], cx: context) {
599599
}
600600
}
601601

602-
fn main(args: ~[~str]) {
602+
fn main() {
603+
let args = os::args();
603604
if vec::len(args) != 2u {
604605
error!("usage: %s <testdir>", args[0]);
605606
return;

src/rustc/driver/rustc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ fn monitor(+f: fn~(diagnostic::emitter)) {
277277
}
278278
}
279279

280-
fn main(args: ~[~str]) {
280+
fn main() {
281+
let args = os::args();
281282
do monitor |demitter| {
282283
run_compiler(args, demitter);
283284
}

src/rustc/front/test.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -415,34 +415,12 @@ fn mk_test_wrapper(cx: test_ctxt,
415415
}
416416

417417
fn mk_main(cx: test_ctxt) -> @ast::item {
418-
let str_pt = path_node(~[cx.sess.ident_of(~"str")]);
419-
let str_ty_inner = @{id: cx.sess.next_node_id(),
420-
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
421-
span: dummy_sp()};
422-
let str_ty = @{id: cx.sess.next_node_id(),
423-
node: ast::ty_uniq({ty: str_ty_inner, mutbl: ast::m_imm}),
424-
span: dummy_sp()};
425-
let args_mt = {ty: str_ty, mutbl: ast::m_imm};
426-
let args_ty_inner = @{id: cx.sess.next_node_id(),
427-
node: ast::ty_vec(args_mt),
428-
span: dummy_sp()};
429-
let args_ty = {id: cx.sess.next_node_id(),
430-
node: ast::ty_uniq({ty: args_ty_inner, mutbl: ast::m_imm}),
431-
span: dummy_sp()};
432-
433-
434-
let args_arg: ast::arg =
435-
{mode: ast::expl(ast::by_val),
436-
ty: @args_ty,
437-
ident: cx.sess.ident_of(~"args"),
438-
id: cx.sess.next_node_id()};
439-
440418
let ret_ty = {id: cx.sess.next_node_id(),
441419
node: ast::ty_nil,
442420
span: dummy_sp()};
443421

444422
let decl: ast::fn_decl =
445-
{inputs: ~[args_arg],
423+
{inputs: ~[],
446424
output: @ret_ty,
447425
cf: ast::return_val};
448426

@@ -465,16 +443,24 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
465443
}
466444

467445
fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
468-
469-
// Get the args passed to main so we can pass the to test_main
470-
let args_path = path_node(~[cx.sess.ident_of(~"args")]);
446+
// Call os::args to generate the vector of test_descs
447+
let args_path = path_node(~[
448+
cx.sess.ident_of(~"os"),
449+
cx.sess.ident_of(~"args")
450+
]);
471451

472452
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
473453

474454
let args_path_expr: ast::expr =
475455
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
476456
node: args_path_expr_, span: dummy_sp()};
477457

458+
let args_call_expr_ = ast::expr_call(@args_path_expr, ~[], false);
459+
460+
let args_call_expr: ast::expr =
461+
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
462+
node: args_call_expr_, span: dummy_sp()};
463+
478464
// Call __test::test to generate the vector of test_descs
479465
let test_path = path_node(~[cx.sess.ident_of(~"tests")]);
480466

@@ -503,7 +489,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
503489

504490
let test_main_call_expr_: ast::expr_ =
505491
ast::expr_call(@test_main_path_expr,
506-
~[@args_path_expr, @test_call_expr], false);
492+
~[@args_call_expr, @test_call_expr], false);
507493

508494
let test_main_call_expr: ast::expr =
509495
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),

src/rustc/middle/trans/base.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,32 +1953,23 @@ fn register_fn_fuller(ccx: @crate_ctxt, sp: span, path: path,
19531953
ast_map::path_to_str(path, ccx.sess.parse_sess.interner));
19541954

19551955
let is_main = is_main_name(path) && !ccx.sess.building_library;
1956-
if is_main { create_main_wrapper(ccx, sp, llfn, node_type); }
1956+
if is_main { create_main_wrapper(ccx, sp, llfn); }
19571957
llfn
19581958
}
19591959

19601960
// Create a _rust_main(args: ~[str]) function which will be called from the
19611961
// runtime rust_start function
1962-
fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
1963-
main_node_type: ty::t) {
1962+
fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef) {
19641963

19651964
if ccx.main_fn != None::<ValueRef> {
19661965
ccx.sess.span_fatal(sp, ~"multiple 'main' functions");
19671966
}
19681967

1969-
let main_takes_argv =
1970-
// invariant!
1971-
match ty::get(main_node_type).sty {
1972-
ty::ty_fn(ref fn_ty) => fn_ty.sig.inputs.len() != 0u,
1973-
_ => ccx.sess.span_fatal(sp, ~"main has a non-function type")
1974-
};
1975-
1976-
let llfn = create_main(ccx, main_llfn, main_takes_argv);
1968+
let llfn = create_main(ccx, main_llfn);
19771969
ccx.main_fn = Some(llfn);
19781970
create_entry_fn(ccx, llfn);
19791971

1980-
fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef,
1981-
takes_argv: bool) -> ValueRef {
1972+
fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef) -> ValueRef {
19821973
let unit_ty = ty::mk_estr(ccx.tcx, ty::vstore_uniq);
19831974
let vecarg_ty: ty::arg =
19841975
{mode: ast::expl(ast::by_val),
@@ -1998,9 +1989,6 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
19981989
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0 as c_uint);
19991990
let llenvarg = llvm::LLVMGetParam(llfdecl, 1 as c_uint);
20001991
let mut args = ~[lloutputarg, llenvarg];
2001-
if takes_argv {
2002-
args.push(llvm::LLVMGetParam(llfdecl, 2 as c_uint));
2003-
}
20041992
Call(bcx, main_llfn, args);
20051993

20061994
build_return(bcx);

src/rustc/middle/typeck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,12 @@ fn check_main_fn_ty(ccx: @crate_ctxt,
301301
}
302302
let mut ok = ty::type_is_nil(fn_ty.sig.output);
303303
let num_args = vec::len(fn_ty.sig.inputs);
304-
ok &= num_args == 0u || num_args == 1u &&
305-
arg_is_argv_ty(tcx, fn_ty.sig.inputs[0]);
304+
ok &= num_args == 0u;
306305
if !ok {
307306
tcx.sess.span_err(
308307
main_span,
309308
fmt!("Wrong type in main function: found `%s`, \
310-
expected `extern fn(++v: ~[~str]) -> ()` \
311-
or `extern fn() -> ()`",
309+
expected `fn() -> ()`",
312310
ty_to_str(tcx, main_t)));
313311
}
314312
}

src/rustdoc/rustdoc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use doc::Item;
33
use pass::Pass;
44
use config::Config;
55

6-
fn main(args: ~[~str]) {
6+
fn main() {
7+
let args = os::args();
78

89
if args.contains(&~"-h") || args.contains(&~"--help") {
910
config::usage();

src/test/bench/core-map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ fn empty_results() -> Results {
142142
}
143143
}
144144

145-
fn main(++args: ~[~str]) {
145+
fn main() {
146+
let args = os::args();
146147
let num_keys = {
147148
if args.len() == 2 {
148149
uint::from_str(args[1]).get()

src/test/bench/core-std.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::map::{Map, HashMap};
88

99
use io::{Reader, ReaderUtil};
1010

11-
fn main(++argv: ~[~str]) {
11+
fn main() {
12+
let argv = os::args();
1213
#macro[
1314
[#bench[id],
1415
maybe_run_test(argv, #stringify(id), id)

src/test/bench/core-uint-to-str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
fn main(++args: ~[~str]) {
1+
fn main() {
2+
let args = os::args();
23
let args = if os::getenv(~"RUST_BENCH").is_some() {
34
~[~"", ~"10000000"]
45
} else if args.len() <= 1u {

src/test/bench/core-vec-append.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ fn collect_dvec(num: uint) -> ~[uint] {
2020
return dvec::unwrap(move result);
2121
}
2222

23-
fn main(++args: ~[~str]) {
23+
fn main() {
24+
let args = os::args();
2425
let args = if os::getenv(~"RUST_BENCH").is_some() {
2526
~[~"", ~"50000000"]
2627
} else if args.len() <= 1u {

src/test/bench/graph500-bfs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ fn validate(edges: ~[(node_id, node_id)],
384384
true
385385
}
386386
387-
fn main(++args: ~[~str]) {
387+
fn main() {
388+
let args = os::args();
388389
let args = if os::getenv(~"RUST_BENCH").is_some() {
389390
~[~"", ~"15", ~"48"]
390391
} else if args.len() <= 1u {

src/test/bench/msgsend-pipes-shared.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ fn run(args: &[~str]) {
9090
assert result == num_bytes * size;
9191
}
9292

93-
fn main(++args: ~[~str]) {
93+
fn main() {
94+
let args = os::args();
9495
let args = if os::getenv(~"RUST_BENCH").is_some() {
9596
~[~"", ~"1000000", ~"10000"]
9697
} else if args.len() <= 1u {

src/test/bench/msgsend-pipes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ fn run(args: &[~str]) {
8787
assert result == num_bytes * size;
8888
}
8989

90-
fn main(++args: ~[~str]) {
90+
fn main() {
91+
let args = os::args();
9192
let args = if os::getenv(~"RUST_BENCH").is_some() {
9293
~[~"", ~"1000000", ~"8"]
9394
} else if args.len() <= 1u {

src/test/bench/msgsend-ring-mutex-arcs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fn thread_ring(i: uint,
5656
};
5757
}
5858

59-
fn main(++args: ~[~str]) {
59+
fn main() {
60+
let args = os::args();
6061
let args = if os::getenv(~"RUST_BENCH").is_some() {
6162
~[~"", ~"100", ~"10000"]
6263
} else if args.len() <= 1u {

src/test/bench/msgsend-ring-pipes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ fn thread_ring(i: uint,
5252
};
5353
}
5454

55-
fn main(++args: ~[~str]) {
55+
fn main() {
56+
let args = os::args();
5657
let args = if os::getenv(~"RUST_BENCH").is_some() {
5758
~[~"", ~"100", ~"10000"]
5859
} else if args.len() <= 1u {

src/test/bench/msgsend-ring-rw-arcs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fn thread_ring(i: uint,
5656
};
5757
}
5858

59-
fn main(++args: ~[~str]) {
59+
fn main() {
60+
let args = os::args();
6061
let args = if os::getenv(~"RUST_BENCH").is_some() {
6162
~[~"", ~"100", ~"10000"]
6263
} else if args.len() <= 1u {

src/test/bench/msgsend-ring.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ fn thread_ring(i: uint,
2121
};
2222
}
2323

24-
fn main(++args: ~[~str]) {
24+
fn main() {
25+
let args = os::args();
2526
let args = if os::getenv(~"RUST_BENCH").is_some() {
2627
~[~"", ~"100", ~"10000"]
2728
} else if args.len() <= 1u {

src/test/bench/msgsend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ fn run(args: ~[~str]) {
5757
io::stdout().write_str(fmt!("Throughput=%f per sec\n", thruput));
5858
}
5959

60-
fn main(++args: ~[~str]) {
60+
fn main() {
61+
let args = os::args();
6162
let args = if os::getenv(~"RUST_BENCH").is_some() {
6263
~[~"", ~"1000000", ~"10000"]
6364
} else if args.len() <= 1u {

src/test/bench/shootout-ackermann.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn ack(m: int, n: int) -> int {
1212
}
1313
}
1414

15-
fn main(++args: ~[~str]) {
15+
fn main() {
16+
let args = os::args();
1617
let args = if os::getenv(~"RUST_BENCH").is_some() {
1718
~[~"", ~"12"]
1819
} else if args.len() <= 1u {

src/test/bench/shootout-binarytrees.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn bottom_up_tree(arena: &r/arena::Arena,
2525
return arena.alloc(|| nil);
2626
}
2727

28-
fn main(++args: ~[~str]) {
28+
fn main() {
29+
let args = os::args();
2930
let args = if os::getenv(~"RUST_BENCH").is_some() {
3031
~[~"", ~"17"]
3132
} else if args.len() <= 1u {

src/test/bench/shootout-chameneos-redux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ fn rendezvous(nn: uint, set: ~[color]) {
178178
io::println(show_number(creatures_met));
179179
}
180180
181-
fn main(++args: ~[~str]) {
181+
fn main() {
182+
let args = os::args();
182183
let args = if os::getenv(~"RUST_BENCH").is_some() {
183184
~[~"", ~"200000"]
184185
} else if args.len() <= 1u {

src/test/bench/shootout-fannkuchredux.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ fn fannkuch(n: int) -> int {
5656
return flips;
5757
}
5858

59-
fn main(++args: ~[~str]) {
59+
fn main() {
60+
let args = os::args();
6061
let args = if os::getenv(~"RUST_BENCH").is_some() {
6162
~[~"", ~"10"]
6263
} else if args.len() <= 1u {

src/test/bench/shootout-fasta.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ fn make_repeat_fasta(wr: io::Writer, id: ~str, desc: ~str, s: ~str, n: int) unsa
7070

7171
fn acid(ch: char, prob: u32) -> aminoacids { return {ch: ch, prob: prob}; }
7272

73-
fn main(++args: ~[~str]) {
73+
fn main() {
74+
let args = os::args();
7475
let args = if os::getenv(~"RUST_BENCH").is_some() {
7576
// alioth tests k-nucleotide with this data at 25,000,000
7677
~[~"", ~"5000000"]

src/test/bench/shootout-fibo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ fn fib(n: int) -> int {
88
}
99
}
1010

11-
fn main(++args: ~[~str]) {
11+
fn main() {
12+
let args = os::args();
1213
let args = if os::getenv(~"RUST_BENCH").is_some() {
1314
~[~"", ~"40"]
1415
} else if args.len() <= 1u {

0 commit comments

Comments
 (0)