Skip to content

Commit

Permalink
Cleaned up trans_fail functions, per eddyb request.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Mar 1, 2014
1 parent 123eb4e commit e2afa1c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Expand Up @@ -1188,7 +1188,7 @@ impl<'a> DynamicFailureHandler<'a> {

let fcx = self.bcx.fcx;
let fail_cx = fcx.new_block(false, "case_fallthrough", None);
controlflow::trans_fail(fail_cx, Some(self.sp), self.msg.clone());
controlflow::trans_fail(fail_cx, self.sp, self.msg.clone());
self.finished.set(Some(fail_cx.llbb));
fail_cx.llbb
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/base.rs
Expand Up @@ -864,7 +864,7 @@ pub fn fail_if_zero<'a>(
}
};
with_cond(cx, is_zero, |bcx| {
controlflow::trans_fail(bcx, Some(span), InternedString::new(text))
controlflow::trans_fail(bcx, span, InternedString::new(text))
})
}
Expand Down
60 changes: 7 additions & 53 deletions src/librustc/middle/trans/controlflow.rs
Expand Up @@ -18,8 +18,6 @@ use middle::trans::debuginfo;
use middle::trans::cleanup;
use middle::trans::cleanup::CleanupMethods;
use middle::trans::expr;
use middle::ty;
use util::ppaux;
use util::ppaux::Repr;

use middle::trans::type_::Type;
Expand Down Expand Up @@ -327,67 +325,23 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>,
return bcx;
}

pub fn trans_fail_expr<'a>(
bcx: &'a Block<'a>,
sp_opt: Option<Span>,
fail_expr: Option<@ast::Expr>)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_fail_expr");
let mut bcx = bcx;
match fail_expr {
Some(arg_expr) => {
let ccx = bcx.ccx();
let tcx = ccx.tcx;
let arg_datum =
unpack_datum!(bcx, expr::trans_to_lvalue(bcx, arg_expr, "fail"));

if ty::type_is_str(arg_datum.ty) {
let (lldata, _) = arg_datum.get_vec_base_and_len(bcx);
return trans_fail_value(bcx, sp_opt, lldata);
} else if bcx.unreachable.get() || ty::type_is_bot(arg_datum.ty) {
return bcx;
} else {
bcx.sess().span_bug(
arg_expr.span, ~"fail called with unsupported type " +
ppaux::ty_to_str(tcx, arg_datum.ty));
}
}
_ => trans_fail(bcx, sp_opt, InternedString::new("explicit failure"))
}
}

pub fn trans_fail<'a>(
bcx: &'a Block<'a>,
sp_opt: Option<Span>,
sp: Span,
fail_str: InternedString)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_fail");
let V_fail_str = C_cstr(bcx.ccx(), fail_str);
return trans_fail_value(bcx, sp_opt, V_fail_str);
}

fn trans_fail_value<'a>(
bcx: &'a Block<'a>,
sp_opt: Option<Span>,
V_fail_str: ValueRef)
-> &'a Block<'a> {
let _icx = push_ctxt("trans_fail_value");
let ccx = bcx.ccx();
let (V_filename, V_line) = match sp_opt {
Some(sp) => {
let sess = bcx.sess();
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
(C_cstr(bcx.ccx(), token::intern_and_get_ident(loc.file.name)),
loc.line as int)
}
None => {
(C_cstr(bcx.ccx(), InternedString::new("<runtime>")), 0)
}
};
let sess = bcx.sess();
let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo);
let V_filename = C_cstr(bcx.ccx(),
token::intern_and_get_ident(loc.file.name));
let V_line = loc.line as int;
let V_str = PointerCast(bcx, V_fail_str, Type::i8p());
let V_filename = PointerCast(bcx, V_filename, Type::i8p());
let args = ~[V_str, V_filename, C_int(ccx, V_line)];
let did = langcall(bcx, sp_opt, "", FailFnLangItem);
let did = langcall(bcx, Some(sp), "", FailFnLangItem);
let bcx = callee::trans_lang_call(bcx, did, args, Some(expr::Ignore)).bcx;
Unreachable(bcx);
return bcx;
Expand Down

7 comments on commit e2afa1c

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging chromatic/rust/fixup_trans_fail = e2afa1c into auto

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromatic/rust/fixup_trans_fail = e2afa1c merged ok, testing candidate = c81b3fb

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c81b3fb

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge sha c81b3fb is stale.

@bors
Copy link
Contributor

@bors bors commented on e2afa1c Mar 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging chromatic/rust/fixup_trans_fail = e2afa1c into auto

Please sign in to comment.