Skip to content

Commit 0cdb0a2

Browse files
committed
remove dead take glue code paths
Closes #7888
1 parent 404de4f commit 0cdb0a2

File tree

4 files changed

+4
-125
lines changed

4 files changed

+4
-125
lines changed

src/librustc/middle/trans/closure.rs

+1-47
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ use back::abi;
1313
use back::link::{mangle_internal_name_by_path_and_seq};
1414
use lib::llvm::{llvm, ValueRef};
1515
use middle::moves;
16-
use middle::lang_items::ClosureExchangeMallocFnLangItem;
1716
use middle::trans::base::*;
1817
use middle::trans::build::*;
19-
use middle::trans::callee;
2018
use middle::trans::common::*;
2119
use middle::trans::datum::{Datum, INIT, ByRef, ZeroMem};
2220
use middle::trans::expr;
2321
use middle::trans::glue;
24-
use middle::trans::machine;
2522
use middle::trans::type_of::*;
2623
use middle::ty;
2724
use util::ppaux::ty_to_str;
@@ -508,52 +505,9 @@ pub fn make_opaque_cbox_take_glue(
508505
return bcx;
509506
}
510507
ast::OwnedSigil => {
511-
/* hard case: fallthrough to code below */
508+
fail!("unique closures are not copyable")
512509
}
513510
}
514-
515-
// ~fn requires a deep copy.
516-
let ccx = bcx.ccx();
517-
let tcx = ccx.tcx;
518-
let llopaquecboxty = Type::opaque_box(ccx).ptr_to();
519-
let cbox_in = Load(bcx, cboxptr);
520-
do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
521-
// Load the size from the type descr found in the cbox
522-
let cbox_in = PointerCast(bcx, cbox_in, llopaquecboxty);
523-
let tydescptr = GEPi(bcx, cbox_in, [0u, abi::box_field_tydesc]);
524-
let tydesc = Load(bcx, tydescptr);
525-
let tydesc = PointerCast(bcx, tydesc, ccx.tydesc_type.ptr_to());
526-
let sz = Load(bcx, GEPi(bcx, tydesc, [0u, abi::tydesc_field_size]));
527-
528-
// Adjust sz to account for the rust_opaque_box header fields
529-
let sz = Add(bcx, sz, machine::llsize_of(ccx, Type::box_header(ccx)));
530-
531-
// Allocate memory, update original ptr, and copy existing data
532-
let opaque_tydesc = PointerCast(bcx, tydesc, Type::i8p());
533-
let mut bcx = bcx;
534-
let alloc_fn = langcall(bcx, None,
535-
fmt!("allocation of type with sigil `%s`",
536-
sigil.to_str()),
537-
ClosureExchangeMallocFnLangItem);
538-
let llresult = unpack_result!(bcx, callee::trans_lang_call(
539-
bcx,
540-
alloc_fn,
541-
[opaque_tydesc, sz],
542-
None));
543-
let cbox_out = PointerCast(bcx, llresult, llopaquecboxty);
544-
call_memcpy(bcx, cbox_out, cbox_in, sz, 1);
545-
Store(bcx, cbox_out, cboxptr);
546-
547-
// Take the (deeply cloned) type descriptor
548-
let tydesc_out = GEPi(bcx, cbox_out, [0u, abi::box_field_tydesc]);
549-
let bcx = glue::take_ty(bcx, tydesc_out, ty::mk_type(tcx));
550-
551-
// Take the data in the tuple
552-
let cdata_out = GEPi(bcx, cbox_out, [0u, abi::box_field_body]);
553-
glue::call_tydesc_glue_full(bcx, cdata_out, tydesc,
554-
abi::tydesc_field_take_glue, None);
555-
bcx
556-
}
557511
}
558512

559513
pub fn make_opaque_cbox_drop_glue(

src/librustc/middle/trans/glue.rs

+3-31
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,6 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
9393
}
9494
}
9595

96-
pub fn take_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> Result {
97-
let _icx = push_ctxt("take_ty_immediate");
98-
match ty::get(t).sty {
99-
ty::ty_box(_) | ty::ty_opaque_box |
100-
ty::ty_evec(_, ty::vstore_box) |
101-
ty::ty_estr(ty::vstore_box) => {
102-
incr_refcnt_of_boxed(bcx, v);
103-
rslt(bcx, v)
104-
}
105-
ty::ty_uniq(_) => {
106-
uniq::duplicate(bcx, v, t)
107-
}
108-
ty::ty_evec(_, ty::vstore_uniq) |
109-
ty::ty_estr(ty::vstore_uniq) => {
110-
tvec::duplicate_uniq(bcx, v, t)
111-
}
112-
_ => rslt(bcx, v)
113-
}
114-
}
115-
11696
pub fn free_ty(cx: block, v: ValueRef, t: ty::t) -> block {
11797
// NB: v is an *alias* of type t here, not a direct value.
11898
let _icx = push_ctxt("free_ty");
@@ -589,23 +569,15 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) -> block {
589569
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
590570
incr_refcnt_of_boxed(bcx, Load(bcx, v)); bcx
591571
}
592-
ty::ty_uniq(_) => {
593-
let Result {bcx, val} = uniq::duplicate(bcx, Load(bcx, v), t);
594-
Store(bcx, val, v);
595-
bcx
596-
}
597-
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
598-
let Result {bcx, val} = tvec::duplicate_uniq(bcx, Load(bcx, v), t);
599-
Store(bcx, val, v);
600-
bcx
601-
}
602572
ty::ty_evec(_, ty::vstore_slice(_))
603573
| ty::ty_estr(ty::vstore_slice(_)) => {
604574
bcx
605575
}
606-
ty::ty_closure(_) => {
576+
ty::ty_closure(ty::ClosureTy { sigil: ast::BorrowedSigil, _ }) |
577+
ty::ty_closure(ty::ClosureTy { sigil: ast::ManagedSigil, _ }) => {
607578
closure::make_closure_glue(bcx, v, t, take_ty)
608579
}
580+
ty::ty_closure(ty::ClosureTy { sigil: ast::OwnedSigil, _ }) => bcx,
609581
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
610582
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
611583
incr_refcnt_of_boxed(bcx, llbox);

src/librustc/middle/trans/tvec.rs

-17
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,6 @@ pub fn alloc_vec(bcx: block,
130130
return rslt(bcx, vptr);
131131
}
132132

133-
pub fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> Result {
134-
let _icx = push_ctxt("tvec::duplicate_uniq");
135-
136-
let fill = get_fill(bcx, get_bodyptr(bcx, vptr, vec_ty));
137-
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
138-
let Result {bcx, val: newptr} = alloc_uniq_raw(bcx, unit_ty, fill, fill);
139-
140-
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
141-
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr, vec_ty));
142-
base::call_memcpy(bcx, new_data_ptr, data_ptr, fill, 1);
143-
144-
let bcx = if ty::type_needs_drop(bcx.tcx(), unit_ty) {
145-
iter_vec_raw(bcx, new_data_ptr, vec_ty, fill, glue::take_ty)
146-
} else { bcx };
147-
return rslt(bcx, newptr);
148-
}
149-
150133
pub fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
151134
block {
152135
let _icx = push_ctxt("tvec::make_drop_glue_unboxed");

src/librustc/middle/trans/uniq.rs

-30
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ use middle::trans::base::*;
1414
use middle::trans::build::*;
1515
use middle::trans::common::*;
1616
use middle::trans::datum::immediate_rvalue;
17-
use middle::trans::datum;
1817
use middle::trans::glue;
1918
use middle::ty;
20-
use middle::trans::machine::llsize_of;
21-
use middle::trans::type_of;
2219

2320
pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
2421
-> block {
@@ -37,30 +34,3 @@ pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
3734
}
3835
}
3936
}
40-
41-
pub fn duplicate(bcx: block, src_box: ValueRef, src_ty: ty::t) -> Result {
42-
let _icx = push_ctxt("uniq::duplicate");
43-
44-
// Load the body of the source (*src)
45-
let src_datum = immediate_rvalue(src_box, src_ty);
46-
let body_datum = src_datum.box_body(bcx);
47-
48-
// Malloc space in exchange heap and copy src into it
49-
if ty::type_contents(bcx.tcx(), src_ty).contains_managed() {
50-
let MallocResult {
51-
bcx: bcx,
52-
box: dst_box,
53-
body: dst_body
54-
} = malloc_general(bcx, body_datum.ty, heap_managed_unique);
55-
body_datum.copy_to(bcx, datum::INIT, dst_body);
56-
57-
rslt(bcx, dst_box)
58-
} else {
59-
let body_datum = body_datum.to_value_datum(bcx);
60-
let llty = type_of(bcx.ccx(), body_datum.ty);
61-
let size = llsize_of(bcx.ccx(), llty);
62-
let Result { bcx: bcx, val: val } = malloc_raw_dyn(bcx, body_datum.ty, heap_exchange, size);
63-
body_datum.copy_to(bcx, datum::INIT, val);
64-
Result { bcx: bcx, val: val }
65-
}
66-
}

0 commit comments

Comments
 (0)