Skip to content

Conditionally enable debug! with --cfg debug #7822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub fn compile_rest(sess: Session,
// mod bar { macro_rules! baz!(() => {{}}) }
//
// baz! should not use this definition unless foo is enabled.
crate = time(time_passes, ~"std macros injection", ||
syntax::ext::expand::inject_std_macros(sess.parse_sess, copy cfg,
crate));

crate = time(time_passes, ~"configuration 1", ||
front::config::strip_unconfigured_items(crate));

Expand All @@ -214,7 +218,7 @@ pub fn compile_rest(sess: Session,
assert!(phases.from != cu_no_trans);

let (llcx, llmod, link_meta) = {
crate = time(time_passes, ~"extra injection", ||
crate = time(time_passes, ~"std injection", ||
front::std_inject::maybe_inject_libstd_ref(sess, crate));

let ast_map = time(time_passes, ~"ast indexing", ||
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ pub fn alloca_maybe_zeroed(cx: block, ty: Type, name: &str, zero: bool) -> Value
let _icx = push_ctxt("alloca");
if cx.unreachable {
unsafe {
return llvm::LLVMGetUndef(ty.to_ref());
return llvm::LLVMGetUndef(ty.ptr_to().to_ref());
}
}
let initcx = base::raw_block(cx.fcx, false, cx.fcx.get_llstaticallocas());
Expand Down
20 changes: 11 additions & 9 deletions src/librustc/middle/trans/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,17 @@ pub fn LoadRangeAssert(cx: block, PointerVal: ValueRef, lo: c_ulonglong,
hi: c_ulonglong, signed: lib::llvm::Bool) -> ValueRef {
let value = Load(cx, PointerVal);

unsafe {
let t = llvm::LLVMGetElementType(llvm::LLVMTypeOf(PointerVal));
let min = llvm::LLVMConstInt(t, lo, signed);
let max = llvm::LLVMConstInt(t, hi, signed);

do [min, max].as_imm_buf |ptr, len| {
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
ptr, len as c_uint));
if !cx.unreachable {
unsafe {
let t = llvm::LLVMGetElementType(llvm::LLVMTypeOf(PointerVal));
let min = llvm::LLVMConstInt(t, lo, signed);
let max = llvm::LLVMConstInt(t, hi, signed);

do [min, max].as_imm_buf |ptr, len| {
llvm::LLVMSetMetadata(value, lib::llvm::MD_range as c_uint,
llvm::LLVMMDNodeInContext(cx.fcx.ccx.llcx,
ptr, len as c_uint));
}
}
}

Expand Down
72 changes: 55 additions & 17 deletions src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ pub fn trans_if(bcx: block,
let _indenter = indenter();

let _icx = push_ctxt("trans_if");

match cond.node {
// `if true` and `if false` can be trans'd more efficiently,
// by dropping branches that are known to be impossible.
ast::expr_lit(@ref l) => match l.node {
ast::lit_bool(true) => {
// if true { .. } [else { .. }]
let then_bcx_in = scope_block(bcx, thn.info(), "if_true_then");
let then_bcx_out = trans_block(then_bcx_in, thn, dest);
let then_bcx_out = trans_block_cleanups(then_bcx_out,
block_cleanups(then_bcx_in));
Br(bcx, then_bcx_in.llbb);
return then_bcx_out;
}
ast::lit_bool(false) => {
match els {
// if false { .. } else { .. }
Some(elexpr) => {
let (else_bcx_in, else_bcx_out) =
trans_if_else(bcx, elexpr, dest, "if_false_else");
Br(bcx, else_bcx_in.llbb);
return else_bcx_out;
}
// if false { .. }
None => return bcx,
}
}
_ => {}
},
_ => {}
}

let Result {bcx, val: cond_val} =
expr::trans_to_datum(bcx, cond).to_result();

Expand All @@ -80,22 +112,8 @@ pub fn trans_if(bcx: block,
// 'else' context
let (else_bcx_in, next_bcx) = match els {
Some(elexpr) => {
let else_bcx_in = scope_block(bcx, els.info(), "else");
let else_bcx_out = match elexpr.node {
ast::expr_if(_, _, _) => {
let elseif_blk = ast_util::block_from_expr(elexpr);
trans_block(else_bcx_in, &elseif_blk, dest)
}
ast::expr_block(ref blk) => {
trans_block(else_bcx_in, blk, dest)
}
// would be nice to have a constraint on ifs
_ => bcx.tcx().sess.bug("strange alternative in if")
};
let else_bcx_out = trans_block_cleanups(else_bcx_out,
block_cleanups(else_bcx_in));

(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
let (else_bcx_in, else_bcx_out) = trans_if_else(bcx, elexpr, dest, "else");
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
}
_ => {
let next_bcx = sub_block(bcx, "next");
Expand All @@ -109,7 +127,27 @@ pub fn trans_if(bcx: block,
then_bcx_in.to_str(), else_bcx_in.to_str());

CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
next_bcx
return next_bcx;

// trans `else [ if { .. } ... | { .. } ]`
fn trans_if_else(bcx: block, elexpr: @ast::expr,
dest: expr::Dest, scope_name: &str) -> (block, block) {
let else_bcx_in = scope_block(bcx, elexpr.info(), scope_name);
let else_bcx_out = match elexpr.node {
ast::expr_if(_, _, _) => {
let elseif_blk = ast_util::block_from_expr(elexpr);
trans_block(else_bcx_in, &elseif_blk, dest)
}
ast::expr_block(ref blk) => {
trans_block(else_bcx_in, blk, dest)
}
// would be nice to have a constraint on ifs
_ => bcx.tcx().sess.bug("strange alternative in if")
};
let else_bcx_out = trans_block_cleanups(else_bcx_out,
block_cleanups(else_bcx_in));
(else_bcx_in, else_bcx_out)
}
}

pub fn join_blocks(parent_bcx: block, in_cxs: &[block]) -> block {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl Datum {
pub fn to_value_datum(&self, bcx: block) -> Datum {
/*!
*
* Yields a by-ref form of this datum. This may involve
* Yields a by-value form of this datum. This may involve
* creation of a temporary stack slot. The value returned by
* this function is not separately rooted from this datum, so
* it will not live longer than the current datum. */
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/astsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ fn build_ctxt(sess: Session,

use rustc::front::config;

let ast = syntax::ext::expand::inject_std_macros(sess.parse_sess,
copy sess.opts.cfg, ast);
let ast = config::strip_unconfigured_items(ast);
let ast = syntax::ext::expand::expand_crate(sess.parse_sess,
copy sess.opts.cfg, ast);
Expand All @@ -138,7 +140,8 @@ fn should_prune_unconfigured_items() {
let source = ~"#[cfg(shut_up_and_leave_me_alone)]fn a() { }";
do from_str(source) |srv| {
do exec(srv) |ctxt| {
assert!(ctxt.ast.node.module.items.is_empty());
// one item: the __std_macros secret module
assert_eq!(ctxt.ast.node.module.items.len(), 1);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/attr_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ mod test {
#[test]
fn should_should_extract_mod_attributes() {
let doc = mk_doc(~"#[doc = \"test\"] mod a { }");
assert!(doc.cratemod().mods()[0].desc() == Some(~"test"));
// hidden __std_macros module at the start.
assert!(doc.cratemod().mods()[1].desc() == Some(~"test"));
}

#[test]
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/desc_to_brief_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ mod test {
#[test]
fn should_promote_desc() {
let doc = mk_doc(~"#[doc = \"desc\"] mod m { }");
assert_eq!(doc.cratemod().mods()[0].brief(), Some(~"desc"));
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().mods()[1].brief(), Some(~"desc"));
}

#[test]
Expand Down
25 changes: 14 additions & 11 deletions src/librustdoc/markdown_index_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ mod test {
use extract;
use markdown_index_pass::run;
use path_pass;
use prune_hidden_pass;
use super::pandoc_header_id;

fn mk_doc(output_style: config::OutputStyle, source: ~str)
Expand All @@ -183,8 +184,10 @@ mod test {
};
let doc = extract::from_srv(srv.clone(), ~"");
let doc = (attr_pass::mk_pass().f)(srv.clone(), doc);
let doc = (prune_hidden_pass::mk_pass().f)(srv.clone(), doc);
let doc = (desc_to_brief_pass::mk_pass().f)(srv.clone(), doc);
let doc = (path_pass::mk_pass().f)(srv.clone(), doc);

run(srv.clone(), doc, config)
}
}
Expand Down Expand Up @@ -240,13 +243,13 @@ mod test {
config::DocPerMod,
~"mod a { } fn b() { }"
);
assert!(doc.cratemod().index.get().entries[0] == doc::IndexEntry {
assert_eq!(doc.cratemod().index.get().entries[0], doc::IndexEntry {
kind: ~"Module",
name: ~"a",
brief: None,
link: ~"a.html"
});
assert!(doc.cratemod().index.get().entries[1] == doc::IndexEntry {
assert_eq!(doc.cratemod().index.get().entries[1], doc::IndexEntry {
kind: ~"Function",
name: ~"b",
brief: None,
Expand All @@ -260,8 +263,7 @@ mod test {
config::DocPerMod,
~"#[doc = \"test\"] mod a { }"
);
assert!(doc.cratemod().index.get().entries[0].brief
== Some(~"test"));
assert_eq!(doc.cratemod().index.get().entries[0].brief, Some(~"test"));
}

#[test]
Expand All @@ -270,12 +272,13 @@ mod test {
config::DocPerCrate,
~"extern { fn b(); }"
);
assert!(doc.cratemod().nmods()[0].index.get().entries[0]
== doc::IndexEntry {
kind: ~"Function",
name: ~"b",
brief: None,
link: ~"#function-b"
});
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().nmods()[0].index.get().entries[0],
doc::IndexEntry {
kind: ~"Function",
name: ~"b",
brief: None,
link: ~"#function-b"
});
}
}
3 changes: 3 additions & 0 deletions src/librustdoc/markdown_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ mod test {
use markdown_writer;
use path_pass;
use page_pass;
use prune_hidden_pass;
use sectionalize_pass;
use trim_pass;
use tystr_pass;
Expand Down Expand Up @@ -557,6 +558,8 @@ mod test {
debug!("doc (path): %?", doc);
let doc = (attr_pass::mk_pass().f)(srv.clone(), doc);
debug!("doc (attr): %?", doc);
let doc = (prune_hidden_pass::mk_pass().f)(srv.clone(), doc);
debug!("doc (prune_hidden): %?", doc);
let doc = (desc_to_brief_pass::mk_pass().f)(srv.clone(), doc);
debug!("doc (desc_to_brief): %?", doc);
let doc = (unindent_pass::mk_pass().f)(srv.clone(), doc);
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ mod test {
.. config::default_config(&Path("input/test.rc"))
};
let doc = mk_doc(~"", ~"mod a { mod b { } }");
let modb = copy doc.cratemod().mods()[0].mods()[0];
// hidden __std_macros module at the start.
let modb = copy doc.cratemod().mods()[1].mods()[0];
let page = doc::ItemPage(doc::ModTag(modb));
let filename = make_local_filename(&config, page);
assert_eq!(filename, Path("output/dir/a_b.html"));
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/page_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ fn fold_nmod(
mod test {
use astsrv;
use config;
use attr_pass;
use doc;
use extract;
use prune_hidden_pass;
use page_pass::run;

fn mk_doc_(
Expand All @@ -162,6 +164,8 @@ mod test {
) -> doc::Doc {
do astsrv::from_str(copy source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = (attr_pass::mk_pass().f)(srv.clone(), doc);
let doc = (prune_hidden_pass::mk_pass().f)(srv.clone(), doc);
run(srv.clone(), doc, output_style)
}
}
Expand All @@ -182,6 +186,7 @@ mod test {
#[test]
fn should_make_a_page_for_every_mod() {
let doc = mk_doc(~"mod a { }");
// hidden __std_macros module at the start.
assert_eq!(doc.pages.mods()[0].name(), ~"a");
}

Expand Down
12 changes: 7 additions & 5 deletions src/librustdoc/path_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ fn should_record_mod_paths() {
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = run(srv.clone(), doc);
assert!(doc.cratemod().mods()[0].mods()[0].mods()[0].path()
== ~[~"a", ~"b"]);
assert!(doc.cratemod().mods()[0].mods()[1].mods()[0].path()
== ~[~"a", ~"d"]);
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().mods()[1].mods()[0].mods()[0].path(),
~[~"a", ~"b"]);
assert_eq!(doc.cratemod().mods()[1].mods()[1].mods()[0].path(),
~[~"a", ~"d"]);
}
}

Expand All @@ -110,6 +111,7 @@ fn should_record_fn_paths() {
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = run(srv.clone(), doc);
assert_eq!(doc.cratemod().mods()[0].fns()[0].path(), ~[~"a"]);
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().mods()[1].fns()[0].path(), ~[~"a"]);
}
}
2 changes: 2 additions & 0 deletions src/librustdoc/sectionalize_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ mod test {
use attr_pass;
use doc;
use extract;
use prune_hidden_pass;
use sectionalize_pass::run;

fn mk_doc(source: ~str) -> doc::Doc {
do astsrv::from_str(copy source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = (attr_pass::mk_pass().f)(srv.clone(), doc);
let doc = (prune_hidden_pass::mk_pass().f)(srv.clone(), doc);
run(srv.clone(), doc)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/sort_item_name_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fn test() {
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = (mk_pass().f)(srv.clone(), doc);
assert_eq!(doc.cratemod().items[0].name(), ~"y");
assert_eq!(doc.cratemod().items[1].name(), ~"z");
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().items[1].name(), ~"y");
assert_eq!(doc.cratemod().items[2].name(), ~"z");
}
}
4 changes: 3 additions & 1 deletion src/librustdoc/sort_item_type_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ fn test() {
do astsrv::from_str(source) |srv| {
let doc = extract::from_srv(srv.clone(), ~"");
let doc = (mk_pass().f)(srv.clone(), doc);
// hidden __std_macros module at the start.
assert_eq!(doc.cratemod().items[0].name(), ~"iconst");
assert_eq!(doc.cratemod().items[1].name(), ~"itype");
assert_eq!(doc.cratemod().items[2].name(), ~"ienum");
assert_eq!(doc.cratemod().items[3].name(), ~"istruct");
assert_eq!(doc.cratemod().items[4].name(), ~"itrait");
assert_eq!(doc.cratemod().items[5].name(), ~"__extensions__");
assert_eq!(doc.cratemod().items[6].name(), ~"ifn");
assert_eq!(doc.cratemod().items[7].name(), ~"imod");
// hidden __std_macros module fits here.
assert_eq!(doc.cratemod().items[8].name(), ~"imod");
}
}
Loading