Skip to content

Rename CodeMap/FileMap to SourceMap/SourceFile #52953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ use syntax::errors::DiagnosticBuilder;
use syntax::parse::{self, token};
use syntax::symbol::Symbol;
use syntax::tokenstream;
use syntax_pos::{FileMap, Pos, FileName};
use syntax_pos::{Pos, FileName};

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

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

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

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

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

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

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

pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {
10 changes: 5 additions & 5 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::codemap::{self, respan, CompilerDesugaringKind, Spanned};
use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned};
use syntax::std_inject;
use syntax::symbol::{keywords, Symbol};
use syntax::tokenstream::{Delimited, TokenStream, TokenTree};
@@ -614,14 +614,14 @@ impl<'a> LoweringContext<'a> {

fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(codemap::ExpnInfo {
mark.set_expn_info(source_map::ExpnInfo {
call_site: span,
def_site: Some(span),
format: codemap::CompilerDesugaring(reason),
format: source_map::CompilerDesugaring(reason),
allow_internal_unstable: true,
allow_internal_unsafe: false,
local_inner_macros: false,
edition: codemap::hygiene::default_edition(),
edition: source_map::hygiene::default_edition(),
});
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
@@ -3621,7 +3621,7 @@ impl<'a> LoweringContext<'a> {
let tail = block.expr.take().map_or_else(
|| {
let LoweredNodeId { node_id, hir_id } = this.next_id();
let span = this.sess.codemap().end_point(unstable_span);
let span = this.sess.source_map().end_point(unstable_span);
hir::Expr {
id: node_id,
span,
10 changes: 5 additions & 5 deletions src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ use middle::cstore::CrateStore;
use session::CrateDisambiguator;
use std::iter::repeat;
use syntax::ast::{NodeId, CRATE_NODE_ID};
use syntax::codemap::CodeMap;
use syntax::source_map::SourceMap;
use syntax_pos::Span;

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

source_file_names.sort_unstable();
2 changes: 1 addition & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
@@ -739,7 +739,7 @@ define_global_metadata_kind!(pub enum GlobalMetaDataKind {
LangItems,
LangItemsMissing,
NativeLibraries,
CodeMap,
SourceMap,
Impls,
ExportedSymbols
});
4 changes: 2 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ use middle::cstore::CrateStore;
use rustc_target::spec::abi::Abi;
use rustc_data_structures::svh::Svh;
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
use syntax::codemap::Spanned;
use syntax::source_map::Spanned;
use syntax::ext::base::MacroKind;
use syntax_pos::{Span, DUMMY_SP};

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

4 changes: 2 additions & 2 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ use util::nodemap::{NodeMap, FxHashSet};
use mir::mono::Linkage;

use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
use syntax::codemap::{self, Spanned};
use syntax::source_map::{self, Spanned};
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
@@ -1100,7 +1100,7 @@ pub type Stmt = Spanned<StmtKind>;
impl fmt::Debug for StmtKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Sadness.
let spanned = codemap::dummy_spanned(self.clone());
let spanned = source_map::dummy_spanned(self.clone());
write!(f,
"stmt({}: {})",
spanned.node.id(),
10 changes: 5 additions & 5 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ pub use self::AnnNode::*;

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

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

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

pub fn new(cm: &'a CodeMap,
pub fn new(cm: &'a SourceMap,
out: Box<dyn Write + 'a>,
ann: &'a dyn PpAnn,
comments: Option<Vec<comments::Comment>>,
28 changes: 14 additions & 14 deletions src/librustc/ich/caching_codemap_view.rs
Original file line number Diff line number Diff line change
@@ -9,29 +9,29 @@
// except according to those terms.

use rustc_data_structures::sync::Lrc;
use syntax::codemap::CodeMap;
use syntax_pos::{BytePos, FileMap};
use syntax::source_map::SourceMap;
use syntax_pos::{BytePos, SourceFile};

#[derive(Clone)]
struct CacheEntry {
time_stamp: usize,
line_number: usize,
line_start: BytePos,
line_end: BytePos,
file: Lrc<FileMap>,
file: Lrc<SourceFile>,
file_index: usize,
}

#[derive(Clone)]
pub struct CachingCodemapView<'cm> {
codemap: &'cm CodeMap,
pub struct CachingSourceMapView<'cm> {
source_map: &'cm SourceMap,
line_cache: [CacheEntry; 3],
time_stamp: usize,
}

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

CachingCodemapView {
codemap,
CachingSourceMapView {
source_map,
line_cache: [entry.clone(), entry.clone(), entry.clone()],
time_stamp: 0,
}
}

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

// Check if the position is in one of the cached lines
@@ -78,9 +78,9 @@ impl<'cm> CachingCodemapView<'cm> {
// 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_valid;
if self.codemap.files().len() > 0 {
let file_index = self.codemap.lookup_filemap_idx(pos);
let file = self.codemap.files()[file_index].clone();
if self.source_map.files().len() > 0 {
let file_index = self.source_map.lookup_source_file_idx(pos);
let file = self.source_map.files()[file_index].clone();

if pos >= file.start_pos && pos < file.end_pos {
cache_entry.file = file;
28 changes: 14 additions & 14 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use hir;
use hir::def_id::{DefId, DefIndex};
use hir::map::DefPathHash;
use hir::map::definitions::Definitions;
use ich::{self, CachingCodemapView, Fingerprint};
use ich::{self, CachingSourceMapView, Fingerprint};
use middle::cstore::CrateStore;
use ty::{TyCtxt, fast_reject};
use mir::interpret::AllocId;
@@ -25,7 +25,7 @@ use std::cell::RefCell;

use syntax::ast;

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

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

pub(super) alloc_id_recursion_tracker: FxHashSet<AllocId>,
}
@@ -100,8 +100,8 @@ impl<'a> StableHashingContext<'a> {
body_resolver: BodyResolver(krate),
definitions,
cstore,
caching_codemap: None,
raw_codemap: sess.codemap(),
caching_source_map: None,
raw_source_map: sess.source_map(),
hash_spans: hash_spans_initial,
hash_bodies: true,
node_id_hashing_mode: NodeIdHashingMode::HashDefPath,
@@ -169,13 +169,13 @@ impl<'a> StableHashingContext<'a> {
}

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

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

let (file_lo, line_lo, col_lo) = match hcx.codemap()
let (file_lo, line_lo, col_lo) = match hcx.source_map()
.byte_pos_to_line_and_col(span.lo) {
Some(pos) => pos,
None => {
Loading