stabilize Strict Provenance and Exposed Provenance APIs
Given that [RFC 3559](https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html) has been accepted, t-lang has approved the concept of provenance to exist in the language. So I think it's time that we stabilize the strict provenance and exposed provenance APIs, and discuss provenance explicitly in the docs:
```rust
// core::ptr
pub const fn without_provenance<T>(addr: usize) -> *const T;
pub const fn dangling<T>() -> *const T;
pub const fn without_provenance_mut<T>(addr: usize) -> *mut T;
pub const fn dangling_mut<T>() -> *mut T;
pub fn with_exposed_provenance<T>(addr: usize) -> *const T;
pub fn with_exposed_provenance_mut<T>(addr: usize) -> *mut T;
impl<T: ?Sized> *const T {
pub fn addr(self) -> usize;
pub fn expose_provenance(self) -> usize;
pub fn with_addr(self, addr: usize) -> Self;
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;
}
impl<T: ?Sized> *mut T {
pub fn addr(self) -> usize;
pub fn expose_provenance(self) -> usize;
pub fn with_addr(self, addr: usize) -> Self;
pub fn map_addr(self, f: impl FnOnce(usize) -> usize) -> Self;
}
impl<T: ?Sized> NonNull<T> {
pub fn addr(self) -> NonZero<usize>;
pub fn with_addr(self, addr: NonZero<usize>) -> Self;
pub fn map_addr(self, f: impl FnOnce(NonZero<usize>) -> NonZero<usize>) -> Self;
}
```
I also did a pass over the docs to adjust them, because this is no longer an "experiment". The `ptr` docs now discuss the concept of provenance in general, and then they go into the two families of APIs for dealing with provenance: Strict Provenance and Exposed Provenance. I removed the discussion of how pointers also have an associated "address space" -- that is not actually tracked in the pointer value, it is tracked in the type, so IMO it just distracts from the core point of provenance. I also adjusted the docs for `with_exposed_provenance` to make it clear that we cannot guarantee much about this function, it's all best-effort.
There are two unstable lints associated with the strict_provenance feature gate; I moved them to a new [strict_provenance_lints](https://github.com/rust-lang/rust/issues/130351) feature since I didn't want this PR to have an even bigger FCP. ;)
`@rust-lang/opsem` Would be great to get some feedback on the docs here. :)
Nominating for `@rust-lang/libs-api.`
Part of https://github.com/rust-lang/rust/issues/95228.
[FCP comment](https://github.com/rust-lang/rust/pull/130350#issuecomment-2395114536)
The mir-opt test format emits MIR to extra files that you can automatically update by specifying
--bless on the command line (just like ui tests updating .stderr files).
--blessable test format
By default 32 bit and 64 bit targets use the same dump files, which can be problematic in the
presence of pointers in constants or other bit width dependent things. In that case you can add
// EMIT_MIR_FOR_EACH_BIT_WIDTH
to your test, causing separate files to be generated for 32bit and 64bit systems.
Testing a particular MIR pass
If you are only testing the behavior of a particular mir-opt pass on some specific input (as is
usually the case), you should add
//@ test-mir-pass: PassName
to the top of the file. This makes sure that other passes don't run which means you'll get the input
you expected and your test won't break when other code changes. This also lets you test passes
that are disabled by default.
Emit a diff of the mir for a specific optimization
This is what you want most often when you want to see how an optimization changes the MIR.
// EMIT_MIR $file_name_of_some_mir_dump.diff
Emit mir after a specific optimization
Use this if you are just interested in the final state after an optimization.
// EMIT_MIR $file_name_of_some_mir_dump.after.mir
Emit mir before a specific optimization
This exists mainly for completeness and is rarely useful.
The LLVM FileCheck tool is used to verify the contents of output MIR against CHECK directives
present in the test file. This works on the runtime MIR, generated by --emit=mir, and not
on the output of a individual passes.
Use // skip-filecheck to prevent FileCheck from running.
To check MIR for function foo, start with a // CHECK-LABEL fn foo( directive.
{{regex}} syntax allows to match regex.
[[name:regex]] syntax allows to bind name to a string matching regex, and refer to it
as [[name]] in later directives, regex should be written not to match a leading space.
Use [[my_local:_.*]] to name a local, and [[my_bb:bb.*]] to name a block.