diff --git a/src/base.rs b/src/base.rs index b0b92a72cf8..0d71438cee9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -21,10 +21,13 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( .map(|debug_context| FunctionDebugContext::new(debug_context, instance, func_id, &name)); // Make FunctionBuilder - let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig); - func.collect_debug_info(); + let context = &mut cx.cached_context; + context.clear(); + context.func.name = ExternalName::user(0, func_id.as_u32()); + context.func.signature = sig; + context.func.collect_debug_info(); let mut func_ctx = FunctionBuilderContext::new(); - let mut bcx = FunctionBuilder::new(&mut func, &mut func_ctx); + let mut bcx = FunctionBuilder::new(&mut context.func, &mut func_ctx); // Predefine ebb's let start_ebb = bcx.create_ebb(); @@ -48,7 +51,7 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( clif_comments, constants_cx: &mut cx.constants_cx, - caches: &mut cx.caches, + vtables: &mut cx.vtables, source_info_set: indexmap::IndexSet::new(), }; @@ -69,13 +72,10 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>( let local_map = fx.local_map; #[cfg(debug_assertions)] - crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &func, &clif_comments, None); + crate::pretty_clif::write_clif_file(cx.tcx, "unopt", instance, &context.func, &clif_comments, None); // Verify function - verify_func(tcx, &clif_comments, &func); - - let context = &mut cx.caches.context; - context.func = func; + verify_func(tcx, &clif_comments, &context.func); // Perform rust specific optimizations crate::optimize::optimize_function(cx.tcx, instance, context, &mut clif_comments); diff --git a/src/common.rs b/src/common.rs index e5b932947cc..3543df9cb86 100644 --- a/src/common.rs +++ b/src/common.rs @@ -269,7 +269,7 @@ pub struct FunctionCx<'clif, 'tcx, B: Backend + 'static> { pub clif_comments: crate::pretty_clif::CommentWriter, pub constants_cx: &'clif mut crate::constant::ConstantCx, - pub caches: &'clif mut Caches<'tcx>, + pub vtables: &'clif mut HashMap<(Ty<'tcx>, Option>), DataId>, pub source_info_set: indexmap::IndexSet, } diff --git a/src/lib.rs b/src/lib.rs index c0a2433ceeb..c318b868ff5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ mod prelude { pub use crate::trap::*; pub use crate::unimpl::unimpl; pub use crate::value_and_place::{CPlace, CPlaceInner, CValue}; - pub use crate::{Caches, CodegenCx}; + pub use crate::CodegenCx; pub struct PrintOnPanic String>(pub F); impl String> Drop for PrintOnPanic { @@ -126,25 +126,12 @@ mod prelude { } } -pub struct Caches<'tcx> { - pub context: Context, - pub vtables: HashMap<(Ty<'tcx>, Option>), DataId>, -} - -impl Default for Caches<'_> { - fn default() -> Self { - Caches { - context: Context::new(), - vtables: HashMap::new(), - } - } -} - pub struct CodegenCx<'clif, 'tcx, B: Backend + 'static> { tcx: TyCtxt<'tcx>, module: &'clif mut Module, constants_cx: ConstantCx, - caches: Caches<'tcx>, + cached_context: Context, + vtables: HashMap<(Ty<'tcx>, Option>), DataId>, debug_context: Option<&'clif mut DebugContext<'tcx>>, } @@ -158,7 +145,8 @@ impl<'clif, 'tcx, B: Backend + 'static> CodegenCx<'clif, 'tcx, B> { tcx, module, constants_cx: ConstantCx::default(), - caches: Caches::default(), + cached_context: Context::new(), + vtables: HashMap::new(), debug_context, } } diff --git a/src/vtable.rs b/src/vtable.rs index c12dff3cdc6..913bb712da3 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -63,11 +63,11 @@ pub fn get_vtable<'tcx>( ty: Ty<'tcx>, trait_ref: Option>, ) -> Value { - let data_id = if let Some(data_id) = fx.caches.vtables.get(&(ty, trait_ref)) { + let data_id = if let Some(data_id) = fx.vtables.get(&(ty, trait_ref)) { *data_id } else { let data_id = build_vtable(fx, ty, trait_ref); - fx.caches.vtables.insert((ty, trait_ref), data_id); + fx.vtables.insert((ty, trait_ref), data_id); data_id };