1306 Commits

Author SHA1 Message Date
Zalathar
51e62a09a3 coverage: Remove -Zcoverage-options=no-mir-spans
This flag turned out to be less useful than anticipated, and interferes with
work towards expansion support.
2025-08-04 13:48:40 +10:00
bors
c23f07d8c5 Auto merge of #144479 - cjgillot:incr-privacy-mod, r=petrochenkov
Perform check_private_in_public by module.

Based on https://github.com/rust-lang/rust/pull/116316
2025-08-02 01:59:11 +00:00
Nicholas Nethercote
e83c8cb26c Move ResolverOutputs out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_resolve` is a better place
for it.
2025-07-31 11:50:23 +10:00
Camille GILLOT
a1f5a6d781 Perform check_private_in_public by module. 2025-07-26 21:21:04 +00:00
Guillaume Gomez
96340f6714 Stop compilation if macro expansion failed 2025-07-25 23:46:28 +02:00
许杰友 Jieyou Xu (Joe)
5e3eb25125
Rollup merge of #142097 - ZuseZ4:offload-host1, r=oli-obk
gpu offload host code generation

r? ghost

This will generate most of the host side code to use llvm's offload feature.
The first PR will only handle automatic mem-transfers to and from the device.
So if a user calls a kernel, we will copy inputs back and forth, but we won't do the actual kernel launch.
Before merging, we will use LLVM's Info infrastructure to verify that the memcopies match what openmp offloa generates in C++. `LIBOMPTARGET_INFO=-1 ./my_rust_binary` should print that a memcpy to and later from the device is happening.

A follow-up PR will generate the actual device-side kernel which will then do computations on the GPU.
A third PR will implement manual host2device and device2host functionality, but the goal is to minimize cases where a user has to overwrite our default handling due to performance issues.

I'm trying to get a full MVP out first, so this just recognizes GPU functions based on magic names. The final frontend will obviously move this over to use proper macros, like I'm already doing it for the autodiff work.
This work will also be compatible with std::autodiff, so one can differentiate GPU kernels.

Tracking:
- https://github.com/rust-lang/rust/issues/131513
2025-07-22 00:54:24 +08:00
Manuel Drehwald
634016478e add -Zoffload=Enable flag behind -Zunstable-options, to enable gpu (host) code generation 2025-07-18 16:24:00 -07:00
Camille GILLOT
3301ac5f7b Integrate stable feature checking into a query. 2025-07-17 23:19:12 +00:00
Camille GILLOT
f7e0891423 Retire stability_index query. 2025-07-17 23:04:19 +00:00
bjorn3
87958ad683 Avoid building C++ for rustc_llvm with --compile-time-deps
This saves about 30s.
2025-07-11 13:32:03 +00:00
Camille GILLOT
c7ee3a5e3f Save metadata among work products. 2025-07-04 14:02:17 +00:00
bors
556d20a834 Auto merge of #143247 - cjgillot:metadata-no-red, r=petrochenkov
Avoid depending on forever-red DepNode when encoding metadata.

Split from https://github.com/rust-lang/rust/pull/114669 for perf

r? `@petrochenkov`
2025-07-04 10:23:18 +00:00
Camille GILLOT
992fa62118 Hash resolutions. 2025-07-02 09:14:34 +00:00
Matthias Krüger
f2231d5324
Rollup merge of #143228 - nnethercote:macro-stats-build-scripts, r=Kobzol
Handle build scripts better in `-Zmacro-stats` output.

Currently all build scripts are listed as `build_script_build` in the stats header. This commit uses `CARGO_PKG_NAME` to improve that.

I tried it on Bevy, it works well, giving output like this on the build script:
```
MACRO EXPANSION STATS: serde build script
```
and this on the crate itself:
```
MACRO EXPANSION STATS: serde
```

r? `@Kobzol`
2025-06-30 20:49:43 +02:00
Nicholas Nethercote
c3c995a275 Handle build scripts better in -Zmacro-stats output.
Currently all build scripts are listed as `build_script_build` in the
stats header. This commit uses `CARGO_PKG_NAME` to improve that.

I tried it on Bevy, it works well, giving output like this on the build
script:
```
MACRO EXPANSION STATS: serde build script
```
and this on the crate itself:
```
MACRO EXPANSION STATS: serde
```
2025-06-30 16:32:00 +10:00
Nicholas Nethercote
e0761a57ab Improve macro-stats printing.
By allowing long names to overlap with the "Uses" field when it has
spare space. This avoids unnecessary line breaks in the output.
2025-06-30 13:33:51 +10:00
Jubilee
b5631095cd
Rollup merge of #142934 - nnethercote:tweak-macro-stats, r=petrochenkov
Tweak `-Zmacro-stats` measurement.

It currently reports net size, i.e. size(output) - size(input). After some use I think this is sub-optimal, and it's better to just report size(output). Because for derive macros the input size is always 1, and for attribute macros it's almost always 1.

r? ```@petrochenkov```
2025-06-24 19:45:33 -07:00
bors
3de5b08ef6 Auto merge of #142979 - matthiaskrgr:rollup-szqah4e, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142645 (Also emit suggestions for usages in the `non_upper_case_globals` lint)
 - rust-lang/rust#142657 (mbe: Clean up code with non-optional `NonterminalKind`)
 - rust-lang/rust#142799 (rustc_session: Add a structure for keeping both explicit and default sysroots)
 - rust-lang/rust#142805 (Emit a single error when importing a path with `_`)
 - rust-lang/rust#142882 (Lazy init diagnostics-only local_names in borrowck)
 - rust-lang/rust#142883 (Add impl_trait_in_bindings tests from rust-lang/rust#61773)
 - rust-lang/rust#142943 (Don't include current rustc version string in feature removed help)
 - rust-lang/rust#142965 ([RTE-497] Ignore `c-link-to-rust-va-list-fn` test on SGX platform)
 - rust-lang/rust#142972 (Add a missing mailmap entry)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-24 21:58:31 +00:00
Guillaume Gomez
e8dd3c356c
Rollup merge of #142944 - nnethercote:stats-tweaks, r=lqd
Stats output tweaks

Some improvements to `-Zinput-stats` and `-Zmeta-stat` inspired by the new `-Zmacro-stats`.

r? `@lqd`
2025-06-24 15:39:42 +02:00
Vadim Petrochenkov
0be37cab97 rustc_session: Add a structure for keeping both explicit and default sysroots
Also avoid creating and cloning sysroot unnecessarily.
2025-06-24 16:00:04 +03:00
Nicholas Nethercote
b2a57e6b42 Tweak -Zinput-stats and -Zmeta-stats output.
To make it match `-Zmacro-stats`, and work better if you have enabled it
for multiple crates.
- Print each crate's name.
- Print a `===` banner at the start and end for separation.
2025-06-24 13:07:14 +10:00
Nicholas Nethercote
8b1abd6578 Make stats code nicer.
Taking inspiration from `-Zmacro-stats`:
- Use "{prefix}" consistently.
- Use names for column widths.
- Write output in a single `eprint!` call, in an attempt to minimize
  interleaving of output from different rustc processes.
- Use `repeat` for the long `---` banners.
2025-06-24 13:05:51 +10:00
Nicholas Nethercote
c3200c3bb5 Tweak -Zmacro-stats measurement.
It currently reports net size, i.e. size(output) - size(input). After
some use I think this is sub-optimal, and it's better to just report
size(output). Because for derive macros the input size is always 1, and
for attribute macros it's almost always 1.
2025-06-24 08:42:14 +10:00
Jubilee
8ba69d0f95
Rollup merge of #142784 - Kobzol:timings-codegen, r=nnethercote
Add codegen timing section

And since we now start and end the sections also using separate functions, also add some light checking if we're generating the sections correctly.

I'm integrating `--timings` into Cargo, and I realized that the codegen timings would be quite useful for that. Frontend can be computed simply as `[start of compilation, start of codegen]` for now.

r? `@nnethercote`
2025-06-23 12:48:20 -07:00
Jakub Beránek
332ae3b7e6
Add codegen timing section 2025-06-23 08:50:17 +02:00
Trevor Gross
7b355110df
Rollup merge of #142384 - celinval:chores-rayon-mv, r=oli-obk
Bringing `rustc_rayon_core` in tree as `rustc_thread_pool`

This PR moves [`rustc_rayon_core`](https://github.com/rust-lang/rustc-rayon/tree/5fadf44/rayon-core) from commit `5fadf44` as suggested in [this zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/187679-t-compiler.2Fparallel-rustc/topic/Bringing.20.60rustc_rayon_core.60.20in.20tree). I tried to split the work into separate commits so it is easy to review. The first commit is a simple copy and paste from the fork, and subsequent changes were made to use the new crate and to ensure the new crate complies with different format and lint expectations.

**Call-out:** I was also wondering if I need to make any further changes to accommodate licensing requirements.

r? oli-obk
2025-06-20 23:25:54 -04:00
bors
15c701fbc9 Auto merge of #142794 - tgross35:rollup-iae7okj, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.)
 - rust-lang/rust#142491 (Rework #[cold] attribute parser)
 - rust-lang/rust#142494 (Fix missing docs in `rustc_attr_parsing`)
 - rust-lang/rust#142495 (Better template for `#[repr]` attributes)
 - rust-lang/rust#142497 (Fix random failure when JS code is executed when the whole file was not read yet)
 - rust-lang/rust#142575 (Ensure copy* intrinsics also perform the static self-init checks)
 - rust-lang/rust#142650 (Refactor Translator)
 - rust-lang/rust#142713 (mbe: Refactor transcription)
 - rust-lang/rust#142755 (rustdoc: Remove `FormatRenderer::cache`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-20 23:09:48 +00:00
Jakub Beránek
31663db896
Rollup merge of #142767 - nnethercote:symbol-cleanups, r=petrochenkov
Some symbol and PathRoot cleanups

I'm looking into unifying how we join and print paths. Here are some preliminary cleanups.

r? ``@petrochenkov``
2025-06-20 20:03:24 +02:00
Trevor Gross
38600a6640
Rollup merge of #142650 - camsteffen:refactor-translator, r=petrochenkov
Refactor Translator

My main motivation was to simplify the usage of `SilentEmitter` for users like rustfmt. A few refactoring opportunities arose along the way.

* Replace `Translate` trait with `Translator` struct
* Replace `Emitter: Translate` with `Emitter::translator`
* Split `SilentEmitter` into `FatalOnlyEmitter` and `SilentEmitter`
2025-06-20 13:36:01 -04:00
Trevor Gross
dd41c06e27
Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obk
Reduce uses of `hir_crate`.

I tried rebasing my old incremental-HIR branch. This is a by-product, which is required if we want to get rid of `hir_crate` entirely.

The second commit is a drive-by cleanup. It can be pulled into its own PR.

r? ````@oli-obk````
2025-06-20 02:50:40 -04:00
Nicholas Nethercote
4a1f445142 Use a symbol for ExpansionConfig::crate_name.
This avoids some symbol interning and `to_string` conversions.
2025-06-20 13:17:39 +10:00
Cameron Steffen
3388d83785 Extract SilentEmitter 2025-06-19 13:05:01 -05:00
Cameron Steffen
316f63bc48 Rename SilentEmitter -> FatalOnlyEmitter 2025-06-19 13:03:17 -05:00
Camille Gillot
ede48910fd
Update compiler/rustc_interface/src/passes.rs
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2025-06-19 13:18:33 +02:00
Urgau
2011ab5152
Rollup merge of #142123 - Kobzol:timings, r=nnethercote
Implement initial support for timing sections (`--json=timings`)

This PR implements initial support for emitting high-level compilation section timings. The idea is to provide a very lightweight way of emitting durations of various compilation sections (frontend, backend, linker, or on a more granular level macro expansion, typeck, borrowck, etc.). The ultimate goal is to stabilize this output (in some form), make Cargo pass `--json=timings` and then display this information in the HTML output of `cargo build --timings`, to make it easier to quickly profile "what takes so long" during the compilation of a Cargo project. I would personally also like if Cargo printed some of this information in the interactive `cargo build` output, but the `build --timings` use-case is the main one.

Now, this information is already available with several other sources, but I don't think that we can just use them as they are, which is why I proposed a new way of outputting this data (`--json=timings`):
- This data is available under `-Zself-profile`, but that is very expensive and forever unstable. It's just a too big of a hammer to tell us the duration it took to run the linker.
- It could also be extracted with `-Ztime-passes`. That is pretty much "for free" in terms of performance, and it can be emitted in a structured form to JSON via `-Ztime-passes-format=json`. I guess that one alternative might be to stabilize this flag in some form, but that form might just be `--json=timings`? I guess what we could do in theory is take the already emitted time passes and reuse them for `--json=timings`. Happy to hear suggestions!

I'm sending this PR mostly for a vibeck, to see if the way I implemented it is passable. There are some things to figure out:
- How do we represent the sections? Originally I wanted to output `{ section, duration }`, but then I realized that it might be more useful to actually emit `start` and `end` events. Both because it enables to see the output incrementally (in case compilation takes a long time and you read the outputs directly, or Cargo decides to show this data in `cargo build` some day in the future), and because it makes it simpler to represent hierarchy (see below). The timestamps currently emit microseconds elapsed from a predetermined point in time (~start of rustc), but otherwise they are fully opaque, and should be only ever used to calculate the duration using `end - start`. We could also precompute the duration for the user in the `end` event, but that would require doing more work in rustc, which I would ideally like to avoid :P
- Do we want to have some form of hierarchy? I think that it would be nice to show some more granular sections rather than just frontend/backend/linker (e.g. macro expansion, typeck and borrowck as a part of the frontend). But for that we would need some way of representing hierarchy. A simple way would be something like `{ parent: "frontend" }`, but I realized that with start/end timestamps we get the hierarchy "for free", only the client will need to reconstruct it from the order of start/end events (e.g. `start A`, `start B` means that `B` is a child of `A`).
- What exactly do we want to stabilize? This is probably a question for later. I think that we should definitely stabilize the format of the emitted JSON objects, and *maybe* some specific section names (but we should also make it clear that they can be missing, e.g. you don't link everytime you invoke `rustc`).

The PR be tested e.g. with `rustc +stage1 src/main.rs --json=timings --error-format=json -Zunstable-options` on a crate without dependencies (it is not easy to use `--json` with stock Cargo, because it also passes this flag to `rustc`, so this will later need Cargo integration to be usable with it).

Zulip discussions: [#t-compiler > Outputting time spent in various compiler sections](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Outputting.20time.20spent.20in.20various.20compiler.20sections/with/518850162)

MCP: https://github.com/rust-lang/compiler-team/issues/873

r? ``@nnethercote``
2025-06-18 19:40:32 +02:00
Urgau
33185d3fd9
Rollup merge of #135656 - joshtriplett:hint-mostly-unused, r=saethlin
Add `-Z hint-mostly-unused` to tell rustc that most of a crate will go unused

This hint allows the compiler to optimize its operation based on this assumption, in order to compile faster. This is a hint, and does not guarantee any particular behavior.

This option can substantially speed up compilation if applied to a large dependency where the majority of the dependency does not get used. This flag may slow down compilation in other cases.

Currently, this option makes the compiler defer as much code generation as possible from functions in the crate, until later crates invoke those functions. Functions that never get invoked will never have code generated for them. For instance, if a crate provides thousands of functions, but only a few of them will get called, this flag will result in the compiler only doing code generation for the called functions. (This uses the same mechanisms as cross-crate inlining of functions.) This does not affect `extern` functions, or functions marked as `#[inline(never)]`.

This option has already existed in nightly as `-Zcross-crate-inline-threshold=always` for some time, and has gotten testing in that form. However, this option is still unstable, to give an opportunity for wider testing in this form.

Some performance numbers, based on a crate with many dependencies having just *one* large dependency set to `-Z hint-mostly-unused` (using Cargo's `profile-rustflags` option):

A release build went from 4m07s to 2m04s.

A non-release build went from 2m26s to 1m28s.
2025-06-18 19:40:30 +02:00
Camille GILLOT
c6e77b3ba6 Reduce uses of hir_crate. 2025-06-18 15:46:19 +00:00
Jakub Beránek
60a59ae523
Emit linker timing section 2025-06-16 11:51:17 +02:00
León Orell Valerian Liehr
0b249d3f85
Rollup merge of #141769 - bjorn3:codegen_metadata_module_rework, r=workingjubilee,saethlin
Move metadata object generation for dylibs to the linker code

This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.

Prerequisite of https://github.com/rust-lang/rust/issues/96708.
2025-06-15 23:51:54 +02:00
bjorn3
3e944fa391 Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
Nicholas Nethercote
376cbc3787 Introduce -Zmacro-stats.
It collects data about macro expansions and prints them in a table after
expansion finishes. It's very useful for detecting macro bloat,
especially for proc macros.

Details:
- It measures code snippets by pretty-printing them and then measuring
  lines and bytes. This required a bunch of additional pretty-printing
  plumbing, in `rustc_ast_pretty` and `rustc_expand`.
- The measurement is done in `MacroExpander::expand_invoc`.
- The measurements are stored in `ExtCtxt::macro_stats`.
2025-06-12 21:17:17 +10:00
Celina G. Val
4aa62ea9e9 Use rustc_thread_pool instead of rustc-rayon-core 2025-06-11 12:26:42 -07:00
Oli Scherer
1b9d38dd08 Remove check_mod_loops query and run the checks per-body instead 2025-06-10 08:41:23 +00:00
Jubilee
41bc5d7f73
Rollup merge of #142089 - bjorn3:sysroot_handling_cleanup3, r=petrochenkov
Replace all uses of sysroot_candidates with get_or_default_sysroot

Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used:
* `get_or_default_sysroot` which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path.,
* `sysroot_candidates` which takes the former and additionally does another attempt at locating using `librustc_driver.so` except without linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the `--sysroot` passed in does not contain a copy of cg_llvm. Back then `get_or_default_sysroot` did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing `sysroot_candidates` can break things is if you have a custom driver inside what looks like a sysroot including the `lib/rustlib` directory, but which is missing some parts of the full sysroot like eg rust-lld.

Follow up to https://github.com/rust-lang/rust/pull/138404
2025-06-08 17:17:54 -07:00
bors
cdd545be1b Auto merge of #141950 - oli-obk:big-body-owner-loop, r=compiler-errors
Move coroutine_by_move_body_def_id into the big check_crate body owner loop

This avoids starting a parallel loop in sequence and instead runs all the queries for a specific DefId together.
2025-06-07 20:06:23 +00:00
Josh Triplett
1b23b64be4 Add -Z hint-mostly-unused to tell rustc that most of a crate will go unused
This hint allows the compiler to optimize its operation based on this
assumption, in order to compile faster. This is a hint, and does not
guarantee any particular behavior.

This option can substantially speed up compilation if applied to a large
dependency where the majority of the dependency does not get used. This flag
may slow down compilation in other cases.

Currently, this option makes the compiler defer as much code generation as
possible from functions in the crate, until later crates invoke those
functions. Functions that never get invoked will never have code generated for
them. For instance, if a crate provides thousands of functions, but only a few
of them will get called, this flag will result in the compiler only doing code
generation for the called functions. (This uses the same mechanisms as
cross-crate inlining of functions.) This does not affect `extern` functions, or
functions marked as `#[inline(never)]`.

Some performance numbers, based on a crate with many dependencies having
just *one* large dependency set to `-Z hint-mostly-unused` (using
Cargo's `profile-rustflags` option):

A release build went from 4m07s to 2m04s.

A non-release build went from 2m26s to 1m28s.
2025-06-06 19:12:00 -07:00
bors
44f415c1d6 Auto merge of #141774 - oli-obk:naked-fn-queries, r=petrochenkov
Change per-module naked fn checks to happen during typeck instead

cc `@Lokathor` `@Amanieu` `@folkertdev`

just seems nicer this way
2025-06-06 18:22:10 +00:00
bjorn3
e4c4c4c677 Fix review comments 2025-06-06 14:20:48 +00:00
bjorn3
dff8ee5b01 Replace all uses of sysroot_candidates with get_or_default_sysroot
Before this change we had two different ways to attempt to locate the
sysroot which are inconsistently used:
* get_or_default_sysroot which tries to locate based on the 0th cli
  argument and if that doesn't work falls back to locating it using the
  librustc_driver.so location and returns a single path.,
* sysroot_candidates which takes the former and additionally does
  another attempt at locating using librustc_driver.so except without
  linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen
backend back when cg_llvm was dynamically linked even for a custom
driver when the --sysroot passed in does not contain a copy of cg_llvm.
Back then get_or_default_sysroot did not attempt to locate the sysroot
based on the location of librustc_driver.so yet. Because that is now
done, the only case where removing sysroot_candidates can break things
is if you have a custom driver inside what looks like a sysroot
including the lib/rustlib directory, but which is missing some parts of
the full sysroot like eg rust-lld.
2025-06-05 16:54:10 +00:00
Matthias Krüger
b7150d4e63
Rollup merge of #141943 - nnethercote:rm-pre-expansion-ast-stats, r=compiler-errors
Remove pre-expansion AST stats.

They're very little value, because they only measure the top-level `main.rs` or `lib.rs` file. (Other `.rs` files don't get read and parsed until expansion occurs.)

I saw an example recently where the pre-expansion AST was 3KB in size and the post-expansion AST was 66MB.

I kept the "POST EXPANSION" in the output header, I think that's useful information to avoid possible confusion about when the measurement happens.

r? `@davidtwco`
2025-06-03 21:53:38 +02:00