Commit graph

1397 commits

Author SHA1 Message Date
Eric Huss
6de57ea1ec [beta] Revert destabilise target-spec-json
This reverts https://github.com/rust-lang/rust/pull/150151 in order to
deal with https://github.com/rust-lang/rust/issues/151729 where the
destabilization caused a problem with building rustc itself with JSON
target specs. There's a fix at
https://github.com/rust-lang/rust/pull/152677, but we would prefer to
not backport that, and instead give ourselves more time to work out the
kinks. Also, the destabilization was incomplete, and the rest of the
changes are in 1.95 (https://github.com/rust-lang/rust/pull/151534 and
https://github.com/rust-lang/cargo/pull/16557), so it would be nice to
keep all the changes together in one release.

This reverts commit a89683dd95, reversing
changes made to 2f1bd3f378.
2026-02-16 09:07:31 -08:00
Felix Rath
8fa2f693bb
Implement incremental caching for derive macro expansions 2026-01-16 07:36:36 +01:00
Jonathan Brouwer
db10879fd1
Rollup merge of #151096 - rm-providers-deref, r=oli-obk
Remove `Deref`/`DerefMut` impl for `Providers`.

It's described as a "backwards compatibility hack to keep the diff small". Removing it requires only a modest amount of churn, and the resulting code is clearer without the invisible derefs.

r? @oli-obk
2026-01-14 11:05:42 +01:00
Nicholas Nethercote
3aa31788b5 Remove Deref/DerefMut impl for Providers.
It's described as a "backwards compatibility hack to keep the diff
small". Removing it requires only a modest amount of churn, and the
resulting code is clearer without the invisible derefs.
2026-01-14 15:55:59 +11:00
Jonathan Brouwer
a89683dd95
Rollup merge of #150151 - destabilise-target-spec-json, r=Kivooeo
Destabilise `target-spec-json`

Per rust-lang/compiler-team#944:

> Per https://github.com/rust-lang/rust/issues/71009, the ability to load target spec JSONs was stabilised accidentally. Within the team, we've always considered the format to be unstable and have changed it freely. This has been feasible as custom targets can only be used with core, like any other target, and so custom targets de-facto require nightly to be used (i.e. to build core manually or use Cargo's -Zbuild-std).
>
> Current build-std RFCs (https://github.com/rust-lang/rfcs/pull/3873, https://github.com/rust-lang/rfcs/pull/3874) propose a mechanism for building core on stable (at the request of Rust for Linux), which combined with a stable target-spec-json format, permit the current format to be used much more widely on stable toolchains. This would prevent us from improving the format - making it less tied to LLVM, switching to TOML, enabling keys in the spec to be stabilised individually, etc.
>
> De-stabilising the format gives us the opportunity to improve the format before it is too challenging to do so. Internal company toolchains and projects like Rust for Linux already use target-spec-json, but must use nightly at some point while doing so, so while it could be inconvenient for those users to destabilise this, it is hoped that an minimal alternative that we could choose to stabilise can be proposed relatively quickly.
2026-01-13 09:01:29 +01:00
Jonathan Brouwer
b5dd72d292
Port #[collapse_debuginfo] to the new attribute parsing system 2026-01-11 10:54:45 +01:00
mu001999
759857cce3 Add missing translator resources for interface parse_cfg and parse_check_cfg 2026-01-04 11:53:31 +08:00
Manuel Drehwald
dfef2e96fe Remove the need to call clang for std::offload usages 2025-12-23 05:20:07 -08:00
David Wood
6c4c4384e8
destabilise target-spec-json 2025-12-19 11:57:34 +00:00
Jonathan Brouwer
f3fa567fdf
Rollup merge of #150032 - Kivooeo:annotate-snippets-stable, r=Muscraft
Use annotate-snippet as default emitter on stable

This is implementation of https://github.com/rust-lang/rust/issues/149932

Now, after MCP was accepted, we can use annotate-snippet as default emitter for errors, that means that we not longer need of previous emitter, so this PR removed previous emitter and makes annotate-snippet new default one both on stable and nightly

(this PR does not remove a code of previous emitter it just removes a `Default` option of `HumanReadableErrorType` enum, and keeping only `HumanReadableErrorType::AnnotateSnippet` as it now uses by default)
2025-12-16 20:21:10 +01:00
Kivooeo
6d6068f6c5 stabilize annotate-snippet as default formatter 2025-12-16 11:20:27 +00:00
bors
08de25c4ea Auto merge of #149273 - bjorn3:crate_locator_improvements, r=petrochenkov
Don't leak sysroot crates through dependencies

Previously if a dependency of the current crate depended on a sysroot crate, then `extern crate` would in the current crate would pick the first loaded version of said sysroot crate even in case of an ambiguity. This is surprising and brittle. For `-Ldependency=` we already blocked this since rust-lang/rust#110229, but the fix didn't account for sysroot crates.

Should fix https://github.com/rust-lang/rust/issues/147966
2025-12-14 09:16:11 +00:00
bors
3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
Jana Dönszelmann
1cbdaf246b
EII collection queries
EII collection queries
2025-12-12 11:28:58 +01:00
Urgau
8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Matthias Krüger
6078dd3bdf
Rollup merge of #147725 - bjorn3:remove_oom_panic, r=Amanieu
Remove -Zoom=panic

There are major questions remaining about the reentrancy that this allows. It doesn't have any users on github outside of a single project that uses it in a panic=abort project to show backtraces. It can still be emulated through `#[alloc_error_handler]` or `set_alloc_error_hook` depending on if you use the standard library or not. And finally it makes it harder to do various improvements to the allocator shim.

With this PR the sole remaining symbol in the allocator shim that is not effectively emulating weak symbols is the symbol that prevents skipping the allocator shim on stable even when it would otherwise be empty because libstd + `#[global_allocator]` is used.

Closes https://github.com/rust-lang/rust/issues/43596
Fixes https://github.com/rust-lang/rust/issues/126683
2025-12-10 07:54:17 +01:00
Hood Chatham
f07a84fde8
Emscripten: Turn wasm-eh on by default
As specified by MCP:
https://github.com/rust-lang/compiler-team/issues/920
Resolves https://github.com/rust-lang/rust/issues/148309
2025-12-03 14:34:07 -08:00
bjorn3
8f55c15bfe Remove -Zoom=panic
There are major questions remaining about the reentrancy that this
allows. It doesn't have any users on github outside of a single project
that uses it in a panic=abort project to show backtraces. It
can still be emulated through #[alloc_error_handler] or
set_alloc_error_hook depending on if you use the standard library or
not. And finally it makes it harder to do various improvements to the
allocator shim.
2025-11-28 19:30:39 +00:00
bjorn3
99649708fe Use cg_llvm's target_config in miri 2025-11-27 19:12:18 +00:00
bjorn3
00ec159c71 Remove PathKind from CrateSource
It is never used anywhere anymore now that existing_matches doesn't use
it anymore. And there is no good reason for any other code to use it in
the future either.
2025-11-27 18:09:05 +00:00
Stuart Cook
3b531a18b5
Rollup merge of #149173 - bjorn3:target_spec_rust_features, r=RalfJung
Use rust rather than LLVM target features in the target spec

This works better with non-LLVM codegen backends.
2025-11-26 23:32:08 +11:00
bjorn3
fedbccd320 Use rust rather than LLVM target features in the target spec
This works better with non-LLVM codegen backends.
2025-11-25 14:39:42 +00:00
bors
23f708107b Auto merge of #149170 - ZuseZ4:automate-offload-packager, r=oli-obk
automate gpu offloading - part 1

Automates step 1 from the rustc-dev-guide offload section:
https://rustc-dev-guide.rust-lang.org/offload/usage.html#compile-instructions
`"clang-offload-packager" "-o" "host.out" "--image=file=device.bc,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp"`

Verified on an MI 250X

cc `@jhuber6,` `@kevinsala,` `@jdoerfert,` `@Sa4dUs`

r? oli-obk
2025-11-23 10:45:30 +00:00
Manuel Drehwald
5fbe5dae42 Only try to link against offload functions if llvm.enzyme is enabled 2025-11-23 00:19:53 -08:00
mu001999
fc822f8c85 Emit error when using path-segment keyword as cfg pred 2025-11-21 18:48:04 +08:00
Weihang Lo
cf57b9b292
fix(span): track unnormalized source len for dep-info
Add `unnormalized_source_len` field to track the byte length
of source files before normalization (the original length).

`unnormalized_source_len` is for writing the correct file length
to dep-info for `-Zchecksum-hash-algorithm`
2025-11-15 09:05:08 -05:00
Weihang Lo
5f385829e2
refactor(span): rename source_len to normalized_source_len
This is a preparation for introducing a unnormalized source length field
2025-11-15 09:05:08 -05:00
ywxt
a4d0507af7 Lock shards while collecting active jobs.
Co-authored-by: Zoxc <zoxc32@gmail.com>
2025-11-14 09:01:22 +08:00
Jeremy Fitzhardinge
5f29f11a4d Add -Zannotate-moves for profiler visibility of move/copy operations
This implements a new unstable compiler flag `-Zannotate-moves` that makes
move and copy operations visible in profilers by creating synthetic debug
information. This is achieved with zero runtime cost by manipulating debug
info scopes to make moves/copies appear as calls to `compiler_move<T, SIZE>`
and `compiler_copy<T, SIZE>` marker functions in profiling tools.

This allows developers to identify expensive move/copy operations in their
code using standard profiling tools, without requiring specialized tooling
or runtime instrumentation.

The implementation works at codegen time. When processing MIR operands
(`Operand::Move` and `Operand::Copy`), the codegen creates an `OperandRef`
with an optional `move_annotation` field containing an `Instance` of the
appropriate profiling marker function. When storing the operand,
`store_with_annotation()` wraps the store operation in a synthetic debug
scope that makes it appear inlined from the marker.

Two marker functions (`compiler_move` and `compiler_copy`) are defined
in `library/core/src/profiling.rs`. These are never actually called -
they exist solely as debug info anchors.

Operations are only annotated if the type:
   - Meets the size threshold (default: 65 bytes, configurable via
     `-Zannotate-moves=SIZE`)
   - Has a non-scalar backend representation (scalars use registers,
     not memcpy)

This has a very small size impact on object file size. With the default
limit it's well under 0.1%, and even with a very small limit of 8 bytes
it's still ~1.5%. This could be enabled by default.
2025-11-06 15:39:45 -08:00
bors
c5e283b0d2 Auto merge of #148188 - Muscraft:annotate-snippets-default-on-nightly, r=estebank
feat: Use annotate-snippets by default on nightly

This PR switches the default renderer to use `annotate-snippets` on nightly, but does not affect stable. This is part of the ongoing effort to use `annotate-snippets` to render all diagnostics.

[MCP](https://github.com/rust-lang/compiler-team/issues/937)

Note: This contains the test change from rust-lang/rust#148004, without the change to the default emitter.

rust-lang/rust#59346
rust-lang/rust-project-goals#123

r? `@davidtwco`
2025-11-06 11:45:06 +00:00
Scott Schafer
9cb7deb0b5
refactor: Make short a field on HumanReadableErrorType varinants 2025-11-05 09:01:07 -07:00
bjorn3
1d34478147 Move warning reporting from flag_to_backend_features to cfg_target_feature
This way warnings are emitted even in a check build.
2025-11-05 10:48:29 +00:00
Paul Murphy
bb9d800b78 Stabilize -Zjump-tables=<bool> into -Cjump-table=<bool> 2025-11-03 08:12:16 -06:00
Paul Murphy
4959d18a97 Rename -Zno-jump-tables to -Zjump-tables=<bool>
Both gcc and llvm accept -fjump-tables as well as -fno-jump-tables. For
consistency, allow rustc to accept -Zjump-tables=yes too.
2025-11-03 08:12:13 -06:00
bjorn3
3d035505a3 Better warning message for crate type unsupported by codegen backend 2025-11-02 12:33:38 +00:00
bjorn3
23edbb67bd Don't require dlltool with the dummy backend on MinGW
The dummy backend should be able to cross-compile to any target without
requiring any external tool or library other than the rust standard
library.
2025-10-31 15:29:32 +00:00
Matthias Krüger
d399bc07f3
Rollup merge of #148252 - Binlogo:threads-outrage-diagnose-tips, r=nnethercote
Improve diagnose for unconditional panic when resource limit

Improve diagnostic message for similar issue rust-lang/rust#115021.

When `parallel_compiler=true`, the Rust compiler frontend sets `-Z threads` to match the number of cores, which is reasonable and common. However, in a constrained environment or with an excessive number of cores (such as 377 mentioned below 😑), it could consume all resources and cause a panic.

Setting a default maximum for `-Z threads` in a parallel compiler is challenging. However, the panic error message can guide the user to check the system limit and explicitly lower the thread count according to their needs.

```
14:55:47 thread 'main' panicked at /rustc/f1586001ace26df7cafeb6534eaf76fb2c5513e5/compiler/rustc_interface/src/util.rs:216:18:

14:55:47 called `Result::unwrap()` on an `Err` value: ThreadPoolBuildError { kind: IOError(Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }) }

...

14:55:47 note: compiler flags: --crate-type lib -C opt-level=z -C embed-bitcode=no -C linker=/cache/84996/rust-sdk/target/shim/aarch64-unknown-linux-ohos/clang -Z unstable-options -C symbol-mangling-version=v0 -Z panic-in-drop=abort -C codegen-units=1 -C debuginfo=1 -C embed-bitcode=yes -Z threads=377 -C link-arg=-Wl,--build-id=sha1 -Z binary-dep-depinfo
```
2025-10-31 02:39:16 +01:00
bjorn3
4b9dc49975 Allow check builds with binaries for the dummy codegen backend 2025-10-30 15:13:05 +00:00
bjorn3
4d7c784caf Handle default features and -Ctarget-features in the dummy backend
This prevents a warning about ABI relevant target features not being set
on x86 and arm. In addition it is required for miri to report correct
features in is_*_feature_detected!() if miri switches to the dummy backend.
2025-10-29 13:43:14 +00:00
Binlogo
5aa2a90724 Improve diagnose for unconditional panic when resource limit 2025-10-29 21:21:25 +08:00
Matthias Krüger
6a7bcec8da
Rollup merge of #148177 - bjorn3:codegen_backend_crate_types, r=WaffleLapkin
Allow codegen backends to indicate which crate types they support

This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.

This is a prerequisite for https://github.com/rust-lang/miri/pull/4648.
2025-10-28 17:49:29 +01:00
bjorn3
9fc1378916 Report correct unsupported crate type for the dummy codegen backend 2025-10-28 14:26:01 +00:00
bors
adaa838976 Auto merge of #148035 - bjorn3:check_skip_codegen_crate, r=madsmtm
Skip codegen_crate call in check mode

This way we don't have to spawn the coordinator thread. Some errors will no longer be emitted with this in check mode. For example the check that `-Ctarget-cpu` is passed on targets that need this.

Suggested by `@saethlin`
2025-10-27 17:24:08 +00:00
bjorn3
b443a59ba8 Allow codegen backends to indicate which crate types they support
This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.
2025-10-27 16:24:33 +00:00
bjorn3
3ce89e257d Use the actual StableCrateId for the incr comp session dir
Previously only --crate-type would be taken into account, not #![crate_type].
2025-10-27 15:56:09 +00:00
bors
4b53279854 Auto merge of #148040 - saethlin:trivial-consts, r=oli-obk
Add a fast path for lowering trivial consts

The objective of this PR is to improve compilation performance for crates that define a lot of trivial consts. This is a flamegraph of a build of a library crate that is just 100,000 trivial consts, taken from a nightly compiler:
<img width="842" height="280" alt="2025-10-25-164005_842x280_scrot" src="https://github.com/user-attachments/assets/e5400aaf-03bd-4461-b905-054aa82ca60f" />
My objective is to target all of the cycles in `eval_to_const_value_raw` that are not part of `mir_built`, because if you look at the `mir_built` for a trivial const, we already have the value available.

In this PR, the definition of a trivial const is this:
```rust
const A: usize = 0;
```
Specifically, we look for if the `mir_built` body is a single basic block containing one assign statement and a return terminator, where the assign statement assigns an `Operand::Constant(Const::Val)`. The MIR dumps for these look like:
```
const A: usize = {
    let mut _0: usize;

    bb0: {
        _0 = const 0_usize;
        return;
    }
}
```

The implementation is built around a new query, `trivial_const(LocalDefId) -> Option<(ConstValue, Ty)>` which returns the contents of the `Const::Val` in the `mir_built` if the `LocalDefId` is a trivial const.

Then I added _debug_ assertions to the beginning of `mir_for_ctfe` and `mir_promoted` to prevent trying to get the body of a trivial const, because that would defeat the optimization here. But these are deliberately _debug_ assertions because the consequence of failing the assertion is that compilation is slow, not corrupt. If we made these hard assertions, I'm sure there are obscure scenarios people will run into where the compiler would ICE instead of continuing on compilation, just a bit slower. I'd like to know about those, but I do not think serving up an ICE is worth it.

With the assertions in place, I just added logic around all the places they were hit, to skip over trying to analyze the bodies of trivial consts.

In the future, I'd like to see this work extended by:
* Pushing detection of trivial consts before MIR building
* Including DefKind::Static and DefKind::InlineConst
* Including consts like `_1 = const 0_usize; _0 = &_1`, which would make a lot of promoteds into trivial consts
* Handling less-trivial consts like `const A: usize = B`, which have `Operand::Constant(Const::Unevaluated)`
2025-10-27 11:02:41 +00:00
Ben Kimock
775da711c6 Add a fast path for lowering trivial consts 2025-10-25 16:59:53 -04:00
bjorn3
5a8ffa4bef Skip codegen_crate call in check mode 2025-10-24 10:25:13 +00:00
Zalathar
98c95c966b Remove current code for embedding command-line args in PDB 2025-10-18 12:24:40 +11:00
Camille GILLOT
ca0379d6cd Diagnose liveness on MIR. 2025-10-11 20:50:21 +00:00