From 84bf599bace38787f2237d2aadc5adf55fe662db Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 11 Mar 2021 11:49:23 +0100 Subject: [PATCH 1/3] Add inlining. --- compiler/rustc_data_structures/src/stable_hasher.rs | 1 + compiler/rustc_macros/src/hash_stable.rs | 2 ++ library/core/src/hash/mod.rs | 13 +++++++++++++ 3 files changed, 16 insertions(+) diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 3850c9b74fddc..ff28784a1dc42 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -35,6 +35,7 @@ impl StableHasher { StableHasher { state: SipHasher128::new_with_keys(0, 0) } } + #[inline] pub fn finish(self) -> W { W::finish(self) } diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index c955c13778276..30569f20793fb 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -74,6 +74,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma s.bound_impl( quote!(::rustc_data_structures::stable_hasher::HashStable<__CTX>), quote! { + #[inline] fn hash_stable( &self, __hcx: &mut __CTX, @@ -119,6 +120,7 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To > ), quote! { + #[inline] fn hash_stable( &self, __hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>, diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index cd47f97496a4a..dcdf019266016 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -548,10 +548,12 @@ mod impls { ($(($ty:ident, $meth:ident),)*) => {$( #[stable(feature = "rust1", since = "1.0.0")] impl Hash for $ty { + #[inline] fn hash(&self, state: &mut H) { state.$meth(*self) } + #[inline] fn hash_slice(data: &[$ty], state: &mut H) { let newlen = data.len() * mem::size_of::<$ty>(); let ptr = data.as_ptr() as *const u8; @@ -582,6 +584,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for bool { + #[inline] fn hash(&self, state: &mut H) { state.write_u8(*self as u8) } @@ -589,6 +592,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for char { + #[inline] fn hash(&self, state: &mut H) { state.write_u32(*self as u32) } @@ -596,6 +600,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for str { + #[inline] fn hash(&self, state: &mut H) { state.write(self.as_bytes()); state.write_u8(0xff) @@ -604,6 +609,7 @@ mod impls { #[stable(feature = "never_hash", since = "1.29.0")] impl Hash for ! { + #[inline] fn hash(&self, _: &mut H) { *self } @@ -613,6 +619,7 @@ mod impls { () => ( #[stable(feature = "rust1", since = "1.0.0")] impl Hash for () { + #[inline] fn hash(&self, _state: &mut H) {} } ); @@ -621,6 +628,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized { #[allow(non_snake_case)] + #[inline] fn hash(&self, state: &mut S) { let ($(ref $name,)+) = *self; $($name.hash(state);)+ @@ -650,6 +658,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for [T] { + #[inline] fn hash(&self, state: &mut H) { self.len().hash(state); Hash::hash_slice(self, state) @@ -658,6 +667,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for &T { + #[inline] fn hash(&self, state: &mut H) { (**self).hash(state); } @@ -665,6 +675,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for &mut T { + #[inline] fn hash(&self, state: &mut H) { (**self).hash(state); } @@ -672,6 +683,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for *const T { + #[inline] fn hash(&self, state: &mut H) { #[cfg(not(bootstrap))] { @@ -701,6 +713,7 @@ mod impls { #[stable(feature = "rust1", since = "1.0.0")] impl Hash for *mut T { + #[inline] fn hash(&self, state: &mut H) { #[cfg(not(bootstrap))] { From fe2d728e62d01cdf80d92f5f4d6ff5eb6ac6d10f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 11 Mar 2021 12:24:56 +0100 Subject: [PATCH 2/3] Remove useless method. --- compiler/rustc_middle/src/ich/hcx.rs | 7 ------- compiler/rustc_span/src/hygiene.rs | 6 ------ compiler/rustc_span/src/lib.rs | 4 ---- 3 files changed, 17 deletions(-) diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index 51b650e5adef8..cf29d21927c0d 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -250,13 +250,6 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { &CACHE } - fn byte_pos_to_line_and_col( - &mut self, - byte: BytePos, - ) -> Option<(Lrc, usize, BytePos)> { - self.source_map().byte_pos_to_line_and_col(byte) - } - fn span_data_to_lines_and_cols( &mut self, span: &SpanData, diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 4ccf657335fed..e67a4ca8fb26b 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -1362,12 +1362,6 @@ fn update_disambiguator(expn_id: ExpnId) { fn hash_spans(&self) -> bool { true } - fn byte_pos_to_line_and_col( - &mut self, - byte: BytePos, - ) -> Option<(Lrc, usize, BytePos)> { - self.caching_source_map.byte_pos_to_line_and_col(byte) - } fn span_data_to_lines_and_cols( &mut self, span: &crate::SpanData, diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index fb6c0873d77e9..1a2e87d28aca4 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1874,10 +1874,6 @@ pub trait HashStableContext { fn expn_id_cache() -> &'static LocalKey; fn hash_crate_num(&mut self, _: CrateNum, hasher: &mut StableHasher); fn hash_spans(&self) -> bool; - fn byte_pos_to_line_and_col( - &mut self, - byte: BytePos, - ) -> Option<(Lrc, usize, BytePos)>; fn span_data_to_lines_and_cols( &mut self, span: &SpanData, From 34e92bbf65aa28a8192dfc0ca1edaaee95d52b37 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 11 Mar 2021 12:31:31 +0100 Subject: [PATCH 3/3] Hash SyntaxContext first. --- compiler/rustc_span/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 1a2e87d28aca4..6030c8a86d9f9 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1902,9 +1902,10 @@ where return; } + self.ctxt().hash_stable(ctx, hasher); + if self.is_dummy() { Hash::hash(&TAG_INVALID_SPAN, hasher); - self.ctxt().hash_stable(ctx, hasher); return; } @@ -1917,7 +1918,6 @@ where Some(pos) => pos, None => { Hash::hash(&TAG_INVALID_SPAN, hasher); - span.ctxt.hash_stable(ctx, hasher); return; } }; @@ -1944,7 +1944,6 @@ where let len = (span.hi - span.lo).0; Hash::hash(&col_line, hasher); Hash::hash(&len, hasher); - span.ctxt.hash_stable(ctx, hasher); } }