Skip to content

Commit f5bd1ca

Browse files
incr.comp.: Make Span decoding more consistent so it doesn't mess up -Zincremental-verify-ich
1 parent 1c0e611 commit f5bd1ca

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/librustc_metadata/decoder.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,23 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
273273
let lo = BytePos::decode(self)?;
274274
let hi = BytePos::decode(self)?;
275275

276+
if lo == BytePos(0) && hi == BytePos(0) {
277+
// Don't try to rebase DUMMY_SP. Otherwise it will look like a valid
278+
// Span again.
279+
return Ok(DUMMY_SP)
280+
}
281+
282+
if hi < lo {
283+
// Consistently map invalid spans to DUMMY_SP.
284+
return Ok(DUMMY_SP)
285+
}
286+
276287
let sess = if let Some(sess) = self.sess {
277288
sess
278289
} else {
279290
bug!("Cannot decode Span without Session.")
280291
};
281292

282-
let (lo, hi) = if lo > hi {
283-
// Currently macro expansion sometimes produces invalid Span values
284-
// where lo > hi. In order not to crash the compiler when trying to
285-
// translate these values, let's transform them into something we
286-
// can handle (and which will produce useful debug locations at
287-
// least some of the time).
288-
// This workaround is only necessary as long as macro expansion is
289-
// not fixed. FIXME(#23480)
290-
(lo, lo)
291-
} else {
292-
(lo, hi)
293-
};
294-
295293
let imported_filemaps = self.cdata().imported_filemaps(&sess.codemap());
296294
let filemap = {
297295
// Optimize for the case that most spans within a translated item
@@ -321,6 +319,16 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
321319
}
322320
};
323321

322+
// Make sure our binary search above is correct.
323+
debug_assert!(lo >= filemap.original_start_pos &&
324+
lo <= filemap.original_end_pos);
325+
326+
if hi < filemap.original_start_pos || hi > filemap.original_end_pos {
327+
// `hi` points to a different FileMap than `lo` which is invalid.
328+
// Again, map invalid Spans to DUMMY_SP.
329+
return Ok(DUMMY_SP)
330+
}
331+
324332
let lo = (lo + filemap.translated_filemap.start_pos) - filemap.original_start_pos;
325333
let hi = (hi + filemap.translated_filemap.start_pos) - filemap.original_start_pos;
326334

0 commit comments

Comments
 (0)