This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit ecc6e95
committed
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::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.1 parent 528343f commit ecc6e95
File tree
5 files changed
+314
-470
lines changed- compiler
- rustc_builtin_macros/src/deriving/generic
- rustc_expand/src
- src/test
- mir-opt
- run-make-fulldeps/coverage-reports
- ui/deriving
5 files changed
+314
-470
lines changedLines changed: 80 additions & 44 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
432 | 433 | | |
433 | 434 | | |
434 | 435 | | |
| |||
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
| 452 | + | |
451 | 453 | | |
452 | 454 | | |
453 | 455 | | |
| |||
729 | 731 | | |
730 | 732 | | |
731 | 733 | | |
| 734 | + | |
732 | 735 | | |
733 | 736 | | |
734 | 737 | | |
| |||
757 | 760 | | |
758 | 761 | | |
759 | 762 | | |
| 763 | + | |
760 | 764 | | |
761 | 765 | | |
762 | 766 | | |
| |||
945 | 949 | | |
946 | 950 | | |
947 | 951 | | |
| 952 | + | |
948 | 953 | | |
949 | 954 | | |
950 | 955 | | |
| |||
953 | 958 | | |
954 | 959 | | |
955 | 960 | | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
| 961 | + | |
965 | 962 | | |
966 | 963 | | |
967 | 964 | | |
968 | | - | |
969 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
970 | 969 | | |
971 | 970 | | |
972 | 971 | | |
973 | 972 | | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
983 | 976 | | |
984 | 977 | | |
985 | 978 | | |
| |||
992 | 985 | | |
993 | 986 | | |
994 | 987 | | |
| 988 | + | |
995 | 989 | | |
996 | 990 | | |
997 | 991 | | |
998 | 992 | | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
1012 | | - | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
1013 | 1015 | | |
1014 | 1016 | | |
1015 | 1017 | | |
| |||
1036 | 1038 | | |
1037 | 1039 | | |
1038 | 1040 | | |
1039 | | - | |
1040 | 1041 | | |
1041 | 1042 | | |
1042 | 1043 | | |
| |||
1045 | 1046 | | |
1046 | 1047 | | |
1047 | 1048 | | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
1054 | 1058 | | |
1055 | | - | |
| 1059 | + | |
| 1060 | + | |
1056 | 1061 | | |
1057 | 1062 | | |
1058 | 1063 | | |
| |||
1522 | 1527 | | |
1523 | 1528 | | |
1524 | 1529 | | |
1525 | | - | |
1526 | | - | |
1527 | 1530 | | |
1528 | 1531 | | |
1529 | 1532 | | |
| |||
1555 | 1558 | | |
1556 | 1559 | | |
1557 | 1560 | | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
1558 | 1594 | | |
1559 | 1595 | | |
1560 | 1596 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
155 | 168 | | |
156 | 169 | | |
157 | 170 | | |
| |||
0 commit comments