Commit Graph

1609 Commits

Author SHA1 Message Date
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
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
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
sgasho
d7e4edd9a1 Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme 2026-07-03 00:43:49 +09:00
Paul Murphy
c340e8a2ba Allow section override when using patchable-function-entries
Sometimes it is necessary to group patchable function entrypoint
records in distinct linker sections. This is the case for some bpf
functions within the linux kernel which shouldn't be visible to
ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form
`prefix_nops,total_nops,record_section`, which places all entry
record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an
optional `section="name"` option to place a function into a specific
section.

This is made possible by llvm attribute `patchable-function-entry-section`
added in llvm 21.
2026-06-29 08:52:28 -05:00
Jonathan Brouwer
4631799a4a Rollup merge of #158185 - xmakro:perf/stable-crate-ids-lockfree, r=mu001999
perf: Make stable_crate_ids reads lock-free after crate loading
2026-06-26 20:22:20 +02:00
Jacob Pratt
a82172d9ca Rollup merge of #158036 - pmur:murp/add-fentry, r=folkertdev
Add -Zinstrument-mcount=fentry to -Zinstrument-mcount

fentry is essentially a simpler version of mcount where the counting function is called before any other function prologue actions happen.

fentry is still used by the linux x86-64 kernel. It's unclear if or when patchable-function-entry will replace it. It is also used by clang for some x86-64 mingw toolchains.

This is only supported on some x86, x86-64, and s390x targets.
2026-06-25 17:53:53 -04:00
bors
973ad0d0ab Auto merge of #158239 - nnethercote:rework-lint-pass-running, r=Urgau
Rework lint pass running



Some cleanups relating to the running of lint passes.

r? @Urgau
2026-06-25 08:22:49 +00:00
aerooneqq
3d19869935 Refactor proc_macro_decls_static 2026-06-22 10:22:53 +03:00
Nicholas Nethercote
9b420de3f7 Rework check_ast_node_inner
It's called in two cases: pre-expansion lists, and early lints. The
appropriate builtin pass is specified at the call site but the
appropriate other passes are chosen within, which is inconsistent.

This commit changes it so everything is chosen within, based on the
boolean `pre_expansion_lint` parameter. `check_ast_node_inner` is split
into `run_passes` and `run_pass`; the extra function is needed because
the genericness of `builtin_lints` is pushed down one level below
`check_ast_node`.
2026-06-22 16:03:45 +10:00
Jonathan Brouwer
45e0dedeaf Rollup merge of #158193 - JonathanBrouwer:late-lint-experiment, r=jdonszelmann
Remove `has_delayed_lints` optimization

Keeping track of `has_delayed_lints` doesn't seem to have a perf effect anymore so let's not make the code more complicated than needed. These flags were previously used so we don't have to iterate over all hir owners, but iterating over all hir owners seems fast enough

cc @jdonszelmann
2026-06-21 14:52:10 +02:00
Jonathan Brouwer
2668f36a40 Rollup merge of #155439 - ranger-ross:cargo-new-build-dir-layout, r=bjorn3,kobzol
Enable Cargo's new build-dir layout

This PR enables the new Cargo `build-dir` layout in boostrap builds with `-Zbuild-dir-new-layout`.

See: [#t-infra/bootstrap > Has anyone tested &#96;./x&#96; with the new build-dir layout?](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Has.20anyone.20tested.20.60.2E.2Fx.60.20with.20the.20new.20build-dir.20layout.3F/with/581660716)

Tracked in: https://github.com/rust-lang/cargo/issues/15010

r? @bjorn3

cc: @epage
2026-06-21 14:52:08 +02:00
Ross Sullivan
61f3e086ac fix: Only add native paths to PATH during macro expansion on windows
This reduces the size of PATH on windows during macro expansion to avoid
hitting windows limits. With the new Cargo build-dir layout this becomes
more important as Cargo now passes more `-L` args which end up bloating
PATH.
2026-06-21 18:44:24 +09:00
Jonathan Brouwer
7a14504a86 Remove has_delayed_lints optimization 2026-06-21 10:01:09 +02:00
xmakro
7c96471b6f perf: Make stable_crate_ids reads lock-free after crate loading 2026-06-20 11:38:00 -07:00
Nicholas Nethercote
43a9857143 Change EarlyCheckNode from a trait to an enum.
It only has two impls, both of which are tuples, which is ugly. An enum
is much simpler and clearer.

Also, `EarlyContextAndPass` doesn't need to be public.
2026-06-19 08:49:59 +10:00
Paul Murphy
6ce0650633 Add -Zinstrument-mcount=fentry to -Zinstrument-mcount
fentry is essentially a simpler version of mcount where the
counting function is called before any other function prologue
actions happen.

fentry is still used by the linux x86-64 kernel. It's unclear if
or when patchable-function-entry will replace it. It is also used
by clang for some x86-64 mingw toolchains.

This is only supported on some x86, x86-64, and s390x targets.
2026-06-17 13:09:33 -05:00
Jonathan Brouwer
3aa45f9798 Rollup merge of #156950 - cezarbbb:staticlib-rename-internal-symbols, r=petrochenkov
Staticlib rename internal symbols

Follow-up to rust-lang/rust#155338.

`-Zstaticlib-rename-internal-symbols` appends a crate-specific suffix (`_rs{StableCrateId}`) to non-exported symbols, resolving duplicate symbol conflicts when linking multiple Rust staticlibs into the same binary.

The implementation collects all defined `GLOBAL/WEAK` symbol names not in the exported set across all .o files, then renames them by extending the strtab and patching symbol name offsets. When combined with `-Zstaticlib-hide-internal-symbols`, the renamed symbols also receive `STV_HIDDEN` visibility.

Supported on ELF targets (Linux, BSD, etc.) and Apple targets (macOS, iOS, etc.). On unsupported targets (Windows), a warning is emitted and the flag has no effect.

r?@bjorn3 @petrochenkov
2026-06-16 22:11:02 +02:00
cezarbbb
796bc58860 add -Zstaticlib-rename-internal-symbols 2026-06-16 09:41:25 +08:00
Camille Gillot
0e9f9312c3 Steal ResolverAstLowering when indexing AST. 2026-06-16 00:10:08 +00:00
Camille GILLOT
5464994cdd Split-up the AST to index it. 2026-06-16 00:10:07 +00:00
Camille Gillot
334a95f9f4 Make lowering incremental.
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2026-06-16 00:08:10 +00:00
Camille Gillot
bfe40ed753 Stop stealing ResolverAstLowering. 2026-06-15 23:24:10 +00:00
Guillaume Gomez
d4b2610172 Rename rustc_interface/src/errors.rs into rustc_interface/src/diagnostics.rs 2026-06-13 14:51:05 +02:00