diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2021-02-23 21:00:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-23 21:00:33 +0100 |
| commit | 86c594426f247ae34ef12f5e4dfd97f5ffe093c8 (patch) | |
| tree | d5683974c4cf47d1debe8e3b5b247e4ece43779a /src | |
| parent | c24744657021aa20bb577eb0e23cc8dcee55805c (diff) | |
| parent | 73d3a1c14ad1703644667f8cb0df8e4d316aa4e1 (diff) | |
| download | rust-86c594426f247ae34ef12f5e4dfd97f5ffe093c8.tar.gz rust-86c594426f247ae34ef12f5e4dfd97f5ffe093c8.zip | |
Merge pull request #1144 from bjorn3/dynamic_module
Use dynamic dispatch for the inner Module
Diffstat (limited to 'src')
| -rw-r--r-- | src/abi/comments.rs | 8 | ||||
| -rw-r--r-- | src/abi/mod.rs | 17 | ||||
| -rw-r--r-- | src/abi/pass_mode.rs | 8 | ||||
| -rw-r--r-- | src/abi/returning.rs | 12 | ||||
| -rw-r--r-- | src/analyze.rs | 2 | ||||
| -rw-r--r-- | src/base.rs | 28 | ||||
| -rw-r--r-- | src/cast.rs | 4 | ||||
| -rw-r--r-- | src/codegen_i128.rs | 2 | ||||
| -rw-r--r-- | src/common.rs | 18 | ||||
| -rw-r--r-- | src/constant.rs | 40 | ||||
| -rw-r--r-- | src/discriminant.rs | 4 | ||||
| -rw-r--r-- | src/driver/aot.rs | 6 | ||||
| -rw-r--r-- | src/driver/jit.rs | 17 | ||||
| -rw-r--r-- | src/driver/mod.rs | 2 | ||||
| -rw-r--r-- | src/inline_asm.rs | 4 | ||||
| -rw-r--r-- | src/intrinsics/cpuid.rs | 2 | ||||
| -rw-r--r-- | src/intrinsics/llvm.rs | 2 | ||||
| -rw-r--r-- | src/intrinsics/mod.rs | 28 | ||||
| -rw-r--r-- | src/intrinsics/simd.rs | 2 | ||||
| -rw-r--r-- | src/lib.rs | 24 | ||||
| -rw-r--r-- | src/num.rs | 14 | ||||
| -rw-r--r-- | src/pointer.rs | 39 | ||||
| -rw-r--r-- | src/pretty_clif.rs | 4 | ||||
| -rw-r--r-- | src/trap.rs | 12 | ||||
| -rw-r--r-- | src/unsize.rs | 8 | ||||
| -rw-r--r-- | src/value_and_place.rs | 58 | ||||
| -rw-r--r-- | src/vtable.rs | 16 |
27 files changed, 162 insertions, 219 deletions
diff --git a/src/abi/comments.rs b/src/abi/comments.rs index 9aab45b62e2..8570805fcd2 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -10,14 +10,14 @@ use cranelift_codegen::entity::EntityRef; use crate::prelude::*; -pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) { +pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, '_>) { fx.add_global_comment( "kind loc.idx param pass mode ty".to_string(), ); } pub(super) fn add_arg_comment<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, kind: &str, local: Option<mir::Local>, local_field: Option<usize>, @@ -62,7 +62,7 @@ pub(super) fn add_arg_comment<'tcx>( )); } -pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) { +pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, '_>) { fx.add_global_comment(String::new()); fx.add_global_comment( "kind local ty size align (abi,pref)".to_string(), @@ -70,7 +70,7 @@ pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module> } pub(super) fn add_local_place_comments<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>, local: Local, ) { diff --git a/src/abi/mod.rs b/src/abi/mod.rs index 32cfb58bd35..849f293c419 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -73,7 +73,7 @@ pub(crate) fn get_function_sig<'tcx>( /// Instance must be monomorphized pub(crate) fn import_function<'tcx>( tcx: TyCtxt<'tcx>, - module: &mut impl Module, + module: &mut dyn Module, inst: Instance<'tcx>, ) -> FuncId { let name = tcx.symbol_name(inst).name.to_string(); @@ -83,10 +83,10 @@ pub(crate) fn import_function<'tcx>( .unwrap() } -impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> { +impl<'tcx> FunctionCx<'_, '_, 'tcx> { /// Instance must be monomorphized pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef { - let func_id = import_function(self.tcx, &mut self.cx.module, inst); + let func_id = import_function(self.tcx, self.cx.module, inst); let func_ref = self .cx .module @@ -167,7 +167,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> { /// Make a [`CPlace`] capable of holding value of the specified type. fn make_local_place<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, local: Local, layout: TyAndLayout<'tcx>, is_ssa: bool, @@ -188,10 +188,7 @@ fn make_local_place<'tcx>( place } -pub(crate) fn codegen_fn_prelude<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - start_block: Block, -) { +pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_block: Block) { fx.bcx.append_block_params_for_function_params(start_block); fx.bcx.switch_to_block(start_block); @@ -344,7 +341,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>( } pub(crate) fn codegen_terminator_call<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span, current_block: Block, func: &Operand<'tcx>, @@ -572,7 +569,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( } pub(crate) fn codegen_drop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span, drop_place: CPlace<'tcx>, ) { diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs index 9dd1e670029..57b5ff9d02b 100644 --- a/src/abi/pass_mode.rs +++ b/src/abi/pass_mode.rs @@ -199,7 +199,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { } pub(super) fn to_casted_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, arg: CValue<'tcx>, cast: CastTarget, ) -> SmallVec<[Value; 2]> { @@ -219,7 +219,7 @@ pub(super) fn to_casted_value<'tcx>( } pub(super) fn from_casted_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, block_params: &[Value], layout: TyAndLayout<'tcx>, cast: CastTarget, @@ -258,7 +258,7 @@ pub(super) fn from_casted_value<'tcx>( /// Get a set of values to be passed as function arguments. pub(super) fn adjust_arg_for_abi<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, arg: CValue<'tcx>, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, ) -> SmallVec<[Value; 2]> { @@ -281,7 +281,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>( /// Create a [`CValue`] containing the value of a function parameter adding clif function parameters /// as necessary. pub(super) fn cvalue_for_param<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, #[cfg_attr(not(debug_assertions), allow(unused_variables))] local: Option<mir::Local>, #[cfg_attr(not(debug_assertions), allow(unused_variables))] local_field: Option<usize>, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, diff --git a/src/abi/returning.rs b/src/abi/returning.rs index a382963bf1e..40a0320b579 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -8,7 +8,7 @@ use smallvec::{smallvec, SmallVec}; /// Can the given type be returned into an ssa var or does it need to be returned on the stack. pub(crate) fn can_return_to_ssa_var<'tcx>( - fx: &FunctionCx<'_, 'tcx, impl Module>, + fx: &FunctionCx<'_, '_, 'tcx>, func: &mir::Operand<'tcx>, args: &[mir::Operand<'tcx>], ) -> bool { @@ -58,7 +58,7 @@ pub(crate) fn can_return_to_ssa_var<'tcx>( /// Return a place where the return value of the current function can be written to. If necessary /// this adds an extra parameter pointing to where the return value needs to be stored. pub(super) fn codegen_return_param<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>, block_params_iter: &mut impl Iterator<Item = Value>, ) -> CPlace<'tcx> { @@ -120,11 +120,11 @@ pub(super) fn codegen_return_param<'tcx>( /// Invokes the closure with if necessary a value representing the return pointer. When the closure /// returns the call return value(s) if any are written to the correct place. -pub(super) fn codegen_with_call_return_arg<'tcx, M: Module, T>( - fx: &mut FunctionCx<'_, 'tcx, M>, +pub(super) fn codegen_with_call_return_arg<'tcx, T>( + fx: &mut FunctionCx<'_, '_, 'tcx>, ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, ret_place: Option<CPlace<'tcx>>, - f: impl FnOnce(&mut FunctionCx<'_, 'tcx, M>, Option<Value>) -> (Inst, T), + f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option<Value>) -> (Inst, T), ) -> (Inst, T) { let return_ptr = match ret_arg_abi.mode { PassMode::Ignore => None, @@ -193,7 +193,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, M: Module, T>( } /// Codegen a return instruction with the right return value(s) if any. -pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Module>) { +pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) { match fx.fn_abi.as_ref().unwrap().ret.mode { PassMode::Ignore | PassMode::Indirect { diff --git a/src/analyze.rs b/src/analyze.rs index 62fbcfe3f7a..9aeea38c091 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -11,7 +11,7 @@ pub(crate) enum SsaKind { Ssa, } -pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, SsaKind> { +pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> { let mut flag_map = fx .mir .local_decls diff --git a/src/base.rs b/src/base.rs index 9b2249956c5..8a45e1bad42 100644 --- a/src/base.rs +++ b/src/base.rs @@ -8,7 +8,7 @@ use rustc_target::abi::call::FnAbi; use crate::prelude::*; pub(crate) fn codegen_fn<'tcx>( - cx: &mut crate::CodegenCx<'tcx, impl Module>, + cx: &mut crate::CodegenCx<'_, 'tcx>, instance: Instance<'tcx>, linkage: Linkage, ) { @@ -209,7 +209,7 @@ pub(crate) fn verify_func( }); } -fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) { +fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) { for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() { let block = fx.get_block(bb); fx.bcx.switch_to_block(block); @@ -453,7 +453,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Module>) { } fn codegen_stmt<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, #[allow(unused_variables)] cur_block: Block, stmt: &Statement<'tcx>, ) { @@ -595,10 +595,7 @@ fn codegen_stmt<'tcx>( let from_ty = operand.layout().ty; let to_ty = fx.monomorphize(to_ty); - fn is_fat_ptr<'tcx>( - fx: &FunctionCx<'_, 'tcx, impl Module>, - ty: Ty<'tcx>, - ) -> bool { + fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { ty.builtin_deref(true) .map( |ty::TypeAndMut { @@ -895,10 +892,7 @@ fn codegen_stmt<'tcx>( } } -fn codegen_array_len<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - place: CPlace<'tcx>, -) -> Value { +fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value { match *place.layout().ty.kind() { ty::Array(_elem_ty, len) => { let len = fx @@ -915,7 +909,7 @@ fn codegen_array_len<'tcx>( } pub(crate) fn codegen_place<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, place: Place<'tcx>, ) -> CPlace<'tcx> { let mut cplace = fx.get_local_place(place.local); @@ -987,7 +981,7 @@ pub(crate) fn codegen_place<'tcx>( } pub(crate) fn codegen_operand<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, operand: &Operand<'tcx>, ) -> CValue<'tcx> { match operand { @@ -999,11 +993,7 @@ pub(crate) fn codegen_operand<'tcx>( } } -pub(crate) fn codegen_panic<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - msg_str: &str, - span: Span, -) { +pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) { let location = fx.get_caller_location(span).load_scalar(fx); let msg_ptr = fx.anonymous_str("assert", msg_str); @@ -1017,7 +1007,7 @@ pub(crate) fn codegen_panic<'tcx>( } pub(crate) fn codegen_panic_inner<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, lang_item: rustc_hir::LangItem, args: &[Value], span: Span, diff --git a/src/cast.rs b/src/cast.rs index 57204de1135..432533c7636 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -3,7 +3,7 @@ use crate::prelude::*; pub(crate) fn clif_intcast( - fx: &mut FunctionCx<'_, '_, impl Module>, + fx: &mut FunctionCx<'_, '_, '_>, val: Value, to: Type, signed: bool, @@ -51,7 +51,7 @@ pub(crate) fn clif_intcast( } pub(crate) fn clif_int_or_float_cast( - fx: &mut FunctionCx<'_, '_, impl Module>, + fx: &mut FunctionCx<'_, '_, '_>, from: Value, from_signed: bool, to_ty: Type, diff --git a/src/codegen_i128.rs b/src/codegen_i128.rs index ed9097e5a5b..60fffa60484 100644 --- a/src/codegen_i128.rs +++ b/src/codegen_i128.rs @@ -5,7 +5,7 @@ use cranelift_codegen::ir::ArgumentPurpose; use crate::prelude::*; pub(crate) fn maybe_codegen<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, checked: bool, lhs: CValue<'tcx>, diff --git a/src/common.rs b/src/common.rs index 1443aedb3b8..2c34c8ee5e8 100644 --- a/src/common.rs +++ b/src/common.rs @@ -130,7 +130,7 @@ pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } pub(crate) fn codegen_icmp_imm( - fx: &mut FunctionCx<'_, '_, impl Module>, + fx: &mut FunctionCx<'_, '_, '_>, intcc: IntCC, lhs: Value, rhs: i128, @@ -241,8 +241,8 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool { } } -pub(crate) struct FunctionCx<'clif, 'tcx, M: Module> { - pub(crate) cx: &'clif mut crate::CodegenCx<'tcx, M>, +pub(crate) struct FunctionCx<'m, 'clif, 'tcx> { + pub(crate) cx: &'clif mut crate::CodegenCx<'m, 'tcx>, pub(crate) tcx: TyCtxt<'tcx>, pub(crate) pointer_type: Type, // Cached from module @@ -269,7 +269,7 @@ pub(crate) struct FunctionCx<'clif, 'tcx, M: Module> { pub(crate) inline_asm_index: u32, } -impl<'tcx, M: Module> LayoutOf for FunctionCx<'_, 'tcx, M> { +impl<'tcx> LayoutOf for FunctionCx<'_, '_, 'tcx> { type Ty = Ty<'tcx>; type TyAndLayout = TyAndLayout<'tcx>; @@ -278,31 +278,31 @@ impl<'tcx, M: Module> LayoutOf for FunctionCx<'_, 'tcx, M> { } } -impl<'tcx, M: Module> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx, M> { +impl<'tcx> layout::HasTyCtxt<'tcx> for FunctionCx<'_, '_, 'tcx> { fn tcx<'b>(&'b self) -> TyCtxt<'tcx> { self.tcx } } -impl<'tcx, M: Module> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, M> { +impl<'tcx> rustc_target::abi::HasDataLayout for FunctionCx<'_, '_, 'tcx> { fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout { &self.tcx.data_layout } } -impl<'tcx, M: Module> layout::HasParamEnv<'tcx> for FunctionCx<'_, 'tcx, M> { +impl<'tcx> layout::HasParamEnv<'tcx> for FunctionCx<'_, '_, 'tcx> { fn param_env(&self) -> ParamEnv<'tcx> { ParamEnv::reveal_all() } } -impl<'tcx, M: Module> HasTargetSpec for FunctionCx<'_, 'tcx, M> { +impl<'tcx> HasTargetSpec for FunctionCx<'_, '_, 'tcx> { fn target_spec(&self) -> &Target { &self.tcx.sess.target } } -impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> { +impl<'tcx> FunctionCx<'_, '_, 'tcx> { pub(crate) fn monomorphize<T>(&self, value: T) -> T where T: TypeFoldable<'tcx> + Copy, diff --git a/src/constant.rs b/src/constant.rs index 60f569bca93..3712357746b 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -28,7 +28,7 @@ enum TodoItem { } impl ConstantCx { - pub(crate) fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut impl Module) { + pub(crate) fn finalize(mut self, tcx: TyCtxt<'_>, module: &mut dyn Module) { //println!("todo {:?}", self.todo); define_all_allocs(tcx, module, &mut self); //println!("done {:?}", self.done); @@ -36,7 +36,7 @@ impl ConstantCx { } } -pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) -> bool { +pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { let mut all_constants_ok = true; for constant in &fx.mir.required_consts { let const_ = fx.monomorphize(constant.literal); @@ -79,11 +79,11 @@ pub(crate) fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) { } pub(crate) fn codegen_tls_ref<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, def_id: DefId, layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { - let data_id = data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false); + let data_id = data_id_for_static(fx.tcx, fx.cx.module, def_id, false); let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func); #[cfg(debug_assertions)] fx.add_comment(local_data_id, format!("tls {:?}", def_id)); @@ -92,11 +92,11 @@ pub(crate) fn codegen_tls_ref<'tcx>( } fn codegen_static_ref<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, def_id: DefId, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { - let data_id = data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false); + let data_id = data_id_for_static(fx.tcx, fx.cx.module, def_id, false); let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func); #[cfg(debug_assertions)] fx.add_comment(local_data_id, format!("{:?}", def_id)); @@ -113,7 +113,7 @@ fn codegen_static_ref<'tcx>( } pub(crate) fn codegen_constant<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, constant: &Constant<'tcx>, ) -> CValue<'tcx> { let const_ = fx.monomorphize(constant.literal); @@ -155,7 +155,7 @@ pub(crate) fn codegen_constant<'tcx>( } pub(crate) fn codegen_const_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, const_val: ConstValue<'tcx>, ty: Ty<'tcx>, ) -> CValue<'tcx> { @@ -189,11 +189,8 @@ pub(crate) fn codegen_const_value<'tcx>( let base_addr = match alloc_kind { Some(GlobalAlloc::Memory(alloc)) => { fx.cx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id)); - let data_id = data_id_for_alloc_id( - &mut fx.cx.module, - ptr.alloc_id, - alloc.mutability, - ); + let data_id = + data_id_for_alloc_id(fx.cx.module, ptr.alloc_id, alloc.mutability); let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func); #[cfg(debug_assertions)] @@ -202,15 +199,14 @@ pub(crate) fn codegen_const_value<'tcx>( } Some(GlobalAlloc::Function(instance)) => { let func_id = - crate::abi::import_function(fx.tcx, &mut fx.cx.module, instance); + crate::abi::import_function(fx.tcx, fx.cx.module, instance); let local_func_id = fx.cx.module.declare_func_in_func(func_id, &mut fx.bcx.func); fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) } Some(GlobalAlloc::Static(def_id)) => { assert!(fx.tcx.is_static(def_id)); - let data_id = - data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false); + let data_id = data_id_for_static(fx.tcx, fx.cx.module, def_id, false); let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func); #[cfg(debug_assertions)] @@ -249,12 +245,12 @@ pub(crate) fn codegen_const_value<'tcx>( } fn pointer_for_allocation<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, alloc: &'tcx Allocation, ) -> crate::pointer::Pointer { let alloc_id = fx.tcx.create_memory_alloc(alloc); fx.cx.constants_cx.todo.push(TodoItem::Alloc(alloc_id)); - let data_id = data_id_for_alloc_id(&mut fx.cx.module, alloc_id, alloc.mutability); + let data_id = data_id_for_alloc_id(fx.cx.module, alloc_id, alloc.mutability); let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func); #[cfg(debug_assertions)] @@ -264,7 +260,7 @@ fn pointer_for_allocation<'tcx>( } fn data_id_for_alloc_id( - module: &mut impl Module, + module: &mut dyn Module, alloc_id: AllocId, mutability: rustc_hir::Mutability, ) -> DataId { @@ -280,7 +276,7 @@ fn data_id_for_alloc_id( fn data_id_for_static( tcx: TyCtxt<'_>, - module: &mut impl Module, + module: &mut dyn Module, def_id: DefId, definition: bool, ) -> DataId { @@ -355,7 +351,7 @@ fn data_id_for_static( } } -fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut impl Module, cx: &mut ConstantCx) { +fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx) { while let Some(todo_item) = cx.todo.pop() { let (data_id, alloc, section_name) = match todo_item { TodoItem::Alloc(alloc_id) => { @@ -456,7 +452,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut impl Module, cx: &mut Constan } pub(crate) fn mir_operand_get_const_val<'tcx>( - fx: &FunctionCx<'_, 'tcx, impl Module>, + fx: &FunctionCx<'_, '_, 'tcx>, operand: &Operand<'tcx>, ) -> Option<&'tcx Const<'tcx>> { match operand { diff --git a/src/discriminant.rs b/src/discriminant.rs index ad635016a91..3815e149ffa 100644 --- a/src/discriminant.rs +++ b/src/discriminant.rs @@ -7,7 +7,7 @@ use rustc_target::abi::{Int, TagEncoding, Variants}; use crate::prelude::*; pub(crate) fn codegen_set_discriminant<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>, variant_index: VariantIdx, ) { @@ -70,7 +70,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>( } pub(crate) fn codegen_get_discriminant<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, value: CValue<'tcx>, dest_layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 1a26642a49b..07c6c27817c 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -119,12 +119,12 @@ fn module_codegen( let cgu = tcx.codegen_unit(cgu_name); let mono_items = cgu.items_in_deterministic_order(tcx); - let module = new_module(tcx, cgu_name.as_str().to_string()); + let mut module = new_module(tcx, cgu_name.as_str().to_string()); let mut cx = crate::CodegenCx::new( tcx, backend_config, - module, + &mut module, tcx.sess.opts.debuginfo != DebugInfo::None, ); super::predefine_mono_items(&mut cx, &mono_items); @@ -150,7 +150,7 @@ fn module_codegen( } } } - let (mut module, global_asm, debug, mut unwind_context) = + let (global_asm, debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize()); crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut unwind_context); diff --git a/src/driver/jit.rs b/src/driver/jit.rs index bab4586e7f6..beb316c58c3 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -57,7 +57,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { .into_iter() .collect::<Vec<(_, (_, _))>>(); - let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false); + let mut cx = crate::CodegenCx::new(tcx, backend_config, &mut jit_module, false); super::time(tcx, "codegen mono items", || { super::predefine_mono_items(&mut cx, &mono_items); @@ -85,7 +85,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { } }); - let (mut jit_module, global_asm, _debug, mut unwind_context) = + let (global_asm, _debug, mut unwind_context) = tcx.sess.time("finalize CodegenCx", || cx.finalize()); jit_module.finalize_definitions(); @@ -145,21 +145,20 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 let jit_module = jit_module.as_mut().unwrap(); let backend_config = BACKEND_CONFIG.with(|backend_config| backend_config.borrow().clone().unwrap()); - let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false); let name = tcx.symbol_name(instance).name.to_string(); - let sig = crate::abi::get_function_sig(tcx, cx.module.isa().triple(), instance); - let func_id = cx - .module + let sig = crate::abi::get_function_sig(tcx, jit_module.isa().triple(), instance); + let func_id = jit_module .declare_function(&name, Linkage::Export, &sig) .unwrap(); - cx.module.prepare_for_function_redefine(func_id).unwrap(); + jit_module.prepare_for_function_redefine(func_id).unwrap(); + let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module, false); tcx.sess.time("codegen fn", || { crate::base::codegen_fn(&mut cx, instance, Linkage::Export) }); - let (jit_module, global_asm, _debug_context, unwind_context) = cx.finalize(); + let (global_asm, _debug_context, unwind_context) = cx.finalize(); assert!(global_asm.is_empty()); jit_module.finalize_definitions(); std::mem::forget(unsafe { unwind_context.register_jit(&jit_module) }); @@ -233,7 +232,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { imported_symbols } -pub(super) fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx, impl Module>, inst: Instance<'tcx>) { +pub(super) fn codegen_shim<'tcx>(cx: &mut CodegenCx<'_, 'tcx>, inst: Instance<'tcx>) { let tcx = cx.tcx; let pointer_type = cx.module.target_config().pointer_type(); diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 360810cb58e..91cfde654f9 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -43,7 +43,7 @@ pub(crate) fn codegen_crate( } fn predefine_mono_items<'tcx>( - cx: &mut crate::CodegenCx<'tcx, impl Module>, + cx: &mut crate::CodegenCx<'_, 'tcx>, mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))], ) { cx.tcx.sess.time("predefine functions", || { diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 04aac780125..c8f027e7b1a 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::InlineAsmOperand; use rustc_target::asm::*; pub(crate) fn codegen_inline_asm<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, _span: Span, template: &[InlineAsmTemplatePiece], operands: &[InlineAsmOperand<'tcx>], @@ -203,7 +203,7 @@ fn generate_asm_wrapper( } fn call_inline_asm<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, asm_name: &str, slot_size: Size, inputs: Vec<(InlineAsmReg, Size, Value)>, diff --git a/src/intrinsics/cpuid.rs b/src/intrinsics/cpuid.rs index c1a1cdbe4eb..4c82e793ad2 100644 --- a/src/intrinsics/cpuid.rs +++ b/src/intrinsics/cpuid.rs @@ -6,7 +6,7 @@ use crate::prelude::*; /// /// This emulates an intel cpu with sse and sse2 support, but which doesn't support anything else. pub(crate) fn codegen_cpuid_call<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, leaf: Value, _subleaf: Value, ) -> (Value, Value, Value, Value) { diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index d58e4d49958..0692da397eb 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -6,7 +6,7 @@ use crate::prelude::*; use rustc_middle::ty::subst::SubstsRef; pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, intrinsic: &str, substs: SubstsRef<'tcx>, args: &[mir::Operand<'tcx>], diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 4aed09d2b14..f0ca7400d50 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -153,12 +153,12 @@ pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx } } -fn simd_for_each_lane<'tcx, M: Module>( - fx: &mut FunctionCx<'_, 'tcx, M>, +fn simd_for_each_lane<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, val: CValue<'tcx>, ret: CPlace<'tcx>, f: impl Fn( - &mut FunctionCx<'_, 'tcx, M>, + &mut FunctionCx<'_, '_, 'tcx>, TyAndLayout<'tcx>, TyAndLayout<'tcx>, Value, @@ -182,13 +182,13 @@ fn simd_for_each_lane<'tcx, M: Module>( } } -fn simd_pair_for_each_lane<'tcx, M: Module>( - fx: &mut FunctionCx<'_, 'tcx, M>, +fn simd_pair_for_each_lane<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, x: CValue<'tcx>, y: CValue<'tcx>, ret: CPlace<'tcx>, f: impl Fn( - &mut FunctionCx<'_, 'tcx, M>, + &mut FunctionCx<'_, '_, 'tcx>, TyAndLayout<'tcx>, TyAndLayout<'tcx>, Value, @@ -215,11 +215,11 @@ fn simd_pair_for_each_lane<'tcx, M: Module>( } } -fn simd_reduce<'tcx, M: Module>( - fx: &mut FunctionCx<'_, 'tcx, M>, +fn simd_reduce<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, val: CValue<'tcx>, ret: CPlace<'tcx>, - f: impl Fn(&mut FunctionCx<'_, 'tcx, M>, TyAndLayout<'tcx>, Value, Value) -> Value, + f: impl Fn(&mut FunctionCx<'_, '_, 'tcx>, TyAndLayout<'tcx>, Value, Value) -> Value, ) { let (lane_count, lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx); let lane_layout = fx.layout_of(lane_ty); @@ -236,11 +236,11 @@ fn simd_reduce<'tcx, M: Module>( ret.write_cvalue(fx, res); } -fn simd_reduce_bool<'tcx, M: Module>( - fx: &mut FunctionCx<'_, 'tcx, M>, +fn simd_reduce_bool<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, val: CValue<'tcx>, ret: CPlace<'tcx>, - f: impl Fn(&mut FunctionCx<'_, 'tcx, M>, Value, Value) -> Value, + f: impl Fn(&mut FunctionCx<'_, '_, 'tcx>, Value, Value) -> Value, ) { let (lane_count, _lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx); assert!(ret.layout().ty.is_bool()); @@ -259,7 +259,7 @@ fn simd_reduce_bool<'tcx, M: Module>( } fn bool_to_zero_or_max_uint<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, val: Value, ) -> CValue<'tcx> { @@ -393,7 +393,7 @@ macro simd_flt_binop($fx:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) { } pub(crate) fn codegen_intrinsic_call<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, instance: Instance<'tcx>, args: &[mir::Operand<'tcx>], destination: Option<(CPlace<'tcx>, BasicBlock)>, diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs index e0eb5c59590..1f8eeb1e714 100644 --- a/src/intrinsics/simd.rs +++ b/src/intrinsics/simd.rs @@ -4,7 +4,7 @@ use super::*; use crate::prelude::*; pub(super) fn codegen_simd_intrinsic_call<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, instance: Instance<'tcx>, args: &[mir::Operand<'tcx>], ret: CPlace<'tcx>, diff --git a/src/lib.rs b/src/lib.rs index 417934f7603..122ad4e366d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,9 +127,9 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> { } } -struct CodegenCx<'tcx, M: Module> { +struct CodegenCx<'m, 'tcx: 'm> { tcx: TyCtxt<'tcx>, - module: M, + module: &'m mut dyn Module, global_asm: String, constants_cx: ConstantCx, cached_context: Context, @@ -138,8 +138,13 @@ struct CodegenCx<'tcx, M: Module> { unwind_context: UnwindContext<'tcx>, } -impl<'tcx, M: Module> CodegenCx<'tcx, M> { - fn new(tcx: TyCtxt<'tcx>, backend_config: BackendConfig, module: M, debug_info: bool) -> Self { +impl<'m, 'tcx> CodegenCx<'m, 'tcx> { + fn new( + tcx: TyCtxt<'tcx>, + backend_config: BackendConfig, + module: &'m mut dyn Module, + debug_info: bool, + ) -> Self { let unwind_context = UnwindContext::new( tcx, module.isa(), @@ -162,14 +167,9 @@ impl<'tcx, M: Module> CodegenCx<'tcx, M> { } } - fn finalize(mut self) -> (M, String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) { - self.constants_cx.finalize(self.tcx, &mut self.module); - ( - self.module, - self.global_asm, - self.debug_context, - self.unwind_context, - ) + fn finalize(self) -> (String, Option<DebugContext<'tcx>>, UnwindContext<'tcx>) { + self.constants_cx.finalize(self.tcx, self.module); + (self.global_asm, self.debug_context, self.unwind_context) } } diff --git a/src/num.rs b/src/num.rs index 2022614841d..4fc0cdfe0e7 100644 --- a/src/num.rs +++ b/src/num.rs @@ -41,7 +41,7 @@ pub(crate) fn bin_op_to_intcc(bin_op: BinOp, signed: bool) -> Option<IntCC> { } fn codegen_compare_bin_op<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, signed: bool, lhs: Value, @@ -54,7 +54,7 @@ fn codegen_compare_bin_op<'tcx>( } pub(crate) fn codegen_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, @@ -103,7 +103,7 @@ pub(crate) fn codegen_binop<'tcx>( } pub(crate) fn codegen_bool_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, @@ -124,7 +124,7 @@ pub(crate) fn codegen_bool_binop<'tcx>( } pub(crate) fn codegen_int_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, @@ -197,7 +197,7 @@ pub(crate) fn codegen_int_binop<'tcx>( } pub(crate) fn codegen_checked_int_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, @@ -350,7 +350,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( } pub(crate) fn codegen_float_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, @@ -395,7 +395,7 @@ pub(crate) fn codegen_float_binop<'tcx>( } pub(crate) fn codegen_ptr_binop<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, bin_op: BinOp, in_lhs: CValue<'tcx>, in_rhs: CValue<'tcx>, diff --git a/src/pointer.rs b/src/pointer.rs index 7b31d0a2007..03b1e6cc4ac 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -36,10 +36,7 @@ impl Pointer { } } - pub(crate) fn const_addr<'a, 'tcx>( - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - addr: i64, - ) -> Self { + pub(crate) fn const_addr(fx: &mut FunctionCx<'_, '_, '_>, addr: i64) -> Self { let addr = fx.bcx.ins().iconst(fx.pointer_type, addr); Pointer { base: PointerBase::Addr(addr), @@ -59,7 +56,7 @@ impl Pointer { (self.base, self.offset) } - pub(crate) fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Module>) -> Value { + pub(crate) fn get_addr(self, fx: &mut FunctionCx<'_, '_, '_>) -> Value { match self.base { PointerBase::Addr(base_addr) => { let offset: i64 = self.offset.into(); @@ -81,19 +78,11 @@ impl Pointer { } } - pub(crate) fn offset<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: Offset32, - ) -> Self { + pub(crate) fn offset(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: Offset32) -> Self { self.offset_i64(fx, extra_offset.into()) } - pub(crate) fn offset_i64<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: i64, - ) -> Self { + pub(crate) fn offset_i64(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: i64) -> Self { if let Some(new_offset) = self.offset.try_add_i64(extra_offset) { Pointer { base: self.base, @@ -126,11 +115,7 @@ impl Pointer { } } - pub(crate) fn offset_value<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - extra_offset: Value, - ) -> Self { + pub(crate) fn offset_value(self, fx: &mut FunctionCx<'_, '_, '_>, extra_offset: Value) -> Self { match self.base { PointerBase::Addr(addr) => Pointer { base: PointerBase::Addr(fx.bcx.ins().iadd(addr, extra_offset)), @@ -159,12 +144,7 @@ impl Pointer { } } - pub(crate) fn load<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - ty: Type, - flags: MemFlags, - ) -> Value { + pub(crate) fn load(self, fx: &mut FunctionCx<'_, '_, '_>, ty: Type, flags: MemFlags) -> Value { match self.base { PointerBase::Addr(base_addr) => fx.bcx.ins().load(ty, flags, base_addr, self.offset), PointerBase::Stack(stack_slot) => fx.bcx.ins().stack_load(ty, stack_slot, self.offset), @@ -172,12 +152,7 @@ impl Pointer { } } - pub(crate) fn store<'a, 'tcx>( - self, - fx: &mut FunctionCx<'a, 'tcx, impl Module>, - value: Value, - flags: MemFlags, - ) { + pub(crate) fn store(self, fx: &mut FunctionCx<'_, '_, '_>, value: Value, flags: MemFlags) { match self.base { PointerBase::Addr(base_addr) => { fx.bcx.ins().store(flags, value, base_addr, self.offset); diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 71020b40473..a5ae7fa829d 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -186,7 +186,7 @@ impl FuncWriter for &'_ CommentWriter { } #[cfg(debug_assertions)] -impl<M: Module> FunctionCx<'_, '_, M> { +impl FunctionCx<'_, '_, '_> { pub(crate) fn add_global_comment<S: Into<String>>(&mut self, comment: S) { self.clif_comments.add_global_comment(comment); } @@ -276,7 +276,7 @@ pub(crate) fn write_clif_file<'tcx>( ); } -impl<M: Module> fmt::Debug for FunctionCx<'_, '_, M> { +impl fmt::Debug for FunctionCx<'_, '_, '_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "{:?}", self.instance.substs)?; writeln!(f, "{:?}", self.local_map)?; diff --git a/src/trap.rs b/src/trap.rs index 67495c74148..bb63d72addf 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -2,7 +2,7 @@ use crate::prelude::*; -fn codegen_print(fx: &mut FunctionCx<'_, '_, impl Module>, msg: &str) { +fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { let puts = fx .cx .module @@ -29,7 +29,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl Module>, msg: &str) { } /// Trap code: user1 -pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, impl Module>, msg: impl AsRef<str>) { +pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<str>) { codegen_print(fx, msg.as_ref()); fx.bcx.ins().trap(TrapCode::User(1)); } @@ -38,7 +38,7 @@ pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, impl Module>, msg: impl AsR /// so you can **not** add instructions to it afterwards. /// /// Trap code: user65535 -pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, impl Module>, msg: impl AsRef<str>) { +pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<str>) { codegen_print(fx, msg.as_ref()); fx.bcx.ins().trap(TrapCode::UnreachableCodeReached); } @@ -47,7 +47,7 @@ pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, impl Module>, msg: im /// /// Trap code: user65535 pub(crate) fn trap_unreachable_ret_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, dest_layout: TyAndLayout<'tcx>, msg: impl AsRef<str>, ) -> CValue<'tcx> { @@ -62,7 +62,7 @@ pub(crate) fn trap_unreachable_ret_value<'tcx>( /// to it afterwards. /// /// Trap code: user65535 -pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg: impl AsRef<str>) { +pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<str>) { codegen_print(fx, msg.as_ref()); let true_ = fx.bcx.ins().iconst(types::I32, 1); fx.bcx.ins().trapnz(true_, TrapCode::User(!0)); @@ -72,7 +72,7 @@ pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl Module>, msg: /// /// Trap code: user65535 pub(crate) fn trap_unimplemented_ret_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, dest_layout: TyAndLayout<'tcx>, msg: impl AsRef<str>, ) -> CValue<'tcx> { diff --git a/src/unsize.rs b/src/unsize.rs index c77ff5d56ba..109aee5a044 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -13,7 +13,7 @@ use crate::prelude::*; /// in an upcast, where the new vtable for an object will be derived /// from the old one. pub(crate) fn unsized_info<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, source: Ty<'tcx>, target: Ty<'tcx>, old_info: Option<Value>, @@ -45,7 +45,7 @@ pub(crate) fn unsized_info<'tcx>( /// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer. fn unsize_thin_ptr<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, src: Value, src_layout: TyAndLayout<'tcx>, dst_layout: TyAndLayout<'tcx>, @@ -89,7 +89,7 @@ fn unsize_thin_ptr<'tcx>( /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` pub(crate) fn coerce_unsized_into<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, src: CValue<'tcx>, dst: CPlace<'tcx>, ) { @@ -142,7 +142,7 @@ pub(crate) fn coerce_unsized_into<'tcx>( // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs pub(crate) fn size_and_align_of_dst<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, info: Value, ) -> (Value, Value) { diff --git a/src/value_and_place.rs b/src/value_and_place.rs index c2520b5c6c4..0dad9b2edaf 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -6,7 +6,7 @@ use cranelift_codegen::entity::EntityRef; use cranelift_codegen::ir::immediates::Offset32; fn codegen_field<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, base: Pointer, extra: Option<Value>, layout: TyAndLayout<'tcx>, @@ -15,7 +15,7 @@ fn codegen_field<'tcx>( let field_offset = layout.fields.offset(field.index()); let field_layout = layout.field(&*fx, field.index()); - let simple = |fx: &mut FunctionCx<'_, '_, _>| { + let simple = |fx: &mut FunctionCx<'_, '_, '_>| { ( base.offset_i64(fx, i64::try_from(field_offset.bytes()).unwrap()), field_layout, @@ -106,10 +106,7 @@ impl<'tcx> CValue<'tcx> { } // FIXME remove - pub(crate) fn force_stack( - self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - ) -> (Pointer, Option<Value>) { + pub(crate) fn force_stack(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Pointer, Option<Value>) { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, meta) => (ptr, meta), @@ -129,7 +126,7 @@ impl<'tcx> CValue<'tcx> { } /// Load a value with layout.abi of scalar - pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> Value { + pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> Value { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { @@ -153,10 +150,7 @@ impl<'tcx> CValue<'tcx> { } /// Load a value pair with layout.abi of scalar pair - pub(crate) fn load_scalar_pair( - self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - ) -> (Value, Value) { + pub(crate) fn load_scalar_pair(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Value, Value) { let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { @@ -183,7 +177,7 @@ impl<'tcx> CValue<'tcx> { pub(crate) fn value_field( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, field: mir::Field, ) -> CValue<'tcx> { let layout = self.1; @@ -219,17 +213,13 @@ impl<'tcx> CValue<'tcx> { } } - pub(crate) fn unsize_value( - self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - dest: CPlace<'tcx>, - ) { + pub(crate) fn unsize_value(self, fx: &mut FunctionCx<'_, '_, 'tcx>, dest: CPlace<'tcx>) { crate::unsize::coerce_unsized_into(fx, self, dest); } /// If `ty` is signed, `const_val` must already be sign extended. pub(crate) fn const_val( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, const_val: ty::ScalarInt, ) -> CValue<'tcx> { @@ -330,7 +320,7 @@ impl<'tcx> CPlace<'tcx> { } pub(crate) fn new_stack_slot( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { assert!(!layout.is_unsized()); @@ -352,7 +342,7 @@ impl<'tcx> CPlace<'tcx> { } pub(crate) fn new_var( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { @@ -366,7 +356,7 @@ impl<'tcx> CPlace<'tcx> { } pub(crate) fn new_var_pair( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, local: Local, layout: TyAndLayout<'tcx>, ) -> CPlace<'tcx> { @@ -402,7 +392,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub(crate) fn to_cvalue(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> CValue<'tcx> { + pub(crate) fn to_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CValue<'tcx> { let layout = self.layout(); match self.inner { CPlaceInner::Var(_local, var) => { @@ -453,11 +443,7 @@ impl<'tcx> CPlace<'tcx> { } } - pub(crate) fn write_cvalue( - self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, - from: CValue<'tcx>, - ) { + pub(crate) fn write_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>) { assert_assignable(fx, from.layout().ty, self.layout().ty); self.write_cvalue_maybe_transmute(fx, from, "write_cvalue"); @@ -465,7 +451,7 @@ impl<'tcx> CPlace<'tcx> { pub(crate) fn write_cvalue_transmute( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>, ) { self.write_cvalue_maybe_transmute(fx, from, "write_cvalue_transmute"); @@ -473,12 +459,12 @@ impl<'tcx> CPlace<'tcx> { fn write_cvalue_maybe_transmute( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>, #[cfg_attr(not(debug_assertions), allow(unused_variables))] method: &'static str, ) { fn transmute_value<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, var: Variable, data: Value, dst_ty: Type, @@ -638,7 +624,7 @@ impl<'tcx> CPlace<'tcx> { pub(crate) fn place_field( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, field: mir::Field, ) -> CPlace<'tcx> { let layout = self.layout(); @@ -686,7 +672,7 @@ impl<'tcx> CPlace<'tcx> { pub(crate) fn place_index( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, index: Value, ) -> CPlace<'tcx> { let (elem_layout, ptr) = match self.layout().ty.kind() { @@ -703,7 +689,7 @@ impl<'tcx> CPlace<'tcx> { CPlace::for_ptr(ptr.offset_value(fx, offset), elem_layout) } - pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Module>) -> CPlace<'tcx> { + pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> { let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty); if has_ptr_meta(fx.tcx, inner_layout.ty) { let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx); @@ -718,7 +704,7 @@ impl<'tcx> CPlace<'tcx> { pub(crate) fn place_ref( self, - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, ) -> CValue<'tcx> { if has_ptr_meta(fx.tcx, self.layout().ty) { @@ -735,7 +721,7 @@ impl<'tcx> CPlace<'tcx> { pub(crate) fn downcast_variant( self, - fx: &FunctionCx<'_, 'tcx, impl Module>, + fx: &FunctionCx<'_, '_, 'tcx>, variant: VariantIdx, ) -> Self { assert!(!self.layout().is_unsized()); @@ -749,7 +735,7 @@ impl<'tcx> CPlace<'tcx> { #[track_caller] pub(crate) fn assert_assignable<'tcx>( - fx: &FunctionCx<'_, 'tcx, impl Module>, + fx: &FunctionCx<'_, '_, 'tcx>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>, ) { diff --git a/src/vtable.rs b/src/vtable.rs index 8f15586a9dc..a1f0aa40f0f 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -15,7 +15,7 @@ fn vtable_memflags() -> MemFlags { flags } -pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: Value) -> Value { +pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -25,7 +25,7 @@ pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: V ) } -pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: Value) -> Value { +pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -35,7 +35,7 @@ pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: Valu ) } -pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: Value) -> Value { +pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Value { let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; fx.bcx.ins().load( pointer_ty(fx.tcx), @@ -46,7 +46,7 @@ pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Module>, vtable: } pub(crate) fn get_ptr_and_method_ref<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, arg: CValue<'tcx>, idx: usize, ) -> (Value, Value) { @@ -68,7 +68,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( } pub(crate) fn get_vtable<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>, ) -> Value { @@ -85,7 +85,7 @@ pub(crate) fn get_vtable<'tcx>( } fn build_vtable<'tcx>( - fx: &mut FunctionCx<'_, 'tcx, impl Module>, + fx: &mut FunctionCx<'_, '_, 'tcx>, layout: TyAndLayout<'tcx>, trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>, ) -> DataId { @@ -94,7 +94,7 @@ fn build_vtable<'tcx>( let drop_in_place_fn = import_function( tcx, - &mut fx.cx.module, + fx.cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.tcx), ); @@ -111,7 +111,7 @@ fn build_vtable<'tcx>( opt_mth.map(|(def_id, substs)| { import_function( tcx, - &mut fx.cx.module, + fx.cx.module, Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs) .unwrap() .polymorphize(fx.tcx), |
