]> git.lizzy.rs Git - rust.git/commitdiff
add a temporary vector_exchange_malloc lang item
authorDaniel Micay <danielmicay@gmail.com>
Tue, 2 Jul 2013 23:24:58 +0000 (19:24 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Mon, 8 Jul 2013 07:41:21 +0000 (03:41 -0400)
src/librustc/middle/lang_items.rs
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/tvec.rs
src/libstd/rt/global_heap.rs

index 0e9361193b0a31a5a9e6640d68089b51c686cb92..d4d1997a56f250d4db38314535a04a379017735f 100644 (file)
@@ -63,33 +63,34 @@ pub enum LangItem {
     FailFnLangItem,                    // 24
     FailBoundsCheckFnLangItem,         // 25
     ExchangeMallocFnLangItem,          // 26
-    ClosureExchangeMallocFnLangItem,   // 27
-    ExchangeFreeFnLangItem,            // 28
-    MallocFnLangItem,                  // 29
-    FreeFnLangItem,                    // 30
-    BorrowAsImmFnLangItem,             // 31
-    BorrowAsMutFnLangItem,             // 32
-    ReturnToMutFnLangItem,             // 33
-    CheckNotBorrowedFnLangItem,        // 34
-    StrDupUniqFnLangItem,              // 35
-    RecordBorrowFnLangItem,            // 36
-    UnrecordBorrowFnLangItem,          // 37
-
-    StartFnLangItem,                   // 38
-
-    TyDescStructLangItem,              // 39
-    TyVisitorTraitLangItem,            // 40
-    OpaqueStructLangItem,              // 41
+    VectorExchangeMallocFnLangItem,    // 27
+    ClosureExchangeMallocFnLangItem,   // 28
+    ExchangeFreeFnLangItem,            // 29
+    MallocFnLangItem,                  // 30
+    FreeFnLangItem,                    // 31
+    BorrowAsImmFnLangItem,             // 32
+    BorrowAsMutFnLangItem,             // 33
+    ReturnToMutFnLangItem,             // 34
+    CheckNotBorrowedFnLangItem,        // 35
+    StrDupUniqFnLangItem,              // 36
+    RecordBorrowFnLangItem,            // 37
+    UnrecordBorrowFnLangItem,          // 38
+
+    StartFnLangItem,                   // 39
+
+    TyDescStructLangItem,              // 40
+    TyVisitorTraitLangItem,            // 41
+    OpaqueStructLangItem,              // 42
 }
 
 pub struct LanguageItems {
-    items: [Option<def_id>, ..42]
+    items: [Option<def_id>, ..43]
 }
 
 impl LanguageItems {
     pub fn new() -> LanguageItems {
         LanguageItems {
-            items: [ None, ..42 ]
+            items: [ None, ..43 ]
         }
     }
 
@@ -129,23 +130,24 @@ pub fn item_name(index: uint) -> &'static str {
             24 => "fail_",
             25 => "fail_bounds_check",
             26 => "exchange_malloc",
-            27 => "closure_exchange_malloc",
-            28 => "exchange_free",
-            29 => "malloc",
-            30 => "free",
-            31 => "borrow_as_imm",
-            32 => "borrow_as_mut",
-            33 => "return_to_mut",
-            34 => "check_not_borrowed",
-            35 => "strdup_uniq",
-            36 => "record_borrow",
-            37 => "unrecord_borrow",
-
-            38 => "start",
-
-            39 => "ty_desc",
-            40 => "ty_visitor",
-            41 => "opaque",
+            27 => "vector_exchange_malloc",
+            28 => "closure_exchange_malloc",
+            29 => "exchange_free",
+            30 => "malloc",
+            31 => "free",
+            32 => "borrow_as_imm",
+            33 => "borrow_as_mut",
+            34 => "return_to_mut",
+            35 => "check_not_borrowed",
+            36 => "strdup_uniq",
+            37 => "record_borrow",
+            38 => "unrecord_borrow",
+
+            39 => "start",
+
+            40 => "ty_desc",
+            41 => "ty_visitor",
+            42 => "opaque",
 
             _ => "???"
         }
@@ -238,6 +240,9 @@ pub fn fail_bounds_check_fn(&self) -> def_id {
     pub fn exchange_malloc_fn(&self) -> def_id {
         self.items[ExchangeMallocFnLangItem as uint].get()
     }
+    pub fn vector_exchange_malloc_fn(&self) -> def_id {
+        self.items[VectorExchangeMallocFnLangItem as uint].get()
+    }
     pub fn closure_exchange_malloc_fn(&self) -> def_id {
         self.items[ClosureExchangeMallocFnLangItem as uint].get()
     }
@@ -331,6 +336,7 @@ pub fn new<'a>(crate: &'a crate, session: Session)
         item_refs.insert(@"fail_bounds_check",
                          FailBoundsCheckFnLangItem as uint);
         item_refs.insert(@"exchange_malloc", ExchangeMallocFnLangItem as uint);
+        item_refs.insert(@"vector_exchange_malloc", VectorExchangeMallocFnLangItem as uint);
         item_refs.insert(@"closure_exchange_malloc", ClosureExchangeMallocFnLangItem as uint);
         item_refs.insert(@"exchange_free", ExchangeFreeFnLangItem as uint);
         item_refs.insert(@"malloc", MallocFnLangItem as uint);
index 09415742b7bee122ac0741ed405416157e4a59eb..f22bc2084ce127e5989e3dc16293ba6b8fdfab37 100644 (file)
@@ -296,12 +296,15 @@ pub fn malloc_raw_dyn(bcx: block,
         heap_exchange => {
             (ty::mk_imm_uniq, bcx.tcx().lang_items.exchange_malloc_fn())
         }
+        heap_exchange_vector => {
+            (ty::mk_imm_uniq, bcx.tcx().lang_items.vector_exchange_malloc_fn())
+        }
         heap_exchange_closure => {
             (ty::mk_imm_uniq, bcx.tcx().lang_items.closure_exchange_malloc_fn())
         }
     };
 
-    if heap == heap_exchange {
+    if heap == heap_exchange || heap == heap_exchange_vector {
         // Grab the TypeRef type of box_ptr_ty.
         let box_ptr_ty = mk_fn(bcx.tcx(), t);
         let llty = type_of(ccx, box_ptr_ty);
index 19c94d95c4f9951cac454965a80da311a5177b72..fb8fa4d6baccb099fef8ed77036b19681800fe8e 100644 (file)
@@ -274,6 +274,7 @@ pub enum heap {
     heap_managed,
     heap_managed_unique,
     heap_exchange,
+    heap_exchange_vector,
     heap_exchange_closure
 }
 
@@ -395,7 +396,7 @@ pub fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
         let f: @fn(block) -> block = |a| glue::trans_free(a, ptr);
         f
       }
-      heap_exchange | heap_exchange_closure => {
+      heap_exchange | heap_exchange_vector | heap_exchange_closure => {
         let f: @fn(block) -> block = |a| glue::trans_exchange_free(a, ptr);
         f
       }
index 9c831db514a52a8e677ceb5197662a0c5f873598..a0d29d56effb2b8df44814c74a4086e45d9621d9 100644 (file)
@@ -464,7 +464,7 @@ fn trans_rvalue_datum_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
                                                       expr, contents);
         }
         ast::expr_vstore(contents, ast::expr_vstore_uniq) => {
-            let heap = heap_for_unique(bcx, expr_ty(bcx, contents));
+            let heap = tvec::heap_for_unique_vector(bcx, expr_ty(bcx, contents));
             return tvec::trans_uniq_or_managed_vstore(bcx, heap,
                                                       expr, contents);
         }
index 233508c5f668bfe5b3b15aa399586b7a51df1dfe..8ff462fbdeec074f389b23ef934602305a795387 100644 (file)
@@ -95,9 +95,17 @@ pub fn alloc_raw(bcx: block, unit_ty: ty::t,
     return rslt(bcx, bx);
 }
 
+pub fn heap_for_unique_vector(bcx: block, t: ty::t) -> heap {
+    if ty::type_contents(bcx.tcx(), t).contains_managed() {
+        heap_managed_unique
+    } else {
+        heap_exchange_vector
+    }
+}
+
 pub fn alloc_uniq_raw(bcx: block, unit_ty: ty::t,
                       fill: ValueRef, alloc: ValueRef) -> Result {
-    alloc_raw(bcx, unit_ty, fill, alloc, base::heap_for_unique(bcx, unit_ty))
+    alloc_raw(bcx, unit_ty, fill, alloc, heap_for_unique_vector(bcx, unit_ty))
 }
 
 pub fn alloc_vec(bcx: block,
@@ -298,7 +306,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
 
     // Handle ~"".
     match heap {
-        heap_exchange => {
+        heap_exchange_vector => {
             match content_expr.node {
                 ast::expr_lit(@codemap::spanned {
                     node: ast::lit_str(s), _
@@ -321,7 +329,7 @@ pub fn trans_uniq_or_managed_vstore(bcx: block, heap: heap, vstore_expr: @ast::e
                 _ => {}
             }
         }
-        heap_exchange_closure => fail!("vectors are not allocated with closure_exchange_alloc"),
+        heap_exchange | heap_exchange_closure => fail!("vectors use vector_exchange_alloc"),
         heap_managed | heap_managed_unique => {}
     }
 
index 1020580d52c008de48056ed273e45fbf93f3517e..0e5b642735725fcc3a6e4f6fb4479f150e24e226 100644 (file)
@@ -85,6 +85,14 @@ pub unsafe fn exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
     malloc_raw(total_size as uint) as *c_char
 }
 
+#[cfg(not(test))]
+#[lang="vector_exchange_malloc"]
+#[inline]
+pub unsafe fn vector_exchange_malloc(align: u32, size: uintptr_t) -> *c_char {
+    let total_size = get_box_size(size as uint, align as uint);
+    malloc_raw(total_size as uint) as *c_char
+}
+
 // FIXME: #7496
 #[cfg(not(test))]
 #[lang="closure_exchange_malloc"]