Commit graph

2970 commits

Author SHA1 Message Date
Mads Marquart
bd1ef0fad2 Invoke xcrun inside sess.time
It can be a fairly expensive operation when the output is not cached, so
it's nice to get some visibility into the runtime cost.
2025-03-27 03:34:17 +01:00
Mads Marquart
713becd7da refactor: Move Apple SDK names to rustc_codegen_ssa:🔙:apple 2025-03-27 03:34:11 +01:00
bors
7d49ae9731 Auto merge of #136410 - saethlin:clean-up-cgu-internal-copy, r=compiler-errors
Remove InstanceKind::generates_cgu_internal_copy

This PR should not contain any behavior changes. Before this PR, the logic for selecting instantiation mode is spread across all of
* `instantiation_mode`
* `cross_crate_inlinable`
* `generates_cgu_internal_copy`
* `requires_inline`

The last two of those functions are not well-designed. The function that actually decides if we generate a CGU-internal copy is `instantiation_mode`, _not_ `generates_cgu_internal_copy`. The function `requires_inline` documents that it is about the LLVM `inline` attribute and that it is a hint. The LLVM attribute is called `inlinehint`, this function is also used by other codegen backends, and since it is part of instantiation mode selection it is *not* a hint.

The goal of this PR is to start cleaning up the logic into a sequence of checks that have a more logical flow and are easier to customize in the future (to do things like improve incrementality or improve optimizations without causing obscure linker errors because you forgot to update another part of the compiler).
2025-03-25 06:36:41 +00:00
bors
e61403aa4c Auto merge of #138634 - saethlin:repeated-uninit, r=scottmcm,oli-obk
Lower to a memset(undef) when Rvalue::Repeat repeats uninit

Fixes https://github.com/rust-lang/rust/issues/138625.

It is technically correct to just do nothing. But if we actually do nothing, we may miss that this is de-initializing something, so instead we just lower to a single memset that writes undef. This is still superior to the memcpy loop, in both quality of code we hand to the backend and LLVM's final output.
2025-03-25 02:09:15 +00:00
Ben Kimock
817e2c598d Remove InstanceKind::generates_cgu_internal_copy 2025-03-24 20:29:24 -04:00
bors
1df5affaca Auto merge of #133984 - DaniPopes:scmp-ucmp, r=scottmcm
Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics

Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics.

These are the intrinsics mentioned in https://github.com/rust-lang/rust/pull/118310, which are now available in LLVM 19.

I couldn't find any follow-up PRs/discussions about this, please let me know if I missed something.

r? `@scottmcm`
2025-03-24 22:53:12 +00:00
bors
4510e86a41 Auto merge of #138629 - Zoxc:graph-anon-hashmap, r=oli-obk
Only use the new node hashmap for anonymous nodes

This is a rebase of https://github.com/rust-lang/rust/pull/112469.

cc `@cjgillot`
2025-03-24 15:02:09 +00:00
Jacob Pratt
9a243cf7d3
Rollup merge of #137736 - bjorn3:compiler_builtins_export_fix, r=petrochenkov
Don't attempt to export compiler-builtins symbols from rust dylibs

They are marked with hidden visibility to prevent them from getting exported, so we shouldn't ask the linker to export them anyway. The only thing that does it cause a warning on macOS.

Part of https://github.com/rust-lang/rust/issues/136096

cc `@jyn514`
2025-03-23 20:44:08 -04:00
bors
48b36c9d59 Auto merge of #128320 - saethlin:link-me-maybe, r=compiler-errors
Avoid no-op unlink+link dances in incr comp

Incremental compilation scales quite poorly with the number of CGUs. This PR improves one reason for that.

The incr comp process hard-links all the files from an old session into a new one, then it runs the backend, which may just hard-link the new session files into the output directory. Then codegen hard-links all the output files back to the new session directory.

This PR (perhaps unimaginatively) fixes the silliness that ensues in the last step. The old `link_or_copy` implementation would be passed pairs of paths which are already the same inode, then it would blindly delete the destination and re-create the hard-link that it just deleted. This PR lets us skip both those operations. We don't skip the other two hard-links.

`cargo +stage1 b && touch crates/core/main.rs && strace -cfw -elink,linkat,unlink,unlinkat cargo +stage1 b` before and then after on `ripgrep-13.0.0`:
```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 52.56    0.024950          25       978       485 unlink
 34.38    0.016318          22       727           linkat
 13.06    0.006200          24       249           unlinkat
------ ----------- ----------- --------- --------- ----------------
100.00    0.047467          24      1954       485 total
```
```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 42.83    0.014521          57       252           unlink
 38.41    0.013021          26       486           linkat
 18.77    0.006362          25       249           unlinkat
------ ----------- ----------- --------- --------- ----------------
100.00    0.033904          34       987           total
```

This reduces the number of hard-links that are causing perf troubles, noted in https://github.com/rust-lang/rust/issues/64291 and https://github.com/rust-lang/rust/issues/137560
2025-03-21 21:03:49 +00:00
Matthias Krüger
0c594da55f
Rollup merge of #138627 - EnzymeAD:autodiff-cleanups, r=oli-obk
Autodiff cleanups

Splitting out some cleanups to reduce the size of my batching PR and simplify ``@haenoe`` 's [PR](https://github.com/rust-lang/rust/pull/138314).

r? ``@oli-obk``

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-03-21 15:48:55 +01:00
bjorn3
530ab61c0e Also check for compiler-builtins in linked_symbols
Otherwise the linker complains about EC symbols missing when compiling
for arm64ec.
2025-03-21 14:06:34 +00:00
bjorn3
63cfd47cb1 Don't attempt to export compiler-builtins symbols from rust dylibs
They are marked with hidden visibility to prevent them from getting
exported, so we shouldn't ask the linker to export them anyway. The only
thing that does it cause a warning on macOS.
2025-03-21 13:59:51 +00:00
Ben Kimock
8e7d8ddffe Lower to a memset(undef) when Rvalue::Repeat repeats uninit 2025-03-19 23:57:49 -04:00
Nicholas Nethercote
8121958fda Use -Wunused_crate_dependencies for compiler crates.
It's very useful. There are some false positives involving integration
tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a
false positive involving `rustc_driver_impl`'s
`rustc_randomized_layouts` feature. And I removed a `rustc_span` mention
in a doc comment in `rustc_log` because it wasn't integral to the
comment but caused a dev-dependency.
2025-03-20 08:59:43 +11:00
Camille GILLOT
5a21f890e9 Only use the new node hashmap for anonymous nodes. 2025-03-19 20:12:37 +01:00
bors
259fdb5212 Auto merge of #138630 - matthiaskrgr:rollup-kk1gogr, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138384 (Move `hir::Item::ident` into `hir::ItemKind`.)
 - #138508 (Clarify "owned data" in E0515.md)
 - #138531 (Store test diffs in job summaries and improve analysis formatting)
 - #138533 (Only use `DIST_TRY_BUILD` for try jobs that were not selected explicitly)
 - #138556 (Fix ICE: attempted to remap an already remapped filename)
 - #138608 (rustc_target: Add target feature constraints for LoongArch)
 - #138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-18 05:58:46 +00:00
bors
493c38ba37 Auto merge of #127173 - bjorn3:mangle_rustc_std_internal_symbol, r=wesleywiser,jieyouxu
Mangle rustc_std_internal_symbols functions

This reduces the risk of issues when using a staticlib or rust dylib compiled with a different rustc version in a rust program. Currently this will either (in the case of staticlib) cause a linker error due to duplicate symbol definitions, or (in the case of rust dylibs) cause rustc_std_internal_symbols functions to be silently overridden. As rust gets more commonly used inside the implementation of libraries consumed with a C interface (like Spidermonkey, Ruby YJIT (curently has to do partial linking of all rust code to hide all symbols not part of the C api), the Rusticl OpenCL implementation in mesa) this is becoming much more of an issue. With this PR the only symbols remaining with an unmangled name are rust_eh_personality (LLVM doesn't allow renaming it) and `__rust_no_alloc_shim_is_unstable`.

Helps mitigate https://github.com/rust-lang/rust/issues/104707

try-job: aarch64-gnu-debug
try-job: aarch64-apple
try-job: x86_64-apple-1
try-job: x86_64-mingw-1
try-job: i686-mingw-1
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: test-various
try-job: armhf-gnu
2025-03-17 22:16:22 +00:00
Manuel Drehwald
f9d0a14639 resolve repeated attribute fixme 2025-03-17 17:06:26 -04:00
Yotam Ofek
36f6bc5e3d Flatten ifs in rustc_codegen_ssa 2025-03-17 18:56:52 +00:00
Matthias Krüger
9adf2189f5
Rollup merge of #137449 - compiler-errors:control-flow, r=Amanieu,lnicola
Denote `ControlFlow` as `#[must_use]`

I've repeatedly hit bugs in the compiler due to `ControlFlow` not being marked `#[must_use]`. There seems to be an accepted ACP to make the type `#[must_use]` (https://github.com/rust-lang/libs-team/issues/444), so this PR implements that part of it.

Most of the usages in the compiler that trigger this new warning are "root" usages (calling into an API that uses control-flow internally, but for which the callee doesn't really care) and have been suppressed by `let _ = ...`, but I did legitimately find one instance of a missing `?` and one for a never-used `ControlFlow` value in #137448.

Presumably this needs an FCP too, so I'm opening this and nominating it for T-libs-api.

This PR also touches the tools (incl. rust-analyzer), but if this went into FCP, I'd split those out into separate PRs which can land before this one does.

r? libs-api
`@rustbot` label: T-libs-api I-libs-api-nominated
2025-03-17 16:34:47 +01:00
bjorn3
b754ef727c Remove implicit #[no_mangle] for #[rustc_std_internal_symbol] 2025-03-17 14:08:09 +00:00
Yotam Ofek
a3e4dff183 Use strip_{prefix|suffix} instead of {starts|ends}_with+indexing 2025-03-17 07:06:10 +00:00
Michael Goulet
380ce74401 Suppress must_use in compiler and tools 2025-03-16 17:47:57 +00:00
许杰友 Jieyou Xu (Joe)
e714c3be9f
Rollup merge of #138549 - scottmcm:option-ssa, r=saethlin
Fix the OperandRef type for NullOp::{UbChecks,ContractChecks}

Stumbled on this while looking at something totally unrelated 🙃

r? saethlin
2025-03-16 13:19:53 +08:00
Scott McMurray
3d42541313 Fix the OperandRef type for NullOp::{UbChecks,ContractChecks} 2025-03-15 19:39:15 -07:00
bors
4d30011f6c Auto merge of #138532 - matthiaskrgr:rollup-mgcynqu, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #138283 (Enforce type of const param correctly in MIR typeck)
 - #138439 (feat: check ARG_MAX on Unix platforms)
 - #138502 (resolve: Avoid some unstable iteration)
 - #138514 (Remove fake borrows of refs that are converted into non-refs in `MakeByMoveBody`)
 - #138524 (Mark myself as unavailable for reviews temporarily)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-15 11:40:17 +00:00
Michael Goulet
b88f85a410 Stop relying on rustc_type_ir in non-type-system crates 2025-03-15 06:42:48 +00:00
Weihang Lo
08166b5b23
feat(linker): check ARG_MAX on Unix platforms
On Unix the limits can be gargantuan anyway so we're pretty
unlikely to hit them, but might still exceed it.
We consult ARG_MAX here to get an estimate.
2025-03-14 09:45:49 -04:00
Weihang Lo
a672448f0d
fix(linker): use arg list estimate on only Windows
Though I doubt anyone running rustc outside Unix/Windows
2025-03-14 09:42:18 -04:00
Weihang Lo
79034bd291
fix(linker): prevent overflow when estimating CLI arg list length
This also updates the estimate on Windows of the length argument
list to `saturating_add` to avoid overflow.
2025-03-14 09:42:12 -04:00
Jacob Pratt
e928a8f4a0
Rollup merge of #138432 - weihanglo:lld, r=lqd
fix: remove the check of lld not supporting @response-file

In LLVM v9, lld has supported `@response-file.`
LLVM v9 was released on 2019-09-19.
The check was added back to 2018-03-14 (1.26.0) via 04442af18b.
It has been more than five years, and we ship our own lld regardlessly.
This should be happily removed.

See also:

* <bb12396f91>
* <https://reviews.llvm.org/D63024>
2025-03-14 01:37:33 -04:00
Jacob Pratt
91e4bab25f
Rollup merge of #138398 - RalfJung:atomic-intrinsics-provenance, r=nnethercote
atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance

The provenance semantics match what Miri implements and what the `AtomicPtr` API expects.
2025-03-14 01:37:32 -04:00
bors
addae0705c Auto merge of #138391 - scottmcm:SSA-discriminants, r=WaffleLapkin
Don't `alloca` just to look at a discriminant

Today we're making LLVM do a bunch of extra work when you match on trivial stuff like `Option<bool>` or `ControlFlow<u8>`.

This PR changes that so that simple types like `Option<u32>` or `Result<(), Box<Error>>` can stay as `OperandValue::ScalarPair` and we can still read the discriminant from them, rather than needing to write them into memory to have a `PlaceValue` just to get the discriminant out.

Fixes #137503
2025-03-14 00:42:31 +00:00
bors
93257e2d20 Auto merge of #138450 - matthiaskrgr:rollup-4im25vf, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #137816 (attempt to support `BinaryFormat::Xcoff` in `naked_asm!`)
 - #138109 (make precise capturing args in rustdoc Json typed)
 - #138343 (Enable `f16` tests for `powf`)
 - #138356 (bump libc to 0.2.171 to fix xous)
 - #138371 (Update compiletest's `has_asm_support` to match rustc)
 - #138404 (Cleanup sysroot locating a bit)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-13 13:34:28 +00:00
Matthias Krüger
ad23e9d705
Rollup merge of #138404 - bjorn3:sysroot_handling_cleanup, r=petrochenkov,jieyouxu
Cleanup sysroot locating a bit

All commits should preserve existing behavior.
2025-03-13 11:28:35 +01:00
Matthias Krüger
762acf53cb
Rollup merge of #137816 - folkertdev:naked-asm-xcoff, r=Noratrieb
attempt to support `BinaryFormat::Xcoff` in `naked_asm!`

Fixes https://github.com/rust-lang/rust/issues/137219

So, the inline assembly support for xcoff is extremely limited. The LLVM [XCOFFAsmParser](1b25c0c4da/llvm/lib/MC/MCParser/XCOFFAsmParser.cpp) does not support many of the attributes that LLVM itself emits, and that should exist based on [the assembler docs](https://www.ibm.com/docs/en/ssw_aix_71/assembler/assembler_pdf.pdf). It also does accept some that should not exist based on those docs.

So, I've tried to do the best I can given those limitations. At least it's better than emitting the directives for elf and having that fail somewhere deep in LLVM. Given that inline assembly for this target is incomplete (under `asm_experimental_arch`), I think that's OK (and again I don't see how we can do better given the limitations in LLVM).

r? ```@Noratrieb``` (given that you reviewed https://github.com/rust-lang/rust/pull/136637)

It seems reasonable to ping the [`powerpc64-ibm-aix` target maintainers](https://doc.rust-lang.org/rustc/platform-support/aix.html), hopefully they have thoughts too: ```@daltenty``` ```@gilamn5tr```
2025-03-13 11:28:20 +01:00
Matthias Krüger
1827ffdef0
Rollup merge of #138346 - folkertdev:naked-asm-windows-endef, r=ChrisDenton
naked functions: on windows emit `.endef` without the symbol name

tracking issue: https://github.com/rust-lang/rust/issues/90957
fixes https://github.com/rust-lang/rust/issues/138320

The `.endef` directive does not take the name as an argument. Apparently the LLVM x86_64 parser does accept this, but on i686 it's rejected. In general `i686` does some special name mangling stuff, so it's good to include it in the naked function tests.

r? ````@ChrisDenton```` (because windows)
2025-03-13 10:58:23 +01:00
Matthias Krüger
5ae93cf5b4
Rollup merge of #138273 - petrochenkov:nonatroot, r=bjorn3
metadata: Ignore sysroot when doing the manual native lib search in rustc

This is the opposite alternative to https://github.com/rust-lang/rust/pull/138170 and another way to make native library search consistent between rustc and linker.

This way the directory list searched by rustc is still a prefix of the directory list considered by linker, but it's a shorter prefix than in #138170.
We can include the sysroot directories into rustc's search again later if the issues with #138170 are resolved, it will be a backward compatible change.

This may break some code doing weird things on unstable rustc, or tier 2-3 targets, like bundling `libunwind.a` or sanitizers into something.
Note that this doesn't affect shipped `libc.a`, because it lives in `self-contained` directories in sysroot, and `self-contained` sysroot is already not included into the rustc's search. All libunwind and sanitizer libs should be moved to `self-contained` sysroot too eventually.

With the consistent search directory list between rustc and linker we can make rustc own the native library search (at least for static libs) and use linker search only as a fallback (like in #123436). This will allow addressing issues like https://github.com/rust-lang/rust/pull/132394 once and for all on all targets.

r? ``@bjorn3``
2025-03-13 10:58:23 +01:00
Scott McMurray
2b15dd1ddd Add more comments to discriminant calculations. 2025-03-13 00:39:18 -07:00
Ralf Jung
88b206d582 atomic intrinsics: clarify which types are supported and (if applicable) what happens with provenance 2025-03-13 08:14:34 +01:00
bors
8536f201ff Auto merge of #138416 - Manishearth:rollup-fejor9p, r=Manishearth
Rollup of 12 pull requests

Successful merges:

 - #134076 (Stabilize `std::io::ErrorKind::InvalidFilename`)
 - #137504 (Move methods from Map to TyCtxt, part 4.)
 - #138175 (Support rmeta inputs for --crate-type=bin --emit=obj)
 - #138259 (Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs)
 - #138280 (fix ICE in pretty-printing `global_asm!`)
 - #138318 (Rustdoc: remove a bunch of `@ts-expect-error` from main.js)
 - #138331 (Use `RUSTC_LINT_FLAGS` more)
 - #138357 (merge `TypeChecker` and `TypeVerifier`)
 - #138394 (remove unnecessary variant)
 - #138403 (Delegation: one more ICE fix for `MethodCall` generation)
 - #138407 (Delegation: reject C-variadics)
 - #138409 (Use sa_sigaction instead of sa_union.__su_sigaction for AIX)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-13 01:37:26 +00:00
Weihang Lo
c8a6fcc3c8
fix: remove the check of lld not supporting @response-file
In LLVM v9, lld has supported @response-file
LLVM v9 was released on 2019-09-19.
And the check was added back to 2018-03-14 (1.26.0) via 04442af18b.
It has been more than five years, and we ship our own lld regardlessly.
This should be happily removed.

See also:

* <bb12396f91>
* <https://reviews.llvm.org/D63024>
2025-03-12 18:36:21 -04:00
bors
249cb84316 Auto merge of #138414 - matthiaskrgr:rollup-9ablqdb, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #137314 (change definitely unproductive cycles to error)
 - #137701 (Convert `ShardedHashMap` to use `hashbrown::HashTable`)
 - #138269 (uefi: fs: Implement FileType, FilePermissions and FileAttr)
 - #138331 (Use `RUSTC_LINT_FLAGS` more)
 - #138345 (Some autodiff cleanups)
 - #138387 (intrinsics: remove unnecessary leading underscore from argument names)
 - #138390 (fix incorrect tracing log)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-12 17:27:43 +00:00
Manish Goregaokar
245d3a90ca
Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, r=onur-ozkan,jieyouxu
Use `RUSTC_LINT_FLAGS` more

An alternative to the failed #138084.

Fixes #138106.

r? `````@jieyouxu`````
2025-03-12 10:19:30 -07:00
Manish Goregaokar
f88f27aff0
Rollup merge of #137504 - nnethercote:remove-Map-4, r=Zalathar
Move methods from Map to TyCtxt, part 4.

A follow-up to https://github.com/rust-lang/rust/pull/137350.

r? ```@Zalathar```
2025-03-12 10:19:26 -07:00
Matthias Krüger
d93ef397ce
Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, r=onur-ozkan,jieyouxu
Use `RUSTC_LINT_FLAGS` more

An alternative to the failed #138084.

Fixes #138106.

r? ````@jieyouxu````
2025-03-12 17:59:08 +01:00
bjorn3
7e8494f0a5 Don't return an error from get_or_default_sysroot
All callers unwrap the result.
2025-03-12 15:05:25 +00:00
bors
aaa2d47dae Auto merge of #138083 - nnethercote:rm-NtItem-NtStmt, r=petrochenkov
Remove `NtItem` and `NtStmt`

Another piece of #124141.

r? `@petrochenkov`
2025-03-12 14:18:36 +00:00
Scott McMurray
143f39362a Don't alloca just to look at a discriminant
Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`.  Let's not.
2025-03-12 00:56:43 -07:00
Nicholas Nethercote
256c27e748 Move methods from Map to TyCtxt, part 4.
Continuing the work from #137350.

Removes the unused methods: `expect_variant`, `expect_field`,
`expect_foreign_item`.

Every method gains a `hir_` prefix.
2025-03-12 08:55:37 +11:00