@@ -24,8 +24,7 @@ pub use self::ExpnFormat::*;
24
24
25
25
use rustc_data_structures:: fx:: FxHashMap ;
26
26
use rustc_data_structures:: stable_hasher:: StableHasher ;
27
- use rustc_data_structures:: sync:: Lrc ;
28
- use std:: cell:: { RefCell , Ref } ;
27
+ use rustc_data_structures:: sync:: { Lrc , Lock , LockGuard } ;
29
28
use std:: cmp;
30
29
use std:: hash:: Hash ;
31
30
use std:: path:: { Path , PathBuf } ;
@@ -126,12 +125,12 @@ impl StableFilemapId {
126
125
//
127
126
128
127
pub struct CodeMap {
129
- pub ( super ) files : RefCell < Vec < Lrc < FileMap > > > ,
128
+ pub ( super ) files : Lock < Vec < Lrc < FileMap > > > ,
130
129
file_loader : Box < FileLoader + Sync + Send > ,
131
130
// This is used to apply the file path remapping as specified via
132
131
// --remap-path-prefix to all FileMaps allocated within this CodeMap.
133
132
path_mapping : FilePathMapping ,
134
- stable_id_to_filemap : RefCell < FxHashMap < StableFilemapId , Lrc < FileMap > > > ,
133
+ stable_id_to_filemap : Lock < FxHashMap < StableFilemapId , Lrc < FileMap > > > ,
135
134
/// In case we are in a doctest, replace all file names with the PathBuf,
136
135
/// and add the given offsets to the line info
137
136
doctest_offset : Option < ( FileName , isize ) > ,
@@ -140,10 +139,10 @@ pub struct CodeMap {
140
139
impl CodeMap {
141
140
pub fn new ( path_mapping : FilePathMapping ) -> CodeMap {
142
141
CodeMap {
143
- files : RefCell :: new ( Vec :: new ( ) ) ,
142
+ files : Lock :: new ( Vec :: new ( ) ) ,
144
143
file_loader : Box :: new ( RealFileLoader ) ,
145
144
path_mapping,
146
- stable_id_to_filemap : RefCell :: new ( FxHashMap ( ) ) ,
145
+ stable_id_to_filemap : Lock :: new ( FxHashMap ( ) ) ,
147
146
doctest_offset : None ,
148
147
}
149
148
}
@@ -161,10 +160,10 @@ impl CodeMap {
161
160
path_mapping : FilePathMapping )
162
161
-> CodeMap {
163
162
CodeMap {
164
- files : RefCell :: new ( Vec :: new ( ) ) ,
165
- file_loader,
163
+ files : Lock :: new ( Vec :: new ( ) ) ,
164
+ file_loader : file_loader ,
166
165
path_mapping,
167
- stable_id_to_filemap : RefCell :: new ( FxHashMap ( ) ) ,
166
+ stable_id_to_filemap : Lock :: new ( FxHashMap ( ) ) ,
168
167
doctest_offset : None ,
169
168
}
170
169
}
@@ -187,7 +186,7 @@ impl CodeMap {
187
186
Ok ( self . new_filemap ( filename, src) )
188
187
}
189
188
190
- pub fn files ( & self ) -> Ref < Vec < Lrc < FileMap > > > {
189
+ pub fn files ( & self ) -> LockGuard < Vec < Lrc < FileMap > > > {
191
190
self . files . borrow ( )
192
191
}
193
192
@@ -209,7 +208,6 @@ impl CodeMap {
209
208
/// intend to set the line information yourself, you should use new_filemap_and_lines.
210
209
pub fn new_filemap ( & self , filename : FileName , src : String ) -> Lrc < FileMap > {
211
210
let start_pos = self . next_start_pos ( ) ;
212
- let mut files = self . files . borrow_mut ( ) ;
213
211
214
212
// The path is used to determine the directory for loading submodules and
215
213
// include files, so it must be before remapping.
@@ -233,7 +231,7 @@ impl CodeMap {
233
231
Pos :: from_usize ( start_pos) ,
234
232
) ) ;
235
233
236
- files. push ( filemap. clone ( ) ) ;
234
+ self . files . borrow_mut ( ) . push ( filemap. clone ( ) ) ;
237
235
238
236
self . stable_id_to_filemap
239
237
. borrow_mut ( )
@@ -273,7 +271,6 @@ impl CodeMap {
273
271
mut file_local_non_narrow_chars : Vec < NonNarrowChar > )
274
272
-> Lrc < FileMap > {
275
273
let start_pos = self . next_start_pos ( ) ;
276
- let mut files = self . files . borrow_mut ( ) ;
277
274
278
275
let end_pos = Pos :: from_usize ( start_pos + source_len) ;
279
276
let start_pos = Pos :: from_usize ( start_pos) ;
@@ -297,16 +294,16 @@ impl CodeMap {
297
294
crate_of_origin,
298
295
src : None ,
299
296
src_hash,
300
- external_src : RefCell :: new ( ExternalSource :: AbsentOk ) ,
297
+ external_src : Lock :: new ( ExternalSource :: AbsentOk ) ,
301
298
start_pos,
302
299
end_pos,
303
- lines : RefCell :: new ( file_local_lines) ,
304
- multibyte_chars : RefCell :: new ( file_local_multibyte_chars) ,
305
- non_narrow_chars : RefCell :: new ( file_local_non_narrow_chars) ,
300
+ lines : Lock :: new ( file_local_lines) ,
301
+ multibyte_chars : Lock :: new ( file_local_multibyte_chars) ,
302
+ non_narrow_chars : Lock :: new ( file_local_non_narrow_chars) ,
306
303
name_hash,
307
304
} ) ;
308
305
309
- files. push ( filemap. clone ( ) ) ;
306
+ self . files . borrow_mut ( ) . push ( filemap. clone ( ) ) ;
310
307
311
308
self . stable_id_to_filemap
312
309
. borrow_mut ( )
@@ -401,8 +398,7 @@ impl CodeMap {
401
398
pub fn lookup_line ( & self , pos : BytePos ) -> Result < FileMapAndLine , Lrc < FileMap > > {
402
399
let idx = self . lookup_filemap_idx ( pos) ;
403
400
404
- let files = self . files . borrow ( ) ;
405
- let f = ( * files) [ idx] . clone ( ) ;
401
+ let f = ( * self . files . borrow ( ) ) [ idx] . clone ( ) ;
406
402
407
403
match f. lookup_line ( pos) {
408
404
Some ( line) => Ok ( FileMapAndLine { fm : f, line : line } ) ,
@@ -810,8 +806,7 @@ impl CodeMap {
810
806
/// Converts an absolute BytePos to a CharPos relative to the filemap.
811
807
pub fn bytepos_to_file_charpos ( & self , bpos : BytePos ) -> CharPos {
812
808
let idx = self . lookup_filemap_idx ( bpos) ;
813
- let files = self . files . borrow ( ) ;
814
- let map = & ( * files) [ idx] ;
809
+ let map = & ( * self . files . borrow ( ) ) [ idx] ;
815
810
816
811
// The number of extra bytes due to multibyte chars in the FileMap
817
812
let mut total_extra_bytes = 0 ;
0 commit comments