Skip to content

Commit

Permalink
mv FileMap SourceFile
Browse files Browse the repository at this point in the history
  • Loading branch information
dsciarra committed Aug 19, 2018
1 parent c655473 commit d6dcbcd
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 126 deletions.
6 changes: 3 additions & 3 deletions src/libproc_macro/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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")]
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ich/caching_codemap_view.rs
Expand Up @@ -10,15 +10,15 @@

use rustc_data_structures::sync::Lrc;
use syntax::codemap::SourceMap;
use syntax_pos::{BytePos, FileMap};
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,
}

Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'cm> CachingCodemapView<'cm> {

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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/hcx.rs
Expand Up @@ -309,7 +309,7 @@ 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 SourceMap). Instead, we hash the (file name, line, column)
// triple, which stays the same even if the containing FileMap has moved
// 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.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ich/impls_syntax.rs
Expand Up @@ -21,7 +21,7 @@ use syntax::feature_gate;
use syntax::parse::token;
use syntax::symbol::{InternedString, LocalInternedString};
use syntax::tokenstream;
use syntax_pos::FileMap;
use syntax_pos::SourceFile;

use hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};

Expand Down Expand Up @@ -427,11 +427,11 @@ impl_stable_hash_for!(enum ::syntax_pos::FileName {
Custom(s)
});

impl<'a> HashStable<StableHashingContext<'a>> for FileMap {
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let FileMap {
let SourceFile {
name: _, // We hash the smaller name_hash instead of this
name_hash,
name_was_remapped,
Expand Down
32 changes: 16 additions & 16 deletions src/librustc/ty/query/on_disk_cache.rs
Expand Up @@ -27,7 +27,7 @@ use session::{CrateDisambiguator, Session};
use std::mem;
use syntax::ast::NodeId;
use syntax::codemap::{SourceMap, StableFilemapId};
use syntax_pos::{BytePos, Span, DUMMY_SP, FileMap};
use syntax_pos::{BytePos, Span, DUMMY_SP, SourceFile};
use syntax_pos::hygiene::{Mark, SyntaxContext, ExpnInfo};
use ty;
use ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
Expand Down Expand Up @@ -63,10 +63,10 @@ pub struct OnDiskCache<'sess> {
cnum_map: Once<IndexVec<CrateNum, Option<CrateNum>>>,

codemap: &'sess SourceMap,
file_index_to_stable_id: FxHashMap<FileMapIndex, StableFilemapId>,
file_index_to_stable_id: FxHashMap<SourceFileIndex, StableFilemapId>,

// These two fields caches that are populated lazily during decoding.
file_index_to_file: Lock<FxHashMap<FileMapIndex, Lrc<FileMap>>>,
file_index_to_file: Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
synthetic_expansion_infos: Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,

// A map from dep-node to the position of the cached query result in
Expand All @@ -83,7 +83,7 @@ pub struct OnDiskCache<'sess> {
// This type is used only for (de-)serialization.
#[derive(RustcEncodable, RustcDecodable)]
struct Footer {
file_index_to_stable_id: FxHashMap<FileMapIndex, StableFilemapId>,
file_index_to_stable_id: FxHashMap<SourceFileIndex, StableFilemapId>,
prev_cnums: Vec<(u32, String, CrateDisambiguator)>,
query_result_index: EncodedQueryResultIndex,
diagnostics_index: EncodedQueryResultIndex,
Expand All @@ -96,7 +96,7 @@ type EncodedDiagnosticsIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>;
type EncodedDiagnostics = Vec<Diagnostic>;

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
struct FileMapIndex(u32);
struct SourceFileIndex(u32);

#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, RustcEncodable, RustcDecodable)]
struct AbsoluteBytePos(u32);
Expand Down Expand Up @@ -173,14 +173,14 @@ impl<'sess> OnDiskCache<'sess> {
{
// Serializing the DepGraph should not modify it:
tcx.dep_graph.with_ignore(|| {
// Allocate FileMapIndices
// Allocate SourceFileIndices
let (file_to_file_index, file_index_to_stable_id) = {
let mut file_to_file_index = FxHashMap();
let mut file_index_to_stable_id = FxHashMap();

for (index, file) in tcx.sess.codemap().files().iter().enumerate() {
let index = FileMapIndex(index as u32);
let file_ptr: *const FileMap = &**file as *const _;
let index = SourceFileIndex(index as u32);
let file_ptr: *const SourceFile = &**file as *const _;
file_to_file_index.insert(file_ptr, index);
file_index_to_stable_id.insert(index, StableFilemapId::new(&file));
}
Expand Down Expand Up @@ -478,13 +478,13 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
codemap: &'x SourceMap,
cnum_map: &'x IndexVec<CrateNum, Option<CrateNum>>,
synthetic_expansion_infos: &'x Lock<FxHashMap<AbsoluteBytePos, SyntaxContext>>,
file_index_to_file: &'x Lock<FxHashMap<FileMapIndex, Lrc<FileMap>>>,
file_index_to_stable_id: &'x FxHashMap<FileMapIndex, StableFilemapId>,
file_index_to_file: &'x Lock<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
file_index_to_stable_id: &'x FxHashMap<SourceFileIndex, StableFilemapId>,
alloc_decoding_session: AllocDecodingSession<'x>,
}

impl<'a, 'tcx, 'x> CacheDecoder<'a, 'tcx, 'x> {
fn file_index_to_file(&self, index: FileMapIndex) -> Lrc<FileMap> {
fn file_index_to_file(&self, index: SourceFileIndex) -> Lrc<SourceFile> {
let CacheDecoder {
ref file_index_to_file,
ref file_index_to_stable_id,
Expand All @@ -495,7 +495,7 @@ impl<'a, 'tcx, 'x> CacheDecoder<'a, 'tcx, 'x> {
file_index_to_file.borrow_mut().entry(index).or_insert_with(|| {
let stable_id = file_index_to_stable_id[&index];
codemap.filemap_by_stable_id(stable_id)
.expect("Failed to lookup FileMap in new context.")
.expect("Failed to lookup SourceFile in new context.")
}).clone()
}
}
Expand Down Expand Up @@ -617,7 +617,7 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
debug_assert_eq!(tag, TAG_VALID_SPAN);
}

let file_lo_index = FileMapIndex::decode(self)?;
let file_lo_index = SourceFileIndex::decode(self)?;
let line_lo = usize::decode(self)?;
let col_lo = BytePos::decode(self)?;
let len = BytePos::decode(self)?;
Expand Down Expand Up @@ -771,14 +771,14 @@ struct CacheEncoder<'enc, 'a, 'tcx, E>
interpret_allocs: FxHashMap<interpret::AllocId, usize>,
interpret_allocs_inverse: Vec<interpret::AllocId>,
codemap: CachingCodemapView<'tcx>,
file_to_file_index: FxHashMap<*const FileMap, FileMapIndex>,
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
}

impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E>
where E: 'enc + ty_codec::TyEncoder
{
fn filemap_index(&mut self, filemap: Lrc<FileMap>) -> FileMapIndex {
self.file_to_file_index[&(&*filemap as *const FileMap)]
fn filemap_index(&mut self, filemap: Lrc<SourceFile>) -> SourceFileIndex {
self.file_to_file_index[&(&*filemap as *const SourceFile)]
}

/// Encode something with additional information that allows to do some
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/debuginfo/metadata.rs
Expand Up @@ -1745,7 +1745,7 @@ pub fn create_global_var_metadata(
pub fn extend_scope_to_file(
cx: &CodegenCx<'ll, '_>,
scope_metadata: &'ll DIScope,
file: &syntax_pos::FileMap,
file: &syntax_pos::SourceFile,
defining_crate: CrateNum,
) -> &'ll DILexicalBlock {
let file_metadata = file_metadata(cx, &file.name, defining_crate);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_errors/emitter.rs
Expand Up @@ -10,7 +10,7 @@

use self::Destination::*;

use syntax_pos::{FileMap, Span, MultiSpan};
use syntax_pos::{SourceFile, Span, MultiSpan};

use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, SourceMapperDyn, DiagnosticId};
use snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
Expand Down Expand Up @@ -127,7 +127,7 @@ pub struct EmitterWriter {
}

struct FileWithAnnotatedLines {
file: Lrc<FileMap>,
file: Lrc<SourceFile>,
lines: Vec<Line>,
multiline_depth: usize,
}
Expand Down Expand Up @@ -177,7 +177,7 @@ impl EmitterWriter {

fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Lrc<FileMap>,
file: Lrc<SourceFile>,
line_index: usize,
ann: Annotation) {

Expand Down Expand Up @@ -307,7 +307,7 @@ impl EmitterWriter {

fn render_source_line(&self,
buffer: &mut StyledBuffer,
file: Lrc<FileMap>,
file: Lrc<SourceFile>,
line: &Line,
width_offset: usize,
code_offset: usize) -> Vec<(usize, Style)> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_errors/lib.rs
Expand Up @@ -55,7 +55,7 @@ pub mod registry;
mod styled_buffer;
mod lock;

use syntax_pos::{BytePos, Loc, FileLinesResult, FileMap, FileName, MultiSpan, Span, NO_EXPANSION};
use syntax_pos::{BytePos, Loc, FileLinesResult, SourceFile, FileName, MultiSpan, Span, NO_EXPANSION};

#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)]
pub enum Applicability {
Expand Down Expand Up @@ -120,7 +120,7 @@ pub trait SourceMapper {
fn span_to_filename(&self, sp: Span) -> FileName;
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
fn call_span_if_macro(&self, sp: Span) -> Span;
fn ensure_filemap_source_present(&self, file_map: Lrc<FileMap>) -> bool;
fn ensure_filemap_source_present(&self, file_map: Lrc<SourceFile>) -> bool;
fn doctest_offset_line(&self, line: usize) -> usize;
}

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -41,15 +41,15 @@ pub use rustc_data_structures::sync::MetadataRef;

pub struct MetadataBlob(pub MetadataRef);

/// Holds information about a syntax_pos::FileMap imported from another crate.
/// Holds information about a syntax_pos::SourceFile imported from another crate.
/// See `imported_filemaps()` for more information.
pub struct ImportedFileMap {
/// This FileMap's byte-offset within the codemap of its original crate
pub struct ImportedSourceFile {
/// This SourceFile's byte-offset within the codemap of its original crate
pub original_start_pos: syntax_pos::BytePos,
/// The end of this FileMap within the codemap of its original crate
/// The end of this SourceFile within the codemap of its original crate
pub original_end_pos: syntax_pos::BytePos,
/// The imported FileMap's representation within the local codemap
pub translated_filemap: Lrc<syntax_pos::FileMap>,
/// The imported SourceFile's representation within the local codemap
pub translated_filemap: Lrc<syntax_pos::SourceFile>,
}

pub struct CrateMetadata {
Expand All @@ -64,7 +64,7 @@ pub struct CrateMetadata {
pub cnum_map: CrateNumMap,
pub cnum: CrateNum,
pub dependencies: Lock<Vec<CrateNum>>,
pub codemap_import_info: RwLock<Vec<ImportedFileMap>>,
pub codemap_import_info: RwLock<Vec<ImportedSourceFile>>,

/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
pub alloc_decoding_state: AllocDecodingState,
Expand Down
22 changes: 11 additions & 11 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -1099,26 +1099,26 @@ impl<'a, 'tcx> CrateMetadata {
///
/// The import algorithm works analogous to how AST items are inlined from an
/// external crate's metadata:
/// For every FileMap in the external codemap an 'inline' copy is created in the
/// For every SourceFile in the external codemap an 'inline' copy is created in the
/// local codemap. The correspondence relation between external and local
/// FileMaps is recorded in the `ImportedFileMap` objects returned from this
/// SourceFiles is recorded in the `ImportedSourceFile` objects returned from this
/// function. When an item from an external crate is later inlined into this
/// crate, this correspondence information is used to translate the span
/// information of the inlined item so that it refers the correct positions in
/// the local codemap (see `<decoder::DecodeContext as SpecializedDecoder<Span>>`).
///
/// The import algorithm in the function below will reuse FileMaps already
/// existing in the local codemap. For example, even if the FileMap of some
/// The import algorithm in the function below will reuse SourceFiles already
/// existing in the local codemap. For example, even if the SourceFile of some
/// source file of libstd gets imported many times, there will only ever be
/// one FileMap object for the corresponding file in the local codemap.
/// one SourceFile object for the corresponding file in the local codemap.
///
/// Note that imported FileMaps do not actually contain the source code of the
/// Note that imported SourceFiles do not actually contain the source code of the
/// file they represent, just information about length, line breaks, and
/// multibyte characters. This information is enough to generate valid debuginfo
/// for items inlined from other crates.
pub fn imported_filemaps(&'a self,
local_codemap: &codemap::SourceMap)
-> ReadGuard<'a, Vec<cstore::ImportedFileMap>> {
-> ReadGuard<'a, Vec<cstore::ImportedSourceFile>> {
{
let filemaps = self.codemap_import_info.borrow();
if !filemaps.is_empty() {
Expand All @@ -1137,9 +1137,9 @@ impl<'a, 'tcx> CrateMetadata {
let external_codemap = self.root.codemap.decode(self);

let imported_filemaps = external_codemap.map(|filemap_to_import| {
// We can't reuse an existing FileMap, so allocate a new one
// We can't reuse an existing SourceFile, so allocate a new one
// containing the information we need.
let syntax_pos::FileMap { name,
let syntax_pos::SourceFile { name,
name_was_remapped,
src_hash,
start_pos,
Expand All @@ -1156,7 +1156,7 @@ impl<'a, 'tcx> CrateMetadata {
// position into frame of reference local to file.
// `SourceMap::new_imported_filemap()` will then translate those
// coordinates to their new global frame of reference when the
// offset of the FileMap is known.
// offset of the SourceFile is known.
for pos in &mut lines {
*pos = *pos - start_pos;
}
Expand All @@ -1182,7 +1182,7 @@ impl<'a, 'tcx> CrateMetadata {
local_version.name, start_pos, end_pos,
local_version.start_pos, local_version.end_pos);

cstore::ImportedFileMap {
cstore::ImportedSourceFile {
original_start_pos: start_pos,
original_end_pos: end_pos,
translated_filemap: local_version,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -42,7 +42,7 @@ use syntax::ast::{self, CRATE_NODE_ID};
use syntax::attr;
use syntax::codemap::Spanned;
use syntax::symbol::keywords;
use syntax_pos::{self, hygiene, FileName, FileMap, Span};
use syntax_pos::{self, hygiene, FileName, SourceFile, Span};

use rustc::hir::{self, PatKind};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
Expand All @@ -62,7 +62,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
interpret_allocs_inverse: Vec<interpret::AllocId>,

// This is used to speed up Span encoding.
filemap_cache: Lrc<FileMap>,
filemap_cache: Lrc<SourceFile>,
}

macro_rules! encoder_methods {
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy(definitions.def_path_table())
}

fn encode_codemap(&mut self) -> LazySeq<syntax_pos::FileMap> {
fn encode_codemap(&mut self) -> LazySeq<syntax_pos::SourceFile> {
let codemap = self.tcx.sess.codemap();
let all_filemaps = codemap.files();

Expand All @@ -350,7 +350,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
!filemap.is_imported()
})
.map(|filemap| {
// When exporting FileMaps, we expand all paths to absolute
// When exporting SourceFiles, we expand all paths to absolute
// paths because any relative paths are potentially relative to
// a wrong directory.
// However, if a path has been modified via
Expand All @@ -361,7 +361,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
FileName::Real(ref name) => {
if filemap.name_was_remapped ||
(name.is_relative() && working_dir_was_remapped) {
// This path of this FileMap has been modified by
// This path of this SourceFile has been modified by
// path-remapping, so we use it verbatim (and avoid cloning
// the whole map in the process).
filemap.clone()
Expand Down

0 comments on commit d6dcbcd

Please sign in to comment.