Skip to content

Commit 4af69f2

Browse files
committed
auto merge of #13344 : eddyb/rust/kill-unboxed-vec, r=cmr
Removes the special `ty_unboxed_vec` type from the type system. It was previously used only during translating `~[T]`/`~str` allocation and drop glue.
2 parents f1f5056 + 2d22243 commit 4af69f2

24 files changed

+208
-375
lines changed

Diff for: src/librustc/metadata/tydecode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
349349
let mt = parse_mt(st, |x,y| conv(x,y));
350350
return ty::mk_rptr(st.tcx, r, mt);
351351
}
352-
'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, |x,y| conv(x,y))),
353352
'V' => {
354353
let mt = parse_mt(st, |x,y| conv(x,y));
355354
let v = parse_vstore(st, |x,y| conv(x,y));

Diff for: src/librustc/metadata/tyencode.rs

-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
298298
mywrite!(w, "v");
299299
enc_vstore(w, cx, v);
300300
}
301-
ty::ty_unboxed_vec(mt) => { mywrite!(w, "U"); enc_mt(w, cx, mt); }
302301
ty::ty_closure(ref f) => {
303302
mywrite!(w, "f");
304303
enc_closure_ty(w, cx, *f);

Diff for: src/librustc/middle/check_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
191191
}
192192
}
193193
}
194-
ty::ty_unboxed_vec(..) | ty::ty_vec(..) => {
194+
ty::ty_vec(..) => {
195195
match *ctor {
196196
vec(n) => Some(format!("vectors of length {}", n)),
197197
_ => None
@@ -282,7 +282,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
282282
ty::ty_vec(_, ty::vstore_fixed(n)) => {
283283
is_useful_specialized(cx, m, v, vec(n), n, left_ty)
284284
}
285-
ty::ty_unboxed_vec(..) | ty::ty_vec(..) => {
285+
ty::ty_vec(..) => {
286286
let max_len = m.iter().rev().fold(0, |max_len, r| {
287287
match r.get(0).node {
288288
PatVec(ref before, _, ref after) => {
@@ -464,7 +464,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
464464
_ => None
465465
}
466466
}
467-
ty::ty_unboxed_vec(..) | ty::ty_vec(..) => {
467+
ty::ty_vec(..) => {
468468

469469
// Find the lengths and slices of all vector patterns.
470470
let mut vec_pat_lens = m.iter().filter_map(|r| {
@@ -529,7 +529,7 @@ fn ctor_arity(cx: &MatchCheckCtxt, ctor: &ctor, ty: ty::t) -> uint {
529529
}
530530
}
531531
ty::ty_struct(cid, _) => ty::lookup_struct_fields(cx.tcx, cid).len(),
532-
ty::ty_unboxed_vec(..) | ty::ty_vec(..) => {
532+
ty::ty_vec(..) => {
533533
match *ctor {
534534
vec(n) => n,
535535
_ => 0u

Diff for: src/librustc/middle/trans/_match.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ fn extract_vec_elems<'a>(
10881088
let _icx = push_ctxt("match::extract_vec_elems");
10891089
let vec_datum = match_datum(bcx, val, pat_id);
10901090
let (base, len) = vec_datum.get_vec_base_and_len(bcx);
1091-
let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id));
1091+
let vec_ty = node_id_type(bcx, pat_id);
1092+
let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty));
10921093

10931094
let mut elems = Vec::from_fn(elem_count, |i| {
10941095
match slice {
@@ -1681,8 +1682,8 @@ fn compile_submatch_continue<'r,
16811682
kind = compare;
16821683
},
16831684
vec_len(..) => {
1684-
let vt = tvec::vec_types(bcx, node_id_type(bcx, pat_id));
1685-
let (_, len) = tvec::get_base_and_len(bcx, val, vt.vec_ty);
1685+
let vec_ty = node_id_type(bcx, pat_id);
1686+
let (_, len) = tvec::get_base_and_len(bcx, val, vec_ty);
16861687
test_val = len;
16871688
kind = compare_vec_len;
16881689
}

Diff for: src/librustc/middle/trans/base.rs

+52-99
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use lib;
3737
use metadata::{csearch, encoder};
3838
use middle::astencode;
3939
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
40-
use middle::lang_items::{MallocFnLangItem, ClosureExchangeMallocFnLangItem};
4140
use middle::trans::_match;
4241
use middle::trans::adt;
4342
use middle::trans::build::*;
@@ -336,111 +335,64 @@ pub fn at_box_body(bcx: &Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef {
336335
GEPi(bcx, boxptr, [0u, abi::box_field_body])
337336
}
338337

339-
// malloc_raw_dyn: allocates a box to contain a given type, but with a
340-
// potentially dynamic size.
341-
pub fn malloc_raw_dyn<'a>(
342-
bcx: &'a Block<'a>,
343-
t: ty::t,
344-
heap: heap,
345-
size: ValueRef)
346-
-> Result<'a> {
347-
let _icx = push_ctxt("malloc_raw");
348-
let ccx = bcx.ccx();
349-
350-
fn require_alloc_fn(bcx: &Block, t: ty::t, it: LangItem) -> ast::DefId {
351-
let li = &bcx.tcx().lang_items;
352-
match li.require(it) {
353-
Ok(id) => id,
354-
Err(s) => {
355-
bcx.sess().fatal(format!("allocation of `{}` {}",
356-
bcx.ty_to_str(t), s));
357-
}
338+
fn require_alloc_fn(bcx: &Block, info_ty: ty::t, it: LangItem) -> ast::DefId {
339+
match bcx.tcx().lang_items.require(it) {
340+
Ok(id) => id,
341+
Err(s) => {
342+
bcx.sess().fatal(format!("allocation of `{}` {}",
343+
bcx.ty_to_str(info_ty), s));
358344
}
359345
}
346+
}
360347

361-
if heap == heap_exchange {
362-
let llty_value = type_of::type_of(ccx, t);
363-
364-
// Allocate space:
365-
let r = callee::trans_lang_call(
366-
bcx,
367-
require_alloc_fn(bcx, t, ExchangeMallocFnLangItem),
368-
[size],
369-
None);
370-
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_value.ptr_to()))
371-
} else {
372-
// we treat ~fn as @ here, which isn't ideal
373-
let langcall = match heap {
374-
heap_managed => {
375-
require_alloc_fn(bcx, t, MallocFnLangItem)
376-
}
377-
heap_exchange_closure => {
378-
require_alloc_fn(bcx, t, ClosureExchangeMallocFnLangItem)
379-
}
380-
_ => fail!("heap_exchange already handled")
381-
};
348+
// The following malloc_raw_dyn* functions allocate a box to contain
349+
// a given type, but with a potentially dynamic size.
382350

383-
// Grab the TypeRef type of box_ptr_ty.
384-
let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
385-
let llty = type_of(ccx, box_ptr_ty);
386-
let llalign = C_uint(ccx, llalign_of_min(ccx, llty) as uint);
387-
388-
// Allocate space:
389-
let drop_glue = glue::get_drop_glue(ccx, t);
390-
let r = callee::trans_lang_call(
391-
bcx,
392-
langcall,
393-
[
394-
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
395-
size,
396-
llalign
397-
],
398-
None);
399-
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
400-
}
401-
}
402-
403-
// malloc_raw: expects an unboxed type and returns a pointer to
404-
// enough space for a box of that type. This includes a rust_opaque_box
405-
// header.
406-
pub fn malloc_raw<'a>(bcx: &'a Block<'a>, t: ty::t, heap: heap)
407-
-> Result<'a> {
408-
let ty = type_of(bcx.ccx(), t);
409-
let size = llsize_of(bcx.ccx(), ty);
410-
malloc_raw_dyn(bcx, t, heap, size)
411-
}
412-
413-
pub struct MallocResult<'a> {
414-
pub bcx: &'a Block<'a>,
415-
pub smart_ptr: ValueRef,
416-
pub body: ValueRef
417-
}
418-
419-
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a smart
420-
// pointer, and pulls out the body
421-
pub fn malloc_general_dyn<'a>(
422-
bcx: &'a Block<'a>,
423-
t: ty::t,
424-
heap: heap,
351+
pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>,
352+
ptr_ty: ty::t,
425353
size: ValueRef)
426-
-> MallocResult<'a> {
427-
assert!(heap != heap_exchange);
428-
let _icx = push_ctxt("malloc_general");
429-
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size);
430-
let body = GEPi(bcx, llbox, [0u, abi::box_field_body]);
354+
-> Result<'a> {
355+
let _icx = push_ctxt("malloc_raw_exchange");
356+
let ccx = bcx.ccx();
431357

432-
MallocResult {
433-
bcx: bcx,
434-
smart_ptr: llbox,
435-
body: body,
436-
}
358+
// Allocate space:
359+
let r = callee::trans_lang_call(bcx,
360+
require_alloc_fn(bcx, ptr_ty, ExchangeMallocFnLangItem),
361+
[size],
362+
None);
363+
364+
let llty_ptr = type_of::type_of(ccx, ptr_ty);
365+
rslt(r.bcx, PointerCast(r.bcx, r.val, llty_ptr))
437366
}
438367

439-
pub fn malloc_general<'a>(bcx: &'a Block<'a>, t: ty::t, heap: heap)
440-
-> MallocResult<'a> {
441-
let ty = type_of(bcx.ccx(), t);
442-
assert!(heap != heap_exchange);
443-
malloc_general_dyn(bcx, t, heap, llsize_of(bcx.ccx(), ty))
368+
pub fn malloc_raw_dyn_managed<'a>(
369+
bcx: &'a Block<'a>,
370+
t: ty::t,
371+
alloc_fn: LangItem,
372+
size: ValueRef)
373+
-> Result<'a> {
374+
let _icx = push_ctxt("malloc_raw_managed");
375+
let ccx = bcx.ccx();
376+
377+
let langcall = require_alloc_fn(bcx, t, alloc_fn);
378+
379+
// Grab the TypeRef type of box_ptr_ty.
380+
let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
381+
let llty = type_of(ccx, box_ptr_ty);
382+
let llalign = C_uint(ccx, llalign_of_min(ccx, llty) as uint);
383+
384+
// Allocate space:
385+
let drop_glue = glue::get_drop_glue(ccx, t);
386+
let r = callee::trans_lang_call(
387+
bcx,
388+
langcall,
389+
[
390+
PointerCast(bcx, drop_glue, Type::glue_fn(ccx, Type::i8p(ccx)).ptr_to()),
391+
size,
392+
llalign
393+
],
394+
None);
395+
rslt(r.bcx, PointerCast(r.bcx, r.val, llty))
444396
}
445397

446398
// Type descriptor and type glue stuff
@@ -708,7 +660,8 @@ pub fn iter_structural_ty<'r,
708660
ty::ty_str(ty::vstore_fixed(_)) |
709661
ty::ty_vec(_, ty::vstore_fixed(_)) => {
710662
let (base, len) = tvec::get_base_and_byte_len(cx, av, t);
711-
cx = tvec::iter_vec_raw(cx, base, t, len, f);
663+
let unit_ty = ty::sequence_element_type(cx.tcx(), t);
664+
cx = tvec::iter_vec_raw(cx, base, unit_ty, len, f);
712665
}
713666
ty::ty_tup(ref args) => {
714667
let repr = adt::represent_type(cx.ccx(), t);

Diff for: src/librustc/middle/trans/cleanup.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
278278
fn schedule_free_value(&self,
279279
cleanup_scope: ScopeId,
280280
val: ValueRef,
281-
heap: common::heap) {
281+
heap: Heap) {
282282
/*!
283283
* Schedules a call to `free(val)`. Note that this is a shallow
284284
* operation.
@@ -814,9 +814,14 @@ impl Cleanup for DropValue {
814814
}
815815
}
816816

817+
pub enum Heap {
818+
HeapManaged,
819+
HeapExchange
820+
}
821+
817822
pub struct FreeValue {
818823
ptr: ValueRef,
819-
heap: common::heap,
824+
heap: Heap,
820825
}
821826

822827
impl Cleanup for FreeValue {
@@ -826,10 +831,10 @@ impl Cleanup for FreeValue {
826831

827832
fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> {
828833
match self.heap {
829-
common::heap_managed => {
834+
HeapManaged => {
830835
glue::trans_free(bcx, self.ptr)
831836
}
832-
common::heap_exchange | common::heap_exchange_closure => {
837+
HeapExchange => {
833838
glue::trans_exchange_free(bcx, self.ptr)
834839
}
835840
}
@@ -901,7 +906,7 @@ pub trait CleanupMethods<'a> {
901906
fn schedule_free_value(&self,
902907
cleanup_scope: ScopeId,
903908
val: ValueRef,
904-
heap: common::heap);
909+
heap: Heap);
905910
fn schedule_clean(&self,
906911
cleanup_scope: ScopeId,
907912
cleanup: ~Cleanup);

Diff for: src/librustc/middle/trans/closure.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use back::abi;
1313
use back::link::mangle_internal_name_by_path_and_seq;
1414
use driver::session::FullDebugInfo;
1515
use lib::llvm::ValueRef;
16+
use middle::lang_items::ClosureExchangeMallocFnLangItem;
1617
use middle::moves;
1718
use middle::trans::base::*;
1819
use middle::trans::build::*;
1920
use middle::trans::common::*;
2021
use middle::trans::datum::{Datum, DatumBlock, Expr, Lvalue, rvalue_scratch_datum};
2122
use middle::trans::debuginfo;
2223
use middle::trans::expr;
24+
use middle::trans::machine::llsize_of;
2325
use middle::trans::type_of::*;
2426
use middle::trans::type_::Type;
2527
use middle::ty;
@@ -168,7 +170,10 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>,
168170
tcx.sess.bug("trying to trans allocation of @fn")
169171
}
170172
ast::OwnedSigil => {
171-
malloc_raw(bcx, cdata_ty, heap_exchange_closure)
173+
let ty = type_of(bcx.ccx(), cdata_ty);
174+
let size = llsize_of(bcx.ccx(), ty);
175+
// we treat proc as @ here, which isn't ideal
176+
malloc_raw_dyn_managed(bcx, cdata_ty, ClosureExchangeMallocFnLangItem, size)
172177
}
173178
ast::BorrowedSigil => {
174179
let cbox_ty = tuplify_box_ty(tcx, cdata_ty);

Diff for: src/librustc/middle/trans/common.rs

-8
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,6 @@ impl<'a> FunctionContext<'a> {
386386
}
387387
}
388388

389-
// Heap selectors. Indicate which heap something should go on.
390-
#[deriving(Eq)]
391-
pub enum heap {
392-
heap_managed,
393-
heap_exchange,
394-
heap_exchange_closure
395-
}
396-
397389
// Basic block context. We create a block context for each basic block
398390
// (single-entry, single-exit sequence of instructions) we generate from Rust
399391
// code. Each basic block we generate is attached to a function, typically

0 commit comments

Comments
 (0)