Skip to content

Commit 1f05868

Browse files
committed
---
yaml --- r: 14754 b: refs/heads/try c: a052197 h: refs/heads/master v: v3
1 parent 0fa2d8b commit 1f05868

22 files changed

+681
-1764
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: c758ef3f386578cffd5353e1b84e94d1f30d760f
5+
refs/heads/try: a0521971b1b9a3203c250591991092a445b50586
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/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]>

branches/try/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

branches/try/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));
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+

branches/try/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)