core_intrinsics
)Expand description
Compiler intrinsics.
The corresponding definitions are in https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/intrinsic.rs. The corresponding const implementations are in https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs.
§Const intrinsics
Note: any changes to the constness of intrinsics should be discussed with the language team. This includes changes in the stability of the constness.
In order to make an intrinsic usable at compile-time, one needs to copy the implementation
from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics to
https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs and add a
#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]
to the intrinsic declaration.
If an intrinsic is supposed to be used from a const fn
with a rustc_const_stable
attribute,
the intrinsic’s attribute must be rustc_const_stable
, too. Such a change should not be done
without T-lang consultation, because it bakes a feature into the language that cannot be
replicated in user code without compiler support.
§Volatiles
The volatile intrinsics provide operations intended to act on I/O memory, which are guaranteed to not be reordered by the compiler across other volatile intrinsics. See the LLVM documentation on [volatile].
§Atomics
The atomic intrinsics provide common atomic operations on machine words, with multiple possible memory orderings. They obey the same semantics as C++11. See the LLVM documentation on [atomics].
A quick refresher on memory ordering:
- Acquire - a barrier for acquiring a lock. Subsequent reads and writes take place after the barrier.
- Release - a barrier for releasing a lock. Preceding reads and writes take place before the barrier.
- Sequentially consistent - sequentially consistent operations are
guaranteed to happen in order. This is the standard mode for working
with atomic types and is equivalent to Java’s
volatile
.
§Unwinding
Rust intrinsics may, in general, unwind. If an intrinsic can never unwind, add the
#[rustc_nounwind]
attribute so that the compiler can make use of this fact.
However, even for intrinsics that may unwind, rustc assumes that a Rust intrinsics will never initiate a foreign (non-Rust) unwind, and thus for panic=abort we can always assume that these intrinsics cannot unwind.
Modules§
- mir
Experimental Rustc internal tooling for hand-writing MIR. - simd
Experimental SIMD compiler intrinsics.