Skip to content

Commit f8447b9

Browse files
committed
Auto merge of rust-lang#111963 - nnethercote:inline-derived-hash, r=lqd
Inline derived `hash` Because most of the other derived functions are inlined: `clone`, `default`, `eq`, `partial_cmp`, `cmp`. The exception is `fmt`, but it tends to not be on hot paths as much. r? `@ghost`
2 parents 089677e + ee013d8 commit f8447b9

File tree

8 files changed

+27
-19
lines changed

8 files changed

+27
-19
lines changed

compiler/rustc_builtin_macros/src/deriving/clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub fn expand_deriving_clone(
6868
_ => cx.span_bug(span, "`#[derive(Clone)]` on trait item or impl item"),
6969
}
7070

71-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
7271
let trait_def = TraitDef {
7372
span,
7473
path: path_std!(clone::Clone),
@@ -82,7 +81,7 @@ pub fn expand_deriving_clone(
8281
explicit_self: true,
8382
nonself_args: Vec::new(),
8483
ret_ty: Self_,
85-
attributes: attrs,
84+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
8685
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
8786
combine_substructure: substructure,
8887
}],

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ pub fn expand_deriving_eq(
1818
is_const: bool,
1919
) {
2020
let span = cx.with_def_site_ctxt(span);
21-
let attrs = thin_vec![
22-
cx.attr_word(sym::inline, span),
23-
cx.attr_nested_word(sym::doc, sym::hidden, span),
24-
cx.attr_word(sym::no_coverage, span)
25-
];
2621
let trait_def = TraitDef {
2722
span,
2823
path: path_std!(cmp::Eq),
@@ -36,7 +31,11 @@ pub fn expand_deriving_eq(
3631
explicit_self: true,
3732
nonself_args: vec![],
3833
ret_ty: Unit,
39-
attributes: attrs,
34+
attributes: thin_vec![
35+
cx.attr_word(sym::inline, span),
36+
cx.attr_nested_word(sym::doc, sym::hidden, span),
37+
cx.attr_word(sym::no_coverage, span)
38+
],
4039
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
4140
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4241
cs_total_eq_assert(a, b, c)

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub fn expand_deriving_ord(
1515
push: &mut dyn FnMut(Annotatable),
1616
is_const: bool,
1717
) {
18-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
1918
let trait_def = TraitDef {
2019
span,
2120
path: path_std!(cmp::Ord),
@@ -29,7 +28,7 @@ pub fn expand_deriving_ord(
2928
explicit_self: true,
3029
nonself_args: vec![(self_ref(), sym::other)],
3130
ret_ty: Path(path_std!(cmp::Ordering)),
32-
attributes: attrs,
31+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3332
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
3433
combine_substructure: combine_substructure(Box::new(|a, b, c| cs_cmp(a, b, c))),
3534
}],

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ pub fn expand_deriving_partial_eq(
8282

8383
// No need to generate `ne`, the default suffices, and not generating it is
8484
// faster.
85-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
8685
let methods = vec![MethodDef {
8786
name: sym::eq,
8887
generics: Bounds::empty(),
8988
explicit_self: true,
9089
nonself_args: vec![(self_ref(), sym::other)],
9190
ret_ty: Path(path_local!(bool)),
92-
attributes: attrs,
91+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
9392
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
9493
combine_substructure: combine_substructure(Box::new(|a, b, c| cs_eq(a, b, c))),
9594
}];

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ pub fn expand_deriving_partial_ord(
1919
let ret_ty =
2020
Path(Path::new_(pathvec_std!(option::Option), vec![Box::new(ordering_ty)], PathKind::Std));
2121

22-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
23-
2422
// Order in which to perform matching
2523
let tag_then_data = if let Annotatable::Item(item) = item
2624
&& let ItemKind::Enum(def, _) = &item.kind {
@@ -48,7 +46,7 @@ pub fn expand_deriving_partial_ord(
4846
explicit_self: true,
4947
nonself_args: vec![(self_ref(), sym::other)],
5048
ret_ty,
51-
attributes: attrs,
49+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
5250
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
5351
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
5452
cs_partial_cmp(cx, span, substr, tag_then_data)

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub fn expand_deriving_default(
2020
) {
2121
item.visit_with(&mut DetectNonVariantDefaultAttr { cx });
2222

23-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
2423
let trait_def = TraitDef {
2524
span,
2625
path: Path::new(vec![kw::Default, sym::Default]),
@@ -34,7 +33,7 @@ pub fn expand_deriving_default(
3433
explicit_self: false,
3534
nonself_args: Vec::new(),
3635
ret_ty: Self_,
37-
attributes: attrs,
36+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3837
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
3938
combine_substructure: combine_substructure(Box::new(|cx, trait_span, substr| {
4039
match substr.fields {

compiler/rustc_builtin_macros/src/deriving/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::deriving::generic::ty::*;
22
use crate::deriving::generic::*;
33
use crate::deriving::{path_std, pathvec_std};
4-
use rustc_ast::{AttrVec, MetaItem, Mutability};
4+
use rustc_ast::{MetaItem, Mutability};
55
use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::symbol::sym;
77
use rustc_span::Span;
@@ -33,7 +33,7 @@ pub fn expand_deriving_hash(
3333
explicit_self: true,
3434
nonself_args: vec![(Ref(Box::new(Path(arg)), Mutability::Mut), sym::state)],
3535
ret_ty: Unit,
36-
attributes: AttrVec::new(),
36+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3737
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
3838
combine_substructure: combine_substructure(Box::new(|a, b, c| {
3939
hash_substructure(a, b, c)

tests/ui/deriving/deriving-all-codegen.stdout

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl ::core::default::Default for Empty {
4444
}
4545
#[automatically_derived]
4646
impl ::core::hash::Hash for Empty {
47+
#[inline]
4748
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
4849
}
4950
#[automatically_derived]
@@ -113,6 +114,7 @@ impl ::core::default::Default for Point {
113114
}
114115
#[automatically_derived]
115116
impl ::core::hash::Hash for Point {
117+
#[inline]
116118
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
117119
::core::hash::Hash::hash(&self.x, state);
118120
::core::hash::Hash::hash(&self.y, state)
@@ -198,6 +200,7 @@ impl ::core::default::Default for PackedPoint {
198200
}
199201
#[automatically_derived]
200202
impl ::core::hash::Hash for PackedPoint {
203+
#[inline]
201204
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
202205
::core::hash::Hash::hash(&{ self.x }, state);
203206
::core::hash::Hash::hash(&{ self.y }, state)
@@ -301,6 +304,7 @@ impl ::core::default::Default for Big {
301304
}
302305
#[automatically_derived]
303306
impl ::core::hash::Hash for Big {
307+
#[inline]
304308
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
305309
::core::hash::Hash::hash(&self.b1, state);
306310
::core::hash::Hash::hash(&self.b2, state);
@@ -478,6 +482,7 @@ impl ::core::fmt::Debug for Unsized {
478482
}
479483
#[automatically_derived]
480484
impl ::core::hash::Hash for Unsized {
485+
#[inline]
481486
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
482487
::core::hash::Hash::hash(&self.0, state)
483488
}
@@ -529,6 +534,7 @@ impl ::core::fmt::Debug for PackedUnsizedU8 {
529534
}
530535
#[automatically_derived]
531536
impl ::core::hash::Hash for PackedUnsizedU8 {
537+
#[inline]
532538
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
533539
::core::hash::Hash::hash(&self.0, state)
534540
}
@@ -584,6 +590,7 @@ impl<T: ::core::default::Default + Trait, U: ::core::default::Default>
584590
#[automatically_derived]
585591
impl<T: ::core::hash::Hash + Trait, U: ::core::hash::Hash> ::core::hash::Hash
586592
for Generic<T, U> where T::A: ::core::hash::Hash {
593+
#[inline]
587594
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
588595
::core::hash::Hash::hash(&self.t, state);
589596
::core::hash::Hash::hash(&self.ta, state);
@@ -701,6 +708,7 @@ impl<T: ::core::hash::Hash + ::core::marker::Copy + Trait,
701708
U: ::core::hash::Hash + ::core::marker::Copy> ::core::hash::Hash for
702709
PackedGeneric<T, U> where T::A: ::core::hash::Hash + ::core::marker::Copy
703710
{
711+
#[inline]
704712
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
705713
::core::hash::Hash::hash(&{ self.0 }, state);
706714
::core::hash::Hash::hash(&{ self.1 }, state);
@@ -795,6 +803,7 @@ impl ::core::fmt::Debug for Enum0 {
795803
}
796804
#[automatically_derived]
797805
impl ::core::hash::Hash for Enum0 {
806+
#[inline]
798807
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
799808
unsafe { ::core::intrinsics::unreachable() }
800809
}
@@ -861,6 +870,7 @@ impl ::core::fmt::Debug for Enum1 {
861870
}
862871
#[automatically_derived]
863872
impl ::core::hash::Hash for Enum1 {
873+
#[inline]
864874
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
865875
match self {
866876
Enum1::Single { x: __self_0 } =>
@@ -937,6 +947,7 @@ impl ::core::default::Default for Fieldless1 {
937947
}
938948
#[automatically_derived]
939949
impl ::core::hash::Hash for Fieldless1 {
950+
#[inline]
940951
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {}
941952
}
942953
#[automatically_derived]
@@ -1004,6 +1015,7 @@ impl ::core::default::Default for Fieldless {
10041015
}
10051016
#[automatically_derived]
10061017
impl ::core::hash::Hash for Fieldless {
1018+
#[inline]
10071019
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
10081020
let __self_tag = ::core::intrinsics::discriminant_value(self);
10091021
::core::hash::Hash::hash(&__self_tag, state)
@@ -1095,6 +1107,7 @@ impl ::core::default::Default for Mixed {
10951107
}
10961108
#[automatically_derived]
10971109
impl ::core::hash::Hash for Mixed {
1110+
#[inline]
10981111
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
10991112
let __self_tag = ::core::intrinsics::discriminant_value(self);
11001113
::core::hash::Hash::hash(&__self_tag, state);
@@ -1224,6 +1237,7 @@ impl ::core::fmt::Debug for Fielded {
12241237
}
12251238
#[automatically_derived]
12261239
impl ::core::hash::Hash for Fielded {
1240+
#[inline]
12271241
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
12281242
let __self_tag = ::core::intrinsics::discriminant_value(self);
12291243
::core::hash::Hash::hash(&__self_tag, state);
@@ -1345,6 +1359,7 @@ impl<T: ::core::fmt::Debug, U: ::core::fmt::Debug> ::core::fmt::Debug for
13451359
#[automatically_derived]
13461360
impl<T: ::core::hash::Hash, U: ::core::hash::Hash> ::core::hash::Hash for
13471361
EnumGeneric<T, U> {
1362+
#[inline]
13481363
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
13491364
let __self_tag = ::core::intrinsics::discriminant_value(self);
13501365
::core::hash::Hash::hash(&__self_tag, state);

0 commit comments

Comments
 (0)