change the type of the argument of `drop_in_place` lang item to `&mut _`
We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:
https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392
This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.
This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:
https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833
------
The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.
One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?
I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)
-------
cc @RalfJung
Closes https://github.com/rust-lang/rust/issues/154274
tests/ui: allow spaces in hashbrown src normalization
If one's home directory contains a space, the default location for the hashbrown source location also contains a space, and so the UI test normalization in issue-21763 fails to normalize as expected.
While this new regex does not handle all valid paths, such as those beginning with `\\?\` or `\\name\`, this handles most absolute UNIX and Windows paths. Relative paths don't seem to be applicable.
Don't return dummy MacroData in `get_macro`
I was experimenting with tool attributes and ast manipulation, and wasted some time figuring out that this was happening. AFAIK all users of `get_macro` are expecting an actual macro (and none were reading the dummy MacroData) so there should be no change in behavior.
Improve caching by introducing `TypingMode::ErasedNotCoherence`
r? @lcnr
This introduces `TypingMode::ErasedNotCoherence`. Most typing modes contain a list of opaque types, which are quite often unused during canonicalization. With this change, any time we try canonicalization, we replace whichever typing mode we're currently in with `ErasedNotcoherence`, attempt to canonicalize, and if that fails *retry* in the original typing mode. If erased mode succeeds, this is beneficial because that way the opaque types don't end up in the cache key, allowing more cache reuse.
This seems to have a small (0.5%) slowdown on most programs, but a dramatic (>60%) speedup in specific cases like the rustc-perf `wg-grammar` benchmark. Some more improvements are expected with "eager normalization", which is work that's under way right now.
add known-bug test for coroutine 'static-yields-non-'static unsoundness (#144442)
Add a `known-bug` regression test for [#144442 ("Unsoundness due to 'static coroutines that yield non-'static values").](https://github.com/rust-lang/rust/issues/144442)
Existing known-bug tests:
```
- tests/ui/closures/static-closures-with-nonstatic-return.rs
- tests/ui/implied-bounds/dyn-erasure-tait.rs
- tests/ui/implied-bounds/dyn-erasure-no-tait.rs
```
Verified in Darwin: running the compiled binary segfaults on current main, so the bug is still present.
Adjust getMCSubtargetInfo signature for LLVM 23+
A recent [LLVM PR](https://github.com/llvm/llvm-project/pull/195032) changed the signature of `getMCSubtargetInfo` to return a reference instead of a pointer. This adjusts uses of the function in `compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp` to account for the different signature.
Always use `ConstFn` context for `const` closures
fixesrust-lang/rust#155803
Since https://github.com/rust-lang/rust/commit/e8a46117795f82f35e2f4087516a8743e28ba174, `hir_body_const_context()` returned the parent's const context for a `const` closure. But a `const` closure can escape its enclosing body via a `fn`-pointer-typed const item or an opaque return type and be invoked at runtime, so it must be const-checked under the most restrictive `ConstFn` context like a regular `const fn`.
r? oli-obk (since you authored the commit mentioned above, feel free to reroll)
Don't run ui-fulldeps tests twice in stage 1
This removes a separate call in the x86_64-gnu-llvm-21-3 job which runs the ui-fulldeps a second time. ui-fulldeps is already running in the first call (`../x.py --stage 1 test`) as it is a default test suite.
This was added in https://github.com/rust-lang/rust/pull/116009, but I think that was a misunderstanding of the problem. The actual problem was fixed in https://github.com/rust-lang/rust/pull/116932 where the actual problem was the use of `&&`.
This doesn't really have much of an impact on CI time (only a couple seconds) because all the tests are skipped with `ignored, up-to-date`. I'm mainly doing this to clean up the script itself for clarity.
port `rustc_ast*` crates from `box_` to `deref_patterns`
Part of rust-lang/rust#156110, this ports the first few crates away from `box_patterns` to `deref_patterns`.
fix: remap ci-llvm debug paths via `-ffile-prefix-map`
### problem:
ci-llvm include paths leak into debuginfo of `librustc_driver` via C/C++ compilation in `rustc_llvm` , causing non-determinism across two stage2 hermetic builds.
this exhibits as suffixes differing in `anon.*.llvm.<hash>` and mismatched GNU Build IDs, this persists even after stripping the debuginfo.
`remap-debuginfo` does not cover this, it only applies to rustc and not to C/C++ compiler.
### fix:
extend debug path remapping to the C/C++ build in `rustc_llvm` by converting `RUSTC_DEBUGINFO_MAP` into corresponding `-fdebug-prefix-map` flags and passing them through `cc::Build`.
**this is a targeted fix in rustc_llvm; a more general solution would involve propagating remap flags across rustc <-> cargo <-> build scripts.**
r? @Urgau
Wasm: remove implicit `__heap_base`/`__data_end` exports
This is kind of a follow-up to rust-lang/rust#147225. Currently `__heap_base`/`__data_end` globals are implicitly exported on `wasm*-unknown-unknown` and `wasm32v1-none`, even though they were only used for Wasm multi-threading, requiring the atomics target feature and shared memory.
Instead users should explicitly opt-in to these features, in which case toolchains, like `wasm-bindgen`, would require some linker flags. After this PR the following would be required for multi-threading support in `wasm-bindgen`:
```
-Clink-arg=--shared-memory -Clink-arg=--max-memory=1073741824 -Clink-arg=--import-memory -Clink-arg=--export=__heap_base -Clink-arg=--export=__wasm_init_tls -Clink-arg=--export=__tls_size -Clink-arg=--export=__tls_align -Clink-arg=--export=__tls_base
```
You will notice that the only new addition is `--export=__heap_base`, apparently `wasm-bindgen` doesn't need `__data_end` anymore (I didn't dig into the original motivation).
---
For context why `wasm-bindgen` needed access to `__heap_base`:
There is currently no mechanism in the Wasm tool conventions that automatically allocates the stack for every thread (e.g. via the `start` function). So `wasm-bindgen` has to explicitly call `malloc` to allocate the stack on the new thread.
However, calling `malloc` itself requires a stack to be present! With the help of `__heap_base` `wasm-bindgen` constructs a temporary stack to make this work. This is obviously quite hacky. A newer implementation could go a different route: e.g. allocate the threads stack in the main thread and passing the right information on, not requiring access to `__heap_base` at all (and avoiding this really messy workaround).
I should also note here that e.g. [`js-bindgen`](https://github.com/wasm-bindgen/js-bindgen), the successor currently being worked on, doesn't need any of these exports because it doesn't rely on post-processing. In which case all of these variables can be accessed by name at link-time, instead of requiring the linker to export each variable for post-processing to find them by name. That is to say: all these workaround are toolchain-specific and not universal to the Wasm targets.
---
r? @alexcrichton
[AIX] add -bdbg:namedsects:ss link arg
On AIX, the PGO runtime and ifunc runtime support requires the named section linker feature which collects the name sections together and generates start/stop symbols for them.
This change adds the option to the default linker args for the target.
generic_const_args: allow paths to non type consts
tracking issue: https://github.com/rust-lang/rust/issues/151972
Non type consts should be usable in the type system in `feature(generic_const_args)`. These are directly plugged into the constant evaluator, unlike type consts, which are attempted to be reasoned about by the type system.
Inherent associated constants are not supported at this time, due to complications around how generic arguments are represented for them (it's currently a mess). The mess is being cleaned up (e.g. https://github.com/rust-lang/rust/pull/154758), so instead of trying to hack support in before the refactoring is done, let's just wait to be able to implement it more cleanly.
r? @BoxyUwU
fix: more descriptive error message for enum to integer
Fixesrust-lang/rust#151116
A more descriptive error message when casting an enum to an Integer. Please review issue linked above.