Commit Graph

1630 Commits

Author SHA1 Message Date
Marcelo Dominguez
55c63da345 Add tests remove extra mode and other fixes 2026-08-12 18:06:07 +03:00
Marcelo Dominguez
a5a9f8cf4f Remove codegen and move manifest out of query 2026-08-12 18:06:07 +03: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
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
Chris Denton
4badd0db1b Increase default stack size to 16MiB 2026-08-09 19:56:58 +00: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
8bb9f279a9 refactor handling of target features in Session 2026-08-06 14:45:53 +02: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
Vadim Petrochenkov
9956e2f9a2 Do not forget to initialize jobserver if only linker is parallel 2026-08-04 23:50:16 +03:00
Joao Roberto
57722cba51 Test that assumptions-on-binders enables next-solver
Cover the flag alone, both orderings with -Znext-solver, override of
-Znext-solver=no, and a UI test that no longer passes -Znext-solver.
2026-08-04 12:42:03 -03:00
Jonathan Brouwer
d1cef67484 Rollup merge of #160454 - Sa4dUs:offload-fix-perf, r=ZuseZ4
Add offload guard flags to typeck to prevent perf regressions

Fixes perf regression in https://github.com/rust-lang/rust/pull/158693

r? @ZuseZ4
2026-08-04 14:41:29 +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
Marcelo Dominguez
e04a81fd8a Add offload guard flags to typeck to prevent perf regressions 2026-08-03 20:14:39 +03:00
Vadim Petrochenkov
496056fb26 Use thread::available_parallelism as the default limit for backend parallelism 2026-08-03 12:17:47 +03:00
Vadim Petrochenkov
a77b6c7844 rustc_data_structures: Cleanup jobserver initialization 2026-08-02 15:41:37 +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
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
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
Jacob Pratt
f25db1a66f Rollup merge of #158693 - Sa4dUs:offload-typeck, r=ZuseZ4
Add type-check to offload intrinisc calls

As discussed in [zulip](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20Inferring.20return.20type.20from.20a.20function.20passed.20to.20an.20intr.2E.2E.2E), in order to support sufficiently generic kernel functions, we need to move away from checking arguments and return types solely via traits on the intrinsic declaration. Instead, these validation checks are now performed during the type-checking phase.

r? @ZuseZ4
2026-07-29 20:48:13 -04:00
Sa4dUs
a6776aad96 proper location 2026-07-29 20:57:29 +03: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
Jonathan Brouwer
581f75e736 Rollup merge of #158460 - ZuseZ4:simplify-enzyme-feature, r=bjorn3
Remove llvm_enzyme feature outside of bootstrap

r? bjorn3
I think you were the one who did the last refactoring on how we pass this feature.

We originally introduced and used this compile-time cfg since we were suspecting that some of the work we did for autodiff was causing a compile time regression even when no autodiff was used. It turned out later that we just did extra work due to a bug, which was fixed.

Thanks to the dlopen work our checks are now much simpler. We only do autodiff work if the -Zautodiff=Enable flag was set. If the flag is set we also just check if libEnzyme is in the sysroot, and if we can not find it, we error out.

I noticed it while fixing some related checks in https://github.com/rust-lang/rust/pull/158333
2026-07-29 14:10:29 +02:00
Manuel Drehwald
ba877845ee Remove llvm_enzyme feature outside of bootstrap 2026-07-28 16:11:31 -04:00
Gary Guo
75999c498f Split register_tool into register_attribute_tool and register_lint_tool
This splits the functionality to two parts per RFC. The `#![register_tool]`
attribute registers the tool in both ways.

Semantics remain unchanged and will be adjusted in later commit.
2026-07-27 19:06:33 +01:00
Gary Guo
747ce1a484 Make AttributeParser::parse_limited accept filters instead of symbol
The existing API is preserved as `parse_limited_sym` as a simple helper.

Similarly, `parse_limited_should_emit` is preserved as
`parse_limited_sym_should_emit`. I've noted that all users targets crate,
so the `target_node_id` and `target` parameters are removed from it.
2026-07-27 17:42:20 +01:00
bjorn3
f9679fa4df 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.
2026-07-23 12:14:56 +02:00
Jonathan Brouwer
92190394b9 Rollup merge of #159659 - mejrs:limit, r=petrochenkov
Move `Limit` out of `rustc_hir`

It feels rather out of place in `rustc_hir`, so this PR moves it to `rustc_data_structures`. Part of hopefully moving attributes from `rustc_hir` to their own crate.

~~This also lets `rustc_type_ir` use it~~ actually rustc_type_ir needs to compile on stable and `rustc_data_structures` uses like 30 features 😢
2026-07-22 18:02:21 +02:00
reucru01
01954614ff Adds -Z implicit-sysroot-deps boolean flag 2026-07-22 11:37:34 +01:00
mejrs
ac91844c53 Fixup Limit imports 2026-07-21 15:26:08 +02:00
Oli Scherer
4e2ebd6235 Remove some dead code 2026-07-21 11:34:36 +02:00
bors
87e5904f5e Auto merge of #159610 - JonathanBrouwer:rollup-Wil0K5d, r=JonathanBrouwer
Rollup of 18 pull requests

Successful merges:

 - rust-lang/rust#159600 (`rust-analyzer` subtree update)
 - rust-lang/rust#158046 (proc_macro: preserve file module spans for inner attrs)
 - rust-lang/rust#159000 (Small cleanups to the incr comp session code)
 - rust-lang/rust#159189 (Account for type alias projections in E0308 "expected/found" shortening logic)
 - rust-lang/rust#159449 (Enable single Location to issue multiple borrows)
 - rust-lang/rust#159544 (Suggest valid command-line crate names)
 - rust-lang/rust#159587 (Improve `AttrItem::span`)
 - rust-lang/rust#159594 (feat(rustc_hir_typeck): suggest `impl Fn` return for capturing closures)
 - rust-lang/rust#159597 (std: use `arc4random_buf` from libc)
 - rust-lang/rust#159599 (Resolver: Record at least 1 ambiguous trait if main decl is not a trait.)
 - rust-lang/rust#158061 (Make `pin!()` more foolproof.)
 - rust-lang/rust#159460 (Do not mark unnormalized const aliases as rigid when normalizing param env)
 - rust-lang/rust#159529 (Add regression test for nested replacement ranges in `collect_tokens`)
 - rust-lang/rust#159571 (Remove unused bundled library lookup for the local crate)
 - rust-lang/rust#159585 (Minor `TokenStream` improvements)
 - rust-lang/rust#159586 (Separate `InterpCx` usage by `ConstAnalysis` phases)
 - rust-lang/rust#159602 (Remove `ItemLike`)
 - rust-lang/rust#159603 (Clarify `push_stream`/`push_tree`)

Failed merges:

 - rust-lang/rust#159590 (Remove some dead code)
2026-07-20 19:20:00 +00:00
Jonathan Brouwer
f64867eb92 Rollup merge of #159000 - bjorn3:simplify_incr_comp_session, r=adwinwhite
Small cleanups to the incr comp session code

Found while working on https://github.com/rust-lang/compiler-team/issues/908. I'm working on some more significant changes, but will leave those to a followup PR.

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-07-20 18:06:01 +02:00
bjorn3
d792ea9d7c Remove unreachable code from finalize_session_directory 2026-07-20 13:28:07 +02:00
Urgau
8e6bd6e388 Query-fy and encode canonical symbols 2026-07-19 17:38:56 +02:00
Jacob Pratt
d685d023b1 Rollup merge of #159390 - petrochenkov:cleanpro, r=nnethercote
rustc: Avoid passing jobserver proxy around the compiler

It is used once, when marking a `rustc_thread_pool` worker thread as blocked. `rustc_thread_pool` already has access to the jobserver proxy, so we can move its use from outside of `mark_blocked` to inside of it.

(The modified part of `rustc_thread_pool` is a rustc-specific extension, not an original rayon-core API.)

This is a simpler cleanup subset of https://github.com/rust-lang/rust/pull/155997.

r? @nnethercote
2026-07-17 23:33:32 -04:00
Jonathan Brouwer
151c662284 Rollup merge of #158843 - cezarbbb:fix-143981-sdylib-write-interface-panic, r=bjorn3
Fix ICE in `write_interface` when the interface file can't be written

Fixes rust-lang/rust#143981.

`write_interface` opened the `sdylib` interface file with `fs::File::create_buffered(...).unwrap()`, so any failure to create it (like `-o` into a non-existent or unwritable directory) will ICE instead of reporting a normal error. Emit `FailedWritingFile` instead, matching the rlink and dep-graph write paths.

Also drop a stray trailing `"` from the `FailedWritingFile` in `diagnostic.rs` and `error.rs`.
2026-07-17 15:22:04 +02:00
Vadim Petrochenkov
cc4af8e81b rustc_interface: Minor cleanup to jobserver initialization 2026-07-17 14:09:43 +03:00
cezarbbb
07069b3a38 Fix ICE in write_interface when the interface file can't be written 2026-07-17 09:00:02 +08:00
Daria Sukhonina
c60e5614e1 rustc: Avoid passing jobserver proxy around the compiler
It is used once, when marking a `rustc_thread_pool` worker thread as blocked.
`rustc_thread_pool` already has access to the jobserver proxy, so we can move its use from outside of `mark_blocked` to inside of it.
2026-07-16 17:22:47 +03:00
Jacob Pratt
57f0adccec Rollup merge of #159250 - GuillaumeGomez:rename-diag, r=JonathanBrouwer
Rename `errors.rs` file to `diagnostics.rs` (13/N)

Follow-up of https://github.com/rust-lang/rust/pull/157485.

r? @JonathanBrouwer
2026-07-14 00:15:25 -04:00
Guillaume Gomez
2a74949017 Update rustc_session::errors import 2026-07-13 22:31:51 +02:00
Jubilee Young
7e1c0b6ebb compiler: Remove -Zmutable-noalias 2026-07-13 10:13:02 -07:00
LorrensP-2158466
72e9ddc07f Wrap the resolver arenas into WorkerLocal in preperation of parallel import resolution. 2026-07-10 11:14:40 +02:00
Jonathan Brouwer
2085491fdf Rollup merge of #156777 - sgasho:test-fix-codegen-llvm-autodiff-2, r=ZuseZ4
Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust

* Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust
* Change some llvm ir check in codegen_llvm/autodiff tests

r? @ZuseZ4
2026-07-05 14:12:03 +02:00