Commit Graph

2246 Commits

Author SHA1 Message Date
Jacob Pratt
5d2cf8f4f8 Rollup merge of #160978 - mejrs:resolve_path, r=nnethercote
move resolve_path to Session inherent method

rustc_passes depends on rustc_expand just for this, which is imo unnecessary.
2026-08-12 20:17:34 -04:00
Marcelo Dominguez
4227e93fd2 Some fixes and error when missing manifest 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
55c63da345 Add tests remove extra mode and other fixes 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
4d52fe93a2 Add 3-pass compilation to support generics and remove no_mangle attr 2026-08-12 18:06:00 +03:00
mejrs
9c162cbbff update comment 2026-08-12 13:03:59 +02:00
mejrs
b9e9138428 move resolve_path to Session inherent method 2026-08-12 12:59:52 +02:00
Jacob Pratt
2dabc21ee4 Rollup merge of #160924 - mejrs:split_cstore, r=JonathanBrouwer
split up `rustc_session`

Followup on https://github.com/rust-lang/rust/pull/160336 cc @JonathanBrouwer (feel free to review if you want)

The first commit splits out the `cstore` module from `rustc_session` into its own crate.

`rustc_session` actually never used it anywhere internally, and there are also several crates that only depend on `rustc_session` for it. So it is a natural candidate to split off.

The second commit is similar; `rustc_hir::definitions` is moved to `rustc_hir_id`; it is used nowhere in `rustc_hir`, except to implement an inherent method:

```rust
impl DefKind {
        pub fn def_path_data(self, name: Option<Symbol>) -> DefPathData { }
}
```

which is used (once) in rustc_middle, so the items in `rustc_hir::definitions` and this conversion function could be in many places. `rustc_hir_id` is the earliest and the easiest, so that's what I went with.

Together these allow `rustc_crate_store`, `rustc_hir` and `rustc_session` to compile in parallel.
Current graph:

<img width="825" height="617" alt="image" src="https://github.com/user-attachments/assets/aa954265-0057-4596-a7c4-38290937fb74" />

Graph after this pr:

<img width="853" height="572" alt="image" src="https://github.com/user-attachments/assets/9bcd16f8-897c-4990-920b-249500b2e78e" />
2026-08-11 21:18:31 -04:00
Jacob Pratt
e5ee77d258 Rollup merge of #160878 - dronavallipranav:add-rust-analyzer-cfg, r=Urgau
Add rust_analyzer to check-cfg names

Add rust_analyzer as a known cfg name, set to expect no values
Add test to verify name is recognized and warned on setting a value

Fixes rust-lang/rust#160736

r? @Urgau
2026-08-11 21:18:28 -04:00
mejrs
b588ef3b37 Move rustc_session cstore module to its own crate 2026-08-11 17:12:12 +02:00
Mark Rousskov
6408d389fc Add -Zwasm-proc-macro flag
This is currently not really implemented, but partial support for it is
added in various places across the tree. This is a patch extracted from
the wider set of work to make review easier, which wires up:

* Unstable flag in rustc
* Bootstrap flag to enable using wasm-proc-macros (this needs an extra
  std compilation, wiring into compiletest)
* Partial compiletest support for the flag (mostly just CLI side of things)
2026-08-11 08:53:28 -04:00
Pranav Dronavalli
0166f5056a Add rust_analyzer to check-cfg names 2026-08-10 16:55:50 -05:00
mejrs
12674a1f58 rustc_session: minimize rustc_hir dependencies 2026-08-10 12:01:06 +02:00
Jonathan Brouwer
c10876b8a1 Rollup merge of #160744 - mejrs:struct-diagnostics-privacy, r=JonathanBrouwer
make more diagnostic structs pub(crate)
2026-08-09 18:22:27 +02:00
Jacob Pratt
3820cc943d Rollup merge of #158517 - JonathanBrouwer:named_fn_trait_parameters, r=JohnTitor
Initial implementation of named `Fn` trait parameters

This is an initial implementation of the feature `named_fn_trait_parameters`.
This implementation is incomplete (and also marked as such) , and needs significant further changes to be implemented correctly. To keep the size of this PR managable, I propose we do this in follow-up PRs.
I've added a test that shows the current behaviour, with `FIXME` comments where the test output is currently incorrect.

Tracking issue: https://github.com/rust-lang/rust/issues/158499
Accepted RFC: https://github.com/rust-lang/rfcs/pull/3955
2026-08-08 23:51:55 -04:00
mejrs
d8ecbe7c01 Move ExprParenthesesNeeded diagnostic struct out of rustc_session
It was never used in that crate, so rustc_parse is the next obvious place to go. It's also used by rustc_hir_typeck, but sharing diagnostics between crates makes it easy for such things to become dead, so duplicate it.
2026-08-08 12:13:25 +02:00
Jonathan Brouwer
6a3b9acf14 Rollup merge of #160530 - RalfJung:internal-target-features, r=nnethercote
refactor handling of target features in Session

`Session` currently contains two lists of target features: `target_features`, which is also exposed in `cfg`, and `unstable_target_features`, which is used internally to communicate between various parts of the compiler which target features are *actually* available, including some that we don't have plans to put in `cfg`, namely "forbidden" target features. The `unstable_target_features` list is *not* equivalent to what nightly code sees in `cfg(target_features)` as the latter excludes "forbidden" target features. Both lists are computed by `fn cfg_target_features` even though one of them is never used for `cfg`. It's all kind of messy.

This PR refactors that: `fn cfg_target_features` is replaced by `fn internal_target_features` which computes all enabled Rust target features (including "forbidden" ones -- which are really more like "internal-only" ones so the 2nd commit renames them). We then compute `cfg(target_features)` from that. The session only stores one list, `internal_target_features`, which corresponds to the previous `unstable_target_features`.

To simplify computing `internal_target_features` I also refactored `parse_rust_feature_list` to better distinguish actual Rust target features from unknown target features that we are just grandfathering in. I also made `implied_target_features` not rebuild the same hash map over and over again. And I got rid of a bunch of silly temporary vectors and iterations over all Rust target features.
2026-08-08 00:38:22 +02:00
bors
88f7399cb4 Auto merge of #160513 - Dnreikronos:assumptions_on_binders/enable_next_solver, r=lcnr,bit-aloo
session: Enable next-solver globally for assumptions-on-binders

Zulip: https://rust-lang.zulipchat.com/#narrow/channel/618216-t-types.2Fcall-for-participation/topic/assumptions.20on.20binders.3A.20enable.20next-solver.20automatically/with/614548133

`-Zassumptions-on-binders` already needs the next trait solver, but you still had to pass `-Znext-solver` by hand. Easy to forget, and some spots (feature gates) read `next_solver.globally` directly, so just special-casing `next_trait_solver_globally()` wouldn't cut it.

After `-Z` parsing, if assumptions-on-binders is on, force `NextSolverConfig { coherence: true, globally: true }`. Same pattern as `-Zretpoline-external-thunk`. Flag order doesn't matter. `-Znext-solver=no` gets overridden too; imo that's the right call since the assumptions code can't run on the old solver. A hard conflict error would also be fine, just more annoying for day-to-day hacking.

Covered the flag alone, both orderings, and `=no` in a unit test. Dropped the explicit `-Znext-solver` from one UI test under `assumptions_on_binders`.

btw idk if we should strip `-Znext-solver` from the rest of that folder asap or leave the redundancy. irl I'd leave it for now. fyi this also means anything checking `next_solver.globally` sees the effective config. ltm if you'd rather go the conflict-error route instead of overriding `=no`.
2026-08-07 00:35:54 +00:00
Ralf Jung
6253cca669 rename 'forbidden' target features to 'internal-only' 2026-08-06 16:49:57 +02:00
Ralf Jung
8bb9f279a9 refactor handling of target features in Session 2026-08-06 14:45:53 +02:00
bors
7608eb7b07 Auto merge of #159343 - jackh726:enable-polonius-alpha, r=lqd,Kobzol
Enable polonius alpha on nightly



 See [rust-lang/compiler-team#](https://github.com/rust-lang/compiler-team/issues/1015)

The first commit here adds an `-Zpolonius=nll` argument for tests and so people can disable alpha on nightly.
2026-08-05 18:18:53 +00:00
Joao Roberto
4f4ef375d8 Warn when assumptions-on-binders overrides -Znext-solver=no
-Zassumptions-on-binders still forces the next solver globally, but an
explicit -Znext-solver=no is surprising to discard silently. Emit an
early warning in that case, matching the staticlib-hide-internal-symbols
precedent for conflicting -Z combos.
2026-08-05 13:47:11 -03:00
Jonathan Brouwer
900f0bcb32 Rollup merge of #159225 - bjorn3:split_incr_comp_session, r=oli-obk
Split IncrCompSession out of Session

This will allow introducing a separate incr comp session dir for the post LTO artifacts in the future. In addition it statically encodes the lifetime of the incr comp session rather than requiring an enum behind a mutex stored in the Session.

Based on https://github.com/rust-lang/rust/pull/159000
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-08-05 13:36:11 +02:00
Jonathan Brouwer
d734ccbb8d Rollup merge of #160387 - petrochenkov:backlimit, r=bjorn3
rustc_codegen_ssa: Correctly apply the static `--jobs-backend` limit to backend parallelism

Follow up to https://github.com/rust-lang/rust/pull/159675.

r? @bjorn3
2026-08-05 13:36:06 +02:00
Vadim Petrochenkov
9956e2f9a2 Do not forget to initialize jobserver if only linker is parallel 2026-08-04 23:50:16 +03:00
Jonathan Brouwer
4182867eb9 Rollup merge of #160457 - RalfJung:llvm-target-feature, r=folkertdev
implement -Zllvm-target-feature

Implements https://github.com/rust-lang/rust/issues/157753
2026-08-04 18:35:29 +02:00
Joao Roberto
08405c023e Enable next solver globally for assumptions-on-binders
Normalize next_solver after -Z parsing so flag order does not matter
and direct readers of next_solver.globally see the effective config.
2026-08-04 12:41:59 -03:00
Jonathan Brouwer
24c22c576f Rollup merge of #160451 - Kobzol:lookup-opt, r=petrochenkov
Deduplicate target and host filesearch

I was looking into preprocessing the search directories somehow, so that both host and target don't have to scan them. However, it would be a bit annoying, because they don't share the tlib path. But then I noticed that the code already used `Arc` for `SearchPath`, which was essentially the same optimization, which made sense before https://github.com/rust-lang/rust/pull/158823. But after that PR, it doesn't make sense to put `SearchPath` into `Arc`, because it doesn't really do anything, and the complex logic moved into `FileSearch`. So this PR puts that under `Arc`, to avoid doing duplicated work in the common case, where `host == target`.

r? petrochenkov
2026-08-04 14:41:28 +02:00
Ralf Jung
08a1b4258c implement -Zllvm-target-feature 2026-08-04 11:25:59 +02:00
Jakub Beránek
3ee6e30969 Rollup merge of #160449 - Kobzol:filesearch-lookup-fix, r=petrochenkov
Fix lookup of object files

I broke this in https://github.com/rust-lang/rust/pull/158823. I wanted to optimize the potentially O(n^2) object file lookup, but didn't realize that we have to search all search paths here, not only files that we already prefiltered for the lib prefixes.

r? @petrochenkov

Fixes: https://github.com/rust-lang/rust/issues/160446
2026-08-04 11:10:32 +02:00
Jakub Beránek
21cfaf72f1 Rollup merge of #160424 - petrochenkov:jobdflt, r=bjorn3
Use `thread::available_parallelism` as the default limit for backend parallelism

Instead of the old scheme with 32-or-unlimited, depending on inherited-ness of the jobserver.

Not sure if this needs some wider discussion or not.
In the most common case (rustc is called from cargo) nothing changes, because cargo already limits the parallelism to `thread::available_parallelism` by default, and passes this limit to rustc through jobserver.

https://github.com/rust-lang/rust/pull/160387 will become simpler if this PR is merged first.
r? @bjorn3 @Zoxc
2026-08-04 11:10:16 +02:00
Jakub Beránek
6c4c536357 Rollup merge of #160184 - pmur:murp/add-mcount-opts, r=mati865
Add -Zinstrument-mcount={fentry-nop-record,fentry-record}

The linux kernel still uses fentry for x86 and s390x arches. s390x depends entirely on the compiler to record and nop these sections.

This facilitates support for inserting nop's and/or recording the location of each mcount call in a special section named `__mcount_loc`.

These attributes are currently only supported with fentry on the s390x target, otherwise they are quietly ignored (except on s390x).
2026-08-04 11:10:13 +02:00
jackh726
a9836a47e2 Enable polonius alpha on nightly 2026-08-03 23:26:56 +00:00
jackh726
f1fac9267e Add -Zpolonius=off option and use it in tests. 2026-08-03 23:26:50 +00:00
Jakub Beránek
07e1398046 Fix lookup of object files 2026-08-03 18:45:53 +02:00
Jakub Beránek
f0d1057e4a Deduplicate target and host filesearch 2026-08-03 18:43:14 +02:00
Vadim Petrochenkov
496056fb26 Use thread::available_parallelism as the default limit for backend parallelism 2026-08-03 12:17:47 +03:00
bors
6c04025a8a Auto merge of #158823 - Kobzol:flatten-search-paths, r=petrochenkov
Flatten all -L search paths into a single list of files



This is an optimization that mostly targets the new [Cargo build dir layout](https://rust-lang.github.io/rust-project-goals/2025h2/cargo-build-dir-layout.html).

Before, Cargo usually used to pass rustc a single `-L` path to a directory containing potentially a large number of `.rlib` or other dependency paths. Rustc is optimized for this, and does a preprocessing step, where it preloads all files from this directory into a sorted vector, in which it then performs binary search to look for files having a given prefix and postfix.

With the new build dir layout, this changes, and Cargo will pass potentially many (even hundreds, if your crate has many dependencies) `-L` directories, where each directory will usually have only 1-2 files. This is not ideal for the current rustc search implementation, because the old preprocessing isn't really worth it when the `-L` directory typically only has a single file, and because rustc will do a lot of work per each `-L` directory in the lookup phase, including some quadratic (O(n^2)) work.

With the `large-workspace` stress test from rustc-perf, where the final binary has ~1000 total and ~500 direct dependencies:
- With the old build dir layout, rustc does 4274 calls to `FilesIndex::query`
- With the new build dir layout, it does `1938314` calls to `FilesIndex::query`. Not ideal :)

This PR modifies the logic so that instead of going through all `-L` directories one by one when we are looking for a specific dependency, we pre-gather all files from all passed `-L` directories at the start, and sort them all together. Then, in the lookup phase, instead of performing <number of -L dirs> * 4 (.rmeta, .rlib, etc.) searched, we only perform the 4 searches across all files. This gets rid of the O(n^2) behavior.

Further improvements could be made, e.g. sort the files just once and then filter it for for both host and target filesearchs. I alsothought about pre-filtering the files further, e.g. based on their `kind`,  but that is not worth it in usual situations, where ~all of the deps will be `.rlib`s or `.rmeta`s anyway. What might work is pre-filtering based on their actual names (we strip known prefixes from them and then search based on the names alone, in a hashmap or something?), but that can be a follow-up.

Diff vs parent. of https://github.com/rust-lang/rust/pull/159857: https://perf.rust-lang.org/compare.html?start=1a833e16546c2eb012758ddd499964fd8afee29e&end=6514e2707b7e90fecbc570eeaa36f3780a9b02b4&stat=instructions%3Au
2026-07-31 22:09:50 +00:00
Jonathan Brouwer
a621f18f80 Rollup merge of #160085 - mejrs:bye_lints, r=JonathanBrouwer,mu001999
Remove various superfluous lint attributes
2026-07-31 16:02:32 +02:00
Jonathan Brouwer
2eb8d7053c Rollup merge of #159675 - petrochenkov:jjj, r=bjorn3
rustc: Support `--jobs` options for limiting parallelism in various parts of the compiler

`--jobs-frontend` for the frontend, `--jobs-backend` for the backend, `--jobs-linker` for the linker, and `-j`/`--jobs` for the overall limit.
See the added docs for more details.
Part of https://github.com/rust-lang/compiler-team/issues/1005.

Any suspicious option combinations are prohibited for now.
r? @bjorn3 @Zoxc
2026-07-31 16:02:23 +02:00
Jakub Beránek
55500ae2e7 Preprocess and sort files from all search paths into one large list 2026-07-31 13:43:49 +02:00
Jonathan Brouwer
858e064041 Implement named fn trait parameters 2026-07-31 13:27:22 +02:00
Jonathan Brouwer
88606fe949 Rollup merge of #160149 - lqd:fix-windows-pac, r=davidtwco
Fix Windows on Arm PAC default

Windows on Arm's branch protection only supports PAC Key B for return address signing. The CLI parsing sets it to Key A though, and it doesn't have access to the target information to fix it. This PR adds an accessor function where we can fix this possible discrepancy, and lints against using the `branch_protection` unstable option field directly.

I don't think we need to have a generic mechanism to allow targets to define the valid options themselves, at least not yet. So this is the rustc version of https://github.com/llvm/llvm-project/pull/203989 and uses basically the same idea to set the correct default.

This fixes the `pointer-auth-link-with-c` run-make [failure](https://triage.rust-lang.org/gha-logs/rust-lang/rust/90283463228) happening in the [LLVM23 update PR](https://github.com/rust-lang/rust/pull/158734).

It's probable people will want to add a `standard` value for branch protection, matching clang, and the current accessor will be a good place to do that, compared to e.g. only having an accessor for `PacRet::key`.
2026-07-31 00:06:37 +02:00
Paul Murphy
3874adb16b Add -Zinstrument-mcount={fentry-nop-record,fentry-record}
The linux kernel still uses fentry for x86 and s390x arches.
s390x depends entirely on the compiler to record and nop
these sections.

This facilitates support for inserting nop's and/or recording the
location of each mcount call in a special section named `__mcount_loc`.

These attributes are currently only supported with fentry on the s390x
target, otherwise they are quietly ignored (except on s390x).
2026-07-30 15:18:09 -05:00
Rémy Rakic
a0e8bb5d07 fix Windows on Arm PAC default key
Windows on Arm only supports PAC Key B for return address signing,
but we don't know the target when parsing the branch protection CLI
flag, and have to adjust this elsewhere.

Accessing the options field directly is now linted against, and the
accessor function `Session::branch_protection` handles the per-target
adjustment.
2026-07-30 11:53:27 +02:00
Jacob Pratt
acb7f30f6f Rollup merge of #157669 - 1c3t3a:cfi-diag-mode, r=rcvalle
cfi: add diag mode support

Currently a Rust CFI failure only inserts a ud2. However, for clang we have the option for a helpful diagnostic message that explains the violation and is especially helpful for fixing it. This message works through hooking the UBSan runtime and calling into it with the necessary information for a helpful error message. In clang, this is enabled via `-fno-sanitize-trap=cfi`.

This change adds the same behavior to rustc's CFI. Instead of a `no-sanitize-trap` flag, we added `-Z cfi-mode={diag|trap}`, with trap as the default. The diag mode will print the following error message for a violation:

```
tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1: runtime error: control flow integrity check for type fn(i32, i32) -> i32 failed during indirect function call
fn_ptr_type_mismatch.ecd806f409c5c1fc-cgu.0: note: fn_ptr_type_mismatch::add_one defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1
```

r? @rcvalle
2026-07-29 20:48:11 -04:00
Vadim Petrochenkov
2b4375dadc rustc: Support --jobs options for limiting parallelism in various parts of the compiler 2026-07-29 15:22:16 +03:00
Jonathan Brouwer
9ad15589b7 Rollup merge of #159717 - adamgemmell:dev/reucru01/no-implicit-sysroot-deps, r=nnethercote
Add `-Zimplicit-sysroot-deps`

This PR, originally authored by @CrooseGit, adds support for a new flag [proposed in the `build-std=always` RFC](https://rust-lang.github.io/rfcs/3874-build-std-always.html#preventing-implicit-sysroot-dependencies). It unblocks work by @Bryanskiy around handling panic strategies in build-std, for which rustc must look for them in `-Ldependency` locations and not the sysroot.

`-Zimplicit-sysroot-deps` is true by default. When false, rustc will not look in the sysroot when attempting to resolve direct dependencies. It is intended to be used by Cargo when using build-std to improve error messages, avoiding the common "duplicate lang item in crate `core`" error that occurs when not all required standard library crates have been built.

Not included in this PR is the behaviour around dependencies injected by rustc in `rustc_metadata`, such as panic runtimes and compiler-builtins, which will be addressed in the future.
2026-07-29 14:10:34 +02:00
mejrs
c955c638ca Remove various superfluous lint attributes 2026-07-29 13:01:52 +02:00
Bastian Kersting
3955b030e0 Refactor to -Zsanitizer-cfi-diag={false,true} and -Zsanitizer-cfi-recover={false,true} 2026-07-28 21:10:13 +00:00
Bastian Kersting
aea066233b cfi: add diag mode support
Currently a Rust CFI failure only inserts a ud2. However, for clang
we have the option for a helpful diagnostic message that explains the
violation and is especially helpful for fixing it. This message works
through hooking the UBSan runtime and calling into it with the
necessary information for a helpful error message. In clang, this is
enabled via -fno-sanitize-trap=cfi.

This change adds the same behavior to rustc's CFI. Instead of a
no-sanitize-trap flag, we added -Z cfi-mode={diag|trap}, with trap
as the default. The diag mode will print the following error message
for a violation:

```
tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1: runtime error: control flow integrity check for type fn(i32, i32) -> i32 failed during indirect function call
fn_ptr_type_mismatch.ecd806f409c5c1fc-cgu.0: note: fn_ptr_type_mismatch::add_one defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tests/ui/sanitizer/cfi/fn-ptr-type-mismatch.rs:1:1
```
2026-07-28 21:10:12 +00:00