Skip to content

Commit 652b312

Browse files
committed
more sound treatment of fn& regions; change all & to be distinct
1 parent 8ee79c7 commit 652b312

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+229
-133
lines changed

src/libcore/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pure fn get<T: copy>(opt: option<T>) -> T {
2929
}
3030
}
3131

32-
pure fn get_ref<T>(opt: &option<T>) -> &T {
32+
pure fn get_ref<T>(opt: &r/option<T>) -> &r/T {
3333
/*!
3434
* Gets an immutable reference to the value inside an option.
3535
*

src/libstd/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<T: const send> &rw_arc<T> {
361361
}
362362
363363
/// To be called inside of the write_downgrade block.
364-
fn downgrade(+token: rw_write_mode<T>) -> rw_read_mode<T> {
364+
fn downgrade(+token: rw_write_mode/&a<T>) -> rw_read_mode/&a<T> {
365365
// The rwlock should assert that the token belongs to us for us.
366366
let state = unsafe { get_shared_immutable_state(&self.x) };
367367
let rw_write_mode((data, t, _poison)) = token;

src/libstd/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl &rwlock {
538538
}
539539

540540
/// To be called inside of the write_downgrade block.
541-
fn downgrade(+token: rwlock_write_mode) -> rwlock_read_mode {
541+
fn downgrade(+token: rwlock_write_mode/&a) -> rwlock_read_mode/&a {
542542
if !ptr::ref_eq(self, token.lock) {
543543
fail ~"Can't downgrade() with a different rwlock's write_mode!";
544544
}

src/libsyntax/ast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ enum def {
8484
def_ty_param(def_id, uint),
8585
def_binding(node_id, binding_mode),
8686
def_use(def_id),
87-
def_upvar(node_id /* local id of closed over var */,
87+
def_upvar(node_id /* id of closed over var */,
8888
@def /* closed over def */,
89-
node_id /* expr node that creates the closure */),
89+
node_id /* expr node that creates the closure */,
90+
node_id /* id for the block/body of the closure expr */),
9091
def_class(def_id, bool /* has constructor */),
9192
def_typaram_binder(node_id), /* class, impl or trait that has ty params */
9293
def_region(node_id),

src/libsyntax/ast_util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pure fn def_id_of_def(d: def) -> def_id {
6060
id
6161
}
6262
def_arg(id, _) | def_local(id, _) | def_self(id) |
63-
def_upvar(id, _, _) | def_binding(id, _) | def_region(id)
63+
def_upvar(id, _, _, _) | def_binding(id, _) | def_region(id)
6464
| def_typaram_binder(id) | def_label(id) => {
6565
local_def(id)
6666
}
@@ -381,9 +381,9 @@ impl inlined_item: inlined_item_utils {
381381
referring to a def_self */
382382
fn is_self(d: ast::def) -> bool {
383383
match d {
384-
def_self(_) => true,
385-
def_upvar(_, d, _) => is_self(*d),
386-
_ => false
384+
def_self(_) => true,
385+
def_upvar(_, d, _, _) => is_self(*d),
386+
_ => false
387387
}
388388
}
389389

src/rustc/driver/driver.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
207207

208208
if upto == cu_typeck { return {crate: crate, tcx: some(ty_cx)}; }
209209

210-
time(time_passes, ~"block-use checking", ||
211-
middle::block_use::check_crate(ty_cx, crate));
212-
213210
time(time_passes, ~"loop checking", ||
214211
middle::check_loop::check_crate(ty_cx, crate));
215212

src/rustc/metadata/tydecode.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ fn parse_substs(st: @pstate, conv: conv_did) -> ty::substs {
128128
fn parse_bound_region(st: @pstate) -> ty::bound_region {
129129
match check next(st) {
130130
's' => ty::br_self,
131-
'a' => ty::br_anon,
131+
'a' => {
132+
let id = parse_int(st) as uint;
133+
assert next(st) == '|';
134+
ty::br_anon(id)
135+
}
132136
'[' => ty::br_named(@parse_str(st, ']')),
133137
'c' => {
134138
let id = parse_int(st);

src/rustc/metadata/tyencode.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ fn enc_region(w: io::Writer, cx: @ctxt, r: ty::region) {
154154
fn enc_bound_region(w: io::Writer, br: ty::bound_region) {
155155
match br {
156156
ty::br_self => w.write_char('s'),
157-
ty::br_anon => w.write_char('a'),
157+
ty::br_anon(idx) => {
158+
w.write_char('a');
159+
w.write_uint(idx);
160+
w.write_char('|');
161+
}
158162
ty::br_named(s) => {
159163
w.write_char('[');
160164
w.write_str(*s);

src/rustc/middle/astencode.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,11 @@ impl ast::def: tr {
363363
ast::def_ty_param(did, v) => ast::def_ty_param(did.tr(xcx), v),
364364
ast::def_binding(nid, bm) => ast::def_binding(xcx.tr_id(nid), bm),
365365
ast::def_use(did) => ast::def_use(did.tr(xcx)),
366-
ast::def_upvar(nid1, def, nid2) => {
367-
ast::def_upvar(xcx.tr_id(nid1), @(*def).tr(xcx), xcx.tr_id(nid2))
366+
ast::def_upvar(nid1, def, nid2, nid3) => {
367+
ast::def_upvar(xcx.tr_id(nid1),
368+
@(*def).tr(xcx),
369+
xcx.tr_id(nid2),
370+
xcx.tr_id(nid3))
368371
}
369372
ast::def_class(did, has_constructor) => {
370373
ast::def_class(did.tr(xcx), has_constructor)

src/rustc/middle/block_use.rs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/rustc/middle/freevars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn collect_freevars(def_map: resolve3::DefMap, blk: ast::blk)
5555
let mut def = df;
5656
while i < depth {
5757
match copy def {
58-
ast::def_upvar(_, inner, _) => { def = *inner; }
58+
ast::def_upvar(_, inner, _, _) => { def = *inner; }
5959
_ => break
6060
}
6161
i += 1;

src/rustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn with_appropriate_checker(cx: ctx, id: node_id, b: fn(check_fn)) {
103103
104104
// copied in data must be copyable, but moved in data can be anything
105105
let is_implicit = fv.is_some();
106-
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
106+
if !is_move { check_copy(cx, id, var_t, sp, is_implicit); }
107107
108108
// check that only immutable variables are implicitly copied in
109109
for fv.each |fv| {
@@ -426,7 +426,7 @@ fn check_imm_free_var(cx: ctx, def: def, sp: span) {
426426
}
427427
}
428428
}
429-
def_upvar(_, def1, _) => {
429+
def_upvar(_, def1, _, _) => {
430430
check_imm_free_var(cx, *def1, sp);
431431
}
432432
def_binding(*) | def_self(*) => { /*ok*/ }

src/rustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl &mem_categorization_ctxt {
378378
mutbl:m_imm, ty:expr_ty}
379379
}
380380

381-
ast::def_upvar(upvid, inner, fn_node_id) => {
381+
ast::def_upvar(upvid, inner, fn_node_id, _) => {
382382
let ty = ty::node_id_to_type(self.tcx, fn_node_id);
383383
let proto = ty::ty_fn_proto(ty);
384384
match proto {

src/rustc/middle/resolve3.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ enum RibKind {
199199

200200
// We passed through a function scope at the given node ID. Translate
201201
// upvars as appropriate.
202-
FunctionRibKind(node_id),
202+
FunctionRibKind(node_id /* func id */, node_id /* body id */),
203203

204204
// We passed through a class, impl, or trait and are now in one of its
205205
// methods. Allow references to ty params that that class, impl or trait
@@ -2752,11 +2752,12 @@ struct Resolver {
27522752
NormalRibKind => {
27532753
// Nothing to do. Continue.
27542754
}
2755-
FunctionRibKind(function_id) => {
2755+
FunctionRibKind(function_id, body_id) => {
27562756
if !is_ty_param {
27572757
def = def_upvar(def_id_of_def(def).node,
27582758
@def,
2759-
function_id);
2759+
function_id,
2760+
body_id);
27602761
}
27612762
}
27622763
MethodRibKind(item_id, method_id) => {
@@ -4164,7 +4165,7 @@ struct Resolver {
41644165

41654166
expr_fn(_, fn_decl, block, capture_clause) |
41664167
expr_fn_block(fn_decl, block, capture_clause) => {
4167-
self.resolve_function(FunctionRibKind(expr.id),
4168+
self.resolve_function(FunctionRibKind(expr.id, block.node.id),
41684169
some(@fn_decl),
41694170
NoTypeParameters,
41704171
block,

src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ fn trans_local_var(cx: block, def: ast::def) -> local_var_result {
24642464
}
24652465
}
24662466
match def {
2467-
ast::def_upvar(nid, _, _) => {
2467+
ast::def_upvar(nid, _, _, _) => {
24682468
assert (cx.fcx.llupvars.contains_key(nid));
24692469
return { val: cx.fcx.llupvars.get(nid), kind: lv_owned };
24702470
}

src/rustc/middle/trans/foreign.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,8 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
961961
let fty = ty::mk_fn(bcx.tcx(), {
962962
purity: ast::impure_fn,
963963
proto:
964-
ty::proto_vstore(ty::vstore_slice(ty::re_bound(ty::br_anon))),
964+
ty::proto_vstore(ty::vstore_slice(
965+
ty::re_bound(ty::br_anon(0)))),
965966
bounds: @~[],
966967
inputs: ~[{
967968
mode: ast::expl(ast::by_val),

src/rustc/middle/tstate/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use {
525525
expr_path(p) {
526526
match tcx.def_map.find(e.id) {
527527
some(def_local(nid, _)) | some(def_arg(nid, _)) |
528-
some(def_binding(nid, _)) | some(def_upvar(nid, _, _)) {
528+
some(def_binding(nid, _)) | some(def_upvar(nid, _, _, _)) {
529529
return @respan(p.span,
530530
carg_ident({ident: p.idents[0], node: nid}));
531531
}

src/rustc/middle/ty.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ enum bound_region {
377377
/// The self region for classes, impls (&T in a type defn or &self/T)
378378
br_self,
379379

380-
/// Anonymous region parameter for a given fn (&T)
381-
br_anon,
380+
/// An anonymous region parameter for a given fn (&T)
381+
br_anon(uint),
382382

383383
/// Named region parameters for functions (a in &a/T)
384384
br_named(ast::ident),
@@ -2192,9 +2192,10 @@ fn index_sty(cx: ctxt, sty: &sty) -> option<mt> {
21922192
pure fn hash_bound_region(br: &bound_region) -> uint {
21932193
match *br { // no idea if this is any good
21942194
ty::br_self => 0u,
2195-
ty::br_anon => 1u,
2196-
ty::br_named(str) => str::hash(str),
2197-
ty::br_cap_avoid(id, br) => id as uint | hash_bound_region(br)
2195+
ty::br_anon(idx) => 1u | (idx << 2),
2196+
ty::br_named(str) => 2u | (str::hash(str) << 2),
2197+
ty::br_cap_avoid(id, br) =>
2198+
3u | (id as uint << 2) | hash_bound_region(br)
21982199
}
21992200
}
22002201

src/rustc/middle/typeck/check.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
23042304
ast::def_ty(_) | ast::def_prim_ty(_) => {
23052305
fcx.ccx.tcx.sess.span_fatal(sp, ~"expected value but found type");
23062306
}
2307-
ast::def_upvar(_, inner, _) => {
2307+
ast::def_upvar(_, inner, _, _) => {
23082308
return ty_param_bounds_and_ty_for_def(fcx, sp, *inner);
23092309
}
23102310
ast::def_ty_param(did, n) => {
@@ -2513,7 +2513,8 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
25132513
let fty = ty::mk_fn(ccx.tcx, {
25142514
purity: ast::impure_fn,
25152515
proto:
2516-
ty::proto_vstore(ty::vstore_slice(ty::re_bound(ty::br_anon))),
2516+
ty::proto_vstore(ty::vstore_slice(
2517+
ty::re_bound(ty::br_anon(0)))),
25172518
bounds: @~[],
25182519
inputs: ~[{
25192520
mode: ast::expl(ast::by_val),

0 commit comments

Comments
 (0)