about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/trans/callee.rs8
-rw-r--r--src/librustc_trans/trans/context.rs5
2 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs
index 4bcb7b09495..176fe7096e7 100644
--- a/src/librustc_trans/trans/callee.rs
+++ b/src/librustc_trans/trans/callee.rs
@@ -262,6 +262,12 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
     let _icx = push_ctxt("trans_fn_pointer_shim");
     let tcx = ccx.tcx();
 
+    let bare_fn_ty = ty::normalize_ty(tcx, bare_fn_ty);
+    match ccx.fn_pointer_shims().borrow().get(&bare_fn_ty) {
+        Some(&llval) => { return llval; }
+        None => { }
+    }
+
     debug!("trans_fn_pointer_shim(bare_fn_ty={})",
            bare_fn_ty.repr(tcx));
 
@@ -345,6 +351,8 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
 
     finish_fn(&fcx, bcx, output_ty);
 
+    ccx.fn_pointer_shims().borrow_mut().insert(bare_fn_ty, llfn);
+
     llfn
 }
 
diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs
index a0b7eb02f02..eedfd8df2c0 100644
--- a/src/librustc_trans/trans/context.rs
+++ b/src/librustc_trans/trans/context.rs
@@ -84,6 +84,7 @@ pub struct LocalCrateContext<'tcx> {
     tn: TypeNames,
     externs: RefCell<ExternMap>,
     item_vals: RefCell<NodeMap<ValueRef>>,
+    fn_pointer_shims: RefCell<FnvHashMap<Ty<'tcx>, ValueRef>>,
     drop_glues: RefCell<FnvHashMap<Ty<'tcx>, ValueRef>>,
     tydescs: RefCell<FnvHashMap<Ty<'tcx>, Rc<tydesc_info<'tcx>>>>,
     /// Set when running emit_tydescs to enforce that no more tydescs are
@@ -573,6 +574,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
         &self.shared.link_meta
     }
 
+    pub fn fn_pointer_shims(&self) -> &RefCell<FnvHashMap<Ty<'tcx>, ValueRef>> {
+        &self.local.fn_pointer_shims
+    }
+
     pub fn drop_glues<'a>(&'a self) -> &'a RefCell<FnvHashMap<Ty<'tcx>, ValueRef>> {
         &self.local.drop_glues
     }