Skip to content

Commit d94ba51

Browse files
committed
---
yaml --- r: 14747 b: refs/heads/try c: 4fc5b82 h: refs/heads/master i: 14745: e254872 14743: a54870d v: v3
1 parent 1d9b459 commit d94ba51

20 files changed

+596
-1535
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: c19ea057faed3e4b1abe03c1d760b7741b135e1b
5+
refs/heads/try: 4fc5b822e218301eedf49ec249fdd1a0adf8ebd6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

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-
rustc/ The self-hosted compiler
5+
comp/ 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;

branches/try/src/rustdoc/attr_parser.rs

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import rustc::syntax::ast;
99
import rustc::front::attr;
1010
import core::tuple;
1111

12-
export crate_attrs, basic_attrs, fn_attrs, arg_attrs,
13-
variant_attrs, res_attrs, method_attrs;
14-
export parse_crate, parse_basic, parse_fn,
15-
parse_variant, parse_res, parse_method;
12+
export crate_attrs, basic_attrs, variant_attrs;
13+
export parse_crate, parse_basic, parse_variant;
1614
export parse_hidden;
1715

1816
type crate_attrs = {
@@ -24,27 +22,10 @@ type basic_attrs = {
2422
desc: option<str>
2523
};
2624

27-
type fn_attrs = {
28-
args: [arg_attrs],
29-
return: option<str>,
30-
failure: option<str>
31-
};
32-
33-
type arg_attrs = {
34-
name: str,
35-
desc: str
36-
};
37-
3825
type variant_attrs = {
3926
desc: option<str>
4027
};
4128

42-
type res_attrs = {
43-
args: [arg_attrs]
44-
};
45-
46-
type method_attrs = fn_attrs;
47-
4829
#[cfg(test)]
4930
mod test {
5031

@@ -231,72 +212,6 @@ fn parse_long_doc<T>(
231212
}
232213
}
233214

234-
fn parse_fn(attrs: [ast::attribute]) -> fn_attrs {
235-
parse_long_doc(attrs, parse_fn_long_doc)
236-
}
237-
238-
fn parse_fn_long_doc(items: [@ast::meta_item]) -> fn_attrs {
239-
let return = attr::meta_item_value_from_list(items, "return");
240-
let failure = attr::meta_item_value_from_list(items, "failure");
241-
let args = parse_args(items);
242-
243-
{
244-
args: args,
245-
return: return,
246-
failure: failure
247-
}
248-
}
249-
250-
fn parse_args(items: [@ast::meta_item]) -> [arg_attrs] {
251-
alt attr::meta_item_list_from_list(items, "args") {
252-
some(items) {
253-
vec::filter_map(items) {|item|
254-
option::map(attr::name_value_str_pair(item)) { |pair|
255-
{
256-
name: tuple::first(pair),
257-
desc: tuple::second(pair)
258-
}
259-
}
260-
}
261-
}
262-
none { [] }
263-
}
264-
}
265-
266-
#[test]
267-
fn parse_fn_should_handle_undocumented_functions() {
268-
let source = "";
269-
let attrs = test::parse_attributes(source);
270-
let attrs = parse_fn(attrs);
271-
assert attrs.return == none;
272-
assert vec::len(attrs.args) == 0u;
273-
}
274-
275-
#[test]
276-
fn parse_fn_should_parse_the_return_value_description() {
277-
let source = "#[doc(return = \"return value\")]";
278-
let attrs = test::parse_attributes(source);
279-
let attrs = parse_fn(attrs);
280-
assert attrs.return == some("return value");
281-
}
282-
283-
#[test]
284-
fn parse_fn_should_parse_the_argument_descriptions() {
285-
let source = "#[doc(args(a = \"arg a\", b = \"arg b\"))]";
286-
let attrs = test::parse_attributes(source);
287-
let attrs = parse_fn(attrs);
288-
assert attrs.args[0] == {name: "a", desc: "arg a"};
289-
assert attrs.args[1] == {name: "b", desc: "arg b"};
290-
}
291-
292-
#[test]
293-
fn parse_fn_should_parse_failure_conditions() {
294-
let source = "#[doc(failure = \"it's the fail\")]";
295-
let attrs = test::parse_attributes(source);
296-
let attrs = parse_fn(attrs);
297-
assert attrs.failure == some("it's the fail");
298-
}
299-
300215
fn parse_variant(attrs: [ast::attribute]) -> variant_attrs {
301216
parse_short_doc_or(
302217
attrs,
@@ -342,29 +257,6 @@ fn should_parse_variant_long_doc() {
342257
assert attrs.desc == some("a");
343258
}
344259

345-
fn parse_res(attrs: [ast::attribute]) -> res_attrs {
346-
parse_long_doc(attrs, parse_res_long_doc)
347-
}
348-
349-
fn parse_res_long_doc(items: [@ast::meta_item]) -> res_attrs {
350-
{
351-
args: parse_args(items)
352-
}
353-
}
354-
355-
#[test]
356-
fn shoulde_parse_resource_arg() {
357-
let source = "#[doc(args(a = \"b\"))]";
358-
let attrs = test::parse_attributes(source);
359-
let attrs = parse_res(attrs);
360-
assert attrs.args[0].name == "a";
361-
assert attrs.args[0].desc == "b";
362-
}
363-
364-
fn parse_method(attrs: [ast::attribute]) -> method_attrs {
365-
parse_fn(attrs)
366-
}
367-
368260
fn parse_hidden(attrs: [ast::attribute]) -> bool {
369261
parse_short_doc_or(
370262
attrs,

0 commit comments

Comments
 (0)