Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't encode file information for span with a dummy location #83132

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,12 @@ where
E: 'a + OpaqueEncoder,
{
fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> {
if *self == DUMMY_SP {
let span_data = self.data();
if self.is_dummy() {
TAG_PARTIAL_SPAN.encode(s)?;
return SyntaxContext::root().encode(s);
return span_data.ctxt.encode(s);
}

let span_data = self.data();
let pos = s.source_map.byte_pos_to_line_and_col(span_data.lo);
let partial_span = match &pos {
Some((file_lo, _, _)) => !file_lo.contains(span_data.hi),
Expand Down
25 changes: 25 additions & 0 deletions src/test/run-make/issue-83112-incr-test-moved-file/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include ../../run-make-fulldeps/tools.mk

# FIXME https://github.com/rust-lang/rust/issues/78911
# ignore-32bit wrong/no cross compiler and sometimes we pass wrong gcc args (-m64)

# Regression test for issue #83112
# The generated test harness code contains spans with a dummy location,
# but a non-dummy SyntaxContext. Previously, the incremental cache was encoding
# these spans as a full span (with a source file index), instead of skipping
# the encoding of the location information. If the file gest moved, the hash
# of the span will be unchanged (since it has a dummy location), so the incr
# cache would end up try to load a non-existent file using the previously
# enccoded source file id.

SRC=$(TMPDIR)/src
INCR=$(TMPDIR)/incr

all:
mkdir $(SRC)
mkdir $(SRC)/mydir
mkdir $(INCR)
cp main.rs $(SRC)/main.rs
$(RUSTC) --test -C incremental=$(INCR) $(SRC)/main.rs
mv $(SRC)/main.rs $(SRC)/mydir/main.rs
$(RUSTC) --test -C incremental=$(INCR) $(SRC)/mydir/main.rs
1 change: 1 addition & 0 deletions src/test/run-make/issue-83112-incr-test-moved-file/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}