diff options
| author | Inokentiy Babushkin <twk@twki.de> | 2017-06-10 13:39:39 +0200 |
|---|---|---|
| committer | Inokentiy Babushkin <twk@twki.de> | 2017-06-10 13:39:39 +0200 |
| commit | 3d2cff0c94a8a882eeca464ef638b0c912cc4f97 (patch) | |
| tree | de5b016f6dcc5e0f8f5a7573df7a8e100d0f9a96 /src/libsyntax | |
| parent | 70fa1fbea7786425471b0d43aae320920fd4e917 (diff) | |
| download | rust-3d2cff0c94a8a882eeca464ef638b0c912cc4f97.tar.gz rust-3d2cff0c94a8a882eeca464ef638b0c912cc4f97.zip | |
Added source hashes to FileMap
We can use these to perform lazy loading of source files belonging to external crates. That way we will be able to show the source code of external spans that have been translated.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 830a457df74..0935ec1b01c 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -27,9 +27,12 @@ use std::rc::Rc; use std::env; use std::fs; +use std::hash::Hasher; use std::io::{self, Read}; use errors::CodeMapper; +use rustc_data_structures::stable_hasher::StableHasher; + /// Return the span itself if it doesn't come from a macro expansion, /// otherwise return the call site span up to the `enclosing_sp` by /// following the `expn_info` chain. @@ -171,11 +174,16 @@ impl CodeMap { let (filename, was_remapped) = self.path_mapping.map_prefix(filename); + let mut hasher: StableHasher<u128> = StableHasher::new(); + hasher.write(src.as_bytes()); + let src_hash = hasher.finish(); + let filemap = Rc::new(FileMap { name: filename, name_was_remapped: was_remapped, crate_of_origin: 0, src: Some(Rc::new(src)), + src_hash: src_hash, start_pos: Pos::from_usize(start_pos), end_pos: Pos::from_usize(end_pos), lines: RefCell::new(Vec::new()), @@ -210,6 +218,7 @@ impl CodeMap { filename: FileName, name_was_remapped: bool, crate_of_origin: u32, + src_hash: u128, source_len: usize, mut file_local_lines: Vec<BytePos>, mut file_local_multibyte_chars: Vec<MultiByteChar>) @@ -233,6 +242,7 @@ impl CodeMap { name_was_remapped: name_was_remapped, crate_of_origin: crate_of_origin, src: None, + src_hash: src_hash, start_pos: start_pos, end_pos: end_pos, lines: RefCell::new(file_local_lines), |
