Skip to content

Commit acca818

Browse files
committed
Auto merge of rust-lang#83064 - cjgillot:fhash, r=jackh726
Tweaks to stable hashing
2 parents e7e1dc1 + 34e92bb commit acca818

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

Diff for: compiler/rustc_data_structures/src/stable_hasher.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl StableHasher {
3535
StableHasher { state: SipHasher128::new_with_keys(0, 0) }
3636
}
3737

38+
#[inline]
3839
pub fn finish<W: StableHasherResult>(self) -> W {
3940
W::finish(self)
4041
}

Diff for: compiler/rustc_macros/src/hash_stable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub fn hash_stable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_ma
7474
s.bound_impl(
7575
quote!(::rustc_data_structures::stable_hasher::HashStable<__CTX>),
7676
quote! {
77+
#[inline]
7778
fn hash_stable(
7879
&self,
7980
__hcx: &mut __CTX,
@@ -119,6 +120,7 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To
119120
>
120121
),
121122
quote! {
123+
#[inline]
122124
fn hash_stable(
123125
&self,
124126
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,

Diff for: compiler/rustc_middle/src/ich/hcx.rs

-7
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,6 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
250250
&CACHE
251251
}
252252

253-
fn byte_pos_to_line_and_col(
254-
&mut self,
255-
byte: BytePos,
256-
) -> Option<(Lrc<SourceFile>, usize, BytePos)> {
257-
self.source_map().byte_pos_to_line_and_col(byte)
258-
}
259-
260253
fn span_data_to_lines_and_cols(
261254
&mut self,
262255
span: &SpanData,

Diff for: compiler/rustc_span/src/hygiene.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1362,12 +1362,6 @@ fn update_disambiguator(expn_id: ExpnId) {
13621362
fn hash_spans(&self) -> bool {
13631363
true
13641364
}
1365-
fn byte_pos_to_line_and_col(
1366-
&mut self,
1367-
byte: BytePos,
1368-
) -> Option<(Lrc<SourceFile>, usize, BytePos)> {
1369-
self.caching_source_map.byte_pos_to_line_and_col(byte)
1370-
}
13711365
fn span_data_to_lines_and_cols(
13721366
&mut self,
13731367
span: &crate::SpanData,

Diff for: compiler/rustc_span/src/lib.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1874,10 +1874,6 @@ pub trait HashStableContext {
18741874
fn expn_id_cache() -> &'static LocalKey<ExpnIdCache>;
18751875
fn hash_crate_num(&mut self, _: CrateNum, hasher: &mut StableHasher);
18761876
fn hash_spans(&self) -> bool;
1877-
fn byte_pos_to_line_and_col(
1878-
&mut self,
1879-
byte: BytePos,
1880-
) -> Option<(Lrc<SourceFile>, usize, BytePos)>;
18811877
fn span_data_to_lines_and_cols(
18821878
&mut self,
18831879
span: &SpanData,
@@ -1906,9 +1902,10 @@ where
19061902
return;
19071903
}
19081904

1905+
self.ctxt().hash_stable(ctx, hasher);
1906+
19091907
if self.is_dummy() {
19101908
Hash::hash(&TAG_INVALID_SPAN, hasher);
1911-
self.ctxt().hash_stable(ctx, hasher);
19121909
return;
19131910
}
19141911

@@ -1921,7 +1918,6 @@ where
19211918
Some(pos) => pos,
19221919
None => {
19231920
Hash::hash(&TAG_INVALID_SPAN, hasher);
1924-
span.ctxt.hash_stable(ctx, hasher);
19251921
return;
19261922
}
19271923
};
@@ -1948,7 +1944,6 @@ where
19481944
let len = (span.hi - span.lo).0;
19491945
Hash::hash(&col_line, hasher);
19501946
Hash::hash(&len, hasher);
1951-
span.ctxt.hash_stable(ctx, hasher);
19521947
}
19531948
}
19541949

Diff for: library/core/src/hash/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,12 @@ mod impls {
548548
($(($ty:ident, $meth:ident),)*) => {$(
549549
#[stable(feature = "rust1", since = "1.0.0")]
550550
impl Hash for $ty {
551+
#[inline]
551552
fn hash<H: Hasher>(&self, state: &mut H) {
552553
state.$meth(*self)
553554
}
554555

556+
#[inline]
555557
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
556558
let newlen = data.len() * mem::size_of::<$ty>();
557559
let ptr = data.as_ptr() as *const u8;
@@ -582,20 +584,23 @@ mod impls {
582584

583585
#[stable(feature = "rust1", since = "1.0.0")]
584586
impl Hash for bool {
587+
#[inline]
585588
fn hash<H: Hasher>(&self, state: &mut H) {
586589
state.write_u8(*self as u8)
587590
}
588591
}
589592

590593
#[stable(feature = "rust1", since = "1.0.0")]
591594
impl Hash for char {
595+
#[inline]
592596
fn hash<H: Hasher>(&self, state: &mut H) {
593597
state.write_u32(*self as u32)
594598
}
595599
}
596600

597601
#[stable(feature = "rust1", since = "1.0.0")]
598602
impl Hash for str {
603+
#[inline]
599604
fn hash<H: Hasher>(&self, state: &mut H) {
600605
state.write(self.as_bytes());
601606
state.write_u8(0xff)
@@ -604,6 +609,7 @@ mod impls {
604609

605610
#[stable(feature = "never_hash", since = "1.29.0")]
606611
impl Hash for ! {
612+
#[inline]
607613
fn hash<H: Hasher>(&self, _: &mut H) {
608614
*self
609615
}
@@ -613,6 +619,7 @@ mod impls {
613619
() => (
614620
#[stable(feature = "rust1", since = "1.0.0")]
615621
impl Hash for () {
622+
#[inline]
616623
fn hash<H: Hasher>(&self, _state: &mut H) {}
617624
}
618625
);
@@ -621,6 +628,7 @@ mod impls {
621628
#[stable(feature = "rust1", since = "1.0.0")]
622629
impl<$($name: Hash),+> Hash for ($($name,)+) where last_type!($($name,)+): ?Sized {
623630
#[allow(non_snake_case)]
631+
#[inline]
624632
fn hash<S: Hasher>(&self, state: &mut S) {
625633
let ($(ref $name,)+) = *self;
626634
$($name.hash(state);)+
@@ -650,6 +658,7 @@ mod impls {
650658

651659
#[stable(feature = "rust1", since = "1.0.0")]
652660
impl<T: Hash> Hash for [T] {
661+
#[inline]
653662
fn hash<H: Hasher>(&self, state: &mut H) {
654663
self.len().hash(state);
655664
Hash::hash_slice(self, state)
@@ -658,20 +667,23 @@ mod impls {
658667

659668
#[stable(feature = "rust1", since = "1.0.0")]
660669
impl<T: ?Sized + Hash> Hash for &T {
670+
#[inline]
661671
fn hash<H: Hasher>(&self, state: &mut H) {
662672
(**self).hash(state);
663673
}
664674
}
665675

666676
#[stable(feature = "rust1", since = "1.0.0")]
667677
impl<T: ?Sized + Hash> Hash for &mut T {
678+
#[inline]
668679
fn hash<H: Hasher>(&self, state: &mut H) {
669680
(**self).hash(state);
670681
}
671682
}
672683

673684
#[stable(feature = "rust1", since = "1.0.0")]
674685
impl<T: ?Sized> Hash for *const T {
686+
#[inline]
675687
fn hash<H: Hasher>(&self, state: &mut H) {
676688
#[cfg(not(bootstrap))]
677689
{
@@ -701,6 +713,7 @@ mod impls {
701713

702714
#[stable(feature = "rust1", since = "1.0.0")]
703715
impl<T: ?Sized> Hash for *mut T {
716+
#[inline]
704717
fn hash<H: Hasher>(&self, state: &mut H) {
705718
#[cfg(not(bootstrap))]
706719
{

0 commit comments

Comments
 (0)