core: check for pointer equality when comparing Eq slices
Because `Eq` types must be reflexively equal, an equal-length slice to the same memory location must be equal.
This is related to #33892 (and #32699) answering this comment from that PR:
> Great! One more easy question: why does this optimization not apply in the non-BytewiseEquality implementation directly above?
Because slices of non-reflexively equal types (like `f64`) are not equal even if it's the same slice. But if the types are `Eq`, we can use this same-address optimization, which this PR implements. Obviously this changes behavior if types violate the reflexivity condition of `Eq`, because their impls of `PartialEq` will no longer be called per-item, but 🤷♂ .
It's not clear how often this optimization comes up in the real world outside of the same-`&str` case covered by #33892, so **I'm requesting a perf run** (on MacOS today, so can't run `rustc_perf` myself). I'm going ahead and making the PR on the basis of being surprised things didn't already work this way.
This is my first time hacking rust itself, so as a perf sanity check I ran `./x.py bench --stage 0 src/lib{std,alloc}`, but the differences were noisy.
To make the existing specialization for `BytewiseEquality` explicit, it's now a supertrait of `Eq + Copy`. `Eq` should be sufficient, but `Copy` was included for clarity.
Rollup of 5 pull requests
Successful merges:
- #62275 (rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.)
- #62465 (Sometimes generate storage statements for temporaries with type `!`)
- #62481 (Use `fold` in `Iterator::last` default implementation)
- #62493 (#62357: doc(ptr): add example for {read,write}_unaligned)
- #62532 (Some more cleanups to syntax::print)
Failed merges:
r? @ghost
Ensure that checkout is with \n line endings
During installation of mingw, at least, the git directories change, so
we need to reset the core.autocrlf config to false.
Once we finish checking out submodules, check that the line endings are
\n and not \r\n.
Artifacts were built via the last try on #62545; I've manually confirmed that `install.sh` appears to no longer have `\r\n` line endings.
Fixes#62276.
Some more cleanups to syntax::print
All of these changes should be functionally equivalent to previous code.
Each commit mostly stands alone and this PR is easiest to review by-commit.
#62357: doc(ptr): add example for {read,write}_unaligned
related to #62357
> With #62323 the only example (that had UB and was thus invalid) in std::ptr::read_unaligned and std::ptr::write_unaligned is removed.
> We should add a valid example of using the aforementioned functions.
Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
rustc_mir: treat DropAndReplace as Drop + Assign in qualify_consts.
This slipped through the cracks and never got implemented (thankfully that just meant it was overly conservative and didn't allow assignments that don't *actually* drop the previous value).
Fixes#62273.
r? @oli-obk
During installation of mingw, at least, the git directories change, so
we need to reset the core.autocrlf config to false.
Once we finish checking out submodules, check that the line endings are
\n and not \r\n.
use visitor for #[structural_match] check
This changes the code so that we recur down the structure of a type of a const (rather than just inspecting at a shallow one or two levels) when we are looking to see if it has an ADT that did not derive `PartialEq` and `Eq`.
Fix#61188Fix#62307
Cc #62336
This enforces that eof() must be called to get the String out, and
generally is better from an API perspective. No users of pretty printing
pre-allocate the buffer.
This function took too many arguments and are simple on the inside;
inlining them makes complexity go down.
hir::print's copy is unfortunately used from librustc_driver so inlining
it is not as straightforward.
Miri: Provide pointer forcing methods for MemPlace and Op
These are useful when one wants to to a lot of work with some place or operand and not to int-to-ptr casts all the time. In particular, this is needed to fix some test failures in Miri: we need to normalize before starting a visitor that walks a run-time value, so that we can later be sure (during the visitor walk) that we have a proper `Pointer`.
Also see the Miri side at https://github.com/rust-lang/miri/pull/830.
Cc @eddyb @oli-obk
Rollup of 5 pull requests
Successful merges:
- #61853 (Emit warning when trying to use PGO in conjunction with unwinding on …)
- #62278 (Add Iterator::partition_in_place() and is_partitioned())
- #62283 (Target::arch can take more than listed options)
- #62393 (Fix pretty-printing of `$crate` (take 4))
- #62474 (Prepare for LLVM 9 update)
Failed merges:
r? @ghost
Prepare for LLVM 9 update
Main changes:
* In preparation for opaque pointer types, the `byval` attribute now takes a type. As such, the argument type needs to be threaded through to the function/callsite attribute application logic.
* On ARM the `+fp-only-sp` and `+d16` features have become `-fp64` and `-d32`. I've switched the target definitions to use the new names, but also added bidirectional emulation so either can be used on any LLVM version for backwards compatibility.
* The datalayout can now specify function pointer alignment. In particular on ARM `Fi8` is specified, which means that function pointer alignment is independent of function alignment. I've added this to our datalayouts to match LLVM (which is something we check) and strip the fnptr alignment for older LLVM versions.
* The fmul/fadd reductions now always respect the accumulator (including for unordered reductions), so we should pass the identity instead of undef.
Open issues:
* https://reviews.llvm.org/D62106 causes linker errors with ld.bdf due to https://sourceware.org/bugzilla/show_bug.cgi?id=24784. To avoid this I've enabled `RelaxELFRelocations`, which results in a GOTPCRELX relocation for `__tls_get_addr` and avoids the issue. However, this is likely not acceptable because relax relocations are not supported by older linker versions. We may need an LLVM option to keep using PLT for `__tls_get_addr` despite `RtLibUseGOT`.
The corresponding llvm-project PR is https://github.com/rust-lang/llvm-project/pull/19.
r? @ghost
Target::arch can take more than listed options
A list of options in a comment like this is almost guaranteed to become out of date: right now it is missing "riscv32" and "riscv64" and perhaps other architectures as well.
Add Iterator::partition_in_place() and is_partitioned()
`partition_in_place()` swaps `&mut T` items in-place to satisfy the
predicate, so all `true` items precede all `false` items. This requires
a `DoubleEndedIterator` so we can search from front and back for items
that need swapping.
`is_partitioned()` checks whether the predicate is already satisfied.