44//! and methods are represented as just a fn ptr and not a full
55//! closure.
66
7- use crate :: abi:: FnAbi ;
7+ use crate :: abi:: { FnAbi , FnAbiLlvmExt } ;
88use crate :: attributes;
99use crate :: llvm;
1010use crate :: context:: CodegenCx ;
1111use crate :: value:: Value ;
1212use rustc_codegen_ssa:: traits:: * ;
1313
14- use rustc:: ty:: { self , TypeFoldable , Instance } ;
15- use rustc:: ty:: layout:: { FnAbiExt , LayoutOf , HasTyCtxt } ;
14+ use rustc:: ty:: { TypeFoldable , Instance } ;
15+ use rustc:: ty:: layout:: { FnAbiExt , HasTyCtxt } ;
1616
1717/// Codegens a reference to a fn/method item, monomorphizing and
1818/// inlining as it goes.
@@ -37,14 +37,14 @@ pub fn get_fn(
3737 return llfn;
3838 }
3939
40- let sig = instance. fn_sig ( cx. tcx ( ) ) ;
4140 let sym = tcx. symbol_name ( instance) . name . as_str ( ) ;
42- debug ! ( "get_fn({:?}: {:?}) => {}" , instance, sig, sym) ;
41+ debug ! ( "get_fn({:?}: {:?}) => {}" , instance, instance. ty( cx. tcx( ) ) , sym) ;
42+
43+ let fn_abi = FnAbi :: of_instance ( cx, instance) ;
4344
4445 let llfn = if let Some ( llfn) = cx. get_declared_value ( & sym) {
45- // Create a fn pointer with the substituted signature.
46- let fn_ptr_ty = tcx. mk_fn_ptr ( sig) ;
47- let llptrty = cx. backend_type ( cx. layout_of ( fn_ptr_ty) ) ;
46+ // Create a fn pointer with the new signature.
47+ let llptrty = fn_abi. ptr_to_llvm_type ( cx) ;
4848
4949 // This is subtle and surprising, but sometimes we have to bitcast
5050 // the resulting fn pointer. The reason has to do with external
@@ -77,15 +77,16 @@ pub fn get_fn(
7777 llfn
7878 }
7979 } else {
80- let sig = tcx. normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & sig) ;
81- let fn_abi = FnAbi :: new ( cx, sig, & [ ] ) ;
8280 let llfn = cx. declare_fn ( & sym, & fn_abi) ;
8381 debug ! ( "get_fn: not casting pointer!" ) ;
8482
8583 if instance. def . is_inline ( tcx) {
8684 attributes:: inline ( cx, llfn, attributes:: InlineAttr :: Hint ) ;
8785 }
88- attributes:: from_fn_attrs ( cx, llfn, Some ( instance. def . def_id ( ) ) , sig. abi ) ;
86+ // FIXME(eddyb) avoid this `Instance::fn_sig` call.
87+ // Perhaps store the relevant information in `FnAbi`?
88+ let sig_abi = instance. fn_sig ( cx. tcx ( ) ) . abi ( ) ;
89+ attributes:: from_fn_attrs ( cx, llfn, Some ( instance. def . def_id ( ) ) , sig_abi) ;
8990
9091 let instance_def_id = instance. def_id ( ) ;
9192
0 commit comments