1
Fork 0
rust/compiler/rustc_builtin_macros/src
Nicholas Nethercote ecc6e95ed4 Don't use match-destructuring for derived ops on structs.
All derive ops currently use match-destructuring to access fields. This
is reasonable for enums, but sub-optimal for structs. E.g.:
```
fn eq(&self, other: &Point) -> bool {
    match *other {
	Self { x: ref __self_1_0, y: ref __self_1_1 } =>
	    match *self {
		Self { x: ref __self_0_0, y: ref __self_0_1 } =>
		    (*__self_0_0) == (*__self_1_0) &&
			(*__self_0_1) == (*__self_1_1),
	    },
    }
}
```
This commit changes derive ops on structs to use field access instead, e.g.:
```
fn eq(&self, other: &Point) -> bool {
    self.x == other.x && self.y == other.y
}
```
This is faster to compile, results in smaller binaries, and is simpler to
generate. Unfortunately, we have to keep the old pattern generating code around
for `repr(packed)` structs because something like `&self.x` (which doesn't show
up in `PartialEq` ops, but does show up in `Debug` and `Hash` ops) isn't
allowed. But this commit at least changes those cases to use let-destructuring
instead of match-destructuring, e.g.:
```
fn hash<__H: ::core:#️⃣:Hasher>(&self, state: &mut __H) -> () {
    {
	let Self(ref __self_0_0) = *self;
	{ ::core:#️⃣:Hash::hash(&(*__self_0_0), state) }
    }
}
```
There are some unnecessary blocks remaining in the generated code, but I
will fix them in a follow-up PR.
2022-07-04 10:48:15 +10:00
..
assert [RFC 2011] Optimize non-consuming operators 2022-06-21 10:56:26 -03:00
deriving Don't use match-destructuring for derived ops on structs. 2022-07-04 10:48:15 +10:00
format_foreign update tests 2021-12-31 12:51:27 -05:00
asm.rs remove unnecessary to_string and String::new for tool_only_span_suggestion 2022-06-13 16:01:16 +09:00
assert.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
cfg.rs macros: use typed identifiers in diag derive 2022-06-24 09:08:25 +01:00
cfg_accessible.rs Remove crate visibility usage in compiler 2022-05-20 20:04:54 -04:00
cfg_eval.rs rustc_parse: Move AST -> TokenStream conversion logic to rustc_ast 2022-05-22 12:01:07 +03:00
cmdline_attrs.rs Unconditionally capture tokens for attributes. 2020-10-21 18:57:29 -04:00
compile_error.rs check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
concat.rs Adopt let else in more places 2022-02-19 17:27:43 +01:00
concat_bytes.rs Adopt let else in more places 2022-02-19 17:27:43 +01:00
concat_idents.rs Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
derive.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
edition_panic.rs Spellchecking some comments 2022-03-30 01:39:38 -04:00
env.rs check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
format.rs Rename some ExtCtxt methods. 2022-06-23 11:10:43 +10:00
format_foreign.rs [rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape 2021-12-31 12:42:15 -05:00
global_allocator.rs Point at type when a static #[global_allocator] doesn't impl GlobalAlloc 2021-12-15 01:40:08 +00:00
lib.rs [RFC 2011] Minimal initial implementation 2022-06-15 07:37:40 -03:00
log_syntax.rs
proc_macro_harness.rs Rename some ExtCtxt methods. 2022-06-23 11:10:43 +10:00
source_util.rs Add support for a new attribute #[debugger_visualizer] to support embedding debugger visualizers into a generated PDB. 2022-05-03 10:53:54 -07:00
standard_library_imports.rs Create 2024 edition 2022-04-02 02:45:49 -04:00
test.rs remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
test_harness.rs Auto merge of #98190 - nnethercote:optimize-derive-Debug-code, r=scottmcm 2022-06-26 15:00:04 +00:00
trace_macros.rs
util.rs Add a lint for duplicated attributes. 2021-12-15 23:43:13 +01:00