For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
ReflectedFn
struct ReflectedFn[func_type: AnyType, //, func: func_type]
A compile-time reflection handle type for a function value.
All methods are @staticmethod — the handle has no runtime state, only
compile-time parameters. Spell access as reflect_fn[func].display_name()
(preferred) or ReflectedFn[func].display_name().
Example:
from std.reflection import reflect_fn
def my_func(x: Int) -> Int:
return x
def main():
print(reflect_fn[my_func].display_name()) # "my_func"
Parameters
- func_type (
AnyType): The function's type. Inferred fromfunc. - func (
func_type): The function value being introspected.
Implemented traits
AnyType,
ImplicitlyDestructible
Methods
display_name
static display_name() -> StaticString
Returns the function's name as declared in source.
The returned name does not include any information about the function's parameters, arguments, or return type.
Example:
def my_func(): pass
print(reflect_fn[my_func].display_name()) # "my_func"
Returns:
StaticString: The function's source-level name.
linkage_name
static linkage_name[*, target: __mlir_type.`!kgen.target` = _current_target()]() -> StaticString
Returns the function's mangled linkage / symbol name.
Parameters:
- target (
__mlir_type.`!kgen.target`): The compilation target (defaults to the current target).
Returns:
StaticString: The symbol name as it appears in the linker.