Skip to content

Commit 29070c3

Browse files
committed
auto merge of #11535 : thestinger/rust/header, r=alexcrichton
Unique pointers and vectors currently contain a reference counting header when containing a managed pointer. This `{ ref_count, type_desc, prev, next }` header is not necessary and not a sensible foundation for tracing. It adds needless complexity to library code and is responsible for breakage in places where the branch has been left out. The `borrow_offset` field can now be removed from `TyDesc` along with the associated handling in the compiler. Closes #9510 Closes #11533
2 parents e063e96 + 77758f0 commit 29070c3

24 files changed

+157
-199
lines changed

src/librustc/back/abi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ 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_borrow_offset: uint = 5u;
49-
pub static tydesc_field_name_offset: uint = 6u;
50-
pub static n_tydesc_fields: uint = 7u;
48+
pub static tydesc_field_name_offset: uint = 5u;
49+
pub static n_tydesc_fields: uint = 6u;
5150

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

src/librustc/middle/trans/_match.rs

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

15861586
if any_uniq_pat(m, col) {
1587-
let pat_ty = node_id_type(bcx, pat_id);
15881587
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-
};
15931588
compile_submatch(bcx, enter_uniq(bcx, dm, m, col, val),
1594-
vec::append(~[unboxed], vals_left), chk);
1589+
vec::append(~[llbox], vals_left), chk);
15951590
return;
15961591
}
15971592

@@ -2231,13 +2226,8 @@ fn bind_irrefutable_pat<'a>(
22312226
}
22322227
}
22332228
ast::PatUniq(inner) => {
2234-
let pat_ty = node_id_type(bcx, pat.id);
22352229
let llbox = Load(bcx, val);
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);
2230+
bcx = bind_irrefutable_pat(bcx, inner, llbox, binding_mode);
22412231
}
22422232
ast::PatRegion(inner) => {
22432233
let loaded_val = Load(bcx, val);

src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 25 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 | heap_managed_unique => {
371+
heap_managed => {
372372
require_alloc_fn(bcx, t, MallocFnLangItem)
373373
}
374374
heap_exchange_closure => {
@@ -392,9 +392,7 @@ pub fn malloc_raw_dyn<'a>(
392392
langcall,
393393
[tydesc, size],
394394
None);
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
395+
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
398396
}
399397
}
400398

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

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-
465442
// Type descriptor and type glue stuff
466443

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

src/librustc/middle/trans/closure.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ 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-
161153
pub fn allocate_cbox<'a>(
162154
bcx: &'a Block<'a>,
163155
sigil: ast::Sigil,
@@ -173,7 +165,7 @@ pub fn allocate_cbox<'a>(
173165
tcx.sess.bug("trying to trans allocation of @fn")
174166
}
175167
ast::OwnedSigil => {
176-
malloc_raw(bcx, cdata_ty, heap_for_unique_closure(bcx, cdata_ty))
168+
malloc_raw(bcx, cdata_ty, heap_exchange_closure)
177169
}
178170
ast::BorrowedSigil => {
179171
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);

src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub struct tydesc_info {
9090
tydesc: ValueRef,
9191
size: ValueRef,
9292
align: ValueRef,
93-
borrow_offset: ValueRef,
9493
name: ValueRef,
9594
take_glue: Cell<Option<ValueRef>>,
9695
drop_glue: Cell<Option<ValueRef>>,
@@ -316,7 +315,6 @@ pub fn warn_not_to_commit(ccx: &CrateContext, msg: &str) {
316315
#[deriving(Eq)]
317316
pub enum heap {
318317
heap_managed,
319-
heap_managed_unique,
320318
heap_exchange,
321319
heap_exchange_closure
322320
}
@@ -498,7 +496,7 @@ pub fn add_clean_temp_mem_in_scope_(bcx: &Block, scope_id: Option<ast::NodeId>,
498496

499497
pub fn add_clean_free(cx: &Block, ptr: ValueRef, heap: heap) {
500498
let free_fn = match heap {
501-
heap_managed | heap_managed_unique => {
499+
heap_managed => {
502500
@GCHeapFreeingCleanupFunction {
503501
ptr: ptr,
504502
} as @CleanupFunction

src/librustc/middle/trans/datum.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,19 +570,14 @@ 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-
}
578573
_ => {
579574
bcx.tcx().sess.bug(format!(
580575
"box_body() invoked on non-box type {}",
581576
ty_to_str(bcx.tcx(), self.ty)));
582577
}
583578
};
584579

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

src/librustc/middle/trans/debuginfo.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,10 +2147,6 @@ 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-
}
21542150
ty::vstore_uniq => {
21552151
let vec_metadata = vec_metadata(cx, mt.ty, usage_site_span);
21562152
pointer_type_metadata(cx, t, vec_metadata)
@@ -2165,12 +2161,8 @@ fn type_metadata(cx: &CrateContext,
21652161
}
21662162
},
21672163
ty::ty_uniq(typ) => {
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-
}
2164+
let pointee = type_metadata(cx, typ, usage_site_span);
2165+
pointer_type_metadata(cx, t, pointee)
21742166
}
21752167
ty::ty_ptr(ref mt) | ty::ty_rptr(_, ref mt) => {
21762168
let pointee = type_metadata(cx, mt.ty, usage_site_span);

src/librustc/middle/trans/expr.rs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -398,29 +398,7 @@ 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(..) => {
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(..) => {
401+
ty::UniqTraitStore(..) | ty::RegionTraitStore(..) => {
424402
source_data
425403
}
426404
};
@@ -608,16 +586,15 @@ fn trans_rvalue_datum_unadjusted<'a>(bcx: &'a Block<'a>, expr: &ast::Expr)
608586
expr, contents);
609587
}
610588
ast::ExprVstore(contents, ast::ExprVstoreUniq) => {
611-
let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
612-
return tvec::trans_uniq_or_managed_vstore(bcx, heap,
589+
return tvec::trans_uniq_or_managed_vstore(bcx, heap_exchange,
613590
expr, contents);
614591
}
615592
ast::ExprBox(_, contents) => {
616593
// Special case for `~T`. (The other case, for GC, is handled in
617594
// `trans_rvalue_dps_unadjusted`.)
618595
let box_ty = expr_ty(bcx, expr);
619596
let contents_ty = expr_ty(bcx, contents);
620-
let heap = heap_for_unique(bcx, contents_ty);
597+
let heap = heap_exchange;
621598
return trans_boxed_expr(bcx, box_ty, contents, contents_ty, heap)
622599
}
623600
ast::ExprLit(lit) => {
@@ -1461,8 +1438,7 @@ fn trans_unary_datum<'a>(
14611438
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_managed)
14621439
}
14631440
ast::UnUniq => {
1464-
let heap = heap_for_unique(bcx, un_ty);
1465-
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap)
1441+
trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap_exchange)
14661442
}
14671443
ast::UnDeref => {
14681444
bcx.sess().bug("deref expressions should have been \

src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ 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-
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-
}
306+
trans_exchange_free(bcx, box_datum.val)
311307
})
312308
}
313309
ty::ty_vec(_, ty::vstore_uniq) | ty::ty_str(ty::vstore_uniq) |
@@ -550,18 +546,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
550546
ppaux::ty_to_str(ccx.tcx, t));
551547
}
552548

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-
565549
let llsize = llsize_of(ccx, llty);
566550
let llalign = llalign_of(ccx, llty);
567551
let name = mangle_internal_name_by_type_and_seq(ccx, t, "tydesc").to_managed();
@@ -580,7 +564,6 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
580564
tydesc: gvar,
581565
size: llsize,
582566
align: llalign,
583-
borrow_offset: borrow_offset,
584567
name: ty_name,
585568
take_glue: Cell::new(None),
586569
drop_glue: Cell::new(None),
@@ -690,15 +673,12 @@ pub fn emit_tydescs(ccx: &CrateContext) {
690673
}
691674
};
692675

693-
debug!("ti.borrow_offset: {}", ccx.tn.val_to_str(ti.borrow_offset));
694-
695676
let tydesc = C_named_struct(ccx.tydesc_type,
696677
[ti.size, // size
697678
ti.align, // align
698679
take_glue, // take_glue
699680
drop_glue, // drop_glue
700681
visit_glue, // visit_glue
701-
ti.borrow_offset, // borrow_offset
702682
ti.name]); // name
703683

704684
unsafe {

src/librustc/middle/trans/reflect.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,7 @@ 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-
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-
}
187+
self.visit(~"evec_" + name, extra)
192188
}
193189
// Should remove mt from box and uniq.
194190
ty::ty_box(typ) => {
@@ -203,11 +199,7 @@ impl<'a> Reflector<'a> {
203199
ty: typ,
204200
mutbl: ast::MutImmutable,
205201
});
206-
if ty::type_contents(bcx.tcx(), t).owns_managed() {
207-
self.visit("uniq_managed", extra)
208-
} else {
209-
self.visit("uniq", extra)
210-
}
202+
self.visit("uniq", extra)
211203
}
212204
ty::ty_ptr(ref mt) => {
213205
let extra = self.c_mt(mt);

src/librustc/middle/trans/tvec.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ pub fn get_alloc(bcx: &Block, vptr: ValueRef) -> ValueRef {
6464
}
6565

6666
pub fn get_bodyptr(bcx: &Block, vptr: ValueRef, t: ty::t) -> ValueRef {
67-
if ty::type_contents(bcx.tcx(), t).owns_managed() {
67+
let vt = vec_types(bcx, t);
68+
69+
let managed = match ty::get(vt.vec_ty).sty {
70+
ty::ty_str(ty::vstore_box) | ty::ty_vec(_, ty::vstore_box) => true,
71+
_ => false
72+
};
73+
74+
if managed {
6875
GEPi(bcx, vptr, [0u, abi::box_field_body])
6976
} else {
7077
vptr
@@ -106,7 +113,6 @@ pub fn alloc_raw<'a>(
106113
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
107114
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
108115
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));
109-
base::maybe_set_managed_unique_rc(bcx, bx, heap);
110116
return rslt(bcx, bx);
111117
}
112118
}
@@ -117,7 +123,7 @@ pub fn alloc_uniq_raw<'a>(
117123
fill: ValueRef,
118124
alloc: ValueRef)
119125
-> Result<'a> {
120-
alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
126+
alloc_raw(bcx, unit_ty, fill, alloc, heap_exchange)
121127
}
122128

123129
pub fn alloc_vec<'a>(
@@ -350,7 +356,7 @@ pub fn trans_uniq_or_managed_vstore<'a>(
350356
}
351357
}
352358
heap_exchange_closure => fail!("vectors use exchange_alloc"),
353-
heap_managed | heap_managed_unique => {}
359+
heap_managed => {}
354360
}
355361

356362
let vt = vec_types_from_expr(bcx, vstore_expr);

src/librustc/middle/trans/type_.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ impl Type {
220220
glue_fn_ty, // take
221221
glue_fn_ty, // drop
222222
glue_fn_ty, // visit
223-
int_ty, // borrow_offset
224223
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
225224
tydesc.set_struct_body(elems, false);
226225

@@ -269,10 +268,6 @@ impl Type {
269268
Type::smart_ptr(ctx, &Type::opaque())
270269
}
271270

272-
pub fn unique(ctx: &CrateContext, ty: &Type) -> Type {
273-
Type::smart_ptr(ctx, ty)
274-
}
275-
276271
pub fn opaque_cbox_ptr(cx: &CrateContext) -> Type {
277272
Type::opaque_box(cx).ptr_to()
278273
}
@@ -281,7 +276,7 @@ impl Type {
281276
let tydesc_ptr = ctx.tydesc_type.ptr_to();
282277
let box_ty = match store {
283278
ty::BoxTraitStore => Type::opaque_box(ctx),
284-
ty::UniqTraitStore => Type::unique(ctx, &Type::i8()),
279+
ty::UniqTraitStore => Type::i8(),
285280
ty::RegionTraitStore(..) => Type::i8()
286281
};
287282
Type::struct_([tydesc_ptr, box_ty.ptr_to()], false)

0 commit comments

Comments
 (0)