Skip to content

Commit c0d6179

Browse files
committed
wip: refactor repr of regions
- we now distinguish bound/free parameters (see region-param test case for why this is necessary) - we also track bounds on region variables - also, restructure fold_ty() to have multiple variants without duplication instead of one overloaded folder. This also allows for using block functions.
1 parent d961f05 commit c0d6179

File tree

12 files changed

+1338
-947
lines changed

12 files changed

+1338
-947
lines changed

src/rustc/metadata/tydecode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
265265
st.pos = st.pos + 1u;
266266
ret ty::mk_res(st.tcx, def, inner, params);
267267
}
268-
'X' { ret ty::mk_var(st.tcx, parse_int(st)); }
268+
'X' {
269+
ret ty::mk_var(st.tcx, ty::ty_vid(parse_int(st) as uint));
270+
}
269271
'Y' { ret ty::mk_type(st.tcx); }
270272
'C' {
271273
let ck = alt check next(st) {

src/rustc/metadata/tyencode.rs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import std::map::hashmap;
55
import syntax::ast::*;
66
import driver::session::session;
77
import middle::ty;
8+
import middle::ty::vid;
89
import syntax::print::pprust::*;
910
import middle::trans::reachable;
1011

@@ -99,23 +100,46 @@ fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
99100
}
100101
enc_ty(w, cx, mt.ty);
101102
}
103+
fn enc_bound_region(w: io::writer, br: ty::bound_region) {
104+
alt br {
105+
ty::br_self { w.write_char('s') }
106+
ty::br_anon { w.write_char('a') }
107+
ty::br_param(id, s) {
108+
w.write_char('[');
109+
w.write_uint(id);
110+
w.write_char('|');
111+
w.write_str(s);
112+
w.write_char(']')
113+
}
114+
}
115+
}
102116
fn enc_region(w: io::writer, r: ty::region) {
103117
alt r {
104-
ty::re_block(nid) {
105-
w.write_char('b'); w.write_int(nid); w.write_char('|');
106-
}
107-
ty::re_self {
108-
w.write_char('s');
109-
}
110-
ty::re_inferred {
111-
w.write_char('i');
112-
}
113-
ty::re_param(id) {
114-
w.write_char('p'); w.write_uint(id); w.write_char('|');
115-
}
116-
ty::re_var(id) {
117-
w.write_char('v'); w.write_uint(id); w.write_char('|');
118-
}
118+
ty::re_bound(br) {
119+
w.write_char('b');
120+
enc_bound_region(w, br);
121+
}
122+
ty::re_free(id, br) {
123+
w.write_char('f');
124+
w.write_char('[');
125+
w.write_int(id);
126+
w.write_char('|');
127+
enc_bound_region(w, br);
128+
w.write_char(']');
129+
}
130+
ty::re_scope(nid) {
131+
w.write_char('s');
132+
w.write_int(nid);
133+
w.write_char('|');
134+
}
135+
ty::re_default {
136+
w.write_char('i');
137+
}
138+
ty::re_var(id) {
139+
w.write_char('v');
140+
w.write_uint(id.to_uint());
141+
w.write_char('|');
142+
}
119143
}
120144
}
121145
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
@@ -199,7 +223,10 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
199223
for t: ty::t in tps { enc_ty(w, cx, t); }
200224
w.write_char(']');
201225
}
202-
ty::ty_var(id) { w.write_char('X'); w.write_str(int::str(id)); }
226+
ty::ty_var(id) {
227+
w.write_char('X');
228+
w.write_uint(id.to_uint());
229+
}
203230
ty::ty_param(id, did) {
204231
w.write_char('p');
205232
w.write_str(cx.ds(did));

0 commit comments

Comments
 (0)