summary refs log tree commit diff
path: root/src/test/ui/deriving/deriving-all-codegen.stdout
AgeCommit message (Collapse)AuthorLines
2022-07-19Remove #[allow(unused_qualifications)] lines from derive diff testMichael Holloway-99/+0
2022-07-13Use `&{self.x}` for packed `Copy` structs.Nicholas Nethercote-20/+6
Because it's more concise than the `let` form.
2022-07-11Handle tags better.Nicholas Nethercote-118/+78
Currently, for the enums and comparison traits we always check the tag for equality before doing anything else. This is a bit clumsy. This commit changes things so that the tags are handled very much like a zeroth field in the enum. For `eq`/ne` this makes the code slightly cleaner. For `partial_cmp` and `cmp` it's a more notable change: in the case where the tags aren't equal, instead of having a tag equality check followed by a tag comparison, it just does a single tag comparison. The commit also improves how `Hash` works for enums: instead of having duplicated code to hash the tag for every arm within the match, we do it just once before the match. All this required replacing the `EnumNonMatchingCollapsed` value with a new `EnumTag` value. For fieldless enums the new code is particularly improved. All the code now produced is close to optimal, being very similar to what you'd write by hand.
2022-07-11Avoid some unnecessary blocks in derive output.Nicholas Nethercote-9/+6
2022-07-11Rename tag-related things.Nicholas Nethercote-90/+89
Use `tag` in names of things referring to tags, instead of the mysterious `vi`. Also change `arg_N` in output to `argN`, which has the same length as `self` and so results in nicer vertical alignments.
2022-07-11Remove unnecessary `&*` sigil pairs in derived code.Nicholas Nethercote-42/+37
By producing `&T` expressions for fields instead of `T`. This matches what the existing comments (e.g. on `FieldInfo`) claim is happening, and it's also what most of the trait-specific code needs. The exception is `PartialEq`, which needs `T` expressions for lots of special case error messaging to work. So we now convert the `&T` back to a `T` for `PartialEq`.
2022-07-11Remove unnecessary sigils and `ref`s in derived code.Nicholas Nethercote-107/+105
E.g. improving code like this: ``` match &*self { &Enum1::Single { x: ref __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` to this: ``` match self { Enum1::Single { x: __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` by removing the `&*`, the `&`, and the `ref`. I suspect the current generated code predates deref-coercion. The commit also gets rid of `use_temporaries`, instead passing around `always_copy`, which makes things a little clearer. And it fixes up some comments.
2022-07-11Add a fieldless enum with one variant to `deriving-all-codegen.rs`.Nicholas Nethercote-0/+74
Because the generated code is different to fieldless enum with multiple variants.
2022-07-11Add a non-`Copy` packed struct to `deriving-all-codegen.rs`.Nicholas Nethercote-20/+113
Because the generatedd code is different to a `Copy` packed struct.
2022-07-11Add a struct with an unsized field to the `deriving-all-codegen.rs` test.Nicholas Nethercote-0/+55
It's an interesting case, requiring the use of `&&` in `Debug::fmt`.
2022-07-05Avoid the unnecessary innermost match in `partial_cmp`/`cmp`.Nicholas Nethercote-105/+23
We currently do a match on the comparison of every field in a struct or enum variant. But the last field has a degenerate match like this: ``` match ::core::cmp::Ord::cmp(&self.y, &other.y) { ::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal, cmp => cmp, }, ``` This commit changes it to this: ``` ::core::cmp::Ord::cmp(&self.y, &other.y), ``` This is fairly straightforward thanks to the existing `cs_fold1` function. The commit also removes the `cs_fold` function which is no longer used. (Note: there is some repetition now in `cs_cmp` and `cs_partial_cmp`. I will remove that in a follow-up PR.)
2022-07-04Avoid unnecessary 1-tuples in derived code.Nicholas Nethercote-31/+31
2022-07-04Don't repeat `AssertParamIs{Clone,Eq}` assertions.Nicholas Nethercote-13/+0
It's common to see repeated assertions like this in derived `clone` and `eq` methods: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` This commit avoids them.
2022-07-04Avoid unnecessary blocks in derive output.Nicholas Nethercote-316/+260
By not committing to either block form or expression form until necessary, we can avoid lots of unnecessary blocks.
2022-07-04Add 0-variant and 1-variant enums to the `deriving-all-codegen.rs` test.Nicholas Nethercote-0/+166
Because they are interesting cases with their own code generation paths.
2022-07-04Add a union to the `deriving-all-codegen.rs` test.Nicholas Nethercote-0/+18
Because `derive(Clone)` on unions triggers special behaviour.
2022-07-04Don't use match-destructuring for derived ops on structs.Nicholas Nethercote-358/+173
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::hash::Hasher>(&self, state: &mut __H) -> () { { let Self(ref __self_0_0) = *self; { ::core::hash::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-04Add an interesting case to the `deriving-all-codegen.rs` test.Nicholas Nethercote-1/+108
2022-06-27Improve derived discriminant testing.Nicholas Nethercote-11/+11
Currently the generated code for methods like `eq`, `ne`, and `partial_cmp` includes stuff like this: ``` let __self_vi = ::core::intrinsics::discriminant_value(&*self); let __arg_1_vi = ::core::intrinsics::discriminant_value(&*other); if true && __self_vi == __arg_1_vi { ... } ``` This commit removes the unnecessary `true &&`, and makes the generating code a little easier to read in the process. It also fixes some errors in comments.
2022-06-27Add a test checking the output of builtin derives.Nicholas Nethercote-0/+1100