Skip to content

Commit 825fd18

Browse files
committed
lots of work to make iface/impls parameterized by regions
- paths can now take region parameters, replacing the dirty hack I was doing before of abusing vstores. vstores are now a bit of a hack though. - fix various small bugs: - we never checked that iface types were compatible when casting to an iface with `as` - we allowed nonsense like int<int> - and more! (actually that may be it)
1 parent 458d2ff commit 825fd18

39 files changed

+849
-547
lines changed

src/librustsyntax/ast.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ type ident = str;
3737
type fn_ident = option<ident>;
3838

3939
#[auto_serialize]
40-
type path = {span: span, global: bool, idents: [ident], types: [@ty]};
40+
type path = {span: span,
41+
global: bool,
42+
idents: [ident],
43+
rp: option<@region>,
44+
types: [@ty]};
4145

4246
#[auto_serialize]
4347
type crate_num = int;
@@ -175,7 +179,7 @@ enum vstore {
175179
vstore_fixed(option<uint>), // [1,2,3,4]/_ or 4
176180
vstore_uniq, // [1,2,3,4]/~
177181
vstore_box, // [1,2,3,4]/@
178-
vstore_slice(region) // [1,2,3,4]/&(foo)?
182+
vstore_slice(@region) // [1,2,3,4]/&(foo)?
179183
}
180184

181185
pure fn is_blockish(p: ast::proto) -> bool {
@@ -462,7 +466,7 @@ enum ty_ {
462466
ty_uniq(mt),
463467
ty_vec(mt),
464468
ty_ptr(mt),
465-
ty_rptr(region, mt),
469+
ty_rptr(@region, mt),
466470
ty_rec([ty_field]),
467471
ty_fn(proto, fn_decl),
468472
ty_tup([@ty]),
@@ -671,8 +675,8 @@ enum item_ {
671675
class_ctor,
672676
region_param
673677
),
674-
item_iface([ty_param], [ty_method]),
675-
item_impl([ty_param], option<@iface_ref> /* iface */,
678+
item_iface([ty_param], region_param, [ty_method]),
679+
item_impl([ty_param], region_param, option<@iface_ref> /* iface */,
676680
@ty /* self */, [@method]),
677681
}
678682

src/librustsyntax/ast_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ fn default_block(stmts1: [@stmt], expr1: option<@expr>, id1: node_id) ->
248248
}
249249

250250
fn ident_to_path(s: span, i: ident) -> @path {
251-
@{span: s, global: false, idents: [i], types: []}
251+
@{span: s, global: false, idents: [i],
252+
rp: none, types: []}
252253
}
253254

254255
pure fn is_unguarded(&&a: arm) -> bool {

src/librustsyntax/ext/auto_serialize.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ impl helpers for ext_ctxt {
130130
}
131131

132132
fn path(span: span, strs: [str]) -> @ast::path {
133-
@{span: span, global: false, idents: strs, types: []}
133+
@{span: span, global: false, idents: strs, rp: none, types: []}
134134
}
135135

136136
fn path_tps(span: span, strs: [str], tps: [@ast::ty]) -> @ast::path {
137-
@{span: span, global: false, idents: strs, types: tps}
137+
@{span: span, global: false, idents: strs, rp: none, types: tps}
138138
}
139139

140140
fn ty_path(span: span, strs: [str], tps: [@ast::ty]) -> @ast::ty {
@@ -193,7 +193,8 @@ impl helpers for ext_ctxt {
193193
}
194194

195195
fn binder_pat(span: span, nm: str) -> @ast::pat {
196-
let path = @{span: span, global: false, idents: [nm], types: []};
196+
let path = @{span: span, global: false, idents: [nm],
197+
rp: none, types: []};
197198
@{id: self.next_id(),
198199
node: ast::pat_ident(path, none),
199200
span: span}

src/librustsyntax/ext/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
3030
}
3131
fn mk_path(cx: ext_ctxt, sp: span, idents: [ast::ident]) ->
3232
@ast::expr {
33-
let path = @{span: sp, global: false, idents: idents, types: []};
33+
let path = @{span: sp, global: false, idents: idents,
34+
rp: none, types: []};
3435
let pathexpr = ast::expr_path(path);
3536
ret @{id: cx.next_id(), node: pathexpr, span: sp};
3637
}

src/librustsyntax/ext/concat_idents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
1717

1818
ret @{id: cx.next_id(),
1919
node: ast::expr_path(@{span: sp, global: false, idents: [res],
20-
types: []}),
20+
rp: none, types: []}),
2121
span: sp};
2222
}

src/librustsyntax/ext/simplext.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut [uint],
334334
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; }
335335
alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
336336
some(match_ident(id)) {
337-
{span: id.span, global: false, idents: [id.node], types: []}
337+
{span: id.span, global: false, idents: [id.node],
338+
rp: none, types: []}
338339
}
339340
some(match_path(a_pth)) { *a_pth }
340341
some(m) { match_error(cx, m, "a path") }
@@ -359,6 +360,7 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut [uint],
359360
(expr_path(@{span: id.span,
360361
global: false,
361362
idents: [id.node],
363+
rp: none,
362364
types: []}), id.span)
363365
}
364366
some(match_path(a_pth)) { (expr_path(a_pth), s) }

src/librustsyntax/fold.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,18 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
287287
with ctor},
288288
rp)
289289
}
290-
item_impl(tps, ifce, ty, methods) {
291-
item_impl(tps, option::map(ifce, {|p| fold_iface_ref(p, fld)}),
290+
item_impl(tps, rp, ifce, ty, methods) {
291+
item_impl(fold_ty_params(tps, fld),
292+
rp,
293+
ifce.map { |p| fold_iface_ref(p, fld) },
292294
fld.fold_ty(ty),
293-
vec::map(methods, fld.fold_method))
295+
vec::map(methods, fld.fold_method))
296+
}
297+
item_iface(tps, rp, methods) {
298+
item_iface(fold_ty_params(tps, fld),
299+
rp,
300+
methods)
294301
}
295-
item_iface(tps, methods) { item_iface(tps, methods) }
296302
item_res(decl, typms, body, did, cid, rp) {
297303
item_res(fold_fn_decl(decl, fld),
298304
fold_ty_params(typms, fld),
@@ -565,6 +571,7 @@ fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
565571
fn noop_fold_path(&&p: path, fld: ast_fold) -> path {
566572
ret {span: fld.new_span(p.span), global: p.global,
567573
idents: vec::map(p.idents, fld.fold_ident),
574+
rp: p.rp,
568575
types: vec::map(p.types, fld.fold_ty)};
569576
}
570577

0 commit comments

Comments
 (0)