Skip to content

Commit 6ebc562

Browse files
committed
---
yaml --- r: 60055 b: refs/heads/master c: 6af447a h: refs/heads/master i: 60053: b8b37aa 60051: 642e52c 60047: 868bb47 v: v3
1 parent ab75457 commit 6ebc562

File tree

8 files changed

+105
-72
lines changed

8 files changed

+105
-72
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: 11f7cb26c27c3eb3af3f7ef4f9cdb85327e6e030
2+
refs/heads/master: 6af447a271a52d0eb4b5e8e3d66e7aede967ac52
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2d28d645422c1617be58c8ca7ad9a457264ca850
55
refs/heads/try: c50a9d5b664478e533ba1d1d353213d70c8ad589

trunk/src/librustc/middle/trans/datum.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,11 @@ pub impl Datum {
548548
}
549549

550550
fn to_rptr(&self, bcx: block) -> Datum {
551-
//! Returns a new datum of region-pointer type containing the
552-
//! the same ptr as this datum (after converting to by-ref
553-
//! using `to_ref_llval()`).
551+
//!
552+
//
553+
// Returns a new datum of region-pointer type containing the
554+
// the same ptr as this datum (after converting to by-ref
555+
// using `to_ref_llval()`).
554556

555557
// Convert to ref, yielding lltype *T. Then create a Rust
556558
// type &'static T (which translates to *T). Construct new

trunk/src/librustc/middle/trans/expr.rs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,30 @@ fn drop_and_cancel_clean(bcx: block, dat: Datum) -> block {
183183

184184
pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock {
185185
debug!("trans_to_datum(expr=%s)", bcx.expr_to_str(expr));
186-
187-
let mut bcx = bcx;
188-
let mut datum = unpack_datum!(bcx, trans_to_datum_unadjusted(bcx, expr));
189-
let adjustment = match bcx.tcx().adjustments.find_copy(&expr.id) {
190-
None => { return DatumBlock {bcx: bcx, datum: datum}; }
191-
Some(adj) => { adj }
192-
};
193-
debug!("unadjusted datum: %s", datum.to_str(bcx.ccx()));
194-
match *adjustment {
195-
AutoAddEnv(*) => {
196-
datum = unpack_datum!(bcx, add_env(bcx, expr, datum));
186+
return match bcx.tcx().adjustments.find(&expr.id) {
187+
None => {
188+
trans_to_datum_unadjusted(bcx, expr)
189+
}
190+
Some(&@AutoAddEnv(*)) => {
191+
let mut bcx = bcx;
192+
let datum = unpack_datum!(bcx, {
193+
trans_to_datum_unadjusted(bcx, expr)
194+
});
195+
add_env(bcx, expr, datum)
197196
}
198-
AutoDerefRef(ref adj) => {
197+
Some(&@AutoDerefRef(ref adj)) => {
198+
let mut bcx = bcx;
199+
let mut datum = unpack_datum!(bcx, {
200+
trans_to_datum_unadjusted(bcx, expr)
201+
});
202+
203+
debug!("unadjusted datum: %s", datum.to_str(bcx.ccx()));
204+
199205
if adj.autoderefs > 0 {
200-
datum =
201-
unpack_datum!(
202-
bcx,
203-
datum.autoderef(bcx, expr.span,
204-
expr.id, adj.autoderefs));
206+
let DatumBlock { bcx: new_bcx, datum: new_datum } =
207+
datum.autoderef(bcx, expr.span, expr.id, adj.autoderefs);
208+
datum = new_datum;
209+
bcx = new_bcx;
205210
}
206211

207212
datum = match adj.autoref {
@@ -219,31 +224,23 @@ pub fn trans_to_datum(bcx: block, expr: @ast::expr) -> DatumBlock {
219224
unpack_datum!(bcx, auto_slice_and_ref(bcx, expr, datum))
220225
}
221226
Some(AutoBorrowFn(*)) => {
222-
let adjusted_ty = ty::adjust_ty(bcx.tcx(), expr.span,
223-
datum.ty, Some(adjustment));
224-
unpack_datum!(bcx, auto_borrow_fn(bcx, adjusted_ty, datum))
227+
// currently, all closure types are
228+
// represented precisely the same, so no
229+
// runtime adjustment is required:
230+
datum
225231
}
226232
};
233+
234+
debug!("after adjustments, datum=%s", datum.to_str(bcx.ccx()));
235+
236+
return DatumBlock {bcx: bcx, datum: datum};
227237
}
228-
}
229-
debug!("after adjustments, datum=%s", datum.to_str(bcx.ccx()));
230-
return DatumBlock {bcx: bcx, datum: datum};
238+
};
231239

232240
fn auto_ref(bcx: block, datum: Datum) -> DatumBlock {
233241
DatumBlock {bcx: bcx, datum: datum.to_rptr(bcx)}
234242
}
235243

236-
fn auto_borrow_fn(bcx: block,
237-
adjusted_ty: ty::t,
238-
datum: Datum) -> DatumBlock {
239-
// Currently, all closure types are represented precisely the
240-
// same, so no runtime adjustment is required, but we still
241-
// must patchup the type.
242-
DatumBlock {bcx: bcx,
243-
datum: Datum {val: datum.val, ty: adjusted_ty,
244-
mode: datum.mode, source: datum.source}}
245-
}
246-
247244
fn auto_slice(bcx: block, expr: @ast::expr, datum: Datum) -> DatumBlock {
248245
// This is not the most efficient thing possible; since slices
249246
// are two words it'd be better if this were compiled in

trunk/src/librustc/middle/ty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,20 +2893,20 @@ pub fn expr_ty_adjusted(cx: ctxt, expr: @ast::expr) -> t {
28932893
*/
28942894

28952895
let unadjusted_ty = expr_ty(cx, expr);
2896-
adjust_ty(cx, expr.span, unadjusted_ty, cx.adjustments.find_copy(&expr.id))
2896+
adjust_ty(cx, expr.span, unadjusted_ty, cx.adjustments.find(&expr.id))
28972897
}
28982898

28992899
pub fn adjust_ty(cx: ctxt,
29002900
span: span,
29012901
unadjusted_ty: ty::t,
2902-
adjustment: Option<@AutoAdjustment>) -> ty::t
2902+
adjustment: Option<&@AutoAdjustment>) -> ty::t
29032903
{
29042904
/*! See `expr_ty_adjusted` */
29052905

29062906
return match adjustment {
29072907
None => unadjusted_ty,
29082908

2909-
Some(@AutoAddEnv(r, s)) => {
2909+
Some(&@AutoAddEnv(r, s)) => {
29102910
match ty::get(unadjusted_ty).sty {
29112911
ty::ty_bare_fn(ref b) => {
29122912
ty::mk_closure(
@@ -2924,7 +2924,7 @@ pub fn adjust_ty(cx: ctxt,
29242924
}
29252925
}
29262926

2927-
Some(@AutoDerefRef(ref adj)) => {
2927+
Some(&@AutoDerefRef(ref adj)) => {
29282928
let mut adjusted_ty = unadjusted_ty;
29292929

29302930
for uint::range(0, adj.autoderefs) |i| {

trunk/src/librustc/middle/typeck/check/regionck.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,37 +118,22 @@ pub impl Rcx {
118118
}
119119

120120
/// Try to resolve the type for the given node.
121-
#[config(stage0)]
122121
fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t {
123122
let ty_unadjusted = self.resolve_node_type(expr.id);
124123
if ty::type_is_error(ty_unadjusted) || ty::type_is_bot(ty_unadjusted) {
125124
ty_unadjusted
126125
} else {
127126
let tcx = self.fcx.tcx();
128127
let adjustments = self.fcx.inh.adjustments;
129-
match adjustments.find_copy(&expr.id) {
128+
match adjustments.find(&expr.id) {
130129
None => ty_unadjusted,
131-
Some(adjustment) => {
132-
ty::adjust_ty(tcx, expr.span, ty_unadjusted,
133-
Some(adjustment))
130+
Some(&adjustment) => {
131+
// FIXME(#3850) --- avoid region scoping errors
132+
ty::adjust_ty(tcx, expr.span, ty_unadjusted, Some(&adjustment))
134133
}
135134
}
136135
}
137136
}
138-
139-
/// Try to resolve the type for the given node.
140-
#[config(not(stage0))]
141-
fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t {
142-
let ty_unadjusted = self.resolve_node_type(expr.id);
143-
if ty::type_is_error(ty_unadjusted) || ty::type_is_bot(ty_unadjusted) {
144-
ty_unadjusted
145-
} else {
146-
let tcx = self.fcx.tcx();
147-
let adjustments = self.fcx.inh.adjustments;
148-
ty::adjust_ty(tcx, expr.span, ty_unadjusted,
149-
adjustments.find_copy(&expr.id))
150-
}
151-
}
152137
}
153138

154139
pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
@@ -665,7 +650,7 @@ fn constrain_regions_in_type_of_node(
665650
// is going to fail anyway, so just stop here and let typeck
666651
// report errors later on in the writeback phase.
667652
let ty0 = rcx.resolve_node_type(id);
668-
let adjustment = rcx.fcx.inh.adjustments.find_copy(&id);
653+
let adjustment = rcx.fcx.inh.adjustments.find(&id);
669654
let ty = ty::adjust_ty(tcx, span, ty0, adjustment);
670655
debug!("constrain_regions_in_type_of_node(\
671656
ty=%s, ty0=%s, id=%d, minimum_lifetime=%?, adjustment=%?)",

trunk/src/rt/rust_task.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@ rust_task::delete_this()
7676
assert(ref_count == 0); // ||
7777
// (ref_count == 1 && this == sched->root_task));
7878

79-
// The borrow list should be freed in the task annihilator
80-
assert(!borrow_list);
79+
if (borrow_list) {
80+
// NOTE should free borrow_list from within rust code!
81+
// If there is a pointer in there, it is a ~[BorrowRecord] pointer,
82+
// which are currently allocated with LIBC malloc/free. But this is
83+
// not really the right way to do this, we should be freeing this
84+
// pointer from Rust code.
85+
free(borrow_list);
86+
borrow_list = NULL;
87+
}
8188

8289
sched_loop->release_task(this);
8390
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests that the scope of the pointer returned from `get()` is
12+
// limited to the deref operation itself, and does not infect the
13+
// block as a whole.
14+
15+
struct Box {
16+
x: uint
17+
}
18+
19+
impl Box {
20+
fn get<'a>(&'a self) -> &'a uint {
21+
&self.x
22+
}
23+
fn set(&mut self, x: uint) {
24+
self.x = x;
25+
}
26+
}
27+
28+
fn fun1() {
29+
// in the past, borrow checker behaved differently when
30+
// init and decl of `v` were distinct
31+
let v;
32+
let mut box = Box {x: 0};
33+
box.set(22);
34+
v = *box.get();
35+
box.set(v+1);
36+
assert_eq!(23, *box.get());
37+
}
38+
39+
fn fun2() {
40+
let mut box = Box {x: 0};
41+
box.set(22);
42+
let v = *box.get();
43+
box.set(v+1);
44+
assert_eq!(23, *box.get());
45+
}
46+
47+
pub fn main() {
48+
fun1();
49+
fun2();
50+
}

trunk/src/test/run-pass/issue-6141-leaking-owned-fn.rs

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

0 commit comments

Comments
 (0)