mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #139490 - RalfJung:unstable-intrinsics-docs, r=oli-obk
Update some comment/docs related to "extern intrinsic" removal Follow-up to https://github.com/rust-lang/rust/pull/139455. r? `@oli-obk`
This commit is contained in:
commit
42fdd7deee
@ -5,15 +5,11 @@
|
||||
//!
|
||||
//! # 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.
|
||||
//!
|
||||
//! //FIXME(#132735) "old" style intrinsics support has been removed
|
||||
//! In order to make an intrinsic usable at compile-time, it needs to be declared in the "new"
|
||||
//! style, i.e. as a `#[rustc_intrinsic]` function, not inside an `extern` block. Then copy the
|
||||
//! implementation from <https://github.com/rust-lang/miri/blob/master/src/intrinsics> to
|
||||
//! In order to make an intrinsic unstable usable at compile-time, copy the implementation from
|
||||
//! <https://github.com/rust-lang/miri/blob/master/src/intrinsics> to
|
||||
//! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs>
|
||||
//! and make the intrinsic declaration a `const fn`.
|
||||
//! and make the intrinsic declaration below a `const fn`. This should be done in coordination with
|
||||
//! wg-const-eval.
|
||||
//!
|
||||
//! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
|
||||
//! `#[rustc_intrinsic_const_stable_indirect]` needs to be added to the intrinsic. Such a change requires
|
||||
|
@ -53,7 +53,8 @@ Various intrinsics have native MIR operations that they correspond to. Instead o
|
||||
backends to implement both the intrinsic and the MIR operation, the `lower_intrinsics` pass
|
||||
will convert the calls to the MIR operation. Backends do not need to know about these intrinsics
|
||||
at all. These intrinsics only make sense without a body, and can be declared as a `#[rustc_intrinsic]`.
|
||||
The body is never used, as calls to the intrinsic do not exist anymore after MIR analyses.
|
||||
The body is never used as the lowering pass implements support for all backends, so we never have to
|
||||
use the fallback logic.
|
||||
|
||||
## Intrinsics without fallback logic
|
||||
|
||||
|
@ -6882,85 +6882,14 @@ pub fn foo() {}
|
||||
|
||||
#[test]
|
||||
fn hover_feature() {
|
||||
check(
|
||||
r#"#![feature(intrinsics$0)]"#,
|
||||
expect![[r#"
|
||||
*intrinsics*
|
||||
```
|
||||
intrinsics
|
||||
```
|
||||
___
|
||||
|
||||
# `intrinsics`
|
||||
|
||||
The tracking issue for this feature is: None.
|
||||
|
||||
Intrinsics are rarely intended to be stable directly, but are usually
|
||||
exported in some sort of stable manner. Prefer using the stable interfaces to
|
||||
the intrinsic directly when you can.
|
||||
|
||||
------------------------
|
||||
|
||||
|
||||
## Intrinsics with fallback logic
|
||||
|
||||
Many intrinsics can be written in pure rust, albeit inefficiently or without supporting
|
||||
some features that only exist on some backends. Backends can simply not implement those
|
||||
intrinsics without causing any code miscompilations or failures to compile.
|
||||
All intrinsic fallback bodies are automatically made cross-crate inlineable (like `#[inline]`)
|
||||
by the codegen backend, but not the MIR inliner.
|
||||
|
||||
```rust
|
||||
#![feature(intrinsics)]
|
||||
#![allow(internal_features)]
|
||||
|
||||
#[rustc_intrinsic]
|
||||
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||
```
|
||||
|
||||
Since these are just regular functions, it is perfectly ok to create the intrinsic twice:
|
||||
|
||||
```rust
|
||||
#![feature(intrinsics)]
|
||||
#![allow(internal_features)]
|
||||
|
||||
#[rustc_intrinsic]
|
||||
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
|
||||
|
||||
mod foo {
|
||||
#[rustc_intrinsic]
|
||||
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
|
||||
panic!("noisy const dealloc")
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The behaviour on backends that override the intrinsic is exactly the same. On other
|
||||
backends, the intrinsic behaviour depends on which implementation is called, just like
|
||||
with any regular function.
|
||||
|
||||
## Intrinsics lowered to MIR instructions
|
||||
|
||||
Various intrinsics have native MIR operations that they correspond to. Instead of requiring
|
||||
backends to implement both the intrinsic and the MIR operation, the `lower_intrinsics` pass
|
||||
will convert the calls to the MIR operation. Backends do not need to know about these intrinsics
|
||||
at all. These intrinsics only make sense without a body, and can be as a `#[rustc_intrinsic]`.
|
||||
The body is never used, as calls to the intrinsic do not exist anymore after MIR analyses.
|
||||
|
||||
## Intrinsics without fallback logic
|
||||
|
||||
These must be implemented by all backends.
|
||||
|
||||
### `#[rustc_intrinsic]` declarations
|
||||
|
||||
These are written like intrinsics with fallback bodies, but the body is irrelevant.
|
||||
Use `loop {}` for the body or call the intrinsic recursively and add
|
||||
`#[rustc_intrinsic_must_be_overridden]` to the function to ensure that backends don't
|
||||
invoke the body.
|
||||
|
||||
"#]],
|
||||
)
|
||||
let (analysis, position) = fixture::position(r#"#![feature(intrinsics$0)]"#);
|
||||
analysis
|
||||
.hover(
|
||||
&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG },
|
||||
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user