Skip to content

Commit 64bf5a8

Browse files
committed
Add a cache so we don't create so many shims.
1 parent 39221a0 commit 64bf5a8

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/librustc_trans/trans/callee.rs

+8
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
262262
let _icx = push_ctxt("trans_fn_pointer_shim");
263263
let tcx = ccx.tcx();
264264

265+
let bare_fn_ty = ty::normalize_ty(tcx, bare_fn_ty);
266+
match ccx.fn_pointer_shims().borrow().get(&bare_fn_ty) {
267+
Some(&llval) => { return llval; }
268+
None => { }
269+
}
270+
265271
debug!("trans_fn_pointer_shim(bare_fn_ty={})",
266272
bare_fn_ty.repr(tcx));
267273

@@ -345,6 +351,8 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
345351

346352
finish_fn(&fcx, bcx, output_ty);
347353

354+
ccx.fn_pointer_shims().borrow_mut().insert(bare_fn_ty, llfn);
355+
348356
llfn
349357
}
350358

src/librustc_trans/trans/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub struct LocalCrateContext<'tcx> {
8484
tn: TypeNames,
8585
externs: RefCell<ExternMap>,
8686
item_vals: RefCell<NodeMap<ValueRef>>,
87+
fn_pointer_shims: RefCell<FnvHashMap<Ty<'tcx>, ValueRef>>,
8788
drop_glues: RefCell<FnvHashMap<Ty<'tcx>, ValueRef>>,
8889
tydescs: RefCell<FnvHashMap<Ty<'tcx>, Rc<tydesc_info<'tcx>>>>,
8990
/// Set when running emit_tydescs to enforce that no more tydescs are
@@ -573,6 +574,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
573574
&self.shared.link_meta
574575
}
575576

577+
pub fn fn_pointer_shims(&self) -> &RefCell<FnvHashMap<Ty<'tcx>, ValueRef>> {
578+
&self.local.fn_pointer_shims
579+
}
580+
576581
pub fn drop_glues<'a>(&'a self) -> &'a RefCell<FnvHashMap<Ty<'tcx>, ValueRef>> {
577582
&self.local.drop_glues
578583
}

0 commit comments

Comments
 (0)