Skip to content

Commit dfd2fff

Browse files
committed
---
yaml --- r: 4938 b: refs/heads/master c: f841e89 h: refs/heads/master v: v3
1 parent e8d7890 commit dfd2fff

File tree

9 files changed

+56
-20
lines changed

9 files changed

+56
-20
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: d9bc3cb10c4d1e856998c8e35ce7d89e0d74f4d6
2+
refs/heads/master: f841e894437843c142ebd7e0b0a18ed00ed52457

trunk/src/comp/front/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) ->
7777
let filtered_stmts = vec::filter_map(filter, b.stmts);
7878
ret {stmts: vec::map(fld.fold_stmt, filtered_stmts),
7979
expr: option::map(fld.fold_expr, b.expr),
80-
id: b.id};
80+
id: b.id, rules: b.rules};
8181
}
8282

8383
fn item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::item) -> bool {

trunk/src/comp/front/test.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import std::option;
44
import std::vec;
55
import syntax::ast;
66
import syntax::ast_util;
7-
import syntax::ast_util::dummy_sp;
7+
import syntax::ast_util::*;
8+
//import syntax::ast_util::dummy_sp;
89
import syntax::fold;
910
import syntax::print::pprust;
1011
import front::attr;
@@ -189,8 +190,8 @@ fn mk_tests(cx: &test_ctxt) -> @ast::item {
189190
// The vector of test_descs for this crate
190191
let test_descs = mk_test_desc_vec(cx);
191192

192-
let body_: ast::blk_ =
193-
{stmts: [], expr: option::some(test_descs), id: cx.next_node_id()};
193+
let body_: ast::blk_ = checked_blk([], option::some(test_descs),
194+
cx.next_node_id());
194195
let body = nospan(body_);
195196

196197
let fn_ = {decl: decl, proto: proto, body: body};
@@ -305,10 +306,8 @@ fn mk_main(cx: &test_ctxt) -> @ast::item {
305306

306307
let test_main_call_expr = mk_test_main_call(cx);
307308

308-
let body_: ast::blk_ =
309-
{stmts: [],
310-
expr: option::some(test_main_call_expr),
311-
id: cx.next_node_id()};
309+
let body_: ast::blk_ = checked_blk([], option::some(test_main_call_expr),
310+
cx.next_node_id());
312311
let body = {node: body_, span: dummy_sp()};
313312

314313
let fn_ = {decl: decl, proto: proto, body: body};

trunk/src/comp/middle/typeck.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,12 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
20812081
check_fn(fcx.ccx, f, id, some(fcx));
20822082
}
20832083
ast::expr_block(b) {
2084-
bot = check_block(fcx, b);
2084+
// If this is an unchecked block, turn off purity-checking
2085+
let fcx_for_block = alt b.node.rules {
2086+
ast::unchecked. { @{ purity: ast::impure_fn with *fcx } }
2087+
_ { fcx }
2088+
};
2089+
bot = check_block(fcx_for_block, b);
20852090
let typ =
20862091
alt b.node.expr {
20872092
some(expr) { expr_ty(tcx, expr) }

trunk/src/comp/syntax/ast.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ tag meta_item_ {
8282

8383
type blk = spanned<blk_>;
8484

85-
type blk_ = {stmts: [@stmt], expr: option::t<@expr>, id: node_id};
85+
type blk_ = {stmts: [@stmt], expr: option::t<@expr>,
86+
id: node_id, rules: check_mode};
8687

8788
type pat = {id: node_id, node: pat_, span: span};
8889

@@ -223,6 +224,15 @@ tag expr_ {
223224
expr_uniq(@expr);
224225
}
225226

227+
/*
228+
// Says whether this is a block the user marked as
229+
// "unchecked"
230+
tag blk_sort {
231+
blk_unchecked; // declared as "exception to effect-checking rules"
232+
blk_checked; // all typing rules apply
233+
}
234+
*/
235+
226236
type mac = spanned<mac_>;
227237

228238
tag mac_ {

trunk/src/comp/syntax/ast_util.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,14 @@ fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); }
184184
fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; }
185185

186186
fn block_from_expr(e: @expr) -> blk {
187-
let blk_ = {stmts: [], expr: option::some::<@expr>(e), id: e.id};
187+
let blk_ = checked_blk([], option::some::<@expr>(e), e.id);
188188
ret {node: blk_, span: e.span};
189189
}
190190

191+
fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id)
192+
-> blk_ {
193+
ret {stmts: stmts1, expr: expr1, id: id1, rules: checked};
194+
}
191195

192196
fn obj_field_from_anon_obj_field(f: &anon_obj_field) -> obj_field {
193197
ret {mut: f.mut, ty: f.ty, ident: f.ident, id: f.id};

trunk/src/comp/syntax/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ fn noop_fold_method(m: &method_, fld: ast_fold) -> method_ {
255255
fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ {
256256
ret {stmts: vec::map(fld.fold_stmt, b.stmts),
257257
expr: option::map(fld.fold_expr, b.expr),
258-
id: b.id};
258+
id: b.id,
259+
rules: b.rules};
259260
}
260261

261262
fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ {

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
837837
} else if p.peek() == token::BINOP(token::OR) {
838838
ret parse_fn_block_expr(p);
839839
} else {
840-
let blk = parse_block_tail(p, lo);
840+
let blk = parse_block_tail(p, lo, ast::checked);
841841
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
842842
}
843843
} else if eat_word(p, "if") {
@@ -860,6 +860,10 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
860860
ret parse_fn_expr(p, ast::proto_block);
861861
} else if eat_word(p, "lambda") {
862862
ret parse_fn_expr(p, ast::proto_closure);
863+
} else if eat_word(p, "unchecked") {
864+
expect(p, token::LBRACE);
865+
let blk = parse_block_tail(p, lo, ast::unchecked);
866+
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
863867
} else if p.peek() == token::LBRACKET {
864868
p.bump();
865869
let mut = parse_mutability(p);
@@ -876,7 +880,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
876880
ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_embed_type(ty))
877881
} else if p.peek() == token::POUND_LBRACE {
878882
p.bump();
879-
let blk = ast::mac_embed_block(parse_block_tail(p, lo));
883+
let blk = ast::mac_embed_block(parse_block_tail(p, lo, ast::checked));
880884
ret mk_mac_expr(p, lo, p.get_hi_pos(), blk);
881885
} else if p.peek() == token::ELLIPSIS {
882886
p.bump();
@@ -1309,7 +1313,7 @@ fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr {
13091313
fn parse_fn_block_expr(p: &parser) -> @ast::expr {
13101314
let lo = p.get_last_lo_pos();
13111315
let decl = parse_fn_block_decl(p);
1312-
let body = parse_block_tail(p, lo);
1316+
let body = parse_block_tail(p, lo, ast::checked);
13131317
let _fn = {decl: decl, proto: ast::proto_block, body: body};
13141318
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn));
13151319
}
@@ -1664,12 +1668,20 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool {
16641668

16651669
fn parse_block(p: &parser) -> ast::blk {
16661670
let lo = p.get_lo_pos();
1667-
expect(p, token::LBRACE);
1668-
be parse_block_tail(p, lo);
1671+
if eat_word(p, "unchecked") {
1672+
be parse_block_tail(p, lo, ast::unchecked);
1673+
}
1674+
else {
1675+
expect(p, token::LBRACE);
1676+
be parse_block_tail(p, lo, ast::checked);
1677+
}
16691678
}
16701679

1680+
// Precondition: already parsed the '{' or '#{'
1681+
// I guess that also means "already parsed the 'impure'" if
1682+
// necessary, and this should take a qualifier.
16711683
// some blocks start with "#{"...
1672-
fn parse_block_tail(p: &parser, lo: uint) -> ast::blk {
1684+
fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk {
16731685
let stmts: [@ast::stmt] = [];
16741686
let expr: option::t<@ast::expr> = none;
16751687
while p.peek() != token::RBRACE {
@@ -1710,7 +1722,7 @@ fn parse_block_tail(p: &parser, lo: uint) -> ast::blk {
17101722
}
17111723
let hi = p.get_hi_pos();
17121724
p.bump();
1713-
let bloc = {stmts: stmts, expr: expr, id: p.get_id()};
1725+
let bloc = {stmts: stmts, expr: expr, id: p.get_id(), rules: s};
17141726
ret spanned(lo, hi, bloc);
17151727
}
17161728

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ tag embed_type { block_macro; block_block_fn; block_normal; }
579579

580580
fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
581581
indented: uint) {
582+
alt blk.node.rules {
583+
ast::unchecked. { word(s.s, "unchecked"); }
584+
_ {}
585+
}
586+
582587
maybe_print_comment(s, blk.span.lo);
583588
let ann_node = node_block(s, blk);
584589
s.ann.pre(ann_node);

0 commit comments

Comments
 (0)