Skip to content

Commit 257d279

Browse files
Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable.
1 parent c208243 commit 257d279

File tree

6 files changed

+121
-138
lines changed

6 files changed

+121
-138
lines changed

src/librustc/ich/impls_syntax.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -455,27 +455,21 @@ impl<'a> HashStable<StableHashingContext<'a>> for FileMap {
455455
src_hash.hash_stable(hcx, hasher);
456456

457457
// We only hash the relative position within this filemap
458-
lines.with_lock(|lines| {
459-
lines.len().hash_stable(hcx, hasher);
460-
for &line in lines.iter() {
461-
stable_byte_pos(line, start_pos).hash_stable(hcx, hasher);
462-
}
463-
});
458+
lines.len().hash_stable(hcx, hasher);
459+
for &line in lines.iter() {
460+
stable_byte_pos(line, start_pos).hash_stable(hcx, hasher);
461+
}
464462

465463
// We only hash the relative position within this filemap
466-
multibyte_chars.with_lock(|multibyte_chars| {
467-
multibyte_chars.len().hash_stable(hcx, hasher);
468-
for &char_pos in multibyte_chars.iter() {
469-
stable_multibyte_char(char_pos, start_pos).hash_stable(hcx, hasher);
470-
}
471-
});
464+
multibyte_chars.len().hash_stable(hcx, hasher);
465+
for &char_pos in multibyte_chars.iter() {
466+
stable_multibyte_char(char_pos, start_pos).hash_stable(hcx, hasher);
467+
}
472468

473-
non_narrow_chars.with_lock(|non_narrow_chars| {
474-
non_narrow_chars.len().hash_stable(hcx, hasher);
475-
for &char_pos in non_narrow_chars.iter() {
476-
stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher);
477-
}
478-
});
469+
non_narrow_chars.len().hash_stable(hcx, hasher);
470+
for &char_pos in non_narrow_chars.iter() {
471+
stable_non_narrow_char(char_pos, start_pos).hash_stable(hcx, hasher);
472+
}
479473
}
480474
}
481475

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
623623
let len = BytePos::decode(self)?;
624624

625625
let file_lo = self.file_index_to_file(file_lo_index);
626-
let lo = file_lo.lines.borrow()[line_lo - 1] + col_lo;
626+
let lo = file_lo.lines[line_lo - 1] + col_lo;
627627
let hi = lo + len;
628628

629629
let expn_info_tag = u8::decode(self)?;

src/librustc_metadata/decoder.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,9 +1138,9 @@ impl<'a, 'tcx> CrateMetadata {
11381138
src_hash,
11391139
start_pos,
11401140
end_pos,
1141-
lines,
1142-
multibyte_chars,
1143-
non_narrow_chars,
1141+
mut lines,
1142+
mut multibyte_chars,
1143+
mut non_narrow_chars,
11441144
name_hash,
11451145
.. } = filemap_to_import;
11461146

@@ -1151,15 +1151,12 @@ impl<'a, 'tcx> CrateMetadata {
11511151
// `CodeMap::new_imported_filemap()` will then translate those
11521152
// coordinates to their new global frame of reference when the
11531153
// offset of the FileMap is known.
1154-
let mut lines = lines.into_inner();
11551154
for pos in &mut lines {
11561155
*pos = *pos - start_pos;
11571156
}
1158-
let mut multibyte_chars = multibyte_chars.into_inner();
11591157
for mbc in &mut multibyte_chars {
11601158
mbc.pos = mbc.pos - start_pos;
11611159
}
1162-
let mut non_narrow_chars = non_narrow_chars.into_inner();
11631160
for swc in &mut non_narrow_chars {
11641161
*swc = *swc - start_pos;
11651162
}

src/libsyntax/codemap.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,7 @@ impl CodeMap {
250250
/// Creates a new filemap and sets its line information.
251251
/// This does not ensure that only one FileMap exists per file name.
252252
pub fn new_filemap_and_lines(&self, filename: &Path, src: &str) -> Lrc<FileMap> {
253-
let fm = self.new_filemap(filename.to_owned().into(), src.to_owned());
254-
let mut byte_pos: u32 = fm.start_pos.0;
255-
for line in src.lines() {
256-
// register the start of this line
257-
fm.next_line(BytePos(byte_pos));
258-
259-
// update byte_pos to include this line and the \n at the end
260-
byte_pos += line.len() as u32 + 1;
261-
}
262-
fm
253+
self.new_filemap(filename.to_owned().into(), src.to_owned())
263254
}
264255

265256

@@ -305,9 +296,9 @@ impl CodeMap {
305296
external_src: Lock::new(ExternalSource::AbsentOk),
306297
start_pos,
307298
end_pos,
308-
lines: Lock::new(file_local_lines),
309-
multibyte_chars: Lock::new(file_local_multibyte_chars),
310-
non_narrow_chars: Lock::new(file_local_non_narrow_chars),
299+
lines: file_local_lines,
300+
multibyte_chars: file_local_multibyte_chars,
301+
non_narrow_chars: file_local_non_narrow_chars,
311302
name_hash,
312303
});
313304

@@ -345,21 +336,22 @@ impl CodeMap {
345336
match self.lookup_line(pos) {
346337
Ok(FileMapAndLine { fm: f, line: a }) => {
347338
let line = a + 1; // Line numbers start at 1
348-
let linebpos = (*f.lines.borrow())[a];
339+
let linebpos = f.lines[a];
349340
let linechpos = self.bytepos_to_file_charpos(linebpos);
350341
let col = chpos - linechpos;
351342

352343
let col_display = {
353-
let non_narrow_chars = f.non_narrow_chars.borrow();
354-
let start_width_idx = non_narrow_chars
344+
let start_width_idx = f
345+
.non_narrow_chars
355346
.binary_search_by_key(&linebpos, |x| x.pos())
356347
.unwrap_or_else(|x| x);
357-
let end_width_idx = non_narrow_chars
348+
let end_width_idx = f
349+
.non_narrow_chars
358350
.binary_search_by_key(&pos, |x| x.pos())
359351
.unwrap_or_else(|x| x);
360352
let special_chars = end_width_idx - start_width_idx;
361-
let non_narrow: usize =
362-
non_narrow_chars[start_width_idx..end_width_idx]
353+
let non_narrow: usize = f
354+
.non_narrow_chars[start_width_idx..end_width_idx]
363355
.into_iter()
364356
.map(|x| x.width())
365357
.sum();
@@ -380,12 +372,12 @@ impl CodeMap {
380372
}
381373
Err(f) => {
382374
let col_display = {
383-
let non_narrow_chars = f.non_narrow_chars.borrow();
384-
let end_width_idx = non_narrow_chars
375+
let end_width_idx = f
376+
.non_narrow_chars
385377
.binary_search_by_key(&pos, |x| x.pos())
386378
.unwrap_or_else(|x| x);
387-
let non_narrow: usize =
388-
non_narrow_chars[0..end_width_idx]
379+
let non_narrow: usize = f
380+
.non_narrow_chars[0..end_width_idx]
389381
.into_iter()
390382
.map(|x| x.width())
391383
.sum();
@@ -830,7 +822,7 @@ impl CodeMap {
830822
// The number of extra bytes due to multibyte chars in the FileMap
831823
let mut total_extra_bytes = 0;
832824

833-
for mbc in map.multibyte_chars.borrow().iter() {
825+
for mbc in map.multibyte_chars.iter() {
834826
debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos);
835827
if mbc.pos < bpos {
836828
// every character is at least one byte, so we only

src/libsyntax/parse/lexer/mod.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ pub struct StringReader<'a> {
5151
pub ch: Option<char>,
5252
pub filemap: Lrc<syntax_pos::FileMap>,
5353
/// Stop reading src at this index.
54-
end_src_index: usize,
55-
/// Whether to record new-lines and multibyte chars in filemap.
56-
/// This is only necessary the first time a filemap is lexed.
57-
/// If part of a filemap is being re-lexed, this should be set to false.
58-
save_new_lines_and_multibyte: bool,
54+
pub end_src_index: usize,
5955
// cached:
6056
peek_tok: token::Token,
6157
peek_span: Span,
@@ -188,7 +184,6 @@ impl<'a> StringReader<'a> {
188184
ch: Some('\n'),
189185
filemap,
190186
end_src_index: src.len(),
191-
save_new_lines_and_multibyte: true,
192187
// dummy values; not read
193188
peek_tok: token::Eof,
194189
peek_span: syntax_pos::DUMMY_SP,
@@ -225,7 +220,6 @@ impl<'a> StringReader<'a> {
225220
let mut sr = StringReader::new_raw_internal(sess, begin.fm, None);
226221

227222
// Seek the lexer to the right byte range.
228-
sr.save_new_lines_and_multibyte = false;
229223
sr.next_pos = span.lo();
230224
sr.end_src_index = sr.src_index(span.hi());
231225

@@ -458,18 +452,6 @@ impl<'a> StringReader<'a> {
458452
let next_ch = char_at(&self.src, next_src_index);
459453
let next_ch_len = next_ch.len_utf8();
460454

461-
if self.ch.unwrap() == '\n' {
462-
if self.save_new_lines_and_multibyte {
463-
self.filemap.next_line(self.next_pos);
464-
}
465-
}
466-
if next_ch_len > 1 {
467-
if self.save_new_lines_and_multibyte {
468-
self.filemap.record_multibyte_char(self.next_pos, next_ch_len);
469-
}
470-
}
471-
self.filemap.record_width(self.next_pos, next_ch);
472-
473455
self.ch = Some(next_ch);
474456
self.pos = self.next_pos;
475457
self.next_pos = self.next_pos + Pos::from_usize(next_ch_len);

0 commit comments

Comments
 (0)