Skip to content

Cleaned up trans_fail(), per eddyb request. #12636

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

Merged
merged 1 commit into from
Mar 2, 2014
Merged
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
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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