]> git.lizzy.rs Git - rust.git/commitdiff
Remove CValue::Func
authorbjorn3 <bjorn3@users.noreply.github.com>
Sun, 19 Aug 2018 08:50:39 +0000 (10:50 +0200)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 19 Aug 2018 08:50:39 +0000 (10:50 +0200)
src/abi.rs
src/common.rs
src/constant.rs

index 7e19a4fba4f3d774790c3b4576b523a6eafb1116..f76aaba1d95b110c22cb96dca6cea3bc2e5fc8a1 100644 (file)
@@ -472,9 +472,15 @@ pub fn codegen_call<'a, 'tcx: 'a>(
             }
         })).collect::<Vec<_>>();
 
-    let inst = match trans_operand(fx, func) {
-        CValue::Func(func, _) => fx.bcx.ins().call(func, &call_args),
-        func => {
+    let call_inst = match fn_ty.sty {
+        TypeVariants::TyFnDef(def_id, substs) => {
+            let func_ref = fx.get_function_ref(
+                Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
+            );
+            fx.bcx.ins().call(func_ref, &call_args)
+        }
+        _ => {
+            let func = trans_operand(fx, func);
             let func = func.load_value(fx);
             let sig = fx.bcx.import_signature(cton_sig_from_fn_ty(fx.tcx, fn_ty));
             fx.bcx.ins().call_indirect(sig, func, &call_args)
@@ -485,7 +491,7 @@ pub fn codegen_call<'a, 'tcx: 'a>(
         PassMode::NoPass => {}
         PassMode::ByVal(_) => {
             if let Some((ret_place, _)) = destination {
-                let results = fx.bcx.inst_results(inst);
+                let results = fx.bcx.inst_results(call_inst);
                 ret_place.write_cvalue(fx, CValue::ByVal(results[0], ret_layout));
             }
         }
index d18b6bf43b2d13ace911a87c85e6b280e11e7103..8227f93f43bcb693afb994b5582ea1e6ebd5a6f1 100644 (file)
@@ -71,13 +71,12 @@ fn codegen_field<'a, 'tcx: 'a>(
 pub enum CValue<'tcx> {
     ByRef(Value, TyLayout<'tcx>),
     ByVal(Value, TyLayout<'tcx>),
-    Func(FuncRef, TyLayout<'tcx>),
 }
 
 impl<'tcx> CValue<'tcx> {
     pub fn layout(&self) -> TyLayout<'tcx> {
         match *self {
-            CValue::ByRef(_, layout) | CValue::ByVal(_, layout) | CValue::Func(_, layout) => layout,
+            CValue::ByRef(_, layout) | CValue::ByVal(_, layout) => layout,
         }
     }
 
@@ -96,10 +95,6 @@ pub fn force_stack<'a>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Val
                 fx.bcx.ins().stack_store(value, stack_slot, 0);
                 fx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
             }
-            CValue::Func(func, ty) => {
-                let func = fx.bcx.ins().func_addr(types::I64, func);
-                CValue::ByVal(func, ty).force_stack(fx)
-            }
         }
     }
 
@@ -115,7 +110,6 @@ pub fn load_value<'a>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Valu
                 fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
             }
             CValue::ByVal(value, _layout) => value,
-            CValue::Func(func, _layout) => fx.bcx.ins().func_addr(types::I64, func),
         }
     }
 
@@ -123,7 +117,6 @@ pub fn expect_byref(self) -> (Value, TyLayout<'tcx>) {
         match self {
             CValue::ByRef(value, layout) => (value, layout),
             CValue::ByVal(_, _) => bug!("Expected CValue::ByRef, found CValue::ByVal: {:?}", self),
-            CValue::Func(_, _) => bug!("Expected CValue::ByRef, found CValue::Func: {:?}", self),
         }
     }
 
@@ -161,7 +154,6 @@ pub fn unchecked_cast_to(self, layout: TyLayout<'tcx>) -> Self {
         match self {
             CValue::ByRef(addr, _) => CValue::ByRef(addr, layout),
             CValue::ByVal(val, _) => CValue::ByVal(val, layout),
-            CValue::Func(fun, _) => CValue::Func(fun, layout),
         }
     }
 }
index 7a1421ccf49c2cf031100c2e349eaebbbb9b72a9..3bbf74b0a314b8a327df2f6d806f943f52b3a6a4 100644 (file)
@@ -109,7 +109,8 @@ fn trans_const_value<'a, 'tcx: 'a>(
             let func_ref = fx.get_function_ref(
                 Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
             );
-            CValue::Func(func_ref, layout)
+            let func_addr = fx.bcx.ins().func_addr(types::I64, func_ref);
+            CValue::ByVal(func_addr, layout)
         }
         _ => trans_const_place(fx, const_).to_cvalue(fx),
     }