diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-04-18 14:27:28 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-09-10 20:18:11 +0200 |
| commit | e85ddeb474665f3af7c447445c273da6117e266d (patch) | |
| tree | 6f2e80f6c78c506df6effcd202c1196284356fd8 /compiler/rustc_span/src | |
| parent | 00485e0c0e8dcd64c57a86d706beb62054921253 (diff) | |
| download | rust-e85ddeb474665f3af7c447445c273da6117e266d.tar.gz rust-e85ddeb474665f3af7c447445c273da6117e266d.zip | |
Encode spans relative to their parent.
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index d744ad4014a..de08c5d8a55 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -2001,6 +2001,7 @@ impl InnerSpan { pub trait HashStableContext { fn def_path_hash(&self, def_id: DefId) -> DefPathHash; fn hash_spans(&self) -> bool; + fn def_span(&self, def_id: LocalDefId) -> Span; fn span_data_to_lines_and_cols( &mut self, span: &SpanData, @@ -2024,22 +2025,35 @@ where fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { const TAG_VALID_SPAN: u8 = 0; const TAG_INVALID_SPAN: u8 = 1; + const TAG_RELATIVE_SPAN: u8 = 2; if !ctx.hash_spans() { return; } - self.ctxt().hash_stable(ctx, hasher); + let span = self.data(); + span.ctxt.hash_stable(ctx, hasher); + span.parent.hash_stable(ctx, hasher); - if self.is_dummy() { + if span.is_dummy() { Hash::hash(&TAG_INVALID_SPAN, hasher); return; } + if let Some(parent) = span.parent { + let def_span = ctx.def_span(parent).data(); + if def_span.contains(span) { + // This span is enclosed in a definition: only hash the relative position. + Hash::hash(&TAG_RELATIVE_SPAN, hasher); + (span.lo - def_span.lo).to_u32().hash_stable(ctx, hasher); + (span.hi - def_span.lo).to_u32().hash_stable(ctx, hasher); + return; + } + } + // 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, line_lo, col_lo, line_hi, col_hi) = match ctx.span_data_to_lines_and_cols(&span) { Some(pos) => pos, |
