Skip to content

Commit 8a1c864

Browse files
committed
Remove CValue::Func
1 parent 72f4877 commit 8a1c864

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/abi.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,15 @@ pub fn codegen_call<'a, 'tcx: 'a>(
472472
}
473473
})).collect::<Vec<_>>();
474474

475-
let inst = match trans_operand(fx, func) {
476-
CValue::Func(func, _) => fx.bcx.ins().call(func, &call_args),
477-
func => {
475+
let call_inst = match fn_ty.sty {
476+
TypeVariants::TyFnDef(def_id, substs) => {
477+
let func_ref = fx.get_function_ref(
478+
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
479+
);
480+
fx.bcx.ins().call(func_ref, &call_args)
481+
}
482+
_ => {
483+
let func = trans_operand(fx, func);
478484
let func = func.load_value(fx);
479485
let sig = fx.bcx.import_signature(cton_sig_from_fn_ty(fx.tcx, fn_ty));
480486
fx.bcx.ins().call_indirect(sig, func, &call_args)
@@ -485,7 +491,7 @@ pub fn codegen_call<'a, 'tcx: 'a>(
485491
PassMode::NoPass => {}
486492
PassMode::ByVal(_) => {
487493
if let Some((ret_place, _)) = destination {
488-
let results = fx.bcx.inst_results(inst);
494+
let results = fx.bcx.inst_results(call_inst);
489495
ret_place.write_cvalue(fx, CValue::ByVal(results[0], ret_layout));
490496
}
491497
}

src/common.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ fn codegen_field<'a, 'tcx: 'a>(
7171
pub enum CValue<'tcx> {
7272
ByRef(Value, TyLayout<'tcx>),
7373
ByVal(Value, TyLayout<'tcx>),
74-
Func(FuncRef, TyLayout<'tcx>),
7574
}
7675

7776
impl<'tcx> CValue<'tcx> {
7877
pub fn layout(&self) -> TyLayout<'tcx> {
7978
match *self {
80-
CValue::ByRef(_, layout) | CValue::ByVal(_, layout) | CValue::Func(_, layout) => layout,
79+
CValue::ByRef(_, layout) | CValue::ByVal(_, layout) => layout,
8180
}
8281
}
8382

@@ -96,10 +95,6 @@ impl<'tcx> CValue<'tcx> {
9695
fx.bcx.ins().stack_store(value, stack_slot, 0);
9796
fx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
9897
}
99-
CValue::Func(func, ty) => {
100-
let func = fx.bcx.ins().func_addr(types::I64, func);
101-
CValue::ByVal(func, ty).force_stack(fx)
102-
}
10398
}
10499
}
105100

@@ -115,15 +110,13 @@ impl<'tcx> CValue<'tcx> {
115110
fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
116111
}
117112
CValue::ByVal(value, _layout) => value,
118-
CValue::Func(func, _layout) => fx.bcx.ins().func_addr(types::I64, func),
119113
}
120114
}
121115

122116
pub fn expect_byref(self) -> (Value, TyLayout<'tcx>) {
123117
match self {
124118
CValue::ByRef(value, layout) => (value, layout),
125119
CValue::ByVal(_, _) => bug!("Expected CValue::ByRef, found CValue::ByVal: {:?}", self),
126-
CValue::Func(_, _) => bug!("Expected CValue::ByRef, found CValue::Func: {:?}", self),
127120
}
128121
}
129122

@@ -161,7 +154,6 @@ impl<'tcx> CValue<'tcx> {
161154
match self {
162155
CValue::ByRef(addr, _) => CValue::ByRef(addr, layout),
163156
CValue::ByVal(val, _) => CValue::ByVal(val, layout),
164-
CValue::Func(fun, _) => CValue::Func(fun, layout),
165157
}
166158
}
167159
}

src/constant.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ fn trans_const_value<'a, 'tcx: 'a>(
109109
let func_ref = fx.get_function_ref(
110110
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
111111
);
112-
CValue::Func(func_ref, layout)
112+
let func_addr = fx.bcx.ins().func_addr(types::I64, func_ref);
113+
CValue::ByVal(func_addr, layout)
113114
}
114115
_ => trans_const_place(fx, const_).to_cvalue(fx),
115116
}

0 commit comments

Comments
 (0)