From fee1204ffa7d5c989a2cb76d6b3bb8daa51af811 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:49:20 +0000 Subject: [PATCH] Stop taking FunctionCx's fn_abi field --- src/abi/mod.rs | 7 ++----- src/abi/returning.rs | 26 +++++++------------------- src/base.rs | 2 +- src/common.rs | 2 +- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/abi/mod.rs b/src/abi/mod.rs index b0af421008a..6363a0d59a4 100644 --- a/src/abi/mod.rs +++ b/src/abi/mod.rs @@ -222,17 +222,15 @@ enum ArgKind<'tcx> { Spread(Vec>>), } - let fn_abi = fx.fn_abi.take().unwrap(); - // FIXME implement variadics in cranelift - if fn_abi.c_variadic { + if fx.fn_abi.c_variadic { fx.tcx.dcx().span_fatal( fx.mir.span, "Defining variadic functions is not yet supported by Cranelift", ); } - let mut arg_abis_iter = fn_abi.args.iter(); + let mut arg_abis_iter = fx.fn_abi.args.iter(); let func_params = fx .mir @@ -279,7 +277,6 @@ enum ArgKind<'tcx> { } assert!(arg_abis_iter.next().is_none(), "ArgAbi left behind"); - fx.fn_abi = Some(fn_abi); assert!(block_params_iter.next().is_none(), "arg_value left behind"); self::comments::add_locals_header_comment(fx); diff --git a/src/abi/returning.rs b/src/abi/returning.rs index 0799a22c6e1..e0f399e616e 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -12,27 +12,15 @@ pub(super) fn codegen_return_param<'tcx>( ssa_analyzed: &rustc_index::IndexSlice, block_params_iter: &mut impl Iterator, ) -> CPlace<'tcx> { - let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode { + let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.ret.mode { PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => { - let is_ssa = - ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty); - ( - super::make_local_place( - fx, - RETURN_PLACE, - fx.fn_abi.as_ref().unwrap().ret.layout, - is_ssa, - ), - smallvec![], - ) + let is_ssa = ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.ret.layout.ty); + (super::make_local_place(fx, RETURN_PLACE, fx.fn_abi.ret.layout, is_ssa), smallvec![]) } PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { let ret_param = block_params_iter.next().unwrap(); assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type); - ( - CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.as_ref().unwrap().ret.layout), - smallvec![ret_param], - ) + (CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.ret.layout), smallvec![ret_param]) } PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { unreachable!("unsized return value") @@ -45,8 +33,8 @@ pub(super) fn codegen_return_param<'tcx>( Some(RETURN_PLACE), None, &ret_param, - &fx.fn_abi.as_ref().unwrap().ret.mode, - fx.fn_abi.as_ref().unwrap().ret.layout, + &fx.fn_abi.ret.mode, + fx.fn_abi.ret.layout, ); ret_place @@ -115,7 +103,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>( /// Codegen a return instruction with the right return value(s) if any. pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) { - match fx.fn_abi.as_ref().unwrap().ret.mode { + match fx.fn_abi.ret.mode { PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { fx.bcx.ins().return_(&[]); } diff --git a/src/base.rs b/src/base.rs index 9c66fa6d9cc..049023f1560 100644 --- a/src/base.rs +++ b/src/base.rs @@ -87,7 +87,7 @@ pub(crate) fn codegen_fn<'tcx>( instance, symbol_name, mir, - fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())), + fn_abi: RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()), bcx, block_map, diff --git a/src/common.rs b/src/common.rs index b038c7194cd..cf0b065414d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -291,7 +291,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) instance: Instance<'tcx>, pub(crate) symbol_name: String, pub(crate) mir: &'tcx Body<'tcx>, - pub(crate) fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>, + pub(crate) fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>, pub(crate) bcx: FunctionBuilder<'clif>, pub(crate) block_map: IndexVec,