Skip to content

Commit 28f9af6

Browse files
committed
Merge branch 'master' of github.com:graydon/rust
2 parents 39b1657 + a1b215a commit 28f9af6

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

src/comp/driver/rustc.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ fn time<T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
108108
ret rv;
109109
}
110110

111+
fn inject_libcore_reference(sess: session::session,
112+
crate: @ast::crate) -> @ast::crate {
113+
114+
fn spanned<copy T>(x: T) -> @ast::spanned<T> {
115+
ret @{node: x,
116+
span: {lo: 0u, hi: 0u,
117+
expanded_from: codemap::os_none}};
118+
}
119+
120+
let n1 = sess.next_node_id();
121+
let n2 = sess.next_node_id();
122+
123+
let vi1 = spanned(ast::view_item_use("core", [], n1));
124+
let vi2 = spanned(ast::view_item_import_glob(@["core"], n2));
125+
126+
let cd1 = spanned(ast::cdir_view_item(vi1));
127+
let cd2 = spanned(ast::cdir_view_item(vi2));
128+
129+
let cdirs = [cd1, cd2] + crate.node.directives;
130+
131+
ret @{node: {directives: cdirs with crate.node} with *crate }
132+
}
133+
134+
111135
fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
112136
output: str) {
113137
let time_passes = sess.get_opts().time_passes;
@@ -126,6 +150,10 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
126150
time(time_passes, "expansion",
127151
bind syntax::ext::expand::expand_crate(sess, crate));
128152

153+
if sess.get_opts().libcore {
154+
crate = inject_libcore_reference(sess, crate);
155+
}
156+
129157
let ast_map =
130158
time(time_passes, "ast indexing",
131159
bind middle::ast_map::map_crate(*crate));
@@ -257,6 +285,7 @@ options:
257285
-o <filename> write output to <filename>
258286
--lib compile a library crate
259287
--static use or produce static libraries
288+
--no-core omit the 'core' library (used and imported by default)
260289
--pretty [type] pretty-print the input instead of compiling
261290
--ls list the symbols defined by a crate file
262291
-L <path> add a directory to the library search path
@@ -362,6 +391,7 @@ fn build_session_options(match: getopts::match)
362391
} else if opt_present(match, "emit-llvm") {
363392
link::output_type_bitcode
364393
} else { link::output_type_exe };
394+
let libcore = !opt_present(match, "no-core");
365395
let verify = !opt_present(match, "no-verify");
366396
let save_temps = opt_present(match, "save-temps");
367397
let debuginfo = opt_present(match, "g");
@@ -409,6 +439,7 @@ fn build_session_options(match: getopts::match)
409439
let sopts: @session::options =
410440
@{library: library,
411441
static: static,
442+
libcore: libcore,
412443
optimize: opt_level,
413444
debuginfo: debuginfo,
414445
verify: verify,
@@ -465,6 +496,7 @@ fn opts() -> [getopts::opt] {
465496
optflag("time-passes"), optflag("time-llvm-passes"),
466497
optflag("no-verify"),
467498
optmulti("cfg"), optflag("test"),
499+
optflag("no-core"),
468500
optflag("lib"), optflag("static"), optflag("gc"),
469501
optflag("stack-growth"),
470502
optflag("no-asm-comments"),

src/comp/driver/session.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type options =
2626
// with additional crate configurations during the compile process
2727
{library: bool,
2828
static: bool,
29+
libcore: bool,
2930
optimize: uint,
3031
debuginfo: bool,
3132
verify: bool,

src/comp/front/test.rs

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type test = {span: span, path: [ast::ident], ignore: bool, should_fail: bool};
1919
type test_ctxt =
2020
@{sess: session::session,
2121
crate: @ast::crate,
22-
next_node_id: node_id_gen,
2322
mutable path: [ast::ident],
2423
mutable testfns: [test]};
2524

@@ -28,22 +27,9 @@ type test_ctxt =
2827
fn modify_for_testing(sess: session::session,
2928
crate: @ast::crate) -> @ast::crate {
3029

31-
// FIXME: This hackasaurus assumes that 200000 is a safe number to start
32-
// generating node_ids at (which is totally not the case). pauls is going
33-
// to land a patch that puts parse_sess into session, which will give us
34-
// access to the real next node_id.
35-
let next_node_id = @mutable 200000;
36-
let next_node_id_fn =
37-
bind fn (next_node_id: @mutable ast::node_id) -> ast::node_id {
38-
let this_node_id = *next_node_id;
39-
*next_node_id += 1;
40-
ret this_node_id;
41-
}(next_node_id);
42-
4330
let cx: test_ctxt =
4431
@{sess: sess,
4532
crate: crate,
46-
next_node_id: next_node_id_fn,
4733
mutable path: [],
4834
mutable testfns: []};
4935

@@ -187,7 +173,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
187173
let item: ast::item =
188174
{ident: "__test",
189175
attrs: [],
190-
id: cx.next_node_id(),
176+
id: cx.sess.next_node_id(),
191177
node: item_,
192178
span: dummy_sp()};
193179

@@ -216,7 +202,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
216202
let test_descs = mk_test_desc_vec(cx);
217203

218204
let body_: ast::blk_ =
219-
default_block([], option::some(test_descs), cx.next_node_id());
205+
default_block([], option::some(test_descs), cx.sess.next_node_id());
220206
let body = nospan(body_);
221207

222208
let fn_ = {decl: decl, proto: proto, body: body};
@@ -225,7 +211,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
225211
let item: ast::item =
226212
{ident: "tests",
227213
attrs: [],
228-
id: cx.next_node_id(),
214+
id: cx.sess.next_node_id(),
229215
node: item_,
230216
span: dummy_sp()};
231217
ret @item;
@@ -240,15 +226,15 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
240226
idents: ["std", "test", "default_test_fn"],
241227
types: []
242228
}),
243-
cx.next_node_id()));
229+
cx.sess.next_node_id()));
244230

245231
let test_desc_ty_path =
246232
@nospan({global: false,
247233
idents: ["std", "test", "test_desc"],
248234
types: [@test_fn_ty]});
249235

250236
let test_desc_ty: ast::ty =
251-
nospan(ast::ty_path(test_desc_ty_path, cx.next_node_id()));
237+
nospan(ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()));
252238

253239
let vec_mt: ast::mt = {ty: @test_desc_ty, mut: ast::imm};
254240

@@ -263,7 +249,7 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
263249
descs += [mk_test_desc_rec(cx, test_)];
264250
}
265251

266-
ret @{id: cx.next_node_id(),
252+
ret @{id: cx.sess.next_node_id(),
267253
node: ast::expr_vec(descs, ast::imm),
268254
span: dummy_sp()};
269255
}
@@ -277,7 +263,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
277263
let name_lit: ast::lit =
278264
nospan(ast::lit_str(ast_util::path_name_i(path)));
279265
let name_expr: ast::expr =
280-
{id: cx.next_node_id(),
266+
{id: cx.sess.next_node_id(),
281267
node: ast::expr_lit(@name_lit),
282268
span: span};
283269

@@ -287,7 +273,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
287273
let fn_path = @nospan({global: false, idents: path, types: []});
288274

289275
let fn_expr: ast::expr =
290-
{id: cx.next_node_id(),
276+
{id: cx.sess.next_node_id(),
291277
node: ast::expr_path(fn_path),
292278
span: span};
293279

@@ -299,7 +285,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
299285
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
300286

301287
let ignore_expr: ast::expr =
302-
{id: cx.next_node_id(),
288+
{id: cx.sess.next_node_id(),
303289
node: ast::expr_lit(@ignore_lit),
304290
span: span};
305291

@@ -309,7 +295,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
309295
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
310296

311297
let fail_expr: ast::expr =
312-
{id: cx.next_node_id(),
298+
{id: cx.sess.next_node_id(),
313299
node: ast::expr_lit(@fail_lit),
314300
span: span};
315301

@@ -320,7 +306,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
320306
ast::expr_rec([name_field, fn_field, ignore_field, fail_field],
321307
option::none);
322308
let desc_rec: ast::expr =
323-
{id: cx.next_node_id(), node: desc_rec_, span: span};
309+
{id: cx.sess.next_node_id(), node: desc_rec_, span: span};
324310
ret @desc_rec;
325311
}
326312

@@ -330,13 +316,13 @@ fn mk_test_wrapper(cx: test_ctxt,
330316
fn_path_expr: ast::expr,
331317
span: span) -> @ast::expr {
332318
let call_expr: ast::expr = {
333-
id: cx.next_node_id(),
319+
id: cx.sess.next_node_id(),
334320
node: ast::expr_call(@fn_path_expr, [], false),
335321
span: span
336322
};
337323

338324
let call_stmt: ast::stmt = nospan(
339-
ast::stmt_expr(@call_expr, cx.next_node_id()));
325+
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
340326

341327
let wrapper_decl: ast::fn_decl = {
342328
inputs: [],
@@ -351,7 +337,7 @@ fn mk_test_wrapper(cx: test_ctxt,
351337
view_items: [],
352338
stmts: [@call_stmt],
353339
expr: option::none,
354-
id: cx.next_node_id(),
340+
id: cx.sess.next_node_id(),
355341
rules: ast::default_blk
356342
});
357343

@@ -362,7 +348,7 @@ fn mk_test_wrapper(cx: test_ctxt,
362348
};
363349

364350
let wrapper_expr: ast::expr = {
365-
id: cx.next_node_id(),
351+
id: cx.sess.next_node_id(),
366352
node: ast::expr_fn(wrapper_fn),
367353
span: span
368354
};
@@ -379,7 +365,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
379365
{mode: ast::by_val,
380366
ty: @args_ty,
381367
ident: "args",
382-
id: cx.next_node_id()};
368+
id: cx.sess.next_node_id()};
383369

384370
let ret_ty = nospan(ast::ty_nil);
385371

@@ -396,7 +382,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
396382

397383
let body_: ast::blk_ =
398384
default_block([], option::some(test_main_call_expr),
399-
cx.next_node_id());
385+
cx.sess.next_node_id());
400386
let body = {node: body_, span: dummy_sp()};
401387

402388
let fn_ = {decl: decl, proto: proto, body: body};
@@ -405,7 +391,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
405391
let item: ast::item =
406392
{ident: "main",
407393
attrs: [],
408-
id: cx.next_node_id(),
394+
id: cx.sess.next_node_id(),
409395
node: item_,
410396
span: dummy_sp()};
411397
ret @item;
@@ -420,7 +406,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
420406
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
421407

422408
let args_path_expr: ast::expr =
423-
{id: cx.next_node_id(), node: args_path_expr_, span: dummy_sp()};
409+
{id: cx.sess.next_node_id(), node: args_path_expr_, span: dummy_sp()};
424410

425411
// Call __test::test to generate the vector of test_descs
426412
let test_path =
@@ -429,12 +415,12 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
429415
let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
430416

431417
let test_path_expr: ast::expr =
432-
{id: cx.next_node_id(), node: test_path_expr_, span: dummy_sp()};
418+
{id: cx.sess.next_node_id(), node: test_path_expr_, span: dummy_sp()};
433419

434420
let test_call_expr_ = ast::expr_call(@test_path_expr, [], false);
435421

436422
let test_call_expr: ast::expr =
437-
{id: cx.next_node_id(), node: test_call_expr_, span: dummy_sp()};
423+
{id: cx.sess.next_node_id(), node: test_call_expr_, span: dummy_sp()};
438424

439425
// Call std::test::test_main
440426
let test_main_path =
@@ -445,14 +431,16 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
445431
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
446432

447433
let test_main_path_expr: ast::expr =
448-
{id: cx.next_node_id(), node: test_main_path_expr_, span: dummy_sp()};
434+
{id: cx.sess.next_node_id(), node: test_main_path_expr_,
435+
span: dummy_sp()};
449436

450437
let test_main_call_expr_: ast::expr_ =
451438
ast::expr_call(@test_main_path_expr,
452439
[@args_path_expr, @test_call_expr], false);
453440

454441
let test_main_call_expr: ast::expr =
455-
{id: cx.next_node_id(), node: test_main_call_expr_, span: dummy_sp()};
442+
{id: cx.sess.next_node_id(), node: test_main_call_expr_,
443+
span: dummy_sp()};
456444

457445
ret @test_main_call_expr;
458446
}

0 commit comments

Comments
 (0)