Skip to content

Commit 83e10a7

Browse files
jdmbrson
authored andcommitted
---
yaml --- r: 3549 b: refs/heads/master c: d485e0d h: refs/heads/master i: 3547: 5d82f9d v: v3
1 parent 04c1adb commit 83e10a7

File tree

10 files changed

+81
-27
lines changed

10 files changed

+81
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 67c9ef9b306e6f45842a474e66d122c96139e02c
2+
refs/heads/master: d485e0d15a6d1f263657fbaa61dc31da780fea2d

trunk/src/comp/front/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ tag expr_ {
275275
expr_index(@expr, @expr);
276276
expr_path(path);
277277
expr_ext(path, vec[@expr], option::t[str], @expr);
278-
expr_fail(option::t[str]);
278+
expr_fail(option::t[@expr]);
279279
expr_break;
280280
expr_cont;
281281
expr_ret(option::t[@expr]);

trunk/src/comp/front/parser.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,12 +841,15 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
841841
lo = ex_ext.span.lo;
842842
ex = ex_ext.node;
843843
} else if (eat_word(p, "fail")) {
844-
auto msg;
845844
alt (p.peek()) {
846-
case (token::LIT_STR(?s)) { msg = some(p.get_str(s)); p.bump(); }
847-
case (_) { msg = none; }
845+
case (token::SEMI) { ex = ast::expr_fail(none) }
846+
case (token::RBRACE) { ex = ast::expr_fail(none) }
847+
case (_) {
848+
auto e = parse_expr(p);
849+
hi = e.span.hi;
850+
ex = ast::expr_fail(some(e));
851+
}
848852
}
849-
ex = ast::expr_fail(msg);
850853
} else if (eat_word(p, "log")) {
851854
auto e = parse_expr(p);
852855
ex = ast::expr_log(1, e);

trunk/src/comp/middle/trans.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6157,13 +6157,8 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
61576157
case (ast::expr_ext(_, _, _, ?expanded)) {
61586158
ret trans_expr(cx, expanded);
61596159
}
6160-
case (ast::expr_fail(?str)) {
6161-
auto failmsg;
6162-
alt (str) {
6163-
case (some(?msg)) { failmsg = msg; }
6164-
case (_) { failmsg = "explicit failure"; }
6165-
}
6166-
ret trans_fail(cx, some(e.span), failmsg);
6160+
case (ast::expr_fail(?expr)) {
6161+
ret trans_fail_expr(cx, some(e.span), expr);
61676162
}
61686163
case (ast::expr_log(?lvl, ?a)) { ret trans_log(lvl, cx, a); }
61696164
case (ast::expr_assert(?a)) {
@@ -6366,9 +6361,40 @@ fn trans_check_expr(&@block_ctxt cx, &@ast::expr e, &str s) -> result {
63666361
ret rslt(next_cx, C_nil());
63676362
}
63686363

6364+
fn trans_fail_expr(&@block_ctxt cx, &option::t[common::span] sp_opt,
6365+
&option::t[@ast::expr] fail_expr)
6366+
-> result {
6367+
alt (fail_expr) {
6368+
case (some(?expr)) {
6369+
auto tcx = cx.fcx.lcx.ccx.tcx;
6370+
auto expr_res = trans_expr(cx, expr);
6371+
auto e_ty = ty::expr_ty(tcx, expr);
6372+
6373+
if (ty::type_is_str(tcx, e_ty)) {
6374+
auto elt = cx.build.GEP(expr_res.val,
6375+
[C_int(0), C_int(abi::vec_elt_data)]);
6376+
ret trans_fail_value(cx, sp_opt, elt);
6377+
} else {
6378+
cx.fcx.lcx.ccx.sess.span_fatal(expr.span,
6379+
"fail called with unsupported \
6380+
type " + ty_to_str(tcx, e_ty));
6381+
}
6382+
}
6383+
case (_) {
6384+
ret trans_fail(cx, sp_opt, "explicit failure");
6385+
}
6386+
}
6387+
}
6388+
63696389
fn trans_fail(&@block_ctxt cx, &option::t[common::span] sp_opt, &str fail_str)
63706390
-> result {
63716391
auto V_fail_str = C_cstr(cx.fcx.lcx.ccx, fail_str);
6392+
ret trans_fail_value(cx, sp_opt, V_fail_str);
6393+
}
6394+
6395+
fn trans_fail_value(&@block_ctxt cx, &option::t[common::span] sp_opt,
6396+
&ValueRef V_fail_str)
6397+
-> result {
63726398
auto V_filename;
63736399
auto V_line;
63746400
alt (sp_opt) {
@@ -6382,9 +6408,9 @@ fn trans_fail(&@block_ctxt cx, &option::t[common::span] sp_opt, &str fail_str)
63826408
V_line = 0;
63836409
}
63846410
}
6385-
V_fail_str = cx.build.PointerCast(V_fail_str, T_ptr(T_i8()));
6411+
auto V_str = cx.build.PointerCast(V_fail_str, T_ptr(T_i8()));
63866412
V_filename = cx.build.PointerCast(V_filename, T_ptr(T_i8()));
6387-
auto args = [cx.fcx.lltaskptr, V_fail_str, V_filename, C_int(V_line)];
6413+
auto args = [cx.fcx.lltaskptr, V_str, V_filename, C_int(V_line)];
63886414
cx.build.Call(cx.fcx.lcx.ccx.upcalls._fail, args);
63896415
cx.build.Unreachable();
63906416
ret rslt(cx, C_nil());

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,19 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
529529
find_pre_post_expr(fcx, operator);
530530
copy_pre_post(fcx.ccx, e.id, operator);
531531
}
532-
case (expr_fail(_)) {
532+
case (expr_fail(?maybe_val)) {
533+
auto prestate;
534+
alt (maybe_val) {
535+
case (none) { prestate = empty_prestate(num_local_vars); }
536+
case (some(?fail_val)) {
537+
find_pre_post_expr(fcx, fail_val);
538+
prestate = expr_precond(fcx.ccx, fail_val);
539+
}
540+
}
533541
set_pre_and_post(fcx.ccx, e.id,
534542
/* if execution continues after fail,
535543
then everything is true! */
536-
empty_prestate(num_local_vars),
544+
prestate,
537545
false_postcond(num_local_vars));
538546
}
539547
case (expr_assert(?p)) {

trunk/src/comp/middle/tstate/states.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,18 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
543543
case (expr_cast(?operand, _)) {
544544
ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
545545
}
546-
case (expr_fail(_)) {
546+
case (expr_fail(?maybe_fail_val)) {
547547
ret set_prestate_ann(fcx.ccx, e.id, pres) |
548548
/* if execution continues after fail, then everything is true!
549549
woo! */
550550
set_poststate_ann(fcx.ccx, e.id,
551-
false_postcond(num_constrs));
551+
false_postcond(num_constrs)) |
552+
alt(maybe_fail_val) {
553+
case (none) { false }
554+
case (some(?fail_val)) {
555+
find_pre_post_state_expr(fcx, pres, fail_val)
556+
}
557+
}
552558
}
553559
case (expr_assert(?p)) {
554560
ret find_pre_post_state_sub(fcx, pres, p, e.id, none);

trunk/src/comp/middle/typeck.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
16221622
auto t = expr_ty(fcx.ccx.tcx, expanded);
16231623
write::ty_only_fixup(fcx, id, t);
16241624
}
1625-
case (ast::expr_fail(_)) { write::bot_ty(fcx.ccx.tcx, id); }
1625+
case (ast::expr_fail(?expr_opt)) {
1626+
alt (expr_opt) {
1627+
case (none) { /* do nothing */ }
1628+
case (some(?e)) { check_expr(fcx, e); }
1629+
}
1630+
write::bot_ty(fcx.ccx.tcx, id);
1631+
}
16261632
case (ast::expr_break) { write::bot_ty(fcx.ccx.tcx, id); }
16271633
case (ast::expr_cont) { write::bot_ty(fcx.ccx.tcx, id); }
16281634
case (ast::expr_ret(?expr_opt)) {

trunk/src/comp/middle/walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
369369

370370
walk_expr(v, expansion);
371371
}
372-
case (ast::expr_fail(_)) { }
372+
case (ast::expr_fail(?eo)) { walk_expr_opt(v, eo); }
373373
case (ast::expr_break) { }
374374
case (ast::expr_cont) { }
375375
case (ast::expr_ret(?eo)) { walk_expr_opt(v, eo); }

trunk/src/comp/pretty/pprust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,10 @@ fn print_expr(&ps s, &@ast::expr expr) {
838838
pclose(s);
839839
}
840840
case (ast::expr_path(?path)) { print_path(s, path); }
841-
case (ast::expr_fail(?str)) {
841+
case (ast::expr_fail(?maybe_fail_val)) {
842842
word(s.s, "fail");
843-
alt (str) {
844-
case (some(?msg)) { word(s.s, #fmt(" \"%s\"", msg)); }
843+
alt (maybe_fail_val) {
844+
case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
845845
case (_) { }
846846
}
847847
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

22

3-
4-
// error-pattern:woooo
5-
fn main() { fail"woooo"; }
3+
// error-pattern:wooooo
4+
fn main() {
5+
auto a = 1;
6+
if (1 == 1) {
7+
a = 2;
8+
}
9+
fail "woooo" + "o";
10+
}

0 commit comments

Comments
 (0)