Skip to content

Commit cd3c6ff

Browse files
committed
---
yaml --- r: 22892 b: refs/heads/master c: ac4e57c h: refs/heads/master v: v3
1 parent be72246 commit cd3c6ff

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 361a9b03e6713f7be5b5d4996f8aeeaa8bb01cb2
2+
refs/heads/master: ac4e57c6400bdd500a1918238fc76abc3b7def3d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/typeck/check.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ import typeck::infer::{resolve_type, force_tvar};
7979

8080
import std::map::str_hash;
8181

82+
type self_info = {
83+
self_ty: ty::t,
84+
node_id: ast::node_id,
85+
};
86+
8287
type fn_ctxt_ =
8388
// var_bindings, locals and next_var_id are shared
8489
// with any nested functions that capture the environment
8590
// (and with any functions whose environment is being captured).
86-
{self_ty: option<ty::t>,
91+
{self_info: option<self_info>,
8792
ret_ty: ty::t,
8893
// Used by loop bodies that return from the outer function
8994
indirect_ret_ty: option<ty::t>,
@@ -122,7 +127,7 @@ fn blank_fn_ctxt(ccx: @crate_ctxt, rty: ty::t,
122127
region_bnd: ast::node_id) -> @fn_ctxt {
123128
// It's kind of a kludge to manufacture a fake function context
124129
// and statement context, but we might as well do write the code only once
125-
@fn_ctxt_({self_ty: none,
130+
@fn_ctxt_({self_info: none,
126131
ret_ty: rty,
127132
indirect_ret_ty: none,
128133
purity: ast::pure_fn,
@@ -170,14 +175,14 @@ fn check_bare_fn(ccx: @crate_ctxt,
170175
decl: ast::fn_decl,
171176
body: ast::blk,
172177
id: ast::node_id,
173-
self_ty: option<ty::t>) {
178+
self_info: option<self_info>) {
174179
let fty = ty::node_id_to_type(ccx.tcx, id);
175180
let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) {f} };
176-
check_fn(ccx, self_ty, fn_ty, decl, body, false, none);
181+
check_fn(ccx, self_info, fn_ty, decl, body, false, none);
177182
}
178183

179184
fn check_fn(ccx: @crate_ctxt,
180-
self_ty: option<ty::t>,
185+
self_info: option<self_info>,
181186
fn_ty: ty::fn_ty,
182187
decl: ast::fn_decl,
183188
body: ast::blk,
@@ -191,20 +196,20 @@ fn check_fn(ccx: @crate_ctxt,
191196
// types with free ones. The free region references will be bound
192197
// the node_id of the body block.
193198

194-
let {isr, self_ty, fn_ty} = {
199+
let {isr, self_info, fn_ty} = {
195200
let old_isr = option::map_default(old_fcx, @nil,
196201
|fcx| fcx.in_scope_regions);
197-
replace_bound_regions_in_fn_ty(tcx, old_isr, self_ty, fn_ty,
202+
replace_bound_regions_in_fn_ty(tcx, old_isr, self_info, fn_ty,
198203
|br| ty::re_free(body.node.id, br))
199204
};
200205

201206
let arg_tys = fn_ty.inputs.map(|a| a.ty);
202207
let ret_ty = fn_ty.output;
203208

204-
debug!{"check_fn(arg_tys=%?, ret_ty=%?, self_ty=%?)",
209+
debug!{"check_fn(arg_tys=%?, ret_ty=%?, self_info.self_ty=%?)",
205210
arg_tys.map(|a| ty_to_str(tcx, a)),
206211
ty_to_str(tcx, ret_ty),
207-
option::map(self_ty, |st| ty_to_str(tcx, st))};
212+
option::map(self_info, |s| ty_to_str(tcx, s.self_ty))};
208213

209214
// ______________________________________________________________________
210215
// Create the function context. This is either derived from scratch or,
@@ -237,7 +242,7 @@ fn check_fn(ccx: @crate_ctxt,
237242
}
238243
} else { none };
239244

240-
@fn_ctxt_({self_ty: self_ty,
245+
@fn_ctxt_({self_info: self_info,
241246
ret_ty: ret_ty,
242247
indirect_ret_ty: indirect_ret_ty,
243248
purity: purity,
@@ -359,11 +364,12 @@ fn check_fn(ccx: @crate_ctxt,
359364
}
360365
}
361366

362-
fn check_method(ccx: @crate_ctxt, method: @ast::method, self_ty: ty::t) {
363-
check_bare_fn(ccx, method.decl, method.body, method.id, some(self_ty));
367+
fn check_method(ccx: @crate_ctxt, method: @ast::method,
368+
self_info: self_info) {
369+
check_bare_fn(ccx, method.decl, method.body, method.id, some(self_info));
364370
}
365371

366-
fn check_class_member(ccx: @crate_ctxt, class_t: ty::t,
372+
fn check_class_member(ccx: @crate_ctxt, class_t: self_info,
367373
cm: @ast::class_member) {
368374
alt cm.node {
369375
ast::instance_var(_,t,_,_,_) { }
@@ -409,20 +415,22 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
409415
let rp = ccx.tcx.region_paramd_items.contains_key(it.id);
410416
debug!{"item_impl %s with id %d rp %b",
411417
*it.ident, it.id, rp};
412-
let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty);
413-
for ms.each |m| { check_method(ccx, m, self_ty);}
418+
let self_info = {self_ty: ccx.to_ty(rscope::type_rscope(rp), ty),
419+
node_id: it.id };
420+
for ms.each |m| { check_method(ccx, m, self_info);}
414421
}
415422
ast::item_class(tps, traits, members, m_ctor, m_dtor) {
416423
let tcx = ccx.tcx;
417-
let class_t = ty::node_id_to_type(tcx, it.id);
424+
let class_t = {self_ty: ty::node_id_to_type(tcx, it.id),
425+
node_id: it.id};
418426

419427
do option::iter(m_ctor) |ctor| {
420428
// typecheck the ctor
421429
check_bare_fn(ccx, ctor.node.dec,
422430
ctor.node.body, ctor.node.id,
423431
some(class_t));
424432
// Write the ctor's self's type
425-
write_ty_to_tcx(tcx, ctor.node.self_id, class_t);
433+
write_ty_to_tcx(tcx, ctor.node.self_id, class_t.self_ty);
426434
}
427435

428436
do option::iter(m_dtor) |dtor| {
@@ -431,7 +439,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
431439
dtor.node.body, dtor.node.id,
432440
some(class_t));
433441
// Write the dtor's self's type
434-
write_ty_to_tcx(tcx, dtor.node.self_id, class_t);
442+
write_ty_to_tcx(tcx, dtor.node.self_id, class_t.self_ty);
435443
};
436444

437445
// typecheck the members
@@ -1123,7 +1131,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
11231131

11241132
fcx.write_ty(expr.id, fty);
11251133

1126-
check_fn(fcx.ccx, fcx.self_ty, fn_ty, decl, body,
1134+
check_fn(fcx.ccx, fcx.self_info, fn_ty, decl, body,
11271135
is_loop_body, some(fcx));
11281136
}
11291137

@@ -2145,12 +2153,12 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
21452153
ret no_params(typ);
21462154
}
21472155
ast::def_self(_) {
2148-
alt fcx.self_ty {
2149-
some(self_ty) {
2150-
ret no_params(self_ty);
2156+
alt fcx.self_info {
2157+
some(self_info) {
2158+
ret no_params(self_info.self_ty);
21512159
}
21522160
none {
2153-
fcx.ccx.tcx.sess.span_bug(sp, ~"def_self with no self_ty");
2161+
fcx.ccx.tcx.sess.span_bug(sp, ~"def_self with no self_info");
21542162
}
21552163
}
21562164
}

trunk/src/rustc/middle/typeck/check/regionmanip.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ import syntax::print::pprust::{expr_to_str};
55
fn replace_bound_regions_in_fn_ty(
66
tcx: ty::ctxt,
77
isr: isr_alist,
8-
self_ty: option<ty::t>,
8+
self_info: option<self_info>,
99
fn_ty: ty::fn_ty,
10-
mapf: fn(ty::bound_region) -> ty::region) -> {isr: isr_alist,
11-
self_ty: option<ty::t>,
12-
fn_ty: ty::fn_ty} {
10+
mapf: fn(ty::bound_region) -> ty::region) ->
11+
{isr: isr_alist, self_info: option<self_info>, fn_ty: ty::fn_ty} {
12+
13+
// Take self_info apart; the self_ty part is the only one we want
14+
// to update here.
15+
let self_ty = alt self_info {
16+
some(s) { some(s.self_ty) }
17+
none { none }
18+
};
1319

1420
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
21+
1522
for self_ty.each |t| { vec::push(all_tys, t) }
1623

17-
debug!{"replace_bound_regions_in_fn_ty(self_ty=%?, fn_ty=%s, all_tys=%?)",
24+
debug!{"replace_bound_regions_in_fn_ty(self_info.self_ty=%?, fn_ty=%s, \
25+
all_tys=%?)",
1826
self_ty.map(|t| ty_to_str(tcx, t)),
1927
ty_to_str(tcx, ty::mk_fn(tcx, fn_ty)),
2028
all_tys.map(|t| ty_to_str(tcx, t))};
@@ -29,12 +37,27 @@ fn replace_bound_regions_in_fn_ty(
2937
});
3038
let t_self = self_ty.map(|t| replace_bound_regions(tcx, isr, t));
3139

32-
debug!{"result of replace_bound_regions_in_fn_ty: self_ty=%?, fn_ty=%s",
40+
debug!{"result of replace_bound_regions_in_fn_ty: self_info.self_ty=%?, \
41+
fn_ty=%s",
3342
t_self.map(|t| ty_to_str(tcx, t)),
3443
ty_to_str(tcx, t_fn)};
3544

45+
46+
// Glue updated self_ty back together with its original node_id.
47+
let new_self_info = alt self_info {
48+
some(s) {
49+
alt check t_self {
50+
some(t) {
51+
some({self_ty: t, node_id: s.node_id})
52+
}
53+
// this 'none' case shouldn't happen
54+
}
55+
}
56+
none { none }
57+
};
58+
3659
ret {isr: isr,
37-
self_ty: t_self,
60+
self_info: new_self_info,
3861
fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) {o} }};
3962

4063

0 commit comments

Comments
 (0)