Skip to content

Commit

Permalink
ICH: Make CachingCodemapView robustly handle invalid spans.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Sep 6, 2016
1 parent 7310a8f commit 3057b7b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
36 changes: 27 additions & 9 deletions src/librustc_incremental/calculate_svh/caching_codemap_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ impl<'tcx> CachingCodemapView<'tcx> {

pub fn byte_pos_to_line_and_col(&mut self,
pos: BytePos)
-> (Rc<FileMap>, usize, BytePos) {
-> Option<(Rc<FileMap>, usize, BytePos)> {
self.time_stamp += 1;

// Check if the position is in one of the cached lines
for cache_entry in self.line_cache.iter_mut() {
if pos >= cache_entry.line_start && pos < cache_entry.line_end {
cache_entry.time_stamp = self.time_stamp;
return (cache_entry.file.clone(),
cache_entry.line_number,
pos - cache_entry.line_start);
return Some((cache_entry.file.clone(),
cache_entry.line_number,
pos - cache_entry.line_start));
}
}

Expand All @@ -78,8 +78,26 @@ impl<'tcx> CachingCodemapView<'tcx> {

// If the entry doesn't point to the correct file, fix it up
if pos < cache_entry.file.start_pos || pos >= cache_entry.file.end_pos {
let file_index = self.codemap.lookup_filemap_idx(pos);
cache_entry.file = self.codemap.files.borrow()[file_index].clone();
let file_valid;
let files = self.codemap.files.borrow();

if files.len() > 0 {
let file_index = self.codemap.lookup_filemap_idx(pos);
let file = files[file_index].clone();

if pos >= file.start_pos && pos < file.end_pos {
cache_entry.file = file;
file_valid = true;
} else {
file_valid = false;
}
} else {
file_valid = false;
}

if !file_valid {
return None;
}
}

let line_index = cache_entry.file.lookup_line(pos).unwrap();
Expand All @@ -90,8 +108,8 @@ impl<'tcx> CachingCodemapView<'tcx> {
cache_entry.line_end = line_bounds.1;
cache_entry.time_stamp = self.time_stamp;

return (cache_entry.file.clone(),
cache_entry.line_number,
pos - cache_entry.line_start);
return Some((cache_entry.file.clone(),
cache_entry.line_number,
pos - cache_entry.line_start));
}
}
15 changes: 9 additions & 6 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
span.hi
};

let (file1, line1, col1) = self.codemap.byte_pos_to_line_and_col(span.lo);
let (file2, line2, col2) = self.codemap.byte_pos_to_line_and_col(span_hi);
let loc1 = self.codemap.byte_pos_to_line_and_col(span.lo);
let loc2 = self.codemap.byte_pos_to_line_and_col(span_hi);

let expansion_kind = match span.expn_id {
NO_EXPANSION => SawSpanExpnKind::NoExpansion,
COMMAND_LINE_EXPN => SawSpanExpnKind::CommandLine,
_ => SawSpanExpnKind::SomeExpansion,
};

SawSpan(&file1.name[..], line1, col1,
&file2.name[..], line2, col2,
expansion_kind).hash(self.st);
SawSpan(loc1.as_ref().map(|&(ref fm, line, col)| (&fm.name[..], line, col)),
loc2.as_ref().map(|&(ref fm, line, col)| (&fm.name[..], line, col)),
expansion_kind)
.hash(self.st);

if expansion_kind == SawSpanExpnKind::SomeExpansion {
let call_site = self.codemap.codemap().source_callsite(span);
Expand Down Expand Up @@ -171,7 +172,9 @@ enum SawAbiComponent<'a> {
SawAssocTypeBinding,
SawAttribute(ast::AttrStyle),
SawMacroDef,
SawSpan(&'a str, usize, BytePos, &'a str, usize, BytePos, SawSpanExpnKind),
SawSpan(Option<(&'a str, usize, BytePos)>,
Option<(&'a str, usize, BytePos)>,
SawSpanExpnKind),
}

/// SawExprComponent carries all of the information that we want
Expand Down

0 comments on commit 3057b7b

Please sign in to comment.