Skip to content

Commit 704eaef

Browse files
Rollup merge of rust-lang#151465 - RalfJung:fn-call-vars, r=mati865
codegen: clarify some variable names around function calls I looked at rust-lang#145932 to try to understand how it works, and quickly got lost in the variable names -- what refers to the caller, what to the callee? So here's my attempt at making those more clear. Hopefully the new names are correct.^^ Cc @JamieCunliffe
2 parents 5cccc7c + 29ed211 commit 704eaef

3 files changed

Lines changed: 38 additions & 27 deletions

File tree

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13971397
fn call(
13981398
&mut self,
13991399
llty: &'ll Type,
1400-
fn_call_attrs: Option<&CodegenFnAttrs>,
1400+
caller_attrs: Option<&CodegenFnAttrs>,
14011401
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
14021402
llfn: &'ll Value,
14031403
args: &[&'ll Value],
14041404
funclet: Option<&Funclet<'ll>>,
1405-
instance: Option<Instance<'tcx>>,
1405+
callee_instance: Option<Instance<'tcx>>,
14061406
) -> &'ll Value {
14071407
debug!("call {:?} with args ({:?})", llfn, args);
14081408

@@ -1414,10 +1414,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14141414
}
14151415

14161416
// Emit CFI pointer type membership test
1417-
self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn);
1417+
self.cfi_type_test(caller_attrs, fn_abi, callee_instance, llfn);
14181418

14191419
// Emit KCFI operand bundle
1420-
let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn);
1420+
let kcfi_bundle = self.kcfi_operand_bundle(caller_attrs, fn_abi, callee_instance, llfn);
14211421
if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) {
14221422
bundles.push(kcfi_bundle);
14231423
}
@@ -1435,17 +1435,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14351435
)
14361436
};
14371437

1438-
if let Some(instance) = instance {
1438+
if let Some(callee_instance) = callee_instance {
14391439
// Attributes on the function definition being called
1440-
let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id());
1441-
if let Some(fn_call_attrs) = fn_call_attrs
1440+
let callee_attrs = self.cx.tcx.codegen_fn_attrs(callee_instance.def_id());
1441+
if let Some(caller_attrs) = caller_attrs
14421442
// If there is an inline attribute and a target feature that matches
14431443
// we will add the attribute to the callsite otherwise we'll omit
14441444
// this and not add the attribute to prevent soundness issues.
1445-
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance)
1445+
&& let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, callee_instance)
14461446
&& self.cx.tcx.is_target_feature_call_safe(
1447-
&fn_defn_attrs.target_features,
1448-
&fn_call_attrs.target_features.iter().cloned().chain(
1447+
&callee_attrs.target_features,
1448+
&caller_attrs.target_features.iter().cloned().chain(
14491449
self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature {
14501450
name: *feat,
14511451
kind: TargetFeatureKind::Implied,
@@ -1470,14 +1470,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14701470
fn tail_call(
14711471
&mut self,
14721472
llty: Self::Type,
1473-
fn_attrs: Option<&CodegenFnAttrs>,
1473+
caller_attrs: Option<&CodegenFnAttrs>,
14741474
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
14751475
llfn: Self::Value,
14761476
args: &[Self::Value],
14771477
funclet: Option<&Self::Funclet>,
1478-
instance: Option<Instance<'tcx>>,
1478+
callee_instance: Option<Instance<'tcx>>,
14791479
) {
1480-
let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance);
1480+
let call =
1481+
self.call(llty, caller_attrs, Some(fn_abi), llfn, args, funclet, callee_instance);
14811482
llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail);
14821483

14831484
match &fn_abi.ret.mode {

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
199199
// do an invoke, otherwise do a call.
200200
let fn_ty = bx.fn_decl_backend_type(fn_abi);
201201

202-
let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
202+
let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() {
203203
Some(bx.tcx().codegen_instance_attrs(fx.instance.def))
204204
} else {
205205
None
206206
};
207-
let fn_attrs = fn_attrs.as_deref();
207+
let caller_attrs = caller_attrs.as_deref();
208208

209209
if !fn_abi.can_unwind {
210210
unwind = mir::UnwindAction::Unreachable;
@@ -233,7 +233,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
233233
};
234234

235235
if kind == CallKind::Tail {
236-
bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
236+
bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance);
237237
return MergingSucc::False;
238238
}
239239

@@ -245,7 +245,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
245245
};
246246
let invokeret = bx.invoke(
247247
fn_ty,
248-
fn_attrs,
248+
caller_attrs,
249249
Some(fn_abi),
250250
fn_ptr,
251251
llargs,
@@ -268,8 +268,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
268268
}
269269
MergingSucc::False
270270
} else {
271-
let llret =
272-
bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx), instance);
271+
let llret = bx.call(
272+
fn_ty,
273+
caller_attrs,
274+
Some(fn_abi),
275+
fn_ptr,
276+
llargs,
277+
self.funclet(fx),
278+
instance,
279+
);
273280
if fx.mir[self.bb].is_cleanup {
274281
bx.apply_attrs_to_cleanup_callsite(llret);
275282
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,13 @@ pub trait BuilderMethods<'a, 'tcx>:
600600
///
601601
/// ## Arguments
602602
///
603-
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
604-
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
605-
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
606-
/// For instance, in the caller of `BuilderMethods::call`.
603+
/// `caller_attrs` are the attributes of the surrounding caller; they have nothing to do with
604+
/// the callee.
605+
///
606+
/// The `caller_attrs`, `fn_abi`, and `callee_instance` arguments are Options because they are
607+
/// advisory. They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI
608+
/// per se. Any ABI-related transformations should be handled by different, earlier stages of
609+
/// codegen. For instance, in the caller of `BuilderMethods::call`.
607610
///
608611
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
609612
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
@@ -620,23 +623,23 @@ pub trait BuilderMethods<'a, 'tcx>:
620623
fn call(
621624
&mut self,
622625
llty: Self::Type,
623-
fn_attrs: Option<&CodegenFnAttrs>,
626+
caller_attrs: Option<&CodegenFnAttrs>,
624627
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
625628
fn_val: Self::Value,
626629
args: &[Self::Value],
627630
funclet: Option<&Self::Funclet>,
628-
instance: Option<Instance<'tcx>>,
631+
callee_instance: Option<Instance<'tcx>>,
629632
) -> Self::Value;
630633

631634
fn tail_call(
632635
&mut self,
633636
llty: Self::Type,
634-
fn_attrs: Option<&CodegenFnAttrs>,
637+
caller_attrs: Option<&CodegenFnAttrs>,
635638
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
636639
llfn: Self::Value,
637640
args: &[Self::Value],
638641
funclet: Option<&Self::Funclet>,
639-
instance: Option<Instance<'tcx>>,
642+
callee_instance: Option<Instance<'tcx>>,
640643
);
641644

642645
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;

0 commit comments

Comments
 (0)