about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-07-02 19:24:58 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-07-08 03:41:21 -0400
commit0aedecf96b08c41ea481eaaebd4e5d2e2325d9c9 (patch)
treee8f72e06d1b1379001abbc9f365e877c538b3b72 /src
parent7bf34c34377986d73376967c7ca967f3bc484c1f (diff)
downloadrust-0aedecf96b08c41ea481eaaebd4e5d2e2325d9c9.tar.gz
rust-0aedecf96b08c41ea481eaaebd4e5d2e2325d9c9.zip
add a temporary vector_exchange_malloc lang item
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/lang_items.rs78
-rw-r--r--src/librustc/middle/trans/base.rs5
-rw-r--r--src/librustc/middle/trans/common.rs3
-rw-r--r--src/librustc/middle/trans/expr.rs2
-rw-r--r--src/librustc/middle/trans/tvec.rs14
-rw-r--r--src/libstd/rt/global_heap.rs8
6 files changed, 68 insertions, 42 deletions
diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs
index 0e9361193b0..d4d1997a56f 100644
--- a/src/librustc/middle/lang_items.rs
+++ b/src/librustc/middle/lang_items.rs
@@ -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 @@ impl LanguageItems {
             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 @@ impl LanguageItems {
     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 @@ impl<'self> LanguageItemCollector<'self> {
         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);
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 09415742b7b..f22bc2084ce 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -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);
diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs
index 19c94d95c4f..fb8fa4d6bac 100644
--- a/src/librustc/middle/trans/common.rs
+++ b/src/librustc/middle/trans/common.rs
@@ -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
       }
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index 9c831db514a..a0d29d56eff 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -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);
         }
diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs
index 233508c5f66..8ff462fbdee 100644
--- a/src/librustc/middle/trans/tvec.rs
+++ b/src/librustc/middle/trans/tvec.rs
@@ -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 => {}
     }
 
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index 1020580d52c..0e5b6427357 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -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"]