Skip to content

Commit 25b1232

Browse files
authored
Rollup merge of #143716 - workingjubilee:document-some-codegen-backend-stuff, r=bjorn3,fee1-dead
compiler: doc/comment some codegen-for-functions interfaces An out-of-date comment gets updated and some underdocumented functions get documented.
2 parents 1412294 + 39f7707 commit 25b1232

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,33 @@ pub trait BuilderMethods<'a, 'tcx>:
554554
/// Called for `StorageDead`
555555
fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
556556

557+
/// "Finally codegen the call"
558+
///
559+
/// ## Arguments
560+
///
561+
/// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory.
562+
/// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se.
563+
/// Any ABI-related transformations should be handled by different, earlier stages of codegen.
564+
/// For instance, in the caller of `BuilderMethods::call`.
565+
///
566+
/// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance`
567+
/// should still do correct codegen, and code should not be miscompiled if they are omitted.
568+
/// It is not a miscompilation in this sense if it fails to run under CFI, other sanitizers, or
569+
/// in the context of other compiler-enhanced security features.
570+
///
571+
/// The typical case that they are None is during the codegen of intrinsics and lang-items,
572+
/// as those are "fake functions" with only a trivial ABI if any, et cetera.
573+
///
574+
/// ## Return
575+
///
576+
/// Must return the value the function will return so it can be written to the destination,
577+
/// assuming the function does not explicitly pass the destination as a pointer in `args`.
557578
fn call(
558579
&mut self,
559580
llty: Self::Type,
560581
fn_attrs: Option<&CodegenFnAttrs>,
561582
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
562-
llfn: Self::Value,
583+
fn_val: Self::Value,
563584
args: &[Self::Value],
564585
funclet: Option<&Self::Funclet>,
565586
instance: Option<Instance<'tcx>>,

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ use crate::mir::operand::OperandRef;
66
use crate::mir::place::PlaceRef;
77

88
pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
9+
/// Higher-level interface to emitting calls to intrinsics
10+
///
911
/// Remember to add all intrinsics here, in `compiler/rustc_hir_analysis/src/check/mod.rs`,
1012
/// and in `library/core/src/intrinsics.rs`; if you need access to any LLVM intrinsics,
1113
/// add them to `compiler/rustc_codegen_llvm/src/context.rs`.
1214
/// Returns `Err` if another instance should be called instead. This is used to invoke
1315
/// intrinsic default bodies in case an intrinsic is not implemented by the backend.
16+
///
17+
/// NOTE: allowed to call [`BuilderMethods::call`]
18+
///
19+
/// [`BuilderMethods::call`]: super::builder::BuilderMethods::call
1420
fn codegen_intrinsic_call(
1521
&mut self,
1622
instance: ty::Instance<'tcx>,
1723
args: &[OperandRef<'tcx, Self::Value>],
18-
result: PlaceRef<'tcx, Self::Value>,
24+
result_dest: PlaceRef<'tcx, Self::Value>,
1925
span: Span,
2026
) -> Result<(), ty::Instance<'tcx>>;
2127

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,16 @@ fn needs_fn_once_adapter_shim(
991991
Ok(false)
992992
}
993993
(ty::ClosureKind::Fn, ty::ClosureKind::FnMut) => {
994-
// The closure fn `llfn` is a `fn(&self, ...)`. We want a
995-
// `fn(&mut self, ...)`. In fact, at codegen time, these are
996-
// basically the same thing, so we can just return llfn.
994+
// The closure fn is a `fn(&self, ...)`, but we want a `fn(&mut self, ...)`.
995+
// At codegen time, these are basically the same, so we can just return the closure.
997996
Ok(false)
998997
}
999998
(ty::ClosureKind::Fn | ty::ClosureKind::FnMut, ty::ClosureKind::FnOnce) => {
1000-
// The closure fn `llfn` is a `fn(&self, ...)` or `fn(&mut
1001-
// self, ...)`. We want a `fn(self, ...)`. We can produce
1002-
// this by doing something like:
999+
// The closure fn is a `fn(&self, ...)` or `fn(&mut self, ...)`, but
1000+
// we want a `fn(self, ...)`. We can produce this by doing something like:
10031001
//
1004-
// fn call_once(self, ...) { call_mut(&self, ...) }
1005-
// fn call_once(mut self, ...) { call_mut(&mut self, ...) }
1002+
// fn call_once(self, ...) { Fn::call(&self, ...) }
1003+
// fn call_once(mut self, ...) { FnMut::call_mut(&mut self, ...) }
10061004
//
10071005
// These are both the same at codegen time.
10081006
Ok(true)

0 commit comments

Comments
 (0)