Skip to content

Commit 7139566

Browse files
committed
---
yaml --- r: 140235 b: refs/heads/try2 c: 38f93f2 h: refs/heads/master i: 140233: a82c22f 140231: a51b9ad v: v3
1 parent 1ed6136 commit 7139566

File tree

9 files changed

+176
-118
lines changed

9 files changed

+176
-118
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3159335ac308d9e3a2d3ada3b9354bf160debbdc
8+
refs/heads/try2: 38f93f2121e111dd9dd149f5bdeaa9a34a4e42f1
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/num/int-template.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ impl Mul<T,T> for T {
200200
#[inline(always)]
201201
fn mul(&self, other: &T) -> T { *self * *other }
202202
}
203+
204+
#[cfg(notest)]
203205
impl Quot<T,T> for T {
204206
///
205207
/// Returns the integer quotient, truncated towards 0. As this behaviour reflects
@@ -222,6 +224,8 @@ impl Quot<T,T> for T {
222224
#[inline(always)]
223225
fn quot(&self, other: &T) -> T { *self / *other }
224226
}
227+
228+
#[cfg(notest)]
225229
impl Rem<T,T> for T {
226230
///
227231
/// Returns the integer remainder after division, satisfying:

branches/try2/src/libcore/num/uint-template.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ impl Mul<T,T> for T {
165165
#[inline(always)]
166166
fn mul(&self, other: &T) -> T { *self * *other }
167167
}
168+
169+
#[cfg(notest)]
168170
impl Quot<T,T> for T {
169171
#[inline(always)]
170172
fn quot(&self, other: &T) -> T { *self / *other }
171173
}
174+
175+
#[cfg(notest)]
172176
impl Rem<T,T> for T {
173177
#[inline(always)]
174178
fn rem(&self, other: &T) -> T { *self % *other }

branches/try2/src/libcore/unstable/lang.rs

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
//! Runtime calls emitted by the compiler.
1212
13+
use uint;
1314
use cast::transmute;
1415
use libc::{c_char, c_uchar, c_void, size_t, uintptr_t, c_int, STDERR_FILENO};
1516
use managed::raw::BoxRepr;
@@ -22,10 +23,9 @@ use task::rt::rust_get_task;
2223
#[allow(non_camel_case_types)]
2324
pub type rust_task = c_void;
2425

25-
#[cfg(target_word_size = "32")]
26-
pub static FROZEN_BIT: uint = 0x80000000;
27-
#[cfg(target_word_size = "64")]
28-
pub static FROZEN_BIT: uint = 0x8000000000000000;
26+
pub static FROZEN_BIT: uint = 1 << (uint::bits - 1);
27+
pub static MUT_BIT: uint = 1 << (uint::bits - 2);
28+
static ALL_BITS: uint = FROZEN_BIT | MUT_BIT;
2929

3030
pub mod rustrt {
3131
use unstable::lang::rust_task;
@@ -196,21 +196,51 @@ pub unsafe fn borrow_as_imm(a: *u8) {
196196
(*a).header.ref_count |= FROZEN_BIT;
197197
}
198198

199+
fn add_borrow_to_task_list(a: *mut BoxRepr, file: *c_char, line: size_t) {
200+
do swap_task_borrow_list |borrow_list| {
201+
let mut borrow_list = borrow_list;
202+
borrow_list.push(BorrowRecord {box: a, file: file, line: line});
203+
borrow_list
204+
}
205+
}
206+
199207
#[cfg(not(stage0))]
200208
#[lang="borrow_as_imm"]
201209
#[inline(always)]
202-
pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) {
210+
pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
203211
let a: *mut BoxRepr = transmute(a);
204-
(*a).header.ref_count |= FROZEN_BIT;
205-
if ::rt::env::get().debug_borrows {
206-
do swap_task_borrow_list |borrow_list| {
207-
let mut borrow_list = borrow_list;
208-
borrow_list.push(BorrowRecord {box: a, file: file, line: line});
209-
borrow_list
212+
213+
let ref_count = (*a).header.ref_count;
214+
if (ref_count & MUT_BIT) != 0 {
215+
fail_borrowed(a, file, line);
216+
} else {
217+
(*a).header.ref_count |= FROZEN_BIT;
218+
if ::rt::env::get().debug_borrows {
219+
add_borrow_to_list(a, file, line);
210220
}
211221
}
222+
ref_count
212223
}
213224

225+
#[cfg(not(stage0))]
226+
#[lang="borrow_as_mut"]
227+
#[inline(always)]
228+
pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
229+
let a: *mut BoxRepr = transmute(a);
230+
231+
let ref_count = (*a).header.ref_count;
232+
if (ref_count & (MUT_BIT|FROZEN_BIT)) != 0 {
233+
fail_borrowed(a, file, line);
234+
} else {
235+
(*a).header.ref_count |= (MUT_BIT|FROZEN_BIT);
236+
if ::rt::env::get().debug_borrows {
237+
add_borrow_to_list(a, file, line);
238+
}
239+
}
240+
ref_count
241+
}
242+
243+
#[cfg(stage0)]
214244
#[lang="return_to_mut"]
215245
#[inline(always)]
216246
pub unsafe fn return_to_mut(a: *u8) {
@@ -222,6 +252,21 @@ pub unsafe fn return_to_mut(a: *u8) {
222252
}
223253
}
224254

255+
#[cfg(not(stage0))]
256+
#[lang="return_to_mut"]
257+
#[inline(always)]
258+
pub unsafe fn return_to_mut(a: *u8, old_ref_count: uint) {
259+
// Sometimes the box is null, if it is conditionally frozen.
260+
// See e.g. #4904.
261+
if !a.is_null() {
262+
let a: *mut BoxRepr = transmute(a);
263+
264+
let ref_count = (*a).header.ref_count & !ALL_BITS;
265+
let old_bits = old_ref_count & ALL_BITS;
266+
(*a).header.ref_count = ref_count | old_bits;
267+
}
268+
}
269+
225270
#[cfg(stage0)]
226271
#[lang="check_not_borrowed"]
227272
#[inline(always)]

branches/try2/src/librustc/middle/lang_items.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ pub enum LangItem {
6666
MallocFnLangItem, // 28
6767
FreeFnLangItem, // 29
6868
BorrowAsImmFnLangItem, // 30
69-
ReturnToMutFnLangItem, // 31
70-
CheckNotBorrowedFnLangItem, // 32
71-
StrDupUniqFnLangItem, // 33
69+
BorrowAsMutFnLangItem, // 31
70+
ReturnToMutFnLangItem, // 32
71+
CheckNotBorrowedFnLangItem, // 33
72+
StrDupUniqFnLangItem, // 34
7273

73-
StartFnLangItem, // 34
74+
StartFnLangItem, // 35
7475
}
7576

7677
pub struct LanguageItems {
@@ -128,11 +129,12 @@ pub impl LanguageItems {
128129
28 => "malloc",
129130
29 => "free",
130131
30 => "borrow_as_imm",
131-
31 => "return_to_mut",
132-
32 => "check_not_borrowed",
133-
33 => "strdup_uniq",
132+
31 => "borrow_as_mut",
133+
32 => "return_to_mut",
134+
33 => "check_not_borrowed",
135+
34 => "strdup_uniq",
134136

135-
34 => "start",
137+
35 => "start",
136138

137139
_ => "???"
138140
}
@@ -237,6 +239,9 @@ pub impl LanguageItems {
237239
pub fn borrow_as_imm_fn(&const self) -> def_id {
238240
self.items[BorrowAsImmFnLangItem as uint].get()
239241
}
242+
pub fn borrow_as_mut_fn(&const self) -> def_id {
243+
self.items[BorrowAsMutFnLangItem as uint].get()
244+
}
240245
pub fn return_to_mut_fn(&const self) -> def_id {
241246
self.items[ReturnToMutFnLangItem as uint].get()
242247
}
@@ -292,6 +297,7 @@ fn LanguageItemCollector(crate: @crate,
292297
item_refs.insert(@~"malloc", MallocFnLangItem as uint);
293298
item_refs.insert(@~"free", FreeFnLangItem as uint);
294299
item_refs.insert(@~"borrow_as_imm", BorrowAsImmFnLangItem as uint);
300+
item_refs.insert(@~"borrow_as_mut", BorrowAsMutFnLangItem as uint);
295301
item_refs.insert(@~"return_to_mut", ReturnToMutFnLangItem as uint);
296302
item_refs.insert(@~"check_not_borrowed",
297303
CheckNotBorrowedFnLangItem as uint);

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -991,63 +991,30 @@ pub fn get_landing_pad(bcx: block) -> BasicBlockRef {
991991
return pad_bcx.llbb;
992992
}
993993

994-
// Arranges for the value found in `*root_loc` to be dropped once the scope
995-
// associated with `scope_id` exits. This is used to keep boxes live when
996-
// there are extant region pointers pointing at the interior.
997-
//
998-
// Note that `root_loc` is not the value itself but rather a pointer to the
999-
// value. Generally it in alloca'd value. The reason for this is that the
1000-
// value is initialized in an inner block but may be freed in some outer
1001-
// block, so an SSA value that is valid in the inner block may not be valid in
1002-
// the outer block. In fact, the inner block may not even execute. Rather
1003-
// than generate the full SSA form, we just use an alloca'd value.
1004-
pub fn add_root_cleanup(bcx: block,
1005-
root_info: RootInfo,
1006-
root_loc: ValueRef,
1007-
ty: ty::t) {
1008-
1009-
debug!("add_root_cleanup(bcx=%s, \
1010-
scope=%d, \
1011-
freezes=%?, \
1012-
root_loc=%s, \
1013-
ty=%s)",
1014-
bcx.to_str(),
1015-
root_info.scope,
1016-
root_info.freeze,
1017-
val_str(bcx.ccx().tn, root_loc),
1018-
ppaux::ty_to_str(bcx.ccx().tcx, ty));
1019-
1020-
let bcx_scope = find_bcx_for_scope(bcx, root_info.scope);
1021-
if root_info.freeze.is_some() {
1022-
add_clean_frozen_root(bcx_scope, root_loc, ty);
1023-
} else {
1024-
add_clean_temp_mem(bcx_scope, root_loc, ty);
1025-
}
1026-
1027-
fn find_bcx_for_scope(bcx: block, scope_id: ast::node_id) -> block {
1028-
let mut bcx_sid = bcx;
1029-
loop {
1030-
bcx_sid = match bcx_sid.node_info {
1031-
Some(NodeInfo { id, _ }) if id == scope_id => {
994+
pub fn find_bcx_for_scope(bcx: block, scope_id: ast::node_id) -> block {
995+
let mut bcx_sid = bcx;
996+
loop {
997+
bcx_sid = match bcx_sid.node_info {
998+
Some(NodeInfo { id, _ }) if id == scope_id => {
1032999
return bcx_sid
10331000
}
10341001

1035-
// NOTE This is messier than it ought to be and not really right
1036-
Some(NodeInfo { callee_id: Some(id), _ }) if id == scope_id => {
1037-
return bcx_sid
1038-
}
1002+
// NOTE This is messier than it ought to be and not really right
1003+
Some(NodeInfo { callee_id: Some(id), _ }) if id == scope_id => {
1004+
return bcx_sid
1005+
}
10391006

1040-
_ => {
1041-
match bcx_sid.parent {
1042-
None => bcx.tcx().sess.bug(
1043-
fmt!("no enclosing scope with id %d", scope_id)),
1044-
Some(bcx_par) => bcx_par
1007+
_ => {
1008+
match bcx_sid.parent {
1009+
None => bcx.tcx().sess.bug(
1010+
fmt!("no enclosing scope with id %d", scope_id)),
1011+
Some(bcx_par) => bcx_par
1012+
}
10451013
}
1046-
}
10471014
}
10481015
}
10491016
}
1050-
}
1017+
10511018

10521019
pub fn do_spill(bcx: block, v: ValueRef, t: ty::t) -> ValueRef {
10531020
if ty::type_is_bot(t) {

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -467,28 +467,40 @@ pub fn add_clean_temp_mem(bcx: block, val: ValueRef, t: ty::t) {
467467
scope_clean_changed(scope_info);
468468
}
469469
}
470-
pub fn add_clean_frozen_root(bcx: block, val: ValueRef, t: ty::t) {
471-
debug!("add_clean_frozen_root(%s, %s, %s)",
472-
bcx.to_str(), val_str(bcx.ccx().tn, val),
473-
t.repr(bcx.tcx()));
474-
let (root, rooted) = root_for_cleanup(bcx, val, t);
475-
let cleanup_type = cleanup_type(bcx.tcx(), t);
470+
pub fn add_clean_return_to_mut(bcx: block,
471+
frozen_val_ref: ValueRef,
472+
bits_val_ref: ValueRef) {
473+
//! When an `@mut` has been frozen, we have to
474+
//! call the lang-item `return_to_mut` when the
475+
//! freeze goes out of scope. We need to pass
476+
//! in both the value which was frozen (`frozen_val`) and
477+
//! the value (`bits_val_ref`) which was returned when the
478+
//! box was frozen initially. Here, both `frozen_val_ref` and
479+
//! `bits_val_ref` are in fact pointers to stack slots.
480+
481+
debug!("add_clean_return_to_mut(%s, %s, %s)",
482+
bcx.to_str(),
483+
val_str(bcx.ccx().tn, frozen_val_ref),
484+
val_str(bcx.ccx().tn, bits_val_ref));
476485
do in_scope_cx(bcx) |scope_info| {
477486
scope_info.cleanups.push(
478-
clean_temp(val, |bcx| {
479-
let bcx = callee::trans_lang_call(
480-
bcx,
481-
bcx.tcx().lang_items.return_to_mut_fn(),
482-
~[
483-
build::Load(bcx,
484-
build::PointerCast(bcx,
485-
root,
486-
T_ptr(T_ptr(T_i8()))))
487-
],
488-
expr::Ignore
489-
);
490-
glue::drop_ty_root(bcx, root, rooted, t)
491-
}, cleanup_type));
487+
clean_temp(
488+
frozen_val_ref,
489+
|bcx| {
490+
callee::trans_lang_call(
491+
bcx,
492+
bcx.tcx().lang_items.return_to_mut_fn(),
493+
~[
494+
build::Load(bcx,
495+
build::PointerCast(bcx,
496+
frozen_val_ref,
497+
T_ptr(T_ptr(T_i8())))),
498+
build::Load(bcx, bits_val_ref)
499+
],
500+
expr::Ignore
501+
)
502+
},
503+
normal_exit_only));
492504
scope_clean_changed(scope_info);
493505
}
494506
}

0 commit comments

Comments
 (0)