diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2019-11-10 17:31:21 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2019-11-22 19:56:38 +0100 |
| commit | 640797fdd700ab30addcd3497621422989f9826f (patch) | |
| tree | 4949c09099ccae4a57ddec922a94ecd660ee2fce | |
| parent | 1de5fdb5babf74f729b008585a8aaf16110bb1fd (diff) | |
| download | rust-640797fdd700ab30addcd3497621422989f9826f.tar.gz rust-640797fdd700ab30addcd3497621422989f9826f.zip | |
Invert flow in impl HashStable of Span.
| -rw-r--r-- | src/librustc/ich/hcx.rs | 20 | ||||
| -rw-r--r-- | src/librustc/ich/impls_syntax.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 14 |
3 files changed, 22 insertions, 13 deletions
diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index a5b131520c2..da45f93b40c 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -281,7 +281,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::NodeId { } } -impl<'a> HashStable<StableHashingContext<'a>> for Span { +impl<'a> syntax_pos::StableHashingContextLike for StableHashingContext<'a> { /// Hashes a span in a stable way. We can't directly hash the span's `BytePos` /// fields (that would be similar to hashing pointers, since those are just /// offsets into the `SourceMap`). Instead, we hash the (file name, line, column) @@ -291,25 +291,25 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span { /// codepoint offsets. For the purpose of the hash that's sufficient. /// Also, hashing filenames is expensive so we avoid doing it twice when the /// span starts and ends in the same file, which is almost always the case. - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + fn hash_stable_span(&mut self, span: &Span, hasher: &mut StableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; const TAG_EXPANSION: u8 = 0; const TAG_NO_EXPANSION: u8 = 1; - if !hcx.hash_spans { + if !self.hash_spans { return } - if *self == DUMMY_SP { + if *span == DUMMY_SP { return std_hash::Hash::hash(&TAG_INVALID_SPAN, hasher); } // If this is not an empty or invalid span, we want to hash the last // position that belongs to it, as opposed to hashing the first // position past it. - let span = self.data(); - let (file_lo, line_lo, col_lo) = match hcx.source_map() + let span = span.data(); + let (file_lo, line_lo, col_lo) = match self.source_map() .byte_pos_to_line_and_col(span.lo) { Some(pos) => pos, None => { @@ -333,9 +333,9 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span { std_hash::Hash::hash(&line_col_len, hasher); if span.ctxt == SyntaxContext::root() { - TAG_NO_EXPANSION.hash_stable(hcx, hasher); + TAG_NO_EXPANSION.hash_stable(self, hasher); } else { - TAG_EXPANSION.hash_stable(hcx, hasher); + TAG_EXPANSION.hash_stable(self, hasher); // Since the same expansion context is usually referenced many // times, we cache a stable hash of it and hash that instead of @@ -352,14 +352,14 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span { } let mut hasher = StableHasher::new(); - expn_id.expn_data().hash_stable(hcx, &mut hasher); + expn_id.expn_data().hash_stable(self, &mut hasher); let sub_hash: Fingerprint = hasher.finish(); let sub_hash = sub_hash.to_smaller_hash(); cache.borrow_mut().insert(expn_id, sub_hash); sub_hash }); - sub_hash.hash_stable(hcx, hasher); + sub_hash.hash_stable(self, hasher); } } } diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index b4800796b14..581653f5bbc 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -17,7 +17,6 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; use smallvec::SmallVec; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -impl<'ctx> syntax_pos::StableHashingContextLike for StableHashingContext<'ctx> {} impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> {} impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {} diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index d11ef5fcab2..25391ad5ce6 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -34,7 +34,7 @@ pub use symbol::{Symbol, sym}; mod analyze_source_file; pub mod fatal_error; -use rustc_data_structures::stable_hasher::StableHasher; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{Lrc, Lock}; use std::borrow::Cow; @@ -245,6 +245,14 @@ impl Ord for Span { } } +impl<CTX> HashStable<CTX> for Span + where CTX: StableHashingContextLike +{ + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { + ctx.hash_stable_span(self, hasher) + } +} + /// A collection of spans. Spans have two orthogonal attributes: /// /// - They can be *primary spans*. In this case they are the locus of @@ -1566,4 +1574,6 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize { /// Requirements for a `StableHashingContext` to be used in this crate. /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in librustc. -pub trait StableHashingContextLike {} +pub trait StableHashingContextLike { + fn hash_stable_span(&mut self, span: &Span, hasher: &mut StableHasher); +} |
