pub struct Function {Show 20 fields
pub name: String,
pub sig: Signature,
pub params: Vec<ObjectId>,
pub param_names: Vec<Option<String>>,
pub is_static: bool,
pub is_inline: bool,
pub noreturn: bool,
pub inline_hint: Option<InlineHint>,
pub cold: bool,
pub deprecated: Option<Option<String>>,
pub section: Option<String>,
pub asm_label: Option<String>,
pub init_kind: Option<InitKind>,
pub safe: Option<SourceRange>,
pub uses_alloca: bool,
pub locals: Vec<ObjectId>,
pub body: Option<Body>,
pub item_name: Option<String>,
pub env: Vec<EnvParam>,
pub range: SourceRange,
}Expand description
A function declared or defined in the translation unit.
Fields§
§name: StringThe name as written in C.
sig: SignatureThe signature every declaration of it must agree on.
params: Vec<ObjectId>The parameter objects. Empty until the definition is seen.
param_names: Vec<Option<String>>The parameter names as first declared, for the generated extern block.
is_static: boolWhether the function was declared static, i.e. is private to the unit.
is_inline: boolWhether the function was declared inline.
noreturn: boolWhether the function was declared _Noreturn (or [[noreturn]]), so
that a call to it ends the statement it is in.
inline_hint: Option<InlineHint>What always_inline / noinline asked for.
cold: boolWhether __attribute__((cold)) marked it unlikely.
deprecated: Option<Option<String>>The message __attribute__((deprecated)) gave, if it was there at all.
section: Option<String>The section __attribute__((section("…"))) asked for.
asm_label: Option<String>The symbol __asm__("name") renamed the function to.
init_kind: Option<InitKind>Whether __attribute__((constructor)) asked for it to run before
main, or destructor for after it.
safe: Option<SourceRange>Where the function was asked to be safe, if
it was: [[cinrs::safe]], __attribute__((cinrs_safe)) or
#pragma cinrs safe.
A safe function is generated as extern "C" fn rather than
unsafe extern "C" fn, and its body is not wrapped in an unsafe
block, so rustc checks it. The range is where the request was
written, which is what the diagnostics about it point at.
uses_alloca: boolWhether the body calls alloca, in which case the generated item opens
with the arena the emulation allocates out of.
alloca’s memory lives until the function returns — not until the end
of the block it was called in — so the arena is per function and is
dropped by the return, which is exactly that lifetime.
locals: Vec<ObjectId>Every automatic object the body declared, in declaration order.
Code generation needs the whole list — not only the ones a let
statement is visible for — because a local declared inside a statement
expression is a binding too and may need renaming apart.
body: Option<Body>The body, present once a definition has been type checked.
item_name: Option<String>The Rust item name, when it is not the C name.
Only a lifted GNU nested function has one: it becomes a
file-scope item, so it needs a name that cannot collide with the C
function of the same name at file scope, while Function::name stays
what the program called it — which is what diagnostics and __func__
say.
env: Vec<EnvParam>The hidden environment parameters a lifted GNU nested function takes in front of its declared ones, in the order they are passed.
Empty for every ordinary function, and for a nested one that captures nothing — which is why such a nested function’s address may still be taken: the generated item has exactly the signature C gave it.
range: SourceRangeWhere the function’s name was written, at its definition if there is one and at its first declaration otherwise.