Skip to content

Commit a052197

Browse files
committed
Merge branch 'master' into floop-for-snapshot
2 parents c758ef3 + e2dad03 commit a052197

21 files changed

+680
-1763
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Brendan Eich <[email protected]>
1414
Brian Anderson <[email protected]>
1515
Chris Double <[email protected]>
1616
Chris Peterson <[email protected]>
17+
Damien Grassart <[email protected]>
1718
Daniel Brooks <[email protected]>
1819
Daniel Luz <[email protected]>
1920
Dave Herman <[email protected]>

src/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This is preliminary version of the Rust compiler.
22

33
Source layout:
44

5-
comp/ The self-hosted compiler
5+
rustc/ The self-hosted compiler
66

77
cargo/ The package manager
88

src/rustc/driver/driver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
163163
let mutbl_map =
164164
time(time_passes, "mutability checking",
165165
bind middle::mutbl::check_crate(ty_cx, crate));
166+
time(time_passes, "region checking",
167+
bind middle::regionck::check_crate(ty_cx, crate));
166168
let (copy_map, ref_map) =
167169
time(time_passes, "alias checking",
168170
bind middle::alias::check_crate(ty_cx, crate));

src/rustc/middle/regionck.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* The region checking pass. Ensures that region-annotated pointers never
3+
* outlive their referents.
4+
*/
5+
6+
import driver::session::session;
7+
import middle::ty;
8+
import std::map::hashmap;
9+
import syntax::{ast, visit};
10+
11+
type ctxt = {
12+
tcx: ty::ctxt,
13+
enclosing_block: option<ast::node_id>
14+
};
15+
16+
fn check_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
17+
ty::walk_ty(cx.tcx, ty::expr_ty(cx.tcx, expr)) { |t|
18+
alt ty::get(t).struct {
19+
ty::ty_rptr(region, _) {
20+
alt region {
21+
ty::re_named(_) | ty::re_caller(_) { /* ok */ }
22+
ty::re_block(rbi) {
23+
let referent_block_id = rbi;
24+
let enclosing_block_id = alt cx.enclosing_block {
25+
none {
26+
cx.tcx.sess.span_bug(expr.span, "block " +
27+
"region type outside " +
28+
"a block?!");
29+
}
30+
some(eb) { eb }
31+
};
32+
33+
let parent_blocks = cx.tcx.region_map.parent_blocks;
34+
while enclosing_block_id != referent_block_id {
35+
if parent_blocks.contains_key(referent_block_id) {
36+
referent_block_id =
37+
parent_blocks.get(referent_block_id);
38+
} else {
39+
// TODO: Enable this.
40+
41+
//cx.tcx.sess.span_err(expr.span,
42+
// "reference escapes " +
43+
// "its block");
44+
break;
45+
}
46+
}
47+
}
48+
}
49+
}
50+
_ { /* no-op */ }
51+
}
52+
}
53+
54+
visit::visit_expr(expr, cx, visitor);
55+
}
56+
57+
fn check_block(blk: ast::blk, cx: ctxt, visitor: visit::vt<ctxt>) {
58+
let new_cx: ctxt = { enclosing_block: some(blk.node.id) with cx };
59+
visit::visit_block(blk, new_cx, visitor);
60+
}
61+
62+
fn check_crate(ty_cx: ty::ctxt, crate: @ast::crate) {
63+
let cx: ctxt = {tcx: ty_cx, enclosing_block: none};
64+
let visitor = visit::mk_vt(@{
65+
visit_expr: check_expr,
66+
visit_block: check_block
67+
with *visit::default_visitor()
68+
});
69+
visit::visit_crate(*crate, cx, visitor);
70+
}
71+

src/rustc/rustc.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod middle {
4545
mod capture;
4646
mod pat_util;
4747
mod region;
48+
mod regionck;
4849

4950
mod tstate {
5051
mod ck;

0 commit comments

Comments
 (0)