Rename `pointer` field on `Pin` A few days ago, I was helping another user create a self-referential type using `PhantomPinned`. However, I noticed an odd behavior when I tried to access one of the type's fields via `Pin`'s `Deref` impl: ```rust use std::{marker::PhantomPinned, ptr}; struct Pinned { data: i32, pointer: *const i32, _pin: PhantomPinned, } fn main() { let mut b = Box::pin(Pinned { data: 42, pointer: ptr::null(), _pin: PhantomPinned, }); { let pinned = unsafe { b.as_mut().get_unchecked_mut() }; pinned.pointer = &pinned.data; } println!("{}", unsafe { *b.pointer }); } ``` ```rust error[E0658]: use of unstable library feature 'unsafe_pin_internals' --> <source>:19:30 | 19 | println!("{}", unsafe { *b.pointer }); | ^^^^^^^^^ error[E0277]: `Pinned` doesn't implement `std::fmt::Display` --> <source>:19:20 | 19 | println!("{}", unsafe { *b.pointer }); | ^^^^^^^^^^^^^^^^^^^^^ `Pinned` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `Pinned` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) ``` Since the user named their field `pointer`, it conflicts with the `pointer` field on `Pin`, which is public but unstable since Rust 1.60.0 with #93176. On versions from 1.33.0 to 1.59.0, where the field on `Pin` is private, this program compiles and prints `42` as expected. To avoid this confusing behavior, this PR renames `pointer` to `__pointer`, so that it's less likely to conflict with a `pointer` field on the underlying type, as accessed through the `Deref` impl. This is technically a breaking change for anyone who names their field `__pointer` on the inner type; if this is undesirable, it could be renamed to something more longwinded. It's also a nightly breaking change for any external users of `unsafe_pin_internals`.
This folder contains tests for MIR optimizations.
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).
--bless
able 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.
Unit testing
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
// unit-test: 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.
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.
// EMIT_MIR $file_name_of_some_mir_dump.before.mir
FileCheck directives
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.
Documentation for FileCheck is available here: https://www.llvm.org/docs/CommandGuide/FileCheck.html