Skip to content

Commit 63b97ea

Browse files
Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable.
1 parent 9a4e5df commit 63b97ea

File tree

6 files changed

+111
-137
lines changed

6 files changed

+111
-137
lines changed

src/librustc/ich/impls_syntax.rs

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

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

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

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

src/librustc/ty/maps/on_disk_cache.rs

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

656656
let file_lo = self.file_index_to_file(file_lo_index);
657-
let lo = file_lo.lines.borrow()[line_lo - 1] + col_lo;
657+
let lo = file_lo.lines[line_lo - 1] + col_lo;
658658
let hi = lo + len;
659659

660660
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
@@ -1180,9 +1180,9 @@ impl<'a, 'tcx> CrateMetadata {
11801180
src_hash,
11811181
start_pos,
11821182
end_pos,
1183-
lines,
1184-
multibyte_chars,
1185-
non_narrow_chars,
1183+
mut lines,
1184+
mut multibyte_chars,
1185+
mut non_narrow_chars,
11861186
name_hash,
11871187
.. } = filemap_to_import;
11881188

@@ -1193,15 +1193,12 @@ impl<'a, 'tcx> CrateMetadata {
11931193
// `CodeMap::new_imported_filemap()` will then translate those
11941194
// coordinates to their new global frame of reference when the
11951195
// offset of the FileMap is known.
1196-
let mut lines = lines.into_inner();
11971196
for pos in &mut lines {
11981197
*pos = *pos - start_pos;
11991198
}
1200-
let mut multibyte_chars = multibyte_chars.into_inner();
12011199
for mbc in &mut multibyte_chars {
12021200
mbc.pos = mbc.pos - start_pos;
12031201
}
1204-
let mut non_narrow_chars = non_narrow_chars.into_inner();
12051202
for swc in &mut non_narrow_chars {
12061203
*swc = *swc - start_pos;
12071204
}

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: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ pub struct StringReader<'a> {
5252
pub filemap: Lrc<syntax_pos::FileMap>,
5353
/// Stop reading src at this index.
5454
pub 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-
pub save_new_lines_and_multibyte: bool,
5955
// cached:
6056
peek_tok: token::Token,
6157
peek_span: Span,
@@ -190,7 +186,6 @@ impl<'a> StringReader<'a> {
190186
ch: Some('\n'),
191187
filemap,
192188
end_src_index: src.len(),
193-
save_new_lines_and_multibyte: true,
194189
// dummy values; not read
195190
peek_tok: token::Eof,
196191
peek_span: syntax_pos::DUMMY_SP,
@@ -227,7 +222,6 @@ impl<'a> StringReader<'a> {
227222
let mut sr = StringReader::new_raw_internal(sess, begin.fm, None);
228223

229224
// Seek the lexer to the right byte range.
230-
sr.save_new_lines_and_multibyte = false;
231225
sr.next_pos = span.lo();
232226
sr.end_src_index = sr.src_index(span.hi());
233227

@@ -460,18 +454,6 @@ impl<'a> StringReader<'a> {
460454
let next_ch = char_at(&self.src, next_src_index);
461455
let next_ch_len = next_ch.len_utf8();
462456

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

0 commit comments

Comments
 (0)