@@ -5434,13 +5434,62 @@ fn hover_feature() {
54345434
54355435 The tracking issue for this feature is: None.
54365436
5437- Intrinsics are never intended to be stable directly, but intrinsics are often
5437+ Intrinsics are rarely intended to be stable directly, but are usually
54385438 exported in some sort of stable manner. Prefer using the stable interfaces to
54395439 the intrinsic directly when you can.
54405440
54415441 ------------------------
54425442
54435443
5444+ ## Intrinsics with fallback logic
5445+
5446+ Many intrinsics can be written in pure rust, albeit inefficiently or without supporting
5447+ some features that only exist on some backends. Backends can simply not implement those
5448+ intrinsics without causing any code miscompilations or failures to compile.
5449+ All intrinsic fallback bodies are automatically made cross-crate inlineable (like `#[inline]`)
5450+ by the codegen backend, but not the MIR inliner.
5451+
5452+ ```rust
5453+ #![feature(rustc_attrs, effects)]
5454+ #![allow(internal_features)]
5455+
5456+ #[rustc_intrinsic]
5457+ const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
5458+ ```
5459+
5460+ Since these are just regular functions, it is perfectly ok to create the intrinsic twice:
5461+
5462+ ```rust
5463+ #![feature(rustc_attrs, effects)]
5464+ #![allow(internal_features)]
5465+
5466+ #[rustc_intrinsic]
5467+ const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
5468+
5469+ mod foo {
5470+ #[rustc_intrinsic]
5471+ const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
5472+ panic!("noisy const dealloc")
5473+ }
5474+ }
5475+
5476+ ```
5477+
5478+ The behaviour on backends that override the intrinsic is exactly the same. On other
5479+ backends, the intrinsic behaviour depends on which implementation is called, just like
5480+ with any regular function.
5481+
5482+ ## Intrinsics lowered to MIR instructions
5483+
5484+ Various intrinsics have native MIR operations that they correspond to. Instead of requiring
5485+ backends to implement both the intrinsic and the MIR operation, the `lower_intrinsics` pass
5486+ will convert the calls to the MIR operation. Backends do not need to know about these intrinsics
5487+ at all.
5488+
5489+ ## Intrinsics without fallback logic
5490+
5491+ These must be implemented by all backends.
5492+
54445493 These are imported as if they were FFI functions, with the special
54455494 `rust-intrinsic` ABI. For example, if one was in a freestanding
54465495 context, but wished to be able to `transmute` between types, and
@@ -5459,7 +5508,8 @@ fn hover_feature() {
54595508 }
54605509 ```
54615510
5462- As with any other FFI functions, these are always `unsafe` to call.
5511+ As with any other FFI functions, these are by default always `unsafe` to call.
5512+ You can add `#[rustc_safe_intrinsic]` to the intrinsic to make it safe to call.
54635513
54645514 "# ] ] ,
54655515 )
0 commit comments