Skip to content

Commit d4974aa

Browse files
committed
---
yaml --- r: 148287 b: refs/heads/try2 c: 8e5f068 h: refs/heads/master i: 148285: 01b78ac 148283: 18843da 148279: a436095 148271: 4383169 148255: a726f28 148223: 57cdbda v: v3
1 parent 8f4369b commit d4974aa

38 files changed

+257
-282
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: 7bebdbd96826cc70c8e39d025a64b76cd64a2ee7
8+
refs/heads/try2: 8e5f068d695af201382138fbc3e63ce9daa437de
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[Macros](guide-macros.html)
2020
[Packaging](guide-rustpkg.html)
2121
[Testing](guide-testing.html)
22-
[Conditions](guide-conditions.html)
22+
[Conditions](guide-conditions.html)
2323
[Rust's Runtime](guide-runtime.html)
2424

2525
# Libraries

branches/try2/src/libextra/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ mod tests {
14591459
}
14601460

14611461
#[test]
1462-
#[ignore(cfg(target_os = "android"))] // FIXME #10958
1462+
#[ignore(cfg(android))] // FIXME #10958
14631463
fn run_tests() {
14641464
// The tests race on tzset. So instead of having many independent
14651465
// tests, we will just call the functions now.

branches/try2/src/libgreen/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#[macro_escape];
1414

1515
use std::fmt;
16+
use std::libc;
1617

1718
// Indicates whether we should perform expensive sanity checks, including rtassert!
1819
// XXX: Once the runtime matures remove the `true` below to turn off rtassert, etc.
@@ -123,7 +124,6 @@ memory and partly incapable of presentation to others.",
123124
abort();
124125

125126
fn abort() -> ! {
126-
use std::unstable::intrinsics;
127-
unsafe { intrinsics::abort() }
127+
unsafe { libc::abort() }
128128
}
129129
}

branches/try2/src/librustc/back/abi.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ pub static tydesc_field_align: uint = 1u;
4545
pub static tydesc_field_take_glue: uint = 2u;
4646
pub static tydesc_field_drop_glue: uint = 3u;
4747
pub static tydesc_field_visit_glue: uint = 4u;
48-
pub static tydesc_field_name_offset: uint = 5u;
49-
pub static n_tydesc_fields: uint = 6u;
48+
pub static tydesc_field_borrow_offset: uint = 5u;
49+
pub static tydesc_field_name_offset: uint = 6u;
50+
pub static n_tydesc_fields: uint = 7u;
5051

5152
// The two halves of a closure: code and environment.
5253
pub static fn_field_code: uint = 0u;

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,9 +1584,14 @@ fn compile_submatch_continue<'r,
15841584
}
15851585

15861586
if any_uniq_pat(m, col) {
1587+
let pat_ty = node_id_type(bcx, pat_id);
15871588
let llbox = Load(bcx, val);
1589+
let unboxed = match ty::get(pat_ty).sty {
1590+
ty::ty_uniq(..) if !ty::type_contents(bcx.tcx(), pat_ty).owns_managed() => llbox,
1591+
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
1592+
};
15881593
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
1589-
vec::append(~[llbox], vals_left), chk);
1594+
vec::append(~[unboxed], vals_left), chk);
15901595
return;
15911596
}
15921597

@@ -2226,8 +2231,13 @@ fn bind_irrefutable_pat<'a>(
22262231
}
22272232
}
22282233
ast::PatUniq(inner) => {
2234+
let pat_ty = node_id_type(bcx, pat.id);
22292235
let llbox = Load(bcx, val);
2230-
bcx = bind_irrefutable_pat(bcx, inner, llbox, binding_mode);
2236+
let unboxed = match ty::get(pat_ty).sty {
2237+
ty::ty_uniq(..) if !ty::type_contents(bcx.tcx(), pat_ty).owns_managed() => llbox,
2238+
_ => GEPi(bcx, llbox, [0u, abi::box_field_body])
2239+
};
2240+
bcx = bind_irrefutable_pat(bcx, inner, unboxed, binding_mode);
22312241
}
22322242
ast::PatRegion(inner) => {
22332243
let loaded_val = Load(bcx, val);

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub fn malloc_raw_dyn<'a>(
368368
} else {
369369
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
370370
let langcall = match heap {
371-
heap_managed => {
371+
heap_managed | heap_managed_unique => {
372372
require_alloc_fn(bcx, t, MallocFnLangItem)
373373
}
374374
heap_exchange_closure => {
@@ -392,7 +392,9 @@ pub fn malloc_raw_dyn<'a>(
392392
langcall,
393393
[tydesc, size],
394394
None);
395-
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
395+
let r = rslt(r.bcx, PointerCast(r.bcx, r.val, llty));
396+
maybe_set_managed_unique_rc(r.bcx, r.val, heap);
397+
r
396398
}
397399
}
398400

@@ -439,6 +441,27 @@ pub fn malloc_general<'a>(bcx: &'a Block, t: ty::t, heap: heap)
439441
malloc_general_dyn(bcx, t, heap, llsize_of(bcx.ccx(), ty))
440442
}
441443

444+
pub fn heap_for_unique(bcx: &Block, t: ty::t) -> heap {
445+
if ty::type_contents(bcx.tcx(), t).owns_managed() {
446+
heap_managed_unique
447+
} else {
448+
heap_exchange
449+
}
450+
}
451+
452+
pub fn maybe_set_managed_unique_rc(bcx: &Block, bx: ValueRef, heap: heap) {
453+
assert!(heap != heap_exchange);
454+
if heap == heap_managed_unique {
455+
// In cases where we are looking at a unique-typed allocation in the
456+
// managed heap (thus have refcount 1 from the managed allocator),
457+
// such as a ~(@foo) or such. These need to have their refcount forced
458+
// to -2 so the annihilator ignores them.
459+
let rc = GEPi(bcx, bx, [0u, abi::box_field_refcnt]);
460+
let rc_val = C_int(bcx.ccx(), -2);
461+
Store(bcx, rc_val, rc);
462+
}
463+
}
464+
442465
// Type descriptor and type glue stuff
443466

444467
pub fn get_tydesc_simple(ccx: &CrateContext, t: ty::t) -> ValueRef {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ pub fn mk_closure_tys(tcx: ty::ctxt,
150150
return cdata_ty;
151151
}
152152

153+
fn heap_for_unique_closure(bcx: &Block, t: ty::t) -> heap {
154+
if ty::type_contents(bcx.tcx(), t).owns_managed() {
155+
heap_managed_unique
156+
} else {
157+
heap_exchange_closure
158+
}
159+
}
160+
153161
pub fn allocate_cbox<'a>(
154162
bcx: &'a Block<'a>,
155163
sigil: ast::Sigil,
@@ -165,7 +173,7 @@ pub fn allocate_cbox<'a>(
165173
tcx.sess.bug("trying to trans allocation of @fn")
166174
}
167175
ast::OwnedSigil => {
168-
malloc_raw(bcx, cdata_ty, heap_exchange_closure)
176+
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
169177
}
170178
ast::BorrowedSigil => {
171179
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct tydesc_info {
9090
tydesc: ValueRef,
9191
size: ValueRef,
9292
align: ValueRef,
93+
borrow_offset: ValueRef,
9394
name: ValueRef,
9495
take_glue: Cell<Option<ValueRef>>,
9596
drop_glue: Cell<Option<ValueRef>>,
@@ -315,6 +316,7 @@ pub fn warn_not_to_commit(ccx: &CrateContext, msg: &str) {
315316
#[deriving(Eq)]
316317
pub enum heap {
317318
heap_managed,
319+
heap_managed_unique,
318320
heap_exchange,
319321
heap_exchange_closure
320322
}
@@ -496,7 +498,7 @@ pub fn add_clean_temp_mem_in_scope_(bcx: &Block, scope_id: Option<ast::NodeId>,
496498

497499
pub fn add_clean_free(cx: &Block, ptr: ValueRef, heap: heap) {
498500
let free_fn = match heap {
499-
heap_managed => {
501+
heap_managed | heap_managed_unique => {
500502
@GCHeapFreeingCleanupFunction {
501503
ptr: ptr,
502504
} as @CleanupFunction

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,14 +570,19 @@ impl Datum {
570570
let (content_ty, header) = match ty::get(self.ty).sty {
571571
ty::ty_box(typ) => (typ, true),
572572
ty::ty_uniq(typ) => (typ, false),
573+
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) => {
574+
let unit_ty = ty::sequence_element_type(bcx.tcx(), self.ty);
575+
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(bcx.tcx(), unit_ty);
576+
(unboxed_vec_ty, true)
577+
}
573578
_ => {
574579
bcx.tcx().sess.bug(format!(
575580
"box_body() invoked on non-box type {}",
576581
ty_to_str(bcx.tcx(), self.ty)));
577582
}
578583
};
579584

580-
if !header {
585+
if !header && !ty::type_contents(bcx.tcx(), content_ty).owns_managed() {
581586
let ptr = self.to_value_llval(bcx);
582587
let ty = type_of::type_of(bcx.ccx(), content_ty);
583588
let body = PointerCast(bcx, ptr, ty.ptr_to());

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,10 @@ fn type_metadata(cx: &CrateContext,
21472147
ty::vstore_fixed(len) => {
21482148
fixed_vec_metadata(cx, mt.ty, len, usage_site_span)
21492149
}
2150+
ty::vstore_uniq if ty::type_contents(cx.tcx, mt.ty).owns_managed() => {
2151+
let boxed_vec_metadata = boxed_vec_metadata(cx, mt.ty, usage_site_span);
2152+
pointer_type_metadata(cx, t, boxed_vec_metadata)
2153+
}
21502154
ty::vstore_uniq => {
21512155
let vec_metadata = vec_metadata(cx, mt.ty, usage_site_span);
21522156
pointer_type_metadata(cx, t, vec_metadata)
@@ -2161,8 +2165,12 @@ fn type_metadata(cx: &CrateContext,
21612165
}
21622166
},
21632167
ty::ty_uniq(typ) => {
2164-
let pointee = type_metadata(cx, typ, usage_site_span);
2165-
pointer_type_metadata(cx, t, pointee)
2168+
if ty::type_contents(cx.tcx, typ).owns_managed() {
2169+
create_pointer_to_box_metadata(cx, t, typ)
2170+
} else {
2171+
let pointee = type_metadata(cx, typ, usage_site_span);
2172+
pointer_type_metadata(cx, t, pointee)
2173+
}
21662174
}
21672175
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {
21682176
let pointee = type_metadata(cx, mt.ty, usage_site_span);

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,29 @@ pub fn trans_to_datum<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
398398
autoderefs));
399399
derefd_datum.to_rptr(bcx).to_value_llval(bcx)
400400
}
401-
ty::UniqTraitStore(..) | ty::RegionTraitStore(..) => {
401+
ty::UniqTraitStore(..) => {
402+
// For a ~T box, there may or may not be a header,
403+
// depending on whether the type T references managed
404+
// boxes. However, since we do not *know* the type T
405+
// for objects, this presents a hurdle. Our solution is
406+
// to load the "borrow offset" from the type descriptor;
407+
// this value will either be 0 or sizeof(BoxHeader), depending
408+
// on the type T.
409+
let llopaque =
410+
PointerCast(bcx, source_data, Type::opaque().ptr_to());
411+
let lltydesc_ptr_ptr =
412+
PointerCast(bcx, vtable,
413+
bcx.ccx().tydesc_type.ptr_to().ptr_to());
414+
let lltydesc_ptr =
415+
Load(bcx, lltydesc_ptr_ptr);
416+
let borrow_offset_ptr =
417+
GEPi(bcx, lltydesc_ptr,
418+
[0, abi::tydesc_field_borrow_offset]);
419+
let borrow_offset =
420+
Load(bcx, borrow_offset_ptr);
421+
InBoundsGEP(bcx, llopaque, [borrow_offset])
422+
}
423+
ty::RegionTraitStore(..) => {
402424
source_data
403425
}
404426
};
@@ -586,15 +608,16 @@ fn trans_rvalue_datum_unadjusted<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
586608
expr, contents);
587609
}
588610
ast::ExprVstore(contents, ast::ExprVstoreUniq) => {
589-
return tvec::trans_uniq_or_managed_vstore(bcx, heap_exchange,
611+
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
612+
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
590613
expr, contents);
591614
}
592615
ast::ExprBox(_, contents) => {
593616
// Special case for `~T`. (The other case, for GC, is handled in
594617
// `trans_rvalue_dps_unadjusted`.)
595618
let box_ty = expr_ty(bcx, expr);
596619
let contents_ty = expr_ty(bcx, contents);
597-
let heap = heap_exchange;
620+
let heap = heap_for_unique(bcx, contents_ty);
598621
return trans_boxed_expr(bcx, box_ty, contents, contents_ty, heap)
599622
}
600623
ast::ExprLit(lit) => {
@@ -1438,7 +1461,8 @@ fn trans_unary_datum<'a>(
14381461
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_managed)
14391462
}
14401463
ast::UnUniq => {
1441-
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_exchange)
1464+
let heap = heap_for_unique(bcx, un_ty);
1465+
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
14421466
}
14431467
ast::UnDeref => {
14441468
bcx.sess().bug("deref expressions should have been \

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ pub fn make_free_glue<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t)
303303
with_cond(bcx, not_null, |bcx| {
304304
let body_datum = box_datum.box_body(bcx);
305305
let bcx = drop_ty(bcx, body_datum.to_ref_llval(bcx), body_datum.ty);
306-
trans_exchange_free(bcx, box_datum.val)
306+
if ty::type_contents(bcx.tcx(), t).owns_managed() {
307+
trans_free(bcx, box_datum.val)
308+
} else {
309+
trans_exchange_free(bcx, box_datum.val)
310+
}
307311
})
308312
}
309313
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
@@ -546,6 +550,18 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
546550
ppaux::ty_to_str(ccx.tcx, t));
547551
}
548552

553+
let has_header = match ty::get(t).sty {
554+
ty::ty_box(..) => true,
555+
ty::ty_uniq(..) => ty::type_contents(ccx.tcx, t).owns_managed(),
556+
_ => false
557+
};
558+
559+
let borrow_offset = if has_header {
560+
ccx.offsetof_gep(llty, [0u, abi::box_field_body])
561+
} else {
562+
C_uint(ccx, 0)
563+
};
564+
549565
let llsize = llsize_of(ccx, llty);
550566
let llalign = llalign_of(ccx, llty);
551567
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
@@ -564,6 +580,7 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
564580
tydesc: gvar,
565581
size: llsize,
566582
align: llalign,
583+
borrow_offset: borrow_offset,
567584
name: ty_name,
568585
take_glue: Cell::new(None),
569586
drop_glue: Cell::new(None),
@@ -673,12 +690,15 @@ pub fn emit_tydescs(ccx: &CrateContext) {
673690
}
674691
};
675692

693+
debug!("ti.borrow_offset: {}", ccx.tn.val_to_str(ti.borrow_offset));
694+
676695
let tydesc = C_named_struct(ccx.tydesc_type,
677696
[ti.size, // size
678697
ti.align, // align
679698
take_glue, // take_glue
680699
drop_glue, // drop_glue
681700
visit_glue, // visit_glue
701+
ti.borrow_offset, // borrow_offset
682702
ti.name]); // name
683703

684704
unsafe {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ impl<'a> Reflector<'a> {
184184
ty::ty_vec(ref mt, vst) => {
185185
let (name, extra) = self.vstore_name_and_extra(t, vst);
186186
let extra = extra + self.c_mt(mt);
187-
self.visit(~"evec_" + name, extra)
187+
if "uniq" == name && ty::type_contents(bcx.tcx(), t).owns_managed() {
188+
self.visit("evec_uniq_managed", extra)
189+
} else {
190+
self.visit(~"evec_" + name, extra)
191+
}
188192
}
189193
// Should remove mt from box and uniq.
190194
ty::ty_box(typ) => {
@@ -199,7 +203,11 @@ impl<'a> Reflector<'a> {
199203
ty: typ,
200204
mutbl: ast::MutImmutable,
201205
});
202-
self.visit("uniq", extra)
206+
if ty::type_contents(bcx.tcx(), t).owns_managed() {
207+
self.visit("uniq_managed", extra)
208+
} else {
209+
self.visit("uniq", extra)
210+
}
203211
}
204212
ty::ty_ptr(ref mt) => {
205213
let extra = self.c_mt(mt);

0 commit comments

Comments
 (0)