rust/compiler
Nicholas Nethercote 5b54363961 Optimize the code produced by derive(Debug).
This commit adds new methods that combine sequences of existing
formatting methods.
- `Formatter::debug_{tuple,struct}_field[12345]_finish`, equivalent to a
  `Formatter::debug_{tuple,struct}` + N x `Debug{Tuple,Struct}::field` +
  `Debug{Tuple,Struct}::finish` call sequence.
- `Formatter::debug_{tuple,struct}_fields_finish` is similar, but can
  handle any number of fields by using arrays.

These new methods are all marked as `doc(hidden)` and unstable. They are
intended for the compiler's own use.

Special-casing up to 5 fields gives significantly better performance
results than always using arrays (as was tried in #95637).

The commit also changes the `Debug` deriving code to use these new methods. For
example, where the old `Debug` code for a struct with two fields would be like
this:
```
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
    match *self {
	Self {
	    f1: ref __self_0_0,
	    f2: ref __self_0_1,
	} => {
	    let debug_trait_builder = &mut ::core::fmt::Formatter::debug_struct(f, "S2");
	    let _ = ::core::fmt::DebugStruct::field(debug_trait_builder, "f1", &&(*__self_0_0));
	    let _ = ::core::fmt::DebugStruct::field(debug_trait_builder, "f2", &&(*__self_0_1));
	    ::core::fmt::DebugStruct::finish(debug_trait_builder)
	}
    }
}
```
the new code is like this:
```
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
    match *self {
	Self {
	    f1: ref __self_0_0,
	    f2: ref __self_0_1,
	} => ::core::fmt::Formatter::debug_struct_field2_finish(
	    f,
	    "S2",
	    "f1",
	    &&(*__self_0_0),
	    "f2",
	    &&(*__self_0_1),
	),
    }
}
```
This shrinks the code produced for `Debug` instances
considerably, reducing compile times and binary sizes.

Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
2022-06-24 09:40:15 +10:00
..
rustc Rollup merge of #97385 - oli-obk:smir-tool-lib, r=pnkfelix 2022-06-14 07:47:24 +09:00
rustc_apfloat Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_arena
rustc_ast Merge TokenStreamBuilder::push into TokenStreamBuilder::build. 2022-06-20 13:46:11 +10:00
rustc_ast_lowering Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister 2022-06-17 10:00:11 +00:00
rustc_ast_passes Auto merge of #97842 - notriddle:notriddle/tuple-docs, r=jsha,GuillaumeGomez 2022-06-16 11:13:30 +00:00
rustc_ast_pretty Fix pretty printing of empty type bound lists in where-clause 2022-06-16 17:24:50 -07:00
rustc_attr Remove rustc_deprecated diagnostics 2022-06-14 19:46:13 -04:00
rustc_borrowck Rollup merge of #98022 - compiler-errors:erroneous-borrowck-span, r=oli-obk 2022-06-21 20:08:10 +09:00
rustc_builtin_macros Optimize the code produced by derive(Debug). 2022-06-24 09:40:15 +10:00
rustc_codegen_cranelift Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister 2022-06-21 16:24:56 +00:00
rustc_codegen_gcc Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister 2022-06-21 16:24:56 +00:00
rustc_codegen_llvm Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister 2022-06-21 16:24:56 +00:00
rustc_codegen_ssa Auto merge of #98098 - bjorn3:archive_refactor, r=michaelwoerister 2022-06-21 16:24:56 +00:00
rustc_const_eval Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk 2022-06-21 11:00:39 +00:00
rustc_data_structures Auto merge of #97674 - nnethercote:oblig-forest-tweaks, r=nikomatsakis 2022-06-20 10:58:56 +00:00
rustc_driver Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
rustc_error_codes Add comment for internal error codes 2022-06-12 19:52:49 -03:00
rustc_error_messages Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnay 2022-06-20 07:37:41 +09:00
rustc_errors Auto merge of #97892 - klensy:fix-spaces, r=oli-obk 2022-06-17 17:30:16 +00:00
rustc_expand Optimize the code produced by derive(Debug). 2022-06-24 09:40:15 +10:00
rustc_feature Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
rustc_fs_util
rustc_graphviz Fully stabilize NLL 2022-06-03 17:16:41 -04:00
rustc_hir Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se 2022-06-19 00:17:13 +02:00
rustc_hir_pretty Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
rustc_incremental Auto merge of #98153 - nnethercote:fix-MissingDoc-quadratic-behaviour, r=cjgillot 2022-06-18 09:57:00 +00:00
rustc_index Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk 2022-06-21 11:00:39 +00:00
rustc_infer Avoid an ICE and instead let the compiler report a useful error 2022-06-21 08:47:02 +00:00
rustc_interface Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se 2022-06-19 00:17:13 +02:00
rustc_lexer
rustc_lint Use ensure for UnusedBrokenConst. 2022-06-19 09:44:32 +02:00
rustc_lint_defs Auto merge of #97652 - RalfJung:cenum_impl_drop_cast, r=nagisa 2022-06-18 00:02:52 +00:00
rustc_llvm Add metadata generation for vtables when using VFE 2022-06-14 14:50:52 +02:00
rustc_log clippy::complexity fixes 2022-05-26 13:14:24 +02:00
rustc_macros Auto merge of #94732 - nnethercote:infallible-encoder, r=bjorn3 2022-06-08 10:24:12 +00:00
rustc_metadata Rollup merge of #98136 - fee1-dead-contrib:rename_impl_constness, r=oli-obk 2022-06-19 15:26:28 +02:00
rustc_middle Auto merge of #98335 - JohnTitor:rollup-j2zudxv, r=JohnTitor 2022-06-21 13:41:37 +00:00
rustc_mir_build Rollup merge of #98267 - compiler-errors:suggest-wildcard-arm, r=oli-obk 2022-06-20 20:13:10 +02:00
rustc_mir_dataflow Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk 2022-06-21 11:00:39 +00:00
rustc_mir_transform Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obk 2022-06-21 11:00:39 +00:00
rustc_monomorphize Rollup merge of #98067 - klensy:compiler-deps2, r=Dylan-DPC 2022-06-15 12:02:02 +09:00
rustc_parse Rollup merge of #98183 - dtolnay:emptybound, r=lcnr 2022-06-20 16:41:46 +09:00
rustc_parse_format Make rustc_parse_format compile on stable 2022-05-03 11:26:58 +02:00
rustc_passes Auto merge of #98153 - nnethercote:fix-MissingDoc-quadratic-behaviour, r=cjgillot 2022-06-18 09:57:00 +00:00
rustc_plugin_impl remove currently unused deps 2022-06-13 22:20:51 +03:00
rustc_privacy Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
rustc_query_impl Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister 2022-06-17 10:00:11 +00:00
rustc_query_system Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister 2022-06-17 10:00:11 +00:00
rustc_resolve Rollup merge of #98267 - compiler-errors:suggest-wildcard-arm, r=oli-obk 2022-06-20 20:13:10 +02:00
rustc_save_analysis Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
rustc_serialize Move finish out of the Encoder trait. 2022-06-16 16:20:32 +10:00
rustc_session Auto merge of #97657 - Urgau:check-cfg-many-mut, r=oli-obk 2022-06-21 07:40:32 +00:00
rustc_smir Rustfmt 2022-06-02 10:29:00 +00:00
rustc_span Optimize the code produced by derive(Debug). 2022-06-24 09:40:15 +10:00
rustc_symbol_mangling Rollup merge of #98067 - klensy:compiler-deps2, r=Dylan-DPC 2022-06-15 12:02:02 +09:00
rustc_target Rollup merge of #98225 - bjorn3:stable_target_json_hash, r=nagisa 2022-06-20 07:37:42 +09:00
rustc_trait_selection Rollup merge of #97805 - coolreader18:trace-suggestions, r=oli-obk 2022-06-21 20:08:09 +09:00
rustc_traits implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_ty_utils implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
rustc_type_ir Move RegionKind to rustc_type_ir 2022-06-19 00:20:27 -04:00
rustc_typeck Rollup merge of #98159 - PrestonFrom:issue_95665, r=petrochenkov 2022-06-20 14:56:41 +02:00