Skip to content

Commit 8aaf7a5

Browse files
committed
Improved documentation of PolyFnSig, FnSig, and FnABI
1 parent 6a69328 commit 8aaf7a5

File tree

2 files changed

+15
-3
lines changed
  • compiler

2 files changed

+15
-3
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,9 @@ pub struct GenSig<'tcx> {
13281328
/// - `inputs`: is the list of arguments and their modes.
13291329
/// - `output`: is the return type.
13301330
/// - `c_variadic`: indicates whether this is a C-variadic function.
1331+
/// NOTE: this signature may not match exactly with the signature of a compiled function.
1332+
/// Attributes like `#[track_caller]` may introduce additional arguments, which are not present here, but are represented in [`rustc_target::abi::call::FnAbi`].
1333+
/// If you are interested in the exact signature and the way arguments are aligned/passed, use [`rustc_target::abi::call::FnAbi`].
13311334
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
13321335
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
13331336
pub struct FnSig<'tcx> {
@@ -1338,10 +1341,11 @@ pub struct FnSig<'tcx> {
13381341
}
13391342

13401343
impl<'tcx> FnSig<'tcx> {
1344+
/// Inputs of this signature.
13411345
pub fn inputs(&self) -> &'tcx [Ty<'tcx>] {
13421346
&self.inputs_and_output[..self.inputs_and_output.len() - 1]
13431347
}
1344-
1348+
/// The return type of this siganture.
13451349
pub fn output(&self) -> Ty<'tcx> {
13461350
self.inputs_and_output[self.inputs_and_output.len() - 1]
13471351
}
@@ -1368,17 +1372,21 @@ pub type PolyFnSig<'tcx> = Binder<'tcx, FnSig<'tcx>>;
13681372

13691373
impl<'tcx> PolyFnSig<'tcx> {
13701374
#[inline]
1375+
/// Returns a [`Binder`] containing the inputs of this signature.
13711376
pub fn inputs(&self) -> Binder<'tcx, &'tcx [Ty<'tcx>]> {
13721377
self.map_bound_ref_unchecked(|fn_sig| fn_sig.inputs())
13731378
}
13741379
#[inline]
1380+
/// Returns a [`Binder`] containing the indexth input of this signature.
13751381
pub fn input(&self, index: usize) -> ty::Binder<'tcx, Ty<'tcx>> {
13761382
self.map_bound_ref(|fn_sig| fn_sig.inputs()[index])
13771383
}
1384+
/// Returns a [`Binder`] containing the inputs and outputs of this signature.
13781385
pub fn inputs_and_output(&self) -> ty::Binder<'tcx, &'tcx List<Ty<'tcx>>> {
13791386
self.map_bound_ref(|fn_sig| fn_sig.inputs_and_output)
13801387
}
13811388
#[inline]
1389+
/// Returns a [`Binder`] containing the return type this signature.
13821390
pub fn output(&self) -> ty::Binder<'tcx, Ty<'tcx>> {
13831391
self.map_bound_ref(|fn_sig| fn_sig.output())
13841392
}
@@ -1391,7 +1399,7 @@ impl<'tcx> PolyFnSig<'tcx> {
13911399
pub fn abi(&self) -> abi::Abi {
13921400
self.skip_binder().abi
13931401
}
1394-
1402+
13951403
pub fn is_fn_trait_compatible(&self) -> bool {
13961404
matches!(
13971405
self.skip_binder(),

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ impl RiscvInterruptKind {
729729

730730
/// Metadata describing how the arguments to a native function
731731
/// should be passed in order to respect the native ABI.
732+
///
733+
/// Signature contained within this function does not have to match the one present in MIR.
734+
/// Certain attributtes, like `#[track_caller]` can introduce addtional arguments, which are present in [`FnAbi`], but not in [`rustc_middle::ty::FnSig`].
735+
/// This difference is not relevant in most cases, but should still be kept in mind.
732736
///
733737
/// I will do my best to describe this structure, but these
734738
/// comments are reverse-engineered and may be inaccurate. -NDM
@@ -749,7 +753,7 @@ pub struct FnAbi<'a, Ty> {
749753
pub fixed_count: u32,
750754

751755
pub conv: Conv,
752-
756+
/// This variable desribes if unwind can cross this function, or if it is invalid to unwind troguh it.
753757
pub can_unwind: bool,
754758
}
755759

0 commit comments

Comments
 (0)