Skip to content

Commit 6bf6d50

Browse files
committed
Auto merge of #52953 - dsciarra:mv-codemap-sourcemap, r=petrochenkov
Rename CodeMap/FileMap to SourceMap/SourceFile A first renaming for #51574
2 parents f28f648 + 6138c82 commit 6bf6d50

File tree

164 files changed

+879
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+879
-858
lines changed

src/libproc_macro/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use syntax::errors::DiagnosticBuilder;
6363
use syntax::parse::{self, token};
6464
use syntax::symbol::Symbol;
6565
use syntax::tokenstream;
66-
use syntax_pos::{FileMap, Pos, FileName};
66+
use syntax_pos::{Pos, FileName};
6767

6868
/// The main type provided by this crate, representing an abstract stream of
6969
/// tokens, or, more specifically, a sequence of token trees.
@@ -308,7 +308,7 @@ impl Span {
308308
#[unstable(feature = "proc_macro_span", issue = "38356")]
309309
pub fn source_file(&self) -> SourceFile {
310310
SourceFile {
311-
filemap: __internal::lookup_char_pos(self.0.lo()).file,
311+
source_file: __internal::lookup_char_pos(self.0.lo()).file,
312312
}
313313
}
314314

@@ -419,7 +419,7 @@ impl !Sync for LineColumn {}
419419
#[unstable(feature = "proc_macro_span", issue = "38356")]
420420
#[derive(Clone)]
421421
pub struct SourceFile {
422-
filemap: Lrc<FileMap>,
422+
source_file: Lrc<syntax_pos::SourceFile>,
423423
}
424424

425425
#[unstable(feature = "proc_macro_span", issue = "38356")]
@@ -432,17 +432,17 @@ impl SourceFile {
432432
///
433433
/// ### Note
434434
/// If the code span associated with this `SourceFile` was generated by an external macro, this
435-
/// may not be an actual path on the filesystem. Use [`is_real`] to check.
435+
/// macro, this may not be an actual path on the filesystem. Use [`is_real`] to check.
436436
///
437437
/// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on
438438
/// the command line, the path as given may not actually be valid.
439439
///
440440
/// [`is_real`]: #method.is_real
441441
#[unstable(feature = "proc_macro_span", issue = "38356")]
442442
pub fn path(&self) -> PathBuf {
443-
match self.filemap.name {
443+
match self.source_file.name {
444444
FileName::Real(ref path) => path.clone(),
445-
_ => PathBuf::from(self.filemap.name.to_string())
445+
_ => PathBuf::from(self.source_file.name.to_string())
446446
}
447447
}
448448

@@ -453,7 +453,7 @@ impl SourceFile {
453453
// This is a hack until intercrate spans are implemented and we can have real source files
454454
// for spans generated in external macros.
455455
// https://github.com/rust-lang/rust/pull/43604#issuecomment-333334368
456-
self.filemap.is_real_file()
456+
self.source_file.is_real_file()
457457
}
458458
}
459459

@@ -471,7 +471,7 @@ impl fmt::Debug for SourceFile {
471471
#[unstable(feature = "proc_macro_span", issue = "38356")]
472472
impl PartialEq for SourceFile {
473473
fn eq(&self, other: &Self) -> bool {
474-
Lrc::ptr_eq(&self.filemap, &other.filemap)
474+
Lrc::ptr_eq(&self.source_file, &other.source_file)
475475
}
476476
}
477477

@@ -1186,7 +1186,7 @@ pub mod __internal {
11861186
use super::{TokenStream, LexError, Span};
11871187

11881188
pub fn lookup_char_pos(pos: BytePos) -> Loc {
1189-
with_sess(|sess, _| sess.codemap().lookup_char_pos(pos))
1189+
with_sess(|sess, _| sess.source_map().lookup_char_pos(pos))
11901190
}
11911191

11921192
pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {

src/librustc/hir/lowering.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use syntax::errors;
6868
use syntax::ext::hygiene::{Mark, SyntaxContext};
6969
use syntax::print::pprust;
7070
use syntax::ptr::P;
71-
use syntax::codemap::{self, respan, CompilerDesugaringKind, Spanned};
71+
use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
7272
use syntax::std_inject;
7373
use syntax::symbol::{keywords, Symbol};
7474
use syntax::tokenstream::{Delimited, TokenStream, TokenTree};
@@ -614,14 +614,14 @@ impl<'a> LoweringContext<'a> {
614614

615615
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
616616
let mark = Mark::fresh(Mark::root());
617-
mark.set_expn_info(codemap::ExpnInfo {
617+
mark.set_expn_info(source_map::ExpnInfo {
618618
call_site: span,
619619
def_site: Some(span),
620-
format: codemap::CompilerDesugaring(reason),
620+
format: source_map::CompilerDesugaring(reason),
621621
allow_internal_unstable: true,
622622
allow_internal_unsafe: false,
623623
local_inner_macros: false,
624-
edition: codemap::hygiene::default_edition(),
624+
edition: source_map::hygiene::default_edition(),
625625
});
626626
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
627627
}
@@ -3621,7 +3621,7 @@ impl<'a> LoweringContext<'a> {
36213621
let tail = block.expr.take().map_or_else(
36223622
|| {
36233623
let LoweredNodeId { node_id, hir_id } = this.next_id();
3624-
let span = this.sess.codemap().end_point(unstable_span);
3624+
let span = this.sess.source_map().end_point(unstable_span);
36253625
hir::Expr {
36263626
id: node_id,
36273627
span,

src/librustc/hir/map/collector.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use middle::cstore::CrateStore;
1818
use session::CrateDisambiguator;
1919
use std::iter::repeat;
2020
use syntax::ast::{NodeId, CRATE_NODE_ID};
21-
use syntax::codemap::CodeMap;
21+
use syntax::source_map::SourceMap;
2222
use syntax_pos::Span;
2323

2424
use ich::StableHashingContext;
@@ -122,7 +122,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
122122
pub(super) fn finalize_and_compute_crate_hash(mut self,
123123
crate_disambiguator: CrateDisambiguator,
124124
cstore: &dyn CrateStore,
125-
codemap: &CodeMap,
125+
source_map: &SourceMap,
126126
commandline_args_hash: u64)
127127
-> (Vec<MapEntry<'hir>>, Svh) {
128128
self
@@ -155,11 +155,11 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
155155
// If we included the full mapping in the SVH, we could only have
156156
// reproducible builds by compiling from the same directory. So we just
157157
// hash the result of the mapping instead of the mapping itself.
158-
let mut source_file_names: Vec<_> = codemap
158+
let mut source_file_names: Vec<_> = source_map
159159
.files()
160160
.iter()
161-
.filter(|filemap| CrateNum::from_u32(filemap.crate_of_origin) == LOCAL_CRATE)
162-
.map(|filemap| filemap.name_hash)
161+
.filter(|source_file| CrateNum::from_u32(source_file.crate_of_origin) == LOCAL_CRATE)
162+
.map(|source_file| source_file.name_hash)
163163
.collect();
164164

165165
source_file_names.sort_unstable();

src/librustc/hir/map/definitions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ define_global_metadata_kind!(pub enum GlobalMetaDataKind {
739739
LangItems,
740740
LangItemsMissing,
741741
NativeLibraries,
742-
CodeMap,
742+
SourceMap,
743743
Impls,
744744
ExportedSymbols
745745
});

src/librustc/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use middle::cstore::CrateStore;
2424
use rustc_target::spec::abi::Abi;
2525
use rustc_data_structures::svh::Svh;
2626
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
27-
use syntax::codemap::Spanned;
27+
use syntax::source_map::Spanned;
2828
use syntax::ext::base::MacroKind;
2929
use syntax_pos::{Span, DUMMY_SP};
3030

@@ -1202,7 +1202,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
12021202
let cmdline_args = sess.opts.dep_tracking_hash();
12031203
collector.finalize_and_compute_crate_hash(crate_disambiguator,
12041204
cstore,
1205-
sess.codemap(),
1205+
sess.source_map(),
12061206
cmdline_args)
12071207
};
12081208

src/librustc/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use util::nodemap::{NodeMap, FxHashSet};
2424
use mir::mono::Linkage;
2525

2626
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
27-
use syntax::codemap::{self, Spanned};
27+
use syntax::source_map::{self, Spanned};
2828
use rustc_target::spec::abi::Abi;
2929
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
3030
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
@@ -1100,7 +1100,7 @@ pub type Stmt = Spanned<StmtKind>;
11001100
impl fmt::Debug for StmtKind {
11011101
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11021102
// Sadness.
1103-
let spanned = codemap::dummy_spanned(self.clone());
1103+
let spanned = source_map::dummy_spanned(self.clone());
11041104
write!(f,
11051105
"stmt({}: {})",
11061106
spanned.node.id(),

src/librustc/hir/print.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use self::AnnNode::*;
1212

1313
use rustc_target::spec::abi::Abi;
1414
use syntax::ast;
15-
use syntax::codemap::{CodeMap, Spanned};
15+
use syntax::source_map::{SourceMap, Spanned};
1616
use syntax::parse::ParseSess;
1717
use syntax::parse::lexer::comments;
1818
use syntax::print::pp::{self, Breaks};
@@ -85,7 +85,7 @@ impl PpAnn for hir::Crate {
8585

8686
pub struct State<'a> {
8787
pub s: pp::Printer<'a>,
88-
cm: Option<&'a CodeMap>,
88+
cm: Option<&'a SourceMap>,
8989
comments: Option<Vec<comments::Comment>>,
9090
literals: Peekable<vec::IntoIter<comments::Literal>>,
9191
cur_cmnt: usize,
@@ -129,7 +129,7 @@ pub const default_columns: usize = 78;
129129
/// Requires you to pass an input filename and reader so that
130130
/// it can scan the input text for comments and literals to
131131
/// copy forward.
132-
pub fn print_crate<'a>(cm: &'a CodeMap,
132+
pub fn print_crate<'a>(cm: &'a SourceMap,
133133
sess: &ParseSess,
134134
krate: &hir::Crate,
135135
filename: FileName,
@@ -149,7 +149,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
149149
}
150150

151151
impl<'a> State<'a> {
152-
pub fn new_from_input(cm: &'a CodeMap,
152+
pub fn new_from_input(cm: &'a SourceMap,
153153
sess: &ParseSess,
154154
filename: FileName,
155155
input: &mut dyn Read,
@@ -173,7 +173,7 @@ impl<'a> State<'a> {
173173
})
174174
}
175175

176-
pub fn new(cm: &'a CodeMap,
176+
pub fn new(cm: &'a SourceMap,
177177
out: Box<dyn Write + 'a>,
178178
ann: &'a dyn PpAnn,
179179
comments: Option<Vec<comments::Comment>>,

src/librustc/ich/caching_codemap_view.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::sync::Lrc;
12-
use syntax::codemap::CodeMap;
13-
use syntax_pos::{BytePos, FileMap};
12+
use syntax::source_map::SourceMap;
13+
use syntax_pos::{BytePos, SourceFile};
1414

1515
#[derive(Clone)]
1616
struct CacheEntry {
1717
time_stamp: usize,
1818
line_number: usize,
1919
line_start: BytePos,
2020
line_end: BytePos,
21-
file: Lrc<FileMap>,
21+
file: Lrc<SourceFile>,
2222
file_index: usize,
2323
}
2424

2525
#[derive(Clone)]
26-
pub struct CachingCodemapView<'cm> {
27-
codemap: &'cm CodeMap,
26+
pub struct CachingSourceMapView<'cm> {
27+
source_map: &'cm SourceMap,
2828
line_cache: [CacheEntry; 3],
2929
time_stamp: usize,
3030
}
3131

32-
impl<'cm> CachingCodemapView<'cm> {
33-
pub fn new(codemap: &'cm CodeMap) -> CachingCodemapView<'cm> {
34-
let files = codemap.files();
32+
impl<'cm> CachingSourceMapView<'cm> {
33+
pub fn new(source_map: &'cm SourceMap) -> CachingSourceMapView<'cm> {
34+
let files = source_map.files();
3535
let first_file = files[0].clone();
3636
let entry = CacheEntry {
3737
time_stamp: 0,
@@ -42,16 +42,16 @@ impl<'cm> CachingCodemapView<'cm> {
4242
file_index: 0,
4343
};
4444

45-
CachingCodemapView {
46-
codemap,
45+
CachingSourceMapView {
46+
source_map,
4747
line_cache: [entry.clone(), entry.clone(), entry.clone()],
4848
time_stamp: 0,
4949
}
5050
}
5151

5252
pub fn byte_pos_to_line_and_col(&mut self,
5353
pos: BytePos)
54-
-> Option<(Lrc<FileMap>, usize, BytePos)> {
54+
-> Option<(Lrc<SourceFile>, usize, BytePos)> {
5555
self.time_stamp += 1;
5656

5757
// Check if the position is in one of the cached lines
@@ -78,9 +78,9 @@ impl<'cm> CachingCodemapView<'cm> {
7878
// If the entry doesn't point to the correct file, fix it up
7979
if pos < cache_entry.file.start_pos || pos >= cache_entry.file.end_pos {
8080
let file_valid;
81-
if self.codemap.files().len() > 0 {
82-
let file_index = self.codemap.lookup_filemap_idx(pos);
83-
let file = self.codemap.files()[file_index].clone();
81+
if self.source_map.files().len() > 0 {
82+
let file_index = self.source_map.lookup_source_file_idx(pos);
83+
let file = self.source_map.files()[file_index].clone();
8484

8585
if pos >= file.start_pos && pos < file.end_pos {
8686
cache_entry.file = file;

src/librustc/ich/hcx.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hir;
1212
use hir::def_id::{DefId, DefIndex};
1313
use hir::map::DefPathHash;
1414
use hir::map::definitions::Definitions;
15-
use ich::{self, CachingCodemapView, Fingerprint};
15+
use ich::{self, CachingSourceMapView, Fingerprint};
1616
use middle::cstore::CrateStore;
1717
use ty::{TyCtxt, fast_reject};
1818
use mir::interpret::AllocId;
@@ -25,7 +25,7 @@ use std::cell::RefCell;
2525

2626
use syntax::ast;
2727

28-
use syntax::codemap::CodeMap;
28+
use syntax::source_map::SourceMap;
2929
use syntax::ext::hygiene::SyntaxContext;
3030
use syntax::symbol::Symbol;
3131
use syntax_pos::{Span, DUMMY_SP};
@@ -57,9 +57,9 @@ pub struct StableHashingContext<'a> {
5757
node_id_hashing_mode: NodeIdHashingMode,
5858

5959
// Very often, we are hashing something that does not need the
60-
// CachingCodemapView, so we initialize it lazily.
61-
raw_codemap: &'a CodeMap,
62-
caching_codemap: Option<CachingCodemapView<'a>>,
60+
// CachingSourceMapView, so we initialize it lazily.
61+
raw_source_map: &'a SourceMap,
62+
caching_source_map: Option<CachingSourceMapView<'a>>,
6363

6464
pub(super) alloc_id_recursion_tracker: FxHashSet<AllocId>,
6565
}
@@ -100,8 +100,8 @@ impl<'a> StableHashingContext<'a> {
100100
body_resolver: BodyResolver(krate),
101101
definitions,
102102
cstore,
103-
caching_codemap: None,
104-
raw_codemap: sess.codemap(),
103+
caching_source_map: None,
104+
raw_source_map: sess.source_map(),
105105
hash_spans: hash_spans_initial,
106106
hash_bodies: true,
107107
node_id_hashing_mode: NodeIdHashingMode::HashDefPath,
@@ -169,13 +169,13 @@ impl<'a> StableHashingContext<'a> {
169169
}
170170

171171
#[inline]
172-
pub fn codemap(&mut self) -> &mut CachingCodemapView<'a> {
173-
match self.caching_codemap {
172+
pub fn source_map(&mut self) -> &mut CachingSourceMapView<'a> {
173+
match self.caching_source_map {
174174
Some(ref mut cm) => {
175175
cm
176176
}
177177
ref mut none => {
178-
*none = Some(CachingCodemapView::new(self.raw_codemap));
178+
*none = Some(CachingSourceMapView::new(self.raw_source_map));
179179
none.as_mut().unwrap()
180180
}
181181
}
@@ -308,9 +308,9 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
308308

309309
// Hash a span in a stable way. We can't directly hash the span's BytePos
310310
// fields (that would be similar to hashing pointers, since those are just
311-
// offsets into the CodeMap). Instead, we hash the (file name, line, column)
312-
// triple, which stays the same even if the containing FileMap has moved
313-
// within the CodeMap.
311+
// offsets into the SourceMap). Instead, we hash the (file name, line, column)
312+
// triple, which stays the same even if the containing SourceFile has moved
313+
// within the SourceMap.
314314
// Also note that we are hashing byte offsets for the column, not unicode
315315
// codepoint offsets. For the purpose of the hash that's sufficient.
316316
// Also, hashing filenames is expensive so we avoid doing it twice when the
@@ -340,7 +340,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
340340
return std_hash::Hash::hash(&TAG_INVALID_SPAN, hasher);
341341
}
342342

343-
let (file_lo, line_lo, col_lo) = match hcx.codemap()
343+
let (file_lo, line_lo, col_lo) = match hcx.source_map()
344344
.byte_pos_to_line_and_col(span.lo) {
345345
Some(pos) => pos,
346346
None => {

0 commit comments

Comments
 (0)