Module std::intrinsics
Functions implemented directly in the compiler.
Functions in this module are not intended for general use, and are usually called by wrapper functions in the standard library (e.g. size_of and unreachable).
Intrinsic functions are not first-class citizens. You cannot take a reference to one, or pass it as an argument to another function. The intrinsic call signature is not strictly enforced (pass as many arguments as you want, they will be ignored, the intrinsic may return a value of different type, etc.). Needless to say, intrinsics do not participate in type inference.
Functions
-
extern "intrinsic" fn compile_warn(reason: &[u8])
Emit a warning message during compilation.
-
extern "intrinsic" fn compile_note(reason: &[u8])
Emit a note during compilation.
-
extern "intrinsic" fn unreachable() -> !
-
extern "intrinsic" fn trap() -> !
Trigger a trap (e.g. through an invalid instruction).
-
extern "intrinsic" fn size_of<T>() -> usize
-
extern "intrinsic" fn type_id<T>() -> usize
-
extern "intrinsic" fn type_name<T>() -> &[u8]
-
extern "intrinsic" fn align_of<T>() -> usize
-
Generate a virtual method table for the given protocol and type.
Do not use directly, use coercion to
&dyn Protocol
instead. Meant to be called from a static initializer. -
Minimal support for unit testing in the compiler.
During AST construction, compiler will collect all the methods with
#[test]
attribute and make them available via this intrinsic.Do not use this directly. If implementing a custom test framework, use the TEST_CASES static instead to ensure that all test cases have been discovered.
-
Enum variants
Do not use directly, use enum_variants instead. Meant to be called from a static initializer (see ENUM_VARIANTS).
-
extern "intrinsic" fn asm(assembly: &[u8])
Inline assembly
-
extern "intrinsic" fn dangling<Ptr>() -> Ptr
Ptr: Pointer -
extern "intrinsic" fn in_const_context() -> bool
-
extern "intrinsic" fn is_const_evaluable<T>(expr: T) -> bool
-
Panics during constant evaluation (aborts compilation).
Invoking this during normal runtime is undefined behavior.
Use panic instead.
-
extern "intrinsic" fn const_note(msg: &[u8])
Writes a note during constant evaluation.
Invoking this during normal runtime is undefined behavior.
Use println instead.
-
extern "intrinsic" fn const_warning(msg: &[u8])
Writes a warning during constant evaluation.
Invoking this during normal runtime is undefined behavior.
Use eprintln instead.
-
extern "intrinsic" fn const_alloc<T>(size: usize) -> &mut T
-
extern "intrinsic" fn volatile<Ptr>(ptr: Ptr) -> Ptr
Ptr: Pointer -
extern "intrinsic" fn tag<T>(tag: &[u8], val: T) -> T
Identity function.
Adds a tag to the IR subtree. This has no effect on the generated code, but is generally preserved accross passes until codegen. Tags control certain aspects of const evaluation and compiler diagnostics. They are not meant to be used by user code.
Tags are currently added when desugaring certain language constructs, such as
for
loops anddefer
expressions.The type, constness and value-kind of the tagged expression are preserved.
let x = 0; std::intrinsics::tag("foo", x) += 1; // this is valid assert_eq!(x, 1);
Run this exampleNo user-facing equivalent.
-
extern "intrinsic" fn codegen_const<T>(name: &[u8]) -> T
Return the value of a C builtin constant
-
extern "intrinsic" fn codegen_func<T>(name: &[u8], ...) -> T
Call a builtin C function
-
extern "intrinsic" fn codegen_type_func<T, Ret>(name: &[u8]) -> T
Call a builtin C "type function" (e.g. sizeof)