Commit Graph

819 Commits

Author SHA1 Message Date
Matthias Krüger
9f2fc640f3
Rollup merge of #126368 - nnethercote:rm-more-unused-crate-deps, r=jackh726
Remove some unnecessary crate dependencies.

A follow-up to #126063.

r? ``@jackh726``
2024-06-14 08:35:50 +02:00
Nicholas Nethercote
12432130a3 Remove some unnecessary crate dependencies. 2024-06-13 15:03:43 +10:00
Amanda Stjerna
d63708b907 Address code review comments on the comments 2024-06-12 15:48:34 +02:00
Amanda Stjerna
3bdcb9d436 Revise documentation after @lqd's comments 2024-06-12 15:47:32 +02:00
Amanda Stjerna
aee846224c Remove a few unnecessary constructions
This shaves off ca 6% of the cycles in `start_walk_from()` in my
experiments.
2024-06-12 15:47:32 +02:00
Amanda Stjerna
b1add7bc04 Slightly faster version of find_state
This version shaves off ca 2% of the cycles in my experiments
and makes the control flow easier to follow for me and hopefully
others, including the compiler.

Someone gave me a working profiler and by God I'm using it.
2024-06-12 15:47:32 +02:00
Amanda Stjerna
14c10ec88e Docstring for for Annotation
Note that this changes no executing code. The change is 100% in documentation.
2024-06-12 15:47:32 +02:00
Amanda Stjerna
582c613be8 Formatting, weird because I just did that 2024-06-12 15:47:32 +02:00
Amanda Stjerna
905db03b28 Simplify path compression logic 2024-06-12 15:47:32 +02:00
Amanda Stjerna
d2a01760bc Documentation fixes 2024-06-12 15:47:32 +02:00
Amanda Stjerna
b1ace388c0 Extend SCC construction to enable extra functionality
This patch has been extracted from #123720. It specifically enhances
`Sccs` to allow tracking arbitrary commutative properties of SCCs, including
- reachable values (max/min)
- SCC-internal values (max/min)

This helps with among other things universe computation: we can now identify
SCC universes as a straightforward "find max/min" operation during SCC construction.

It's also more or less zero-cost; don't use the new features, don't pay for them.

This commit also vastly extends the documentation of the SCCs module, which I had a very hard time following.
2024-06-12 15:47:32 +02:00
Oli Scherer
0bc2001879 Require any function with a tait in its signature to actually constrain a hidden type 2024-06-12 08:53:59 +00:00
Nicholas Nethercote
29629d0075 Remove some unused crate dependencies.
I found these by setting the `unused_crate_dependencies` lint
temporarily to `Warn`.
2024-06-10 19:55:49 +10:00
r0cky
dabd05bbab Apply x clippy --fix and x fmt 2024-05-30 09:51:27 +08:00
Peter Jaszkowiak
4913ab8f77
Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00
Matthias Krüger
3c40e383df
Rollup merge of #124818 - compiler-errors:ena, r=Mark-Simulacrum
Update ena to 0.14.3

Includes https://github.com/rust-lang/ena/pull/53, which removes a trivial `Self: Sized` bound that prevents `ena` from building on the new solver.
2024-05-11 08:00:15 +02:00
Nicholas Nethercote
58a06b6a99 Remove enum_from_u32.
It's a macro that just creates an enum with a `from_u32` method. It has
two arms. One is unused and the other has a single use.

This commit inlines that single use and removes the whole macro. This
increases readability because we don't have two different macros
interacting (`enum_from_u32` and `language_item_table`).
2024-05-09 09:01:59 +10:00
Nicholas Nethercote
d3d01e1cd3 Remove vec_linked_list.
It provides a way to effectively embed a linked list within an
`IndexVec` and also iterate over that list. It's written in a very
generic way, involving two traits `Links` and `LinkElem`. But the
`Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the
whole thing is only used in one module within `rustc_borrowck`. So I
think it's over-engineered and hard to read. Plus it has no comments.

This commit removes it, and adds a (non-generic) local iterator for the
use within `rustc_borrowck`. Much simpler.
2024-05-09 08:13:24 +10:00
Nicholas Nethercote
f5d7d346a4 Remove TinyList.
It is optimized for lists with a single element, avoiding the need for
an allocation in that case. But `SmallVec<[T; 1]>` also avoids the
allocation, and is better in general: more standard, log2 number of
allocations if the list exceeds one item, and a much more capable API.

This commit removes `TinyList` and converts the two uses to
`SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant
file so they are in just two sections (`pub` and non-`pub`), ordered
alphabetically, instead of many sections. (This is a relevant part of
the change because I had to decide where to add a `use` item for
`SmallVec`.)
2024-05-09 08:13:24 +10:00
Nicholas Nethercote
d7814e72eb Document Pu128.
And move the `repr` line after the `derive` line, where it's harder to
overlook. (I overlooked it initially, and didn't understand how this
type worked.)
2024-05-09 08:13:24 +10:00
Nicholas Nethercote
55b6ff8e41 Remove extern crate tracing.
`use` is a nicer way of doing things.
2024-05-08 12:52:31 +10:00
Nicholas Nethercote
351c0fa2a3 Reorder top-level crate items.
- `use` before `mod`
- `pub` before `non-pub`
- Alphabetical order within sections
2024-05-07 10:20:04 +10:00
Nicholas Nethercote
df8fe7dd34 Remove macro_use from stable_hasher.
Normal `use` items are nicer.
2024-05-07 10:19:12 +10:00
Michael Goulet
2af0871297 Update ena to 0.14.3 2024-05-06 14:32:39 -04:00
bors
0d7b2fb797 Auto merge of #123441 - saethlin:fixed-len-file-names, r=oli-obk
Stabilize the size of incr comp object file names

The current implementation does not produce stable-length paths, and we create the paths in a way that makes our allocation behavior is nondeterministic. I think `@eddyb` fixed a number of other cases like this in the past, and this PR fixes another one. Whether that actually matters I have no idea, but we still have bimodal behavior in rustc-perf and the non-uniformity in `find` and `ls` was bothering me.

I've also removed the truncation of the mangled CGU names. Before this PR incr comp paths look like this:
```
target/debug/incremental/scratch-38izrrq90cex7/s-gux6gz0ow8-1ph76gg-ewe1xj434l26w9up5bedsojpd/261xgo1oqnd90ry5.o
```
And after, they look like this:
```
target/debug/incremental/scratch-035omutqbfkbw/s-gux6borni0-16r3v1j-6n64tmwqzchtgqzwwim5amuga/55v2re42sztc8je9bva6g8ft3.o
```

On the one hand, I'm sure this will break some people's builds because they're on Windows and only a few bytes from the path length limit. But if we're that seriously worried about the length of our file names, I have some other ideas on how to make them smaller. And last time I deleted some hash truncations from the compiler, there was a huge drop in the number if incremental compilation ICEs that were reported: https://github.com/rust-lang/rust/pull/110367https://github.com/rust-lang/rust/pull/110367

---

Upon further reading, this PR actually fixes a bug. This comment says the CGU names are supposed to be a fixed-length hash, and before this PR they aren't: ca7d34efa9/compiler/rustc_monomorphize/src/partitioning.rs (L445-L448)
2024-05-03 17:41:48 +00:00
bors
f5efc3c286 Auto merge of #124521 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68
Bump bootstrap compiler to latest beta

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday

This also cherry-picks d716d72586548963f32e5c8d57c41db0065fa6e0 from the beta branching, to continue to workaround #122758.

r? bootstrap
2024-05-02 09:21:43 +00:00
Waffle Lapkin
3c815a644c Add UnordMap::try_insert 2024-05-02 03:49:46 +02:00
Mark Rousskov
43f9a5ec0c Mark more entries in rustc_data_structures as no_inline for docs
This is a workaround for #122758, but it's not clear why 1.79 requires a
more extensive amount of no_inline than the previous release. Seems like
there's something relatively subtle happening here.
2024-05-01 21:01:51 -04:00
León Orell Valerian Liehr
dec1d16a9b
Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
Nicholas Nethercote
4814fd0a4b Remove extern crate rustc_macros from numerous crates. 2024-04-29 10:21:54 +10:00
Markus Reiter
33e68aadc9
Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
Ben Kimock
6ee3713b08 Stabilize the size of incr comp object file names 2024-04-22 10:50:07 -04:00
Maybe Waffle
523fe2b67b Add tests for predecessor-aware VecGraph mode 2024-04-18 17:32:42 +00:00
Maybe Waffle
fa134b5e0f Add graph::depth_first_search_as_undirected 2024-04-15 23:20:52 +00:00
Maybe Waffle
7d2cb3dda7 Make graph::DepthFirstSearch accept G by value
It's required for the next commit.

Note that you can still have `G = &H`, since there are implementations of all
the graph traits for references.
2024-04-15 23:20:52 +00:00
Maybe Waffle
86a576528c Add an opt-in to store incoming edges in VecGraph + some docs 2024-04-15 23:20:52 +00:00
许杰友 Jieyou Xu (Joe)
5580ae9795
Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease
`rustc_data_structures::graph` mini refactor

Who doesn't love to breathe dust from the ancient times?
2024-04-15 16:56:18 +01:00
Maybe Waffle
435db9b9bd Use RPITIT for Successors and Predecessors traits
Now with RPITIT instead of GAT!
2024-04-15 13:34:08 +00:00
Maybe Waffle
e8d2221e3b Make depth_first_search into a standalone function
Does not necessarily change much, but we never overwrite it, so I see no reason
for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
2024-04-14 16:03:08 +00:00
Maybe Waffle
3124fa9310 Document ControlFlowGraph 2024-04-14 15:53:38 +00:00
Maybe Waffle
f5144938bd Rename WithNumEdges => NumEdges and WithStartNode => StartNode 2024-04-14 15:51:29 +00:00
Maybe Waffle
0d5fc9bf58 Merge {With,Graph}{Successors,Predecessors} into {Successors,Predecessors}
Now with GAT!
2024-04-14 15:48:53 +00:00
Maybe Waffle
398da593a5 Merge WithNumNodes into DirectedGraph 2024-04-14 15:46:40 +00:00
bors
af6a1613b3 Auto merge of #123175 - Nilstrieb:debug-strict-overflow, r=wesleywiser
Add add/sub methods that only panic with debug assertions to rustc

This mitigates the perf impact of enabling overflow checks on rustc. The change to use overflow checks will be done in a later PR.

For rust-lang/compiler-team#724, based on data gathered in #119440.
2024-04-13 17:18:42 +00:00
Nilstrieb
5039160c5b Add add/sub methods that only panic with debug assertions to rustc
This mitigates the perf impact of enabling overflow checks on rustc.
The change to use overflow checks will be done in a later PR.
2024-04-13 17:03:12 +02:00
Vadim Petrochenkov
b40ea03f8a rustc_index: Add a ZERO constant to index types
It is commonly used.
2024-04-03 19:06:22 +03:00
bors
bf71daedc2 Auto merge of #121851 - michaelwoerister:mcp-533-effective-vis, r=cjgillot
Use FxIndexMap instead FxHashMap to stabilize iteration order in EffectiveVisibilities

Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-03-31 16:22:38 +00:00
Urgau
16d11c539f Add support for NonNull in ambiguous_wide_ptr_comparisions 2024-03-29 22:02:07 +01:00
Michael Woerister
7e4bc4a373 Remove and disallow HashStable impl of HashMap. 2024-03-27 14:57:01 +01:00
bors
df8ac8f1d7 Auto merge of #122568 - RalfJung:mentioned-items, r=oli-obk
recursively evaluate the constants in everything that is 'mentioned'

This is another attempt at fixing https://github.com/rust-lang/rust/issues/107503. The previous attempt at https://github.com/rust-lang/rust/pull/112879 seems stuck in figuring out where the [perf regression](https://perf.rust-lang.org/compare.html?start=c55d1ee8d4e3162187214692229a63c2cc5e0f31&end=ec8de1ebe0d698b109beeaaac83e60f4ef8bb7d1&stat=instructions:u) comes from. In  https://github.com/rust-lang/rust/pull/122258 I learned some things, which informed the approach this PR is taking.

Quoting from the new collector docs, which explain the high-level idea:
```rust
//! One important role of collection is to evaluate all constants that are used by all the items
//! which are being collected. Codegen can then rely on only encountering constants that evaluate
//! successfully, and if a constant fails to evaluate, the collector has much better context to be
//! able to show where this constant comes up.
//!
//! However, the exact set of "used" items (collected as described above), and therefore the exact
//! set of used constants, can depend on optimizations. Optimizing away dead code may optimize away
//! a function call that uses a failing constant, so an unoptimized build may fail where an
//! optimized build succeeds. This is undesirable.
//!
//! To fix this, the collector has the concept of "mentioned" items. Some time during the MIR
//! pipeline, before any optimization-level-dependent optimizations, we compute a list of all items
//! that syntactically appear in the code. These are considered "mentioned", and even if they are in
//! dead code and get optimized away (which makes them no longer "used"), they are still
//! "mentioned". For every used item, the collector ensures that all mentioned items, recursively,
//! do not use a failing constant. This is reflected via the [`CollectionMode`], which determines
//! whether we are visiting a used item or merely a mentioned item.
//!
//! The collector and "mentioned items" gathering (which lives in `rustc_mir_transform::mentioned_items`)
//! need to stay in sync in the following sense:
//!
//! - For every item that the collector gather that could eventually lead to build failure (most
//!   likely due to containing a constant that fails to evaluate), a corresponding mentioned item
//!   must be added. This should use the exact same strategy as the ecollector to make sure they are
//!   in sync. However, while the collector works on monomorphized types, mentioned items are
//!   collected on generic MIR -- so any time the collector checks for a particular type (such as
//!   `ty::FnDef`), we have to just onconditionally add this as a mentioned item.
//! - In `visit_mentioned_item`, we then do with that mentioned item exactly what the collector
//!   would have done during regular MIR visiting. Basically you can think of the collector having
//!   two stages, a pre-monomorphization stage and a post-monomorphization stage (usually quite
//!   literally separated by a call to `self.monomorphize`); the pre-monomorphizationn stage is
//!   duplicated in mentioned items gathering and the post-monomorphization stage is duplicated in
//!   `visit_mentioned_item`.
//! - Finally, as a performance optimization, the collector should fill `used_mentioned_item` during
//!   its MIR traversal with exactly what mentioned item gathering would have added in the same
//!   situation. This detects mentioned items that have *not* been optimized away and hence don't
//!   need a dedicated traversal.

enum CollectionMode {
    /// Collect items that are used, i.e., actually needed for codegen.
    ///
    /// Which items are used can depend on optimization levels, as MIR optimizations can remove
    /// uses.
    UsedItems,
    /// Collect items that are mentioned. The goal of this mode is that it is independent of
    /// optimizations: the set of "mentioned" items is computed before optimizations are run.
    ///
    /// The exact contents of this set are *not* a stable guarantee. (For instance, it is currently
    /// computed after drop-elaboration. If we ever do some optimizations even in debug builds, we
    /// might decide to run them before computing mentioned items.) The key property of this set is
    /// that it is optimization-independent.
    MentionedItems,
}
```
And the `mentioned_items` MIR body field docs:
```rust
    /// Further items that were mentioned in this function and hence *may* become monomorphized,
    /// depending on optimizations. We use this to avoid optimization-dependent compile errors: the
    /// collector recursively traverses all "mentioned" items and evaluates all their
    /// `required_consts`.
    ///
    /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
    /// All that's relevant is that this set is optimization-level-independent, and that it includes
    /// everything that the collector would consider "used". (For example, we currently compute this
    /// set after drop elaboration, so some drop calls that can never be reached are not considered
    /// "mentioned".) See the documentation of `CollectionMode` in
    /// `compiler/rustc_monomorphize/src/collector.rs` for more context.
    pub mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>,
```

Fixes #107503
2024-03-21 09:01:18 +00:00