Skip to content

Commit 28fe3dc

Browse files
committed
---
yaml --- r: 14823 b: refs/heads/try c: 8cbaebb h: refs/heads/master i: 14821: d7f57be 14819: fe3f98e 14815: adb5c0a v: v3
1 parent d410ba7 commit 28fe3dc

File tree

7 files changed

+63
-16
lines changed

7 files changed

+63
-16
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: b968c8e6cd362567bf0047a96d261691dfca43e8
5+
refs/heads/try: 8cbaebbb49a875728f95d413d7352f77cc97d04c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/metadata/tyencode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
103103
ty::re_block(nid) {
104104
w.write_char('b'); w.write_int(nid); w.write_char('|');
105105
}
106+
ty::re_inferred { w.write_char('?'); }
106107
}
107108
}
108109
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {

branches/try/src/rustc/middle/region.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import std::map::hashmap;
1515

1616
/* Represents the type of the most immediate parent node. */
1717
enum parent {
18-
pa_item(ast::node_id),
18+
pa_fn_item(ast::node_id),
1919
pa_block(ast::node_id),
2020
pa_nested_fn(ast::node_id),
21+
pa_item(ast::node_id),
2122
pa_crate
2223
}
2324

@@ -66,6 +67,7 @@ fn region_to_scope(region_map: @region_map, region: ty::region)
6667
ty::re_caller(def_id) { def_id.node }
6768
ty::re_named(def_id) { region_map.region_name_to_fn.get(def_id) }
6869
ty::re_block(node_id) { node_id }
70+
ty::re_inferred { fail "unresolved region in region_to_scope" }
6971
};
7072
}
7173

@@ -90,10 +92,11 @@ fn get_inferred_region(cx: ctxt, sp: syntax::codemap::span) -> ty::region {
9092
// TODO: What do we do if we're in an alt?
9193

9294
ret alt cx.parent {
93-
pa_item(item_id) | pa_nested_fn(item_id) {
95+
pa_fn_item(item_id) | pa_nested_fn(item_id) {
9496
ty::re_caller({crate: ast::local_crate, node: item_id})
9597
}
9698
pa_block(block_id) { ty::re_block(block_id) }
99+
pa_item(_) { ty::re_inferred }
97100
pa_crate { cx.sess.span_bug(sp, "inferred region at crate level?!"); }
98101
}
99102
}
@@ -121,10 +124,16 @@ fn resolve_ty(ty: @ast::ty, cx: ctxt, visitor: visit::vt<ctxt>) {
121124
region = ty::re_named(def_id);
122125

123126
alt cx.parent {
124-
pa_item(fn_id) | pa_nested_fn(fn_id) {
127+
pa_fn_item(fn_id) | pa_nested_fn(fn_id) {
125128
let rf = cx.region_map.region_name_to_fn;
126129
rf.insert(def_id, fn_id);
127130
}
131+
pa_item(_) {
132+
cx.sess.span_err(ty.span,
133+
"named region not " +
134+
"allowed in this " +
135+
"context");
136+
}
128137
pa_block(_) {
129138
cx.sess.span_err(ty.span,
130139
"unknown region `" +
@@ -152,7 +161,10 @@ fn resolve_ty(ty: @ast::ty, cx: ctxt, visitor: visit::vt<ctxt>) {
152161

153162
fn record_parent(cx: ctxt, child_id: ast::node_id) {
154163
alt cx.parent {
155-
pa_item(parent_id) | pa_block(parent_id) | pa_nested_fn(parent_id) {
164+
pa_fn_item(parent_id) |
165+
pa_item(parent_id) |
166+
pa_block(parent_id) |
167+
pa_nested_fn(parent_id) {
156168
cx.region_map.parents.insert(child_id, parent_id);
157169
}
158170
pa_crate { /* no-op */ }
@@ -231,8 +243,12 @@ fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
231243

232244
fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
233245
// Items create a new outer block scope as far as we're concerned.
246+
let parent = alt item.node {
247+
ast::item_fn(_, _, _) { pa_fn_item(item.id) }
248+
_ { pa_item(item.id) }
249+
};
234250
let new_cx: ctxt = {bindings: @list::nil,
235-
parent: pa_item(item.id),
251+
parent: parent,
236252
in_alt: false
237253
with cx};
238254
visit::visit_item(item, new_cx, visitor);

branches/try/src/rustc/middle/regionck.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ fn check_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
4949
"escapes its block");
5050
}
5151
}
52+
ty::re_inferred {
53+
cx.tcx.sess.span_bug(expr.span,
54+
"unresolved region");
55+
}
5256
}
5357
}
5458
_ { /* no-op */ }

branches/try/src/rustc/middle/ty.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export field;
3535
export field_idx;
3636
export get_field;
3737
export get_fields;
38-
export fm_general;
38+
export fm_general, fm_rptr;
3939
export get_element_type;
4040
export is_binopable;
4141
export is_pred_ty;
@@ -88,7 +88,7 @@ export ty_uint, mk_uint, mk_mach_uint;
8888
export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
8989
export ty_var, mk_var;
9090
export ty_self, mk_self;
91-
export region, re_named, re_caller, re_block;
91+
export region, re_named, re_caller, re_block, re_inferred;
9292
export get, type_has_params, type_has_vars, type_has_rptrs, type_id;
9393
export same_type;
9494
export ty_var_id;
@@ -234,7 +234,8 @@ type fn_ty = {proto: ast::proto,
234234
enum region {
235235
re_named(def_id),
236236
re_caller(def_id),
237-
re_block(node_id)
237+
re_block(node_id),
238+
re_inferred /* currently unresolved (for typedefs) */
238239
}
239240

240241
// NB: If you change this, you'll probably want to change the corresponding
@@ -571,6 +572,7 @@ fn walk_ty(cx: ctxt, ty: t, f: fn(t)) {
571572
enum fold_mode {
572573
fm_var(fn@(int) -> t),
573574
fm_param(fn@(uint, def_id) -> t),
575+
fm_rptr(fn@(region) -> region),
574576
fm_general(fn@(t) -> t),
575577
}
576578

@@ -581,6 +583,7 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
581583
alt fld {
582584
fm_var(_) { if !tb.has_vars { ret ty; } }
583585
fm_param(_) { if !tb.has_params { ret ty; } }
586+
fm_rptr(_) { if !tb.has_rptrs { ret ty; } }
584587
fm_general(_) {/* no fast path */ }
585588
}
586589

@@ -597,9 +600,6 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
597600
ty_ptr(tm) {
598601
ty = mk_ptr(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
599602
}
600-
ty_rptr(r, tm) {
601-
ty = mk_rptr(cx, r, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
602-
}
603603
ty_vec(tm) {
604604
ty = mk_vec(cx, {ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
605605
}
@@ -647,6 +647,11 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
647647
ty_param(id, did) {
648648
alt fld { fm_param(folder) { ty = folder(id, did); } _ {} }
649649
}
650+
ty_rptr(r, tm) {
651+
let region = alt fld { fm_rptr(folder) { folder(r) } _ { r } };
652+
ty = mk_rptr(cx, region,
653+
{ty: fold_ty(cx, fld, tm.ty), mutbl: tm.mutbl});
654+
}
650655
ty_constr(subty, cs) {
651656
ty = mk_constr(cx, fold_ty(cx, fld, subty), cs);
652657
}
@@ -1161,6 +1166,7 @@ fn hash_type_structure(st: sty) -> uint {
11611166
re_named(_) { 1u }
11621167
re_caller(_) { 2u }
11631168
re_block(_) { 3u }
1169+
re_inferred { 4u }
11641170
}
11651171
}
11661172
alt st {

branches/try/src/rustc/middle/typeck.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,19 @@ enum mode { m_collect, m_check, m_check_tyvar(@fn_ctxt), }
247247
// internal notion of a type. `getter` is a function that returns the type
248248
// corresponding to a definition ID:
249249
fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
250-
fn getter(tcx: ty::ctxt, _use_site: ast::node_id, mode: mode,
250+
fn subst_inferred_regions(tcx: ty::ctxt, use_site: ast::node_id,
251+
ty: ty::t) -> ty::t {
252+
ret ty::fold_ty(tcx, ty::fm_rptr({|r|
253+
if r == ty::re_inferred {
254+
tcx.region_map.ast_type_to_inferred_region.get(use_site)
255+
} else {
256+
r
257+
}
258+
}), ty);
259+
}
260+
fn getter(tcx: ty::ctxt, use_site: ast::node_id, mode: mode,
251261
id: ast::def_id) -> ty::ty_param_bounds_and_ty {
252-
// FIXME (pcwalton): Doesn't work with region inference.
253-
alt mode {
262+
let tpt = alt mode {
254263
m_check | m_check_tyvar(_) { ty::lookup_item_type(tcx, id) }
255264
m_collect {
256265
if id.crate != ast::local_crate { csearch::get_type(tcx, id) }
@@ -268,7 +277,13 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
268277
}
269278
}
270279
}
280+
};
281+
282+
if ty::type_has_rptrs(tpt.ty) {
283+
ret {bounds: tpt.bounds,
284+
ty: subst_inferred_regions(tcx, use_site, tpt.ty)};
271285
}
286+
ret tpt;
272287
}
273288
fn ast_mt_to_mt(tcx: ty::ctxt, use_site: ast::node_id, mode: mode,
274289
mt: ast::mt) -> ty::mt {
@@ -327,7 +342,11 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
327342
ast::ty_rptr(region, mt) {
328343
let region = alt region.node {
329344
ast::re_inferred | ast::re_self {
330-
tcx.region_map.ast_type_to_inferred_region.get(ast_ty.id)
345+
let attir = tcx.region_map.ast_type_to_inferred_region;
346+
alt attir.find(ast_ty.id) {
347+
some(resolved_region) { resolved_region }
348+
none { ty::re_inferred }
349+
}
331350
}
332351
ast::re_named(_) {
333352
tcx.region_map.ast_type_to_region.get(region.id)

branches/try/src/rustc/util/ppaux.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
7373
re_named(_) { "<name>." } // TODO: include name
7474
re_caller(_) { "<caller>." }
7575
re_block(_) { "<block>." } // TODO: include line number
76+
re_inferred { "" }
7677
}
7778
}
7879

0 commit comments

Comments
 (0)