Commit Graph

485 Commits

Author SHA1 Message Date
Michael Goulet
ca44416023 Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure 2024-02-06 02:22:58 +00:00
Michael Goulet
427896dd7e Construct body for by-move coroutine closure output 2024-02-06 02:22:58 +00:00
Michael Goulet
fc4fff4038 Build a shim to call async closures with different AsyncFn trait kinds 2024-02-06 02:22:58 +00:00
Nicholas Nethercote
0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
klensy
17f0919e8a rustc_monomorphize: fix outdated comment in partition 2024-02-03 14:50:24 +03:00
clubby789
fd29f74ff8 Remove unused features 2024-01-25 14:01:33 +00:00
Matthias Krüger
0c45e3c7dd
Rollup merge of #119895 - oli-obk:track_errors_3, r=matthewjasper
Remove `track_errors` entirely

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

r? `@matthewjasper`

There are some diagnostic changes adding new diagnostics or not emitting some anymore. We can improve upon that in follow-up work imo.
2024-01-25 08:39:42 +01:00
León Orell Valerian Liehr
6131ba62ad
Rollup merge of #120139 - compiler-errors:fnonce-shim, r=BoxyUwU
Do not normalize closure signature when building `FnOnce` shim

It is not necessary to normalize the closure signature when building an `FnOnce` shim for an `Fn`/`FnMut` closure. That closure shim is just calling `FnMut::call_mut(&mut self)` anyways.

It's also somewhat sketchy that we were ever doing this to begin with, since we're normalizing with a `ParamEnv::reveal_all()` param-env, which is definitely not right with possibly polymorphic substs.

This cuts out a tiny bit of unnecessary work in `Instance::resolve` and simplifies the signature because now we can unconditionally return an `Instance`.
2024-01-23 21:53:56 +01:00
Oli Scherer
db7cd57091 Remove track_errors entirely 2024-01-23 15:23:22 +00:00
Nicholas Nethercote
e164cf30f8 Rename TyCtxt::emit_spanned_lint as TyCtxt::emit_node_span_lint. 2024-01-23 08:09:05 +11:00
Michael Goulet
f700ee4e70 Do not normalize closure signature when building FnOnce shim 2024-01-22 16:50:30 +00:00
Nadrieril
e8d1c2ef9c
Rollup merge of #118811 - EbbDrop:is-sorted-by-bool, r=Mark-Simulacrum
Use `bool` instead of `PartiolOrd` as return value of the comparison closure in `{slice,Iteraotr}::is_sorted_by`

Changes the function signature of the closure given to `{slice,Iteraotr}::is_sorted_by` to return a `bool` instead of a `PartiolOrd` as suggested by the libs-api team here: https://github.com/rust-lang/rust/issues/53485#issuecomment-1766411980.

This means these functions now return true if the closure returns true for all the pairs of values.
2024-01-21 06:38:35 +01:00
EbbDrop
606eeb84ad Use bool instead of PartiolOrd in is_sorted_by 2024-01-20 21:38:34 +01:00
Oli Scherer
557b111870 Make crate_inherent_impls fallible and stop using track_errors for it 2024-01-17 10:02:29 +00:00
Martin Nordholts
8f440f06c6 large_assignments: Lint on specific large args passed to functions 2024-01-15 19:07:12 +01:00
Martin Nordholts
16ba56c242 compiler: Lower fn call arg spans down to MIR
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-15 19:07:11 +01:00
Nilstrieb
da26317a8a Stop mentioning internal lang items in no_std binary errors
When writing a no_std binary, you'll be greeted with nonsensical errors
mentioning lang items like eh_personality and start. That's pretty bad
because it makes you think that you need to define them somewhere! But
oh no, now you're getting the `internal_features` lint telling you that
you shouldn't use them! But you need a no_std binary! What now?

No problem! Writing a no_std binary is super easy. Just use panic=abort
and supply your own platform specific entrypoint symbol (like `main`)
and you're good to go. Would be nice if the compiler told you that,
right?

This makes it so that it does do that.
2024-01-10 21:18:54 +01:00
Nicholas Nethercote
3c4f1d85af Rename {create,emit}_warning as {create,emit}_warn.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
Michael Goulet
f361b591ef
Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors
Cleanup error handlers: round 5

More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171.

r? ````@compiler-errors````
2024-01-05 10:57:21 -05:00
Nicholas Nethercote
505c1371d0 Rename some Diagnostic setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be
considered setters. Four of them have a `set_` prefix. This doesn't seem
necessary for a type that implements the builder pattern. This commit
removes the `set_` prefixes on those four methods.
2024-01-03 19:40:20 +11:00
Michael Goulet
07adee7072 is_coroutine -> is_coroutine_or_closure 2023-12-30 15:24:15 +00:00
Nicholas Nethercote
8a9db25459 Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Nicholas Nethercote
e7724a2e31 Add level arg to into_diagnostic.
And make all hand-written `IntoDiagnostic` impls generic, by using
`DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
`dcx.struct_err(...)`.

This means the `create_*` functions are the source of the error level.
This change will let us remove `struct_diagnostic`.

Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
it's necessary to pass diagnostics tests now that it's used in
`into_diagnostic` functions.
2023-12-19 09:19:25 +11:00
Nicholas Nethercote
f422dca3ae Rename many DiagCtxt arguments. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
09af8a667c Rename Session::span_diagnostic as Session::dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
bors
1559dd2dbf Auto merge of #118770 - saethlin:fix-inline-never-uses, r=nnethercote
Fix cases where std accidentally relied on inline(never)

This PR increases the power of `-Zcross-crate-inline-threshold=always` so that it applies through `#[inline(never)]`. Note that though this is called "cross-crate-inlining" in this case especially it is _just_ lazy per-CGU codegen. The MIR inliner and LLVM still respect the attribute as much as they ever have.

Trying to bootstrap with the new `-Zcross-crate-inline-threshold=always` change revealed two bugs:

We have special intrinsics `assert_inhabited`, `assert_zero_valid`, and `assert_mem_uniniitalized_valid` which codegen backends will lower to nothing or a call to `panic_nounwind`.  Since we may not have any call to `panic_nounwind` in MIR but emit one anyway, we need to specially tell `MirUsedCollector` about this situation.

`#[lang = "start"]` is special-cased already so that `MirUsedCollector` will collect it, but then when we make it cross-crate-inlinable it is only assigned to a CGU based on whether `MirUsedCollector` saw a call to it, which of course we didn't.

---

I started looking into this because https://github.com/rust-lang/rust/pull/118683 revealed a case where we were accidentally relying on a function being `#[inline(never)]`, and cranking up cross-crate-inlinability seems like a way to find other situations like that.

r? `@nnethercote` because I don't like what I'm doing to the CGU partitioning code here but I can't come up with something much better
2023-12-15 04:54:14 +00:00
Ben Kimock
e559172249 Fix cases where std accidentally relied on inline(never) 2023-12-14 08:30:36 -05:00
Lukasz Anforowicz
981c4e3ce6 Add unstable -Zdefault-hidden-visibility cmdline flag for rustc.
The new flag has been described in the Major Change Proposal at
https://github.com/rust-lang/compiler-team/issues/656
2023-12-13 21:14:23 +00:00
Matthias Krüger
646d627661
Rollup merge of #118693 - saethlin:alignment-check-symbol-reachable, r=bjorn3
Tell MirUsedCollector that the pointer alignment checks calls its panic symbol

Fixes https://github.com/rust-lang/rust/pull/118683 (not an issue, but that PR is a basically a bug report)

When we had `panic_immediate_abort` start adding `#[inline]` to this panic function, builds started breaking because we failed to write up the MIR assert terminator to the correct panic shim. Things happened to work before by pure luck because without this feature enabled, the function we're inserting calls to is `#[inline(never)]` so we always generated code for it.

r? bjorn3
2023-12-08 06:44:42 +01:00
Ralf Jung
cb86303342 ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
Ben Kimock
aa58ccb53e Tell MirUsedCollector that the pointer alignment checks calls its panic symbol 2023-12-06 21:30:23 -05:00
bohan
f23befe6c1 merge DefKind::Coroutine into DefKind::Closure 2023-11-26 21:05:08 +08:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote
a733082be9 Avoid need for {D,Subd}iagnosticMessage imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Nicholas Nethercote
f405ce86c2 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Zalathar
6f1ca8d9eb coverage: Change query codegened_and_inlined_items to a plain function
This query has a name that sounds general-purpose, but in fact it has
coverage-specific semantics, and (fortunately) is only used by coverage code.

Because it is only ever called once (from one designated CGU), it doesn't need
to be a query, and we can change it to a regular function instead.
2023-10-21 12:20:05 +11:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Nicholas Nethercote
a145b498e0 Remove UnknownPartitionStrategy error.
This became unused in #112053, when `-Zcgu-partitioning-strategy` was
removed.
2023-10-18 14:42:58 +11:00
Nicholas Nethercote
4f923376b6 Streamline build_skip_move_check_fns.
It's just a `filter_map(...).collect()`.
2023-10-18 14:42:57 +11:00
Nicholas Nethercote
55c5ab9fbc Inline and remove item_requires_monomorphization.
It's very simple and has a single call site.
2023-10-18 14:26:19 +11:00
Nicholas Nethercote
42c8803fe8 Remove empty MirUsedCollector::visit_local.
It has not effect, because the default `visit_local` in `mir::Visitor`
is already empty.
2023-10-18 14:24:15 +11:00
Nicholas Nethercote
025eb20a86 Remove unneeded dependencies from rustc_monomorphize. 2023-10-18 14:23:51 +11:00
Martin Nordholts
56e4715fc6 rustc_monomorphize: Introduce check_fn_args_move_size()
So that we later can improve the accuracy of diagnostics.
2023-10-07 10:29:37 +02:00
Martin Nordholts
41d24ccb49 rustc_monomorphize: Move limit check into check_move_size()
And rename to check_operand_move_size(). Later we will introduce
check_fn_args_move_size().
2023-10-07 10:29:16 +02:00
Jubilee
6d1c3a40cb
Rollup merge of #116277 - RalfJung:post-mono, r=oli-obk
dont call mir.post_mono_checks in codegen

It seems like all tests are still passing when I remove this... let's see what CI says.
2023-10-06 16:37:46 -07:00
Ralf Jung
fa248cd9e6 add some comments explaining how the required_consts stuff fits together 2023-10-06 18:25:23 +02:00
Matthias Krüger
144862ede8
Rollup merge of #115863 - chenyukang:yukang-add-message-tidy-check, r=davidtwco
Add check_unused_messages in tidy

From https://github.com/rust-lang/rust/pull/115728#issuecomment-1715490553
The check is not 100% accurate, I guess it's enough for now.
2023-10-03 12:24:11 +02:00
bors
6b99cf1d35 Auto merge of #116163 - compiler-errors:lazyness, r=oli-obk
Don't store lazyness in `DefKind::TyAlias`

1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query.
2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase.

r? `@oli-obk` cc `@fmease`
2023-09-27 01:48:53 +00:00
lcnr
3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Michael Goulet
d6ce9ce115 Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
Guillaume Gomez
208f6ed95c
Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Ralf Jung
c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
yukang
42a033affa Cleanup unused messages in ftl files 2023-09-20 19:09:01 +08:00
Ralf Jung
ea22adbabd adjust constValue::Slice to work for arbitrary slice types 2023-09-19 20:17:43 +02:00
Ralf Jung
5a0a1ff0cd move ConstValue into mir
this way we have mir::ConstValue and ty::ValTree as reasonably parallel
2023-09-19 11:11:02 +02:00
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
bors
e437e57954 Auto merge of #115804 - RalfJung:valtree-to-const-val, r=oli-obk
consistently pass ty::Const through valtrees

Some drive-by things extracted from https://github.com/rust-lang/rust/pull/115748.
2023-09-14 15:34:31 +00:00
bors
5e71913156 Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk
treat host effect params as erased in codegen

This fixes the changes brought to codegen tests when effect params are added to libcore, by not attempting to monomorphize functions that get the host param by being `const fn`.

r? `@oli-obk`
2023-09-14 13:42:30 +00:00
Deadbeef
a0a801cd38 treat host effect params as erased generics in codegen
This fixes the changes brought to codegen tests when effect params are
added to libcore, by not attempting to monomorphize functions that get
the host param by being `const fn`.
2023-09-14 07:34:35 +00:00
Ralf Jung
19fb2c7ccd found another place where we can eval() a const, and go through valtrees 2023-09-14 07:56:01 +02:00
Ralf Jung
0f8908da27 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
Ralf Jung
551f481ffb use AllocId instead of Allocation in ConstValue::ByRef 2023-09-14 07:26:24 +02:00
Matthias Krüger
6f180ea954
Rollup merge of #115492 - Enselic:large-box-move, r=oli-obk
Allow `large_assignments` for Box/Arc/Rc initialization

Does the `stop linting in box/arc initialization` task of #83518.

r? `@oli-obk` who is E-mentor.
2023-09-05 07:15:16 +02:00
Matthias Krüger
a73c663ec4
Rollup merge of #115353 - Enselic:no-optimized-mir, r=oli-obk
Emit error instead of ICE when optimized MIR is missing

Closes #51388
2023-09-05 07:15:15 +02:00
Martin Nordholts
789451b43a Allow large_assignments for Box/Arc/Rc initialization
Does the `stop linting in box/arc initialization` task of 83518.
2023-09-03 08:15:25 +02:00
Martin Nordholts
456007af12 Emit error instead of ICE when optimized MIR is missing
Closes 51388.
2023-08-30 20:43:31 +02:00
bors
c587fd4185 Auto merge of #114774 - Enselic:less-move-size-noise, r=oli-obk
Avoid duplicate `large_assignments` lints

By checking for overlapping spans.

This PR does the "reduce noisiness" task in #83518.

r? `@oli-obk` who added E-mentor and E-help-wanted and wrote the initial code.

(The fix itself is in dc82736677. The two commits before that are just small refactorings.)
2023-08-28 13:36:19 +00:00
Ralf Jung
4c53783f3c when terminating during unwinding, show the reason why 2023-08-24 13:28:26 +02:00
Ralf Jung
818ec8e23a give some unwind-related terminators a more clear name 2023-08-20 15:52:38 +02:00
Martin Nordholts
dc82736677 Avoid duplicate large_assignments lints
By checking for overlapping spans.
2023-08-13 08:19:50 +02:00
Martin Nordholts
1f56ff8f26 rustc_monomorphize: Reduce check_move_size() indentation 2023-08-13 08:19:49 +02:00
Martin Nordholts
af86069ab1 rustc_monomorphize: Add check_move_size() helper 2023-08-13 08:19:49 +02:00
León Orell Valerian Liehr
5468336d6b
Store the laziness of type aliases in the DefKind 2023-08-07 15:54:31 +02:00
Ralf Jung
2984670cea avoid 'miri' when refering to the shared interpreter 2023-08-02 16:52:03 +02:00
Matthias Krüger
c3cd05198a
Rollup merge of #113872 - nnethercote:tweak-cgu-sorting, r=pnkfelix
Tweak CGU sorting in a couple of places.

In `base.rs`, tweak how the CGU size interleaving works. Since #113777, it's much more common to have multiple CGUs with identical sizes. With the existing code these same-sized items ended up in the opposite-to-desired order due to the stable sorting. The code now starts with a reverse sort (like is done in `partitioning.rs`) which gives the behaviour we want. This doesn't matter much for perf, but makes profiles in `samply` look more like what we expect.

In `partitioning.rs`, we can use `sort_by_key` instead of `sort_by_cached_key` because `CGU::size_estimate()` is cheap. (There is an identical CGU sort earlier in that function that already uses `sort_by_key`.)

r? `@pnkfelix`
2023-07-27 06:04:12 +02:00
Matthias Krüger
af2b370100 more clippy::style fixes:
get_first
single_char_add_str
unnecessary_mut_passed
manual_map
manual_is_ascii_check
2023-07-23 23:39:04 +02:00
Matthias Krüger
ed4c5fef72 fix some clippy::style findings
comparison_to_empty
iter_nth_zero
for_kv_map
manual_next_back
redundant_pattern
2023-07-23 23:36:56 +02:00
Nicholas Nethercote
8c31219d5c Tweak CGU sorting in a couple of places.
In `base.rs`, tweak how the CGU size interleaving works. Since #113777,
it's much more common to have multiple CGUs with identical sizes. With
the existing code these same-sized items ended up in the
opposite-to-desired order due to the stable sorting. The code now starts
with a reverse sort (like is done in `partitioning.rs`) which gives the
behaviour we want. This doesn't matter much for perf, but makes profiles
in `samply` look more like what we expect.

In `partitioning.rs`, we can use `sort_by_key` instead of
`sort_by_cached_key` because `CGU::size_estimate()` is cheap. (There is
an identical CGU sort earlier in that function that already uses
`sort_by_key`.)
2023-07-20 09:58:13 +10:00
Nicholas Nethercote
05de5d6f64 Change the primary CGU merging algorithm.
Instead of repeatedly merging the two smallest CGUs, we now use a
merging algorithm that aims to minimize the duplication of inlined
functions.

`exa-0.10.1` was one benchmark that saw particularly good results. The
old CGU stats:
```
INTERNALIZE
- unique items: 2774 (1216 root + 1558 inlined), unique size: 122065 (77219 root + 44846 inlined)
- placed items: 3834 (1216 root + 2618 inlined), placed size: 154552 (77219 root + 77333 inlined)
- placed/unique items ratio: 1.38, placed/unique size ratio: 1.27
- CGUs: 16, mean size: 9659.5, sizes: [11791, 11634, 11173, 10987, 10939, 10507, 9992, 9813, 9593, 9580, 9030, 8447, 7975, 7961, 7876, 7254]
```
The new CGU stats:
```
INTERNALIZE
- unique items: 2774 (1216 root + 1558 inlined), unique size: 122065 (77219 root + 44846 inlined)
- placed items: 3626 (1216 root + 2410 inlined), placed size: 147201 (77219 root + 69982 inlined)
- placed/unique items ratio: 1.31, placed/unique size ratio: 1.21
- CGUs: 16, mean size: 9200.1, sizes: [11634, 10939, 10227, 9555, 9178, 9167, 8879, 8804, 8604, 8603 (x3), 8602 (x2), 8601, 8600]
```
The difference is in the number of inlined items. There are 1558 unique
inlined items. With the old algorithm these were placed 2618 times,
resulting in 1060 duplicates. With the new algorithm these were placed
2410 times, resulting in 852 duplicates. Also, the mean CGU size dropped
from 9659.5 to 9200.1, and the CGU size distribution tightened, with the
biggest one a little smaller and the smallest ones a little bigger.
2023-07-19 07:23:11 +10:00
Nicholas Nethercote
b2c3948892 Split the CGU merging loop.
It has two conditions. This commit splits it in two, one per condition.
The next commit will change the first loop.
2023-07-19 07:23:11 +10:00
Nicholas Nethercote
77b053a2dd Add MonoItemData::inlined. 2023-07-19 07:23:09 +10:00
Nicholas Nethercote
87c509da95 Ignore unreachable inlined items in debug_dump.
They're quite rare, and ignoring them simplifies things quite a bit, and
further reduces the number of calls to `MonoItem::size_estimate` to the
number of placed items (one per root item, and one or more per reachable
inlined item).
2023-07-17 08:44:48 +10:00
Nicholas Nethercote
edd1f3827e Store item size estimate in MonoItemData.
This means we call `MonoItem::size_estimate` (which involves a query)
less often: just once per mono item, and then once more per inline item
placement. After that we can reuse the stored value as necessary. This
means `CodegenUnit::compute_size_estimate` is cheaper.
2023-07-17 08:44:48 +10:00
Nicholas Nethercote
b52f9eb6ca Introduce MonoItemData.
It replaces `(Linkage, Visibility)`, making the code nicer. Plus the
next commit will add another field.
2023-07-17 08:44:48 +10:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Santiago Pastorino
20429af7a3
Replace RPITIT current impl with new strategy that lowers as a GAT 2023-07-08 18:21:34 -03:00
bors
d1389b9b48 Auto merge of #113484 - matthiaskrgr:rollup-goq2u0d, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #112931 (Enable zlib in LLVM on aarch64-apple-darwin)
 - #113158 (tests: unset `RUSTC_LOG_COLOR` in a test)
 - #113173 (CI: include workflow name in concurrency group)
 - #113335 (Reveal opaques in new solver)
 - #113390 (CGU formation tweaks)
 - #113399 (Structurally normalize again for byte string lit pat checking)
 - #113412 (Add basic types to SMIR)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-07-08 18:36:58 +00:00
Matthias Krüger
d5b1ef98b0
Rollup merge of #113390 - nnethercote:cgu-tweaks, r=wesleywiser
CGU formation tweaks

Minor improvements I found while trying out something bigger that didn't work out.

r? ``@wesleywiser``
2023-07-08 15:49:46 +02:00
Nilstrieb
2beabbbf6f Rename adjustment::PointerCast and variants using it to PointerCoercion
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related
casts, when in reality their just used to share a some enum variants. Make it clear there these
are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07 18:17:16 +02:00
Michael Goulet
3f8919c09b get rid of a bit more calls to poly_select 2023-07-06 16:50:12 +00:00
Nicholas Nethercote
fc8536669c Diagnose unsorted CGUs.
An assertion failure was reported in #112946. This extra information
will help diagnose the problem.
2023-07-06 18:27:25 +10:00
Nicholas Nethercote
3078e4d804 Minor comment fix. 2023-07-06 11:07:22 +10:00
Nicholas Nethercote
b51169c178 Remove the field name from MonoItemPlacement::SingleCgu.
It's needless verbosity.
2023-07-06 10:35:57 +10:00
Nicholas Nethercote
22d4c798ec Use iter() instead of iter_mut() in one place. 2023-07-06 10:35:57 +10:00
Nicholas Nethercote
142075a9fb Make UsageMap::get_user_items infallible.
It's nicer this way.
2023-07-06 10:35:57 +10:00
Nicholas Nethercote
666b1b68a7 Tweak thread names for CGU processing.
For non-incremental builds on Unix, currently all the thread names look
like `opt regex.f10ba03eb5ec7975-cgu.0`. But they are truncated by
`pthread_setname` to `opt regex.f10ba`, hiding the numeric suffix that
distinguishes them. This is really annoying when using a profiler like
Samply.

This commit changes these thread names to a form like `opt cgu.0`, which
is much better.
2023-06-26 09:14:45 +10:00
Nicholas Nethercote
487bdeb519 Improve ordering and naming of CGUs for non-incremental builds.
Currently there are two problems.

First, the CGUS don't end up in size order. The merging loop does sort
by size on each iteration, but we don't sort after the final merge, so
typically there is one CGU out of place. (And sometimes we don't enter
the merging loop at all, in which case they end up in random order.)

Second, we then assign names that differ only by a numeric suffix, and
then we sort them lexicographically by name, giving us an order like
this:

regex.f10ba03eb5ec7975-cgu.1
regex.f10ba03eb5ec7975-cgu.10
regex.f10ba03eb5ec7975-cgu.11
regex.f10ba03eb5ec7975-cgu.12
regex.f10ba03eb5ec7975-cgu.13
regex.f10ba03eb5ec7975-cgu.14
regex.f10ba03eb5ec7975-cgu.15
regex.f10ba03eb5ec7975-cgu.2
regex.f10ba03eb5ec7975-cgu.3
regex.f10ba03eb5ec7975-cgu.4
regex.f10ba03eb5ec7975-cgu.5
regex.f10ba03eb5ec7975-cgu.6
regex.f10ba03eb5ec7975-cgu.7
regex.f10ba03eb5ec7975-cgu.8
regex.f10ba03eb5ec7975-cgu.9

These two problems are really annoying when debugging and profiling the
CGUs.

This commit ensures CGUs are sorted by name *and* reverse sorted by
size. This involves (a) one extra sort by size operation, and (b)
padding the numeric indices with zeroes, e.g.
`regex.f10ba03eb5ec7975-cgu.01`.

(Note that none of this applies for incremental builds, where a
different hash-based CGU naming scheme is used.)
2023-06-26 09:14:11 +10:00
Nicholas Nethercote
abde9ba527 Tweak CGU size estimate code.
- Rename `create_size_estimate` as `compute_size_estimate`, because that
  makes more sense for the second and subsequent calls for each CGU.
- Change `CodegenUnit::size_estimate` from `Option<usize>` to `usize`.
  We can still assert that `compute_size_estimate` is called first.
- Move the size estimation for `place_mono_items` inside the function,
  for consistency with `merge_codegen_units`.
2023-06-22 09:33:06 +10:00
Nicholas Nethercote
105ac1c26d Merge root and inlined item placement.
There's no longer any need for them to be separate, and putting them
together reduces the amount of code.
2023-06-22 08:10:29 +10:00
Nicholas Nethercote
6f228e3420 Inline before merging CGUs.
Because CGU merging relies on CGU sizes, but the CGU sizes before
inlining aren't accurate.

This requires tweaking how the sizes are updated during merging: if CGU
A and B both have an inlined function F, then `size(A + B)` will be a
little less than `size(A) + size(B)`, because `A + B` will only have one
copy of F. Also, the minimum CGU size is increased because it now has to
account for inlined functions.

This change doesn't have much effect on compile perf, but it makes
follow-on changes that involve more sophisticated reasoning about CGU
sizes much easier.
2023-06-22 08:10:29 +10:00
Nicholas Nethercote
f6cadae163 Streamline some comments. 2023-06-22 08:10:29 +10:00
bors
a8a29070f0 Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Remove `box_free` lang item

This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
2023-06-17 16:10:57 +00:00
DrMeepster
a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Nicholas Nethercote
2af5f2276d Merge CGUs in a nicer way. 2023-06-15 18:58:23 +10:00
Nicholas Nethercote
e414d25e94 Make partition more consistent.
Always put the `create_size_estimate` calls and `debug_dump` calls
within a timed scopes. This makes the four main steps look more similar
to each other.
2023-06-15 10:39:39 +10:00
Nicholas Nethercote
57a7c8f577 Fix bug in mark_code_coverage_dead_code_cgus.
The comment says "Find the smallest CGU that has exported symbols and
put the dead function stubs in that CGU". But the code sorts the CGUs by
size (smallest first) and then searches them in reverse order, which
means it will find the *largest* CGU that has exported symbols.

The erroneous code was introduced in #92142.

This commit changes it to use a simpler search, avoiding the sort, and
fixes the bug in the process.
2023-06-15 10:39:04 +10:00
Nicholas Nethercote
9d7295f0be Move dead CGU marking code out of partition.
The other major steps in `partition` have their own function, so it's
nice for this one to be likewise.
2023-06-15 10:02:13 +10:00
Nicholas Nethercote
7c3ce02a11 Introduce a minimum CGU size in non-incremental builds.
Because tiny CGUs make compilation less efficient *and* result in worse
generated code.

We don't do this when the number of CGUs is explicitly given, because
there are times when the requested number is very important, as
described in some comments within the commit. So the commit also
introduces a `CodegenUnits` type that distinguishes between default
values and user-specified values.

This change has a roughly neutral effect on walltimes across the
rustc-perf benchmarks; there are some speedups and some slowdowns. But
it has significant wins for most other metrics on numerous benchmarks,
including instruction counts, cycles, binary size, and max-rss. It also
reduces parallelism, which is good for reducing jobserver competition
when multiple rustc processes are running at the same time. It's smaller
benchmarks that benefit the most; larger benchmarks already have CGUs
that are all larger than the minimum size.

Here are some example before/after CGU sizes for opt builds.

- html5ever
  - CGUs: 16, mean size: 1196.1, sizes: [3908, 2992, 1706, 1652, 1572,
    1136, 1045, 948, 946, 938, 579, 471, 443, 327, 286, 189]
  - CGUs: 4, mean size: 4396.0, sizes: [6706, 3908, 3490, 3480]

- libc
  - CGUs: 12, mean size: 35.3, sizes: [163, 93, 58, 53, 37, 8, 2 (x6)]
  - CGUs: 1, mean size: 424.0, sizes: [424]

- tt-muncher
  - CGUs: 5, mean size: 1819.4, sizes: [8508, 350, 198, 34, 7]
  - CGUs: 1, mean size: 9075.0, sizes: [9075]

Note that CGUs of size 100,000+ aren't unusual in larger programs.
2023-06-14 10:57:44 +10:00
Nicholas Nethercote
95d85899ce Add more measurements to the CGU debug printing.
For example, we go from this:
```
FINAL (4059 items, total_size=232342; 16 CGUs, max_size=39608,
min_size=5468, max_size/min_size=7.2):
- CGU[0] regex.f2ff11e98f8b05c7-cgu.0 (318 items, size=39608):
  - fn ...
  - fn ...
```
to this:
```
FINAL
- unique items: 2726 (1459 root + 1267 inlined), unique size: 201214 (146046 root + 55168 inlined)
- placed items: 4059 (1459 root + 2600 inlined), placed size: 232342 (146046 root + 86296 inlined)
- placed/unique items ratio: 1.49, placed/unique size ratio: 1.15
- CGUs: 16, mean size: 14521.4, sizes: [39608, 31122, 20318, 20236, 16268, 13777, 12310, 10531, 10205, 9810, 9250, 9065 (x2), 7785, 7524, 5468]

- CGU[0]
  - regex.f2ff11e98f8b05c7-cgu.0, size: 39608
  - items: 318, mean size: 124.6, sizes: [28395, 3418, 558, 485, 259, 228, 176, 166, 146, 118, 117 (x3), 114 (x5), 113 (x3), 101, 84, 82, 77, 76, 72, 71 (x2), 66, 65, 62, 61, 59 (x2), 57, 55, 54 (x2), 53 (x4), 52 (x5), 51 (x4), 50, 48, 47, 46, 45 (x3), 44, 43 (x5), 42, 40, 38 (x4), 37, 35, 34 (x2), 32 (x2), 31, 30, 28 (x2), 27 (x2), 26 (x3), 24 (x2), 23 (x3), 22 (x2), 21, 20, 16 (x4), 15, 13 (x7), 12 (x3), 11 (x6), 10, 9 (x2), 8 (x4), 7 (x8), 6 (x38), 5 (x21), 4 (x7), 3 (x45), 2 (x63), 1 (x13)]
  - fn ...
  - fn ...
```
This is a lot more information, distinguishing between root items and
inlined items, showing how much duplication there is of inlined items,
plus the full range of sizes for CGUs and items within CGUs. All of
which is really helpful when analyzing this stuff and trying different
CGU formation algorithms.
2023-06-14 10:15:59 +10:00
Nicholas Nethercote
51821515b3 Remove PartitioningCx::target_cgu_count.
Because that value can be easily obtained from `Partitioning::tcx`.
2023-06-13 16:47:09 +10:00
Nicholas Nethercote
853345635b Move mono_item_placement construction.
It's currently created in `place_inlined_mono_items` and then used in
`internalize_symbols`. This commit moves the creation to
`internalize_symbols`.
2023-06-07 11:02:15 +10:00
Nicholas Nethercote
1defd30764 Remove PlacedRootMonoItems::roots.
It's no longer used.
2023-06-07 10:27:00 +10:00
Nicholas Nethercote
8dbb3475b9 Split loop in place_inlined_mono_item.
This loop is doing two different things. For inlined items, it's adding
them to the CGU. For all items, it's recording them in
`mono_item_placements`.

This commit splits it into two separate loops. This avoids putting root
mono items into `reachable`, and removes the low-value check that
`roots` doesn't contain inlined mono items.
2023-06-07 10:27:00 +10:00
Nicholas Nethercote
fe3b646565 Merge the two loops in internalize_symbols.
Because they have a lot of overlap.
2023-06-07 10:27:00 +10:00
Nicholas Nethercote
392045b7e7 Make the two loops in internalize_symbols have the same form.
Because the next commit will merge them.
2023-06-07 10:27:00 +10:00
Nicholas Nethercote
9fd6d97915 Improve sorting in debug_dump.
Currently it sorts by symbol name, which is a mangled name like
`_ZN1a4main17hb29587cdb6db5f42E`, which leads to non-obvious orderings.

This commit changes it to use the existing
`items_in_deterministic_order`, which iterates in source code order.
2023-06-07 10:26:58 +10:00
Nicholas Nethercote
0a1cd5baa4 Remove some unnecessary &muts. 2023-06-05 08:17:31 +10:00
Nicholas Nethercote
4f800b56d0 Clarify follow_inlining.
I found this confusing because it includes the root item, plus the
inlined items reachable from the root item. The new formulation
separates the two parts more clearly.
2023-06-02 13:07:30 +10:00
Nicholas Nethercote
3806bad6cf Simplify place_inlined_mono_items.
Currently it overwrites all the CGUs with new CGUs. But those new CGUs
are just copies of the old CGUs, possibly with some things added. This
commit changes things so that each CGU just gets added to in place,
which makes things simpler and clearer.
2023-06-02 13:07:30 +10:00
Nicholas Nethercote
f1fe797ee2 Change representation of UsageMap::used_map.
It currently uses ranges, which index into `UsageMap::used_items`. This
commit changes it to just use `Vec`, which is much simpler to construct
and use. This change does result in more allocations, but it is few
enough that the perf impact is negligible.
2023-06-02 13:07:30 +10:00
Nicholas Nethercote
5b0c56b333 Introduce UsageMap::user_map.
`UsageMap` contains `used_map`, which maps from an item to the item it
uses. This commit add `user_map`, which is the inverse.

We already compute this inverse, but later on, and it is only held as a
local variable. Its simpler and nicer to put it next to `used_map`.
2023-06-02 13:07:30 +10:00
Nicholas Nethercote
de2911f454 Overhaul CGU formation terminology.
Currently, the code uses multiple words to describe when a mono item `f`
uses a mono item `g`, all of which have problems.

- `f` references `g`: confusing because there are multiple kinds of use,
  e.g. "`f` calls `g`" is one, but "`f` takes a (`&T`-style) reference
  of `g`" is another, and that's two subtly different meanings of
  "reference" in play.

- `f` accesses `g`: meh, "accesses" makes me think of data, and this is
  code.

- `g` is a neighbor (or neighbour) of `f`: is verbose, and doesn't
  capture the directionality.

This commit changes the code to use "`f` uses `g`" everywhere. I think
it's better than the current terminology, and the consistency is
important.

Also, `InliningMap` is renamed `UsageMap` because (a) it was always
mostly about usage, and (b) the inlining information it did record was
removed in a recent commit.
2023-06-02 13:07:28 +10:00
Matthias Krüger
c6aec9459e
Rollup merge of #112155 - nnethercote:debug_dump, r=wesleywiser
Improve CGU debug printing.

- Add more total and per-CGU measurements.
- Ensure CGUs are sorted by name before the first `debug_dump` calls, for deterministic output.
- Print items within CGUs in sorted-by-name order, for deterministic output.
- Add some assertions and comments clarifying sortedness of CGUs at various points.

An example, before:
```
INITIAL PARTITIONING (5 CodegenUnits, max=29, min=1, max/min=29.0):
CodegenUnit scev95ysd7g4b0z estimated size 2:
 - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] estimated size 2

CodegenUnit 1j0frgtl72rsz24q estimated size 29:
 - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] estimated size 17
 - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] estimated size 12

CodegenUnit 5dbzi1e5qm0d7kj2 estimated size 4:
 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] estimated size 1
 - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] estimated size 1
 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] estimated size 1
 - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] estimated size 1

CodegenUnit 220m1mqa2mlbg7r3 estimated size 1:
 - fn main [(External, Hidden)] [hb29587cdb6db5f42E] estimated size 1

CodegenUnit 4ulbh241f7tvyn7x estimated size 6:
 - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] estimated size 6
```
and after:
```
INITIAL PARTITIONING (9 items, total_size=42; 5 CGUs, max_size=29, min_size=1, max_size/min_size=29.0):
- CGU[0] 1j0frgtl72rsz24q (2 items, size=29):
  - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] (size=12)
  - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] (size=17)

- CGU[1] 220m1mqa2mlbg7r3 (1 items, size=1):
  - fn main [(External, Hidden)] [hb29587cdb6db5f42E] (size=1)

- CGU[2] 4ulbh241f7tvyn7x (1 items, size=6):
  - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] (size=6)

- CGU[3] 5dbzi1e5qm0d7kj2 (4 items, size=4):
  - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] (size=1)
  - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] (size=1)
  - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] (size=1)
  - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] (size=1)

- CGU[4] scev95ysd7g4b0z (1 items, size=2):
  - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] (size=2)
```

r? ``@wesleywiser``
2023-06-01 22:47:33 +02:00
Nicholas Nethercote
1191bea6ab Improve CGU debug printing.
- Add more total and per-CGU measurements.
- Ensure CGUs are sorted by name before the first `debug_dump` calls,
  for deterministic output.
- Print items within CGUs in sorted-by-name order, for deterministic
  output.
- Add some assertions and comments clarifying sortedness of CGUs at
  various points.

An example, before:
```
INITIAL PARTITIONING (5 CodegenUnits, max=29, min=1, max/min=29.0):
CodegenUnit scev95ysd7g4b0z estimated size 2:
 - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] estimated size 2

CodegenUnit 1j0frgtl72rsz24q estimated size 29:
 - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] estimated size 17
 - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] estimated size 12

CodegenUnit 5dbzi1e5qm0d7kj2 estimated size 4:
 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] estimated size 1
 - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] estimated size 1
 - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] estimated size 1
 - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] estimated size 1

CodegenUnit 220m1mqa2mlbg7r3 estimated size 1:
 - fn main [(External, Hidden)] [hb29587cdb6db5f42E] estimated size 1

CodegenUnit 4ulbh241f7tvyn7x estimated size 6:
 - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] estimated size 6
```
and after:
```
INITIAL PARTITIONING (9 items, total_size=42; 5 CGUs, max_size=29, min_size=1, max_size/min_size=29.0):
- CGU[0] 1j0frgtl72rsz24q (2 items, size=29):
  - fn std::rt::lang_start::<()> [(External, Hidden)] [h4ca942948e9cb931E] (size=12)
  - fn std::rt::lang_start::<()>::{closure#0} [(External, Hidden)] [h695c7b5d6a212565E] (size=17)

- CGU[1] 220m1mqa2mlbg7r3 (1 items, size=1):
  - fn main [(External, Hidden)] [hb29587cdb6db5f42E] (size=1)

- CGU[2] 4ulbh241f7tvyn7x (1 items, size=6):
  - fn std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()> [(External, Hidden)] [h41dada2c21a1259dE] (size=6)

- CGU[3] 5dbzi1e5qm0d7kj2 (4 items, size=4):
  - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim(vtable) [(External, Hidden)] [h595d414cbb7651d5E] (size=1)
  - fn <[closure@std::rt::lang_start<()>::{closure#0}] as std::ops::FnOnce<()>>::call_once - shim [(External, Hidden)] [h24eaa44f03b2b233E] (size=1)
  - fn <fn() as std::ops::FnOnce<()>>::call_once - shim(fn()) [(External, Hidden)] [hf338f5339c3711acE] (size=1)
  - fn std::ptr::drop_in_place::<[closure@std::rt::lang_start<()>::{closure#0}]> - shim(None) [(External, Hidden)] [h17a19dcdb40600daE] (size=1)

- CGU[4] scev95ysd7g4b0z (1 items, size=2):
  - fn <() as std::process::Termination>::report [(External, Hidden)] [h082b15a6d07338dcE] (size=2)
```
2023-06-01 11:31:22 +10:00
Nicholas Nethercote
cc21d9aa52 Don't compute inlining status of mono items in advance.
We record inlining status for mono items in `MonoItems`, and then
transfer it to `InliningMap`, for later use in
`InliningMap::with_inlining_candidates`.

But we can just compute inlining status directly in
`InliningMap::with_inlining_candidates`, because the mono item is right
there. There's no need to compute it in advance.

This commit changes the code to do that, removing the need for
`MonoItems` and `InliningMap::inlines`. This does result in more calls
to `instantiation_mode` (one per static occurrence) but the performance
effect is negligible.
2023-05-31 21:53:31 +10:00
Matthias Krüger
7ca941f18e
Rollup merge of #112053 - nnethercote:rm-Zcpu-partitioning-strategy, r=wesleywiser
Remove `-Zcgu-partitioning-strategy`.

This option was introduced three years ago, but it's never been meaningfully used, and `default` is the only acceptable value.

Also, I think the `Partition` trait presents an interface that is too closely tied to the existing strategy and would probably be wrong for other strategies. (My rule of thumb is to not make something generic until there are at least two instances of it, to avoid this kind of problem.)

Also, I don't think providing multiple partitioning strategies to the user is a good idea, because the compiler already has enough obscure knobs.

This commit removes the option, along with the `Partition` trait, and the `Partitioner` and `DefaultPartitioning` types. I left the existing code in `compiler/rustc_monomorphize/src/partitioning/default.rs`, though I could be persuaded that moving it into
`compiler/rustc_monomorphize/src/partitioning/mod.rs` is better.

r? ``@wesleywiser``
2023-05-31 07:07:00 +02:00
Nicholas Nethercote
5ed014977e Rename partitioning/mod.rs as partitioning.rs.
Because it's now the only file within
`compiler/rustc_monomorphize/src/partitioning/`.
2023-05-30 17:48:55 +10:00
Nicholas Nethercote
66cf072ac8 Merge default.rs into mod.rs.
Within `compiler/rustc_monomorphize/src/partitioning/`, because the
previous commit removed the need for `default.rs` to be a separate file.
2023-05-30 17:48:54 +10:00
Nicholas Nethercote
97d4a38de9 Remove -Zcgu-partitioning-strategy.
This option was introduced three years ago, but it's never been
meaningfully used, and `default` is the only acceptable value.

Also, I think the `Partition` trait presents an interface that is too
closely tied to the existing strategy and would probably be wrong for
other strategies. (My rule of thumb is to not make something generic
until there are at least two instances of it, to avoid this kind of
problem.)

Also, I don't think providing multiple partitioning strategies to the
user is a good idea, because the compiler already has enough obscure
knobs.

This commit removes the option, along with the `Partition` trait, and
the `Partitioner` and `DefaultPartitioning` types. I left the existing
code in `compiler/rustc_monomorphize/src/partitioning/default.rs`,
though I could be persuaded that moving it into
`compiler/rustc_monomorphize/src/partitioning/mod.rs` is better.
2023-05-30 17:48:49 +10:00
lcnr
08d149ca85 EarlyBinder::new -> EarlyBinder::bind 2023-05-29 13:46:10 +02:00
Kyle Matsuda
03534ac8b7 Replace EarlyBinder(x) with EarlyBinder::new(x) 2023-05-28 10:44:50 -06:00
Matthias Krüger
78cc117f7b
Rollup merge of #111899 - nnethercote:cgu-cleanups, r=wesleywiser
CGU cleanups

Some code clarity improvements I found when reading this code closely.

r? ``@wesleywiser``
2023-05-26 08:24:07 +02:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Nicholas Nethercote
e6b99a6521 Add struct for the return type of place_root_mono_items.
As per review request.
2023-05-26 07:28:02 +10:00
Nicholas Nethercote
86754cd8f2 Remove some unnecessary pub markers. 2023-05-25 14:27:37 +10:00
Nicholas Nethercote
59c5259bc9 Add a clarifying comment.
This is something that took me some time to figure out.
2023-05-24 12:33:35 +10:00
Nicholas Nethercote
20de2ba759 Remove {Pre,Post}InliningPartitioning.
I find that these structs obfuscate the code. Removing them and just
passing the individual fields around makes the `Partition` method
signatures a little longer, but makes the data flow much clearer. E.g.

- `codegen_units` is mutable all the way through.
- `codegen_units`'s length is changed by `merge_codegen_units`, but only
  the individual elements are changed by `place_inlined_mono_items` and
  `internalize_symbols`.
- `roots`, `internalization_candidates`, and `mono_item_placements` are
  all immutable after creation, and all used by just one of the four
  methods.
2023-05-24 12:33:35 +10:00
Nicholas Nethercote
b39b7098ea Remove the merging module.
Three of the four methods in `DefaultPartitioning` are defined in
`default.rs`. But `merge_codegen_units` is defined in a separate module,
`merging`, even though it's less than 100 lines of code and roughly the
same size as the other three methods. (Also, the `merging` module
currently sits alongside `default`, when it should be a submodule of
`default`, adding to the confusion.)

In #74275 this explanation was given:

> I pulled this out into a separate module since it seemed like we might
> want a few different merge algorithms to choose from.

But in the three years since there have been no additional merging
algorithms, and there is no mechanism for choosing between different
merging algorithms. (There is a mechanism,
`-Zcgu-partitioning-strategy`, for choosing between different
partitioning strategies, but the merging algorithm is just one piece of
a partitioning strategy.)

This commit merges `merging` into `default`, making the code easier to
navigate and read.
2023-05-24 12:25:58 +10:00
Nicholas Nethercote
e26c0c92bd Inline and remove numbered_codegen_unit_name.
It is small and has a single call site, and this change will facilitate
the next commit.
2023-05-24 10:05:15 +10:00
Nicholas Nethercote
1bb957efc6 Improve CGU partitioning debug output.
- Pass a slice instead of an iterator to `debug_dump`.
- For each CGU set, print: the number of CGUs, the max and min size, and
  the ratio of the max and min size (which indicates how evenly sized
  they are).
- Print a `FINAL` entry, showing the absolute final results.
2023-05-19 08:48:28 +10:00
Nicholas Nethercote
1551495d32 Fix an ICE in CGU dumping code. 2023-05-19 08:48:28 +10:00
John Kåre Alsaker
54b582a0e8 Finish move of query.rs 2023-05-17 01:57:21 +02:00
John Kåre Alsaker
fff20a703d Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
Kyle Matsuda
82f57c16b7 use EarlyBinder in tcx.(try_)subst_mir_and_normalize_erasing_regions 2023-05-06 22:32:39 -06:00
Kyle Matsuda
e5d10cdbc3 make (try_)subst_and_normalize_erasing_regions take EarlyBinder 2023-05-06 22:32:39 -06:00