1012 Commits

Author SHA1 Message Date
Nicholas Nethercote
301655eafe Revert introduction of [workspace.dependencies].
This was done in #145740 and #145947. It is causing problems for people
using r-a on anything that uses the rustc-dev rustup package, e.g. Miri,
clippy.

This repository has lots of submodules and subtrees and various
different projects are carved out of pieces of it. It seems like
`[workspace.dependencies]` will just be more trouble than it's worth.
2025-09-02 19:12:54 +10:00
bors
75ee9ffd5e Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU
`-Znext-solver`: support non-defining uses in closures

Cleaned up version of rust-lang/rust#139587, finishing the implementation of https://github.com/rust-lang/types-team/issues/129. This does not affect stable. The reasoning for why this is the case is subtle however.

## What does it do

We split `do_mir_borrowck` into `borrowck_collect_region_constraints` and `borrowck_check_region_constraints`, where `borrowck_collect_region_constraints` returns an enormous `CollectRegionConstraintsResult` struct which contains all the relevant data to actually handle opaque type uses and to check the region constraints later on.

`query mir_borrowck` now simply calls `BorrowCheckRootCtxt::do_mir_borrowck` which starts by iterating over all nested bodies of the current function - visiting nested bodies before their parents - and computing their `CollectRegionConstraintsResult`.

After we've collected all constraints it's time to actually compute the concrete types for the opaques defined by this function. With this PR we now compute the concrete types of opaques for each body before using them to check the non-defining uses of any of them.

After we've computed the concrete types by using all bodies, we use `apply_computed_concrete_opaque_types` for each body to constrain non-defining uses, before finally finishing with `borrowck_check_region_constraints`. We always visit nested bodies before their parents when doing this.

## `ClosureRegionRequirements`

As we only call `borrowck_collect_region_constraints` for nested bodies before type checking the parent, we can't simply use the final `ClosureRegionRequirements` of the nested body during MIR type check. We instead track that we need to apply these requirements in `deferred_closure_requirements`.

We now manually apply the final closure requirements to each body after handling opaque types.

This works, except that we may need the region constraints of nested bodies to successfully define an opaque type in the parent. This is handled by using a new `fn compute_closure_requirements_modulo_opaques` which duplicates region checking - while ignoring any errors - before we've added the constraints from `apply_computed_concrete_opaque_types`. This is necessary for a lot of async tests, as pretty much the entire function is inside of an async block while the opaque type gets defined in the parent.

As an performance optimization we only use `fn compute_closure_requirements_modulo_opaques` in case the nested body actually depends on any opaque types. Otherwise we eagerly call `borrowck_check_region_constraints` and apply the final closure region requirements right away.

## Impact on stable code

Handling the opaque type uses in the parent function now only uses the closure requirements *modulo opaques*, while it previously also considered member constraints from nested bodies. `External` regions are never valid choice regions. Also, member constraints will never constrain a member region if it is required to be outlived by an external region, as that fails the upper-bound check. 564ee21912/compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs (L90-L96)

Member constraints therefore never add constraints for external regions :>

r? `@BoxyUwU`
2025-09-01 20:56:46 +00:00
lcnr
b8160e9f38 use defining uses of all bodies to constrain non-defining uses
support non-defining uses in closures
2025-09-01 22:08:03 +02:00
Nicholas Nethercote
8fc0813e29 Add measureme to [workspace.dependencies]. 2025-08-28 20:12:14 +10:00
Nicholas Nethercote
2b26476ccd Add rustc-hash to [workspace.dependencies]. 2025-08-28 20:11:43 +10:00
Nicholas Nethercote
77b047aaab Add indexmap to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
Nicholas Nethercote
77d2f0c16e Add tempfile to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
Nicholas Nethercote
d263d3a88c Add either to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
Nicholas Nethercote
12dc789bc6 Add libc to [workspace.dependencies]. 2025-08-28 20:10:54 +10:00
Nicholas Nethercote
b4c8fe2b4b Remove unnecessary [dependencies.unicode-properties] entries.
The Cargo style guide says to put dependencies on a single line if they
fit.
2025-08-28 08:08:40 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Nicholas Nethercote
82c4b9c51b Add bitflags to [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
Nicholas Nethercote
777e2d6a2a Add thin-vec to newly added [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
Camille Gillot
689171d38e Uplift rustc_mir_transform::coverage::counters::union_find to rustc_data_structures. 2025-08-22 02:22:51 +00:00
Jakub Beránek
4ef18ab062
Allow pretty printing paths with -Zself-profile-events=args 2025-07-25 22:24:21 +02:00
Jakub Beránek
37115f1bd6
Fix wrong cache event query key 2025-07-07 15:16:42 +02:00
Matthias Krüger
567c51d584
Rollup merge of #143406 - scottmcm:did-we-need-that-unsafe, r=compiler-errors
Remove some unnecessary `unsafe` in VecCache

I'm pretty sure, but until perf confirms,
r? ghost
2025-07-05 00:12:10 +02:00
Scott McMurray
15286f220e Remove some unnecessary unsafe in VecCache 2025-07-03 17:42:43 -07:00
Jana Dönszelmann
f6d37a25a9
Rollup merge of #134006 - klensy:typos, r=nnethercote
setup typos check in CI

This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying?

Also includes commits with actual typo fixes.

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

typos check currently turned for:
* ./compiler
* ./library
* ./src/bootstrap
* ./src/librustdoc

After merging, PRs which enables checks for other crates (tools) can be implemented too.

Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr.

Check typos: `python x.py test tidy --extra-checks=spellcheck`
Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo)

Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03 13:29:35 +02:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
bors
b94bd12401 Auto merge of #142978 - Kobzol:query-hit, r=oli-obk
Add new self-profiling event to cheaply aggregate query cache hit counts

Self-profile can record various types of things, some of them are not enabled, like query cache hits. Rustc currently records cache hits as "instant" measureme events, which records the thread ID, current timestamp, and constructs an individual event for each such cache hit. This is incredibly expensive, in a small hello world benchmark that just depends on serde, it makes compilation with nightly go from ~3s (with `-Zself-profile`) to ~15s (with `-Zself-profile -Zself-profile-events=default,query-cache-hit`).

We'd like to add query cache hits to rustc-perf (https://github.com/rust-lang/rustc-perf/pull/2168), but there we only need the actualy cache hit counts, not the timestamp/thread ID metadata associated with it.

This PR adds a new `query-cache-hit-count` event. Instead of generating individual instant events, it simply aggregates cache hit counts per *query invocation* (so a combination of a query and its arguments, if I understand it correctly) using an atomic counter. At the end of the compilation session, these counts are then dumped to the self-profile log using integer events (in a similar fashion as how we record artifact sizes). I suppose that we could dedup the query invocations in rustc directly, but I don't think it's really required. In local experiments with the hello world + serde case, the query invocation records generated ~30 KiB more data in the self-profile, which was ~10% increase in this case.

With this PR, the overhead of `-Zself-profile` seems to be the same as before, at least on my machine, so I also enabled query cache hit counts by default when self profiling is enabled.

We should also modify `analyzeme`, specifically [this](https://github.com/rust-lang/measureme/blob/master/analyzeme/src/analysis.rs#L139), and make it load the integer events with query cache hit counts. I can do that as a follow-up, it's not required to be done in sync with this PR, and it doesn't require changes in rustc.

CC `@cjgillot`

r? `@oli-obk`
2025-07-02 11:41:14 +00:00
Jakub Beránek
b49ca021e1
Use portable AtomicU64 2025-07-02 10:04:35 +02:00
Josh Stone
e851e3e16e Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
Jakub Beránek
e8fc30ee05
Do not store empty cache hit counts 2025-06-26 08:14:34 +02:00
Jakub Beránek
04ff853e13
Add new self-profile event for aggregating query hit counts 2025-06-25 11:09:58 +02:00
Guillaume Gomez
f1fa46d3ba
Rollup merge of #142868 - klensy:dc, r=oli-obk
remove few allow(dead_code)

Few from serial/parallel compiler leftovers and few from bootstrap.
2025-06-22 17:35:36 +02:00
klensy
2ddbe39bfb remove allow(dead_code) leftovers from serial/parallel compiler 2025-06-22 13:05:09 +03: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
David Wood
884d0e031a
library/compiler: add PointeeSized bounds
As core uses an extern type (`ptr::VTable`), the default `?Sized` to
`MetaSized` migration isn't sufficient, and some code that previously
accepted `VTable` needs relaxed to continue to accept extern types.

Similarly, the compiler uses many extern types in `rustc_codegen_llvm`
and in the `rustc_middle::ty::List` implementation (`OpaqueListContents`)
some bounds must be relaxed to continue to accept these types.

Unfortunately, due to the current inability to relax `Deref::Target`,
some of the bounds in the standard library are forced to be stricter than
they ideally would be.
2025-06-16 23:04:33 +00:00
Nicholas Nethercote
bdfe1b9fb0 Overhaul the thousands module.
It currently only inserts separators into `usize`s, because that's all
that has been needed so far. `-Zmacro-stats` will need `isize` and `f64`
handling, so this commit adds that.
2025-06-12 15:26:06 +10:00
Celina G. Val
f52c6eee02 Another round of tidy / warning fixes 2025-06-11 16:56:01 -07:00
Celina G. Val
4aa62ea9e9 Use rustc_thread_pool instead of rustc-rayon-core 2025-06-11 12:26:42 -07:00
Jubilee
940a43677a
Rollup merge of #142194 - bjorn3:less_unstable_features, r=jieyouxu
Remove all unused feature gates from the compiler
2025-06-08 17:17:58 -07:00
bjorn3
9223704f4b Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
Josh Triplett
8a56ed4c89 SlotIndex::from_index: Factor out a constant for the first bucket size 2025-06-05 16:57:59 -07:00
Josh Triplett
9837c3c3f8 Simplify vec_cache::tests::slot_index_exhaustive by pulling out 0 case
`slot_index_exhaustive` has additional complexity in its loop that only
applies for index 0. Pull that case out of the loop.
2025-06-05 12:12:28 -07:00
Josh Triplett
43ee7cd57c Simplify and optimize SlotIndex::from_index
Break out bucket 0 (containing `idx < 4096`) as an early return, which
simplifies the remainder of the function, and allows optimizing the
`checked_ilog2` since it can no longer return `None`.

This reduces the runtime of `vec_cache::tests::slot_index_exhaustive`
(which calls `SlotIndex::from_index` for every `u32`, twice) from ~15.5s
to ~13.3s.
2025-06-05 12:09:00 -07:00
onur-ozkan
37cd39f3ce handle cfg bootstrap on compiler and miri
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-05-30 21:03:54 +03:00
Matthias Krüger
706dc70916
Rollup merge of #139668 - matthewjasper:upper-bound-fix, r=compiler-errors
Handle regions equivalent to 'static in non_local_bounds

`non_local_bounds` would only find non local bounds that strictly bound a given region, but it's possible that a local region is equated to 'static when showing a type referencing a locally bound lifetime, such as `dyn Any + 'a` in the tests added, is well-formed. In this case we should return 'static.

closes #122704
closes #139004
2025-05-22 16:02:26 +02:00
Trevor Gross
999967a57d Rename cfg_match! to cfg_select!
At [1] it was pointed out that `cfg_match!` syntax does not actually
align well with match syntax, which is a possible source of confusion.
The comment points out that usage is instead more similar to ecosystem
`select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

Tracking issue: https://github.com/rust-lang/rust/issues/115585

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-20 21:16:23 +00:00
klensy
9cacafdd1a compiler & tools: bump windows crate to dedupe versions 2025-05-17 15:26:38 +03:00
Philipp Krones
60750ca0a1
tempfile dep bump fallout 2025-05-15 19:55:43 +02:00
bors
3ef8e64ce9 Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk
Use thread local dep graph encoding

This adds thread local encoding of dep graph nodes. Each thread has a `MemEncoder` that gets flushed to the global `FileEncoder` when it exceeds 64 kB. Each thread also has a local cache of dep indices. This means there can now be empty gaps in `SerializedDepGraph`.

Indices are marked green and also allocated by the new atomic operation `DepNodeColorMap::try_mark_green` as the encoder lock is removed.
2025-05-07 12:39:54 +00:00
Zalathar
9e7fb67838 Rename graph::implementation::Graph to LinkedGraph 2025-05-06 14:35:06 +10:00
bors
3350c1eb3f Auto merge of #139965 - amandasystems:marginally-improved-scc-annotations, r=lcnr
Decouple SCC annotations from SCCs

This rewires SCC annotations to have them be a separate, visitor-type data structure. It was broken out of #130227, which needed them to be able to remove unused annotations after computation without recomputing the SCCs themselves.

As a drive-by it also removes some redundant code from the hot loop in SCC construction for a performance improvement.

r? lcnr
2025-05-01 16:04:19 +00:00
John Kåre Alsaker
d3ec14bbec Use thread local dep graph encoding 2025-05-01 10:20:31 +02:00
bors
6e23095adf Auto merge of #140145 - Zoxc:job-server-proxy, r=SparrowLii
Add a jobserver proxy to ensure at least one token is always held

This adds a jobserver proxy to ensure at least one token is always held by `rustc`. Currently with `-Z threads` `rustc` can temporarily give up all its tokens, causing `cargo` to spawn additional `rustc` instances beyond the job limit.

The current behavior causes an issue with `cargo fix` which has a global lock preventing concurrent `rustc` instances, but it also holds a jobserver token, causing a deadlock when `rustc` gives up its token. That is fixed by this PR.

Fixes https://github.com/rust-lang/rust/issues/67385.
Fixes https://github.com/rust-lang/rust/issues/133873.
Fixes https://github.com/rust-lang/rust/issues/140093.
2025-05-01 04:11:52 +00:00
John Kåre Alsaker
ef9403371f Drop AST on a separate thread and prefetch hir_crate 2025-04-29 14:03:07 +02:00
John Kåre Alsaker
cff9efde74 Add a jobserver proxy to ensure at least one token is always held 2025-04-29 07:20:13 +02:00
Amanda Stjerna
b660ab9f69 Use associated types for SCC annotations, per code review suggestion 2025-04-28 14:59:04 +02:00