Skip to content

Commit 3f8fe12

Browse files
authored
Unrolled build for #145505
Rollup merge of #145505 - cjgillot:tweak-span-cache, r=petrochenkov Simplify span caches Split from #143882 r? `@petrochenkov`
2 parents 16ad385 + a843730 commit 3f8fe12

File tree

2 files changed

+37
-44
lines changed

2 files changed

+37
-44
lines changed

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -645,34 +645,29 @@ impl<'a, 'tcx> SpanDecoder for CacheDecoder<'a, 'tcx> {
645645
let parent = Option::<LocalDefId>::decode(self);
646646
let tag: u8 = Decodable::decode(self);
647647

648-
if tag == TAG_PARTIAL_SPAN {
649-
return Span::new(BytePos(0), BytePos(0), ctxt, parent);
650-
} else if tag == TAG_RELATIVE_SPAN {
651-
let dlo = u32::decode(self);
652-
let dto = u32::decode(self);
653-
654-
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
655-
let span = Span::new(
656-
enclosing.lo + BytePos::from_u32(dlo),
657-
enclosing.lo + BytePos::from_u32(dto),
658-
ctxt,
659-
parent,
660-
);
661-
662-
return span;
663-
} else {
664-
debug_assert_eq!(tag, TAG_FULL_SPAN);
665-
}
666-
667-
let file_lo_index = SourceFileIndex::decode(self);
668-
let line_lo = usize::decode(self);
669-
let col_lo = RelativeBytePos::decode(self);
670-
let len = BytePos::decode(self);
671-
672-
let file_lo = self.file_index_to_file(file_lo_index);
673-
let lo = file_lo.lines()[line_lo - 1] + col_lo;
674-
let lo = file_lo.absolute_position(lo);
675-
let hi = lo + len;
648+
let (lo, hi) = match tag {
649+
TAG_PARTIAL_SPAN => (BytePos(0), BytePos(0)),
650+
TAG_RELATIVE_SPAN => {
651+
let dlo = u32::decode(self);
652+
let dto = u32::decode(self);
653+
654+
let enclosing = self.tcx.source_span_untracked(parent.unwrap()).data_untracked();
655+
(enclosing.lo + BytePos::from_u32(dlo), enclosing.lo + BytePos::from_u32(dto))
656+
}
657+
TAG_FULL_SPAN => {
658+
let file_lo_index = SourceFileIndex::decode(self);
659+
let line_lo = usize::decode(self);
660+
let col_lo = RelativeBytePos::decode(self);
661+
let len = BytePos::decode(self);
662+
663+
let file_lo = self.file_index_to_file(file_lo_index);
664+
let lo = file_lo.lines()[line_lo - 1] + col_lo;
665+
let lo = file_lo.absolute_position(lo);
666+
let hi = lo + len;
667+
(lo, hi)
668+
}
669+
_ => unreachable!(),
670+
};
676671

677672
Span::new(lo, hi, ctxt, parent)
678673
}

compiler/rustc_span/src/caching_source_map_view.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,25 @@ impl<'sm> CachingSourceMapView<'sm> {
123123

124124
if lo_cache_idx != -1 && hi_cache_idx != -1 {
125125
// Cache hit for span lo and hi. Check if they belong to the same file.
126-
let result = {
127-
let lo = &self.line_cache[lo_cache_idx as usize];
128-
let hi = &self.line_cache[hi_cache_idx as usize];
126+
let lo_file_index = self.line_cache[lo_cache_idx as usize].file_index;
127+
let hi_file_index = self.line_cache[hi_cache_idx as usize].file_index;
129128

130-
if lo.file_index != hi.file_index {
131-
return None;
132-
}
133-
134-
(
135-
lo.file.stable_id,
136-
lo.line_number,
137-
span_data.lo - lo.line.start,
138-
hi.line_number,
139-
span_data.hi - hi.line.start,
140-
)
141-
};
129+
if lo_file_index != hi_file_index {
130+
return None;
131+
}
142132

143133
self.line_cache[lo_cache_idx as usize].touch(self.time_stamp);
144134
self.line_cache[hi_cache_idx as usize].touch(self.time_stamp);
145135

146-
return Some(result);
136+
let lo = &self.line_cache[lo_cache_idx as usize];
137+
let hi = &self.line_cache[hi_cache_idx as usize];
138+
return Some((
139+
lo.file.stable_id,
140+
lo.line_number,
141+
span_data.lo - lo.line.start,
142+
hi.line_number,
143+
span_data.hi - hi.line.start,
144+
));
147145
}
148146

149147
// No cache hit or cache hit for only one of span lo and hi.

0 commit comments

Comments
 (0)