Skip to content

Commit 99252bf

Browse files
authored
Rollup merge of #83132 - Aaron1011:fix/incr-cache-dummy, r=estebank
Don't encode file information for span with a dummy location Fixes #83112 The location information for a dummy span isn't real, so don't encode it. This brings the incr comp cache code into line with the Span `StableHash` impl, which doesn't hash the location information for dummy spans. Previously, we would attempt to load the 'original' file from a dummy span - if the file id changed (e.g. due to being moved on disk), we would get an ICE, since the Span was still valid due to its hash being unchanged.
2 parents ebba9a4 + 7429c68 commit 99252bf

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1045,12 +1045,12 @@ where
10451045
E: 'a + OpaqueEncoder,
10461046
{
10471047
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
1048-
if *self == DUMMY_SP {
1048+
let span_data = self.data();
1049+
if self.is_dummy() {
10491050
TAG_PARTIAL_SPAN.encode(s)?;
1050-
return SyntaxContext::root().encode(s);
1051+
return span_data.ctxt.encode(s);
10511052
}
10521053

1053-
let span_data = self.data();
10541054
let pos = s.source_map.byte_pos_to_line_and_col(span_data.lo);
10551055
let partial_span = match &pos {
10561056
Some((file_lo, _, _)) => !file_lo.contains(span_data.hi),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
# FIXME https://github.com/rust-lang/rust/issues/78911
4+
# ignore-32bit wrong/no cross compiler and sometimes we pass wrong gcc args (-m64)
5+
6+
# Regression test for issue #83112
7+
# The generated test harness code contains spans with a dummy location,
8+
# but a non-dummy SyntaxContext. Previously, the incremental cache was encoding
9+
# these spans as a full span (with a source file index), instead of skipping
10+
# the encoding of the location information. If the file gest moved, the hash
11+
# of the span will be unchanged (since it has a dummy location), so the incr
12+
# cache would end up try to load a non-existent file using the previously
13+
# enccoded source file id.
14+
15+
SRC=$(TMPDIR)/src
16+
INCR=$(TMPDIR)/incr
17+
18+
all:
19+
mkdir $(SRC)
20+
mkdir $(SRC)/mydir
21+
mkdir $(INCR)
22+
cp main.rs $(SRC)/main.rs
23+
$(RUSTC) --test -C incremental=$(INCR) $(SRC)/main.rs
24+
mv $(SRC)/main.rs $(SRC)/mydir/main.rs
25+
$(RUSTC) --test -C incremental=$(INCR) $(SRC)/mydir/main.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

0 commit comments

Comments
 (0)