granite-rust/compiler/rustc_error_messages/locales/en-US
Matthias Krüger 863d1f653a
Rollup merge of #105481 - lqd:mono-stats, r=wesleywiser
Start improving monomorphization items stats

As described in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Compile-time.20case-study.3A.20AWS.20crates/near/314560832), some stats about monomorphization collection would be interesting to have, in a different form than `-Zprint-mono-items`: to have some visibility into the cost of the mono items, we'd like to know how many are instantiated and what is their estimated size.

That can be a proxy to analyze sources of slow compile times, although in the future, we'd also like to add more realistic stats from the actual backend's lowering.

This PR adds a new `-Z dump-mono-stats` flag which will output some stats in a `{crate_name}.mono-items.md` file (the flag optionally takes an output directory parameter, for easier use within a workspace than printing to stdout).

For example,

```rust
fn compute<T>(collection: Vec<T>) -> usize {
    collection.len() + 19 - 0 * 9 - 18 - 1 * 1 // random code to increase the function's size
}

fn main() {
    dbg!(compute(vec![0u8, 1, 2]));
    dbg!(compute(vec![0u64, 1, 2]));
    dbg!(compute(vec!["0", "1", "2", "3"]));
}
```

will output a file with this markdown table (abridged for readability), for a debug build:

| Item | Instantiation count | Estimated Cost Per Instantiation | Total Estimated Cost |
| --- | ---: | ---: | ---: |
| alloc::alloc::box_free | 3 | 122 | 366 |
| std::alloc::Global::alloc_impl | 1 | 284 | 284 |
| alloc::raw_vec::RawVec::<T, A>::current_memory | 3 | 82 | 246 |
| std::ptr::align_offset | 1 | 222 | 222 |
| std::slice::hack::into_vec | 3 | 67 | 201 |
| <std::vec::Vec<T, A> as std::ops::Drop>::drop | 3 | 66 | 198 |
| std::ptr::mut_ptr::<impl *mut T>::is_null | 4 | 47 | 188 |
| main | 1 | 163 | 163 |
| std::ptr::NonNull::<T>::new_unchecked | 4 | 37 | 148 |
...

<details>
<summary>Click for full output</summary>

| Item | Instantiation count | Estimated Cost Per Instantiation | Total Estimated Cost |
| --- | ---: | ---: | ---: |
| alloc::alloc::box_free | 3 | 122 | 366 |
| std::alloc::Global::alloc_impl | 1 | 284 | 284 |
| alloc::raw_vec::RawVec::<T, A>::current_memory | 3 | 82 | 246 |
| std::ptr::align_offset | 1 | 222 | 222 |
| std::slice::hack::into_vec | 3 | 67 | 201 |
| <std::vec::Vec<T, A> as std::ops::Drop>::drop | 3 | 66 | 198 |
| std::ptr::mut_ptr::<impl *mut T>::is_null | 4 | 47 | 188 |
| main | 1 | 163 | 163 |
| std::ptr::NonNull::<T>::new_unchecked | 4 | 37 | 148 |
| std::boxed::Box::<T, A>::into_unique | 3 | 48 | 144 |
| std::boxed::Box::<T, A>::leak | 3 | 39 | 117 |
| std::alloc::Layout::array::inner | 1 | 107 | 107 |
| std::ptr::align_offset::mod_inv | 1 | 103 | 103 |
| std::boxed::Box::<T, A>::into_raw_with_allocator | 3 | 31 | 93 |
| std::fmt::Arguments::<'a>::new_v1 | 1 | 80 | 80 |
| <alloc::raw_vec::RawVec<T, A> as std::ops::Drop>::drop | 3 | 26 | 78 |
| alloc::raw_vec::RawVec::<T, A>::from_raw_parts_in | 3 | 26 | 78 |
| alloc::alloc::exchange_malloc | 1 | 75 | 75 |
| std::ptr::const_ptr::<impl *const T>::is_null | 1 | 75 | 75 |
| std::ptr::const_ptr::<impl *const T>::is_aligned_to | 1 | 64 | 64 |
| compute | 3 | 20 | 60 |
| std::ptr::const_ptr::<impl *const T>::align_offset | 1 | 55 | 55 |
| std::ptr::read | 1 | 52 | 52 |
| <std::alloc::Global as std::alloc::Allocator>::deallocate | 1 | 50 | 50 |
| std::ptr::mut_ptr::<impl *mut T>::guaranteed_eq | 1 | 48 | 48 |
| std::fmt::ArgumentV1::<'a>::new_display | 2 | 22 | 44 |
| std::ptr::Alignment::new_unchecked | 1 | 42 | 42 |
| core::fmt::num::<impl std::fmt::Debug for usize>::fmt | 1 | 40 | 40 |
| std::result::Result::<T, E>::unwrap_unchecked | 1 | 37 | 37 |
| std::cmp::Ord::min | 1 | 32 | 32 |
| std::cmp::impls::<impl std::cmp::Ord for usize>::cmp | 1 | 31 | 31 |
| std::intrinsics::is_aligned_and_not_null | 1 | 27 | 27 |
| std::rt::lang_start | 1 | 27 | 27 |
| std::ptr::NonNull::<T>::new | 1 | 24 | 24 |
| std::fmt::ArgumentV1::<'a>::new_debug | 1 | 22 | 22 |
| std::fmt::Arguments::<'a>::new_v1_formatted | 1 | 19 | 19 |
| std::rt::lang_start::{closure#0} | 1 | 17 | 17 |
| std::sys_common::backtrace::__rust_begin_short_backtrace | 1 | 16 | 16 |
| std::slice::<impl [T]>::into_vec | 3 | 5 | 15 |
| <std::ptr::NonNull<T> as std::convert::From<std::ptr::Unique<T>>>::from | 1 | 14 | 14 |
| <&T as std::fmt::Debug>::fmt | 1 | 12 | 12 |
| <&T as std::fmt::Display>::fmt | 1 | 12 | 12 |
| std::vec::Vec::<T, A>::len | 3 | 2 | 6 |
| <T as std::convert::Into<U>>::into | 1 | 5 | 5 |
| <T as std::convert::From<T>>::from | 1 | 2 | 2 |
| <() as std::process::Termination>::report | 1 | 2 | 2 |
| std::hint::unreachable_unchecked | 1 | 2 | 2 |
| core::fmt::UnsafeArg::new | 1 | 1 | 1 |

</details>

Since we discussed it together, r? `@wesleywiser.`
2022-12-15 22:02:57 +01:00
..
ast_lowering.ftl Improve the help message for an invalid calling convention 2022-09-22 22:18:30 +02:00
ast_passes.ftl Make async fn in traits work 2022-09-09 01:31:45 +00:00
attr.ftl Reorder diagnostics in code order, then alphabetical order 2022-08-22 20:19:19 +02:00
borrowck.ftl Match crate and slug names 2022-11-21 15:24:50 +01:00
builtin_macros.ftl Replace - with _ in ftl slugs for better grepability 2022-08-12 22:22:55 +02:00
codegen_gcc.ftl Move linkage type check to HIR analysis and fix semantics issues. 2022-12-05 15:05:43 -08:00
codegen_llvm.ftl Move linkage type check to HIR analysis and fix semantics issues. 2022-12-05 15:05:43 -08:00
codegen_ssa.ftl Move some codegen-y methods from rustc_hir_analysis::collect -> rustc_codegen_ssa 2022-12-13 05:01:36 +00:00
compiletest.ftl errors: rename typeck.ftl to hir_analysis.ftl 2022-10-03 13:52:17 +01:00
const_eval.ftl Addressed trailing newlines, odd whitespace skipped by x.py fmt 2022-08-22 12:38:16 -03:00
driver.ftl add UI test for unpretty 2022-08-30 09:31:52 +08:00
errors.ftl ADD - IntoDiagnostic conformance for TargetDataLayoutErrors in rustc_errors 2022-10-12 16:54:25 -04:00
expand.ftl Migrate parts of rustc_expand to session diagnostics 2022-12-10 11:02:41 +01:00
hir_analysis.ftl Ensure async trait impls are async (or otherwise return an opaque type) 2022-12-14 16:38:21 -08:00
hir_typeck.ftl Match crate and slug names 2022-11-21 15:24:50 +01:00
infer.ftl fix up a fluent message 2022-11-13 04:16:08 +01:00
interface.ftl Prefix fluent resources with interface_ 2022-08-22 14:59:41 +02:00
lint.ftl Fix opaque_hidden_inferred_bound lint ICE 2022-10-05 19:47:19 +00:00
metadata.ftl Remove extra . in metadata_lib_filename_form 2022-11-22 17:07:19 +11:00
middle.ftl Match crate and slug names 2022-11-21 15:24:50 +01:00
mir_dataflow.ftl Rename rustc_mir_dataflow diagnostic to mir_dataflow 2022-08-23 13:48:15 +01:00
monomorphize.ftl add -Z dump-mono-stats 2022-12-14 20:17:52 +00:00
parse.ftl fix #105366, suggest impl in the scenario of typo with fn 2022-12-10 11:01:52 +08:00
passes.ftl Print all labels, even if they have no span. Fall back to main item's span. 2022-11-11 14:45:28 +00:00
plugin_impl.ftl Migrate rustc_plugin_impl to SessionDiagnostic 2022-08-22 16:35:05 +01:00
privacy.ftl change AccessLevels representation 2022-09-14 18:11:00 +03:00
query_system.ftl query_system: finish migration 2022-10-10 14:20:16 +01:00
resolve.ftl migrating rustc_resolve to SessionDiagnostic. work in progress. start 2022-11-13 19:39:26 +05:30
save_analysis.ftl save_analysis: Migrate diagnostics 2022-08-24 06:50:16 +09:00
session.ftl Match crate and slug names 2022-11-21 15:24:50 +01:00
symbol_mangling.ftl UPDATE - merge and avoid translations for symbol mangling test output 2022-09-13 16:19:32 -04:00
trait_selection.ftl Porting 'compiler/rustc_trait_selection' to translatable diagnostics - Part 1 2022-09-01 12:54:50 -05:00
ty_utils.ftl Migrate rustc_ty_utils to use SessionDiagnostic 2022-08-26 14:36:51 +01:00