From 3d2cff0c94a8a882eeca464ef638b0c912cc4f97 Mon Sep 17 00:00:00 2001 From: Inokentiy Babushkin Date: Sat, 10 Jun 2017 13:39:39 +0200 Subject: 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. --- src/libsyntax/codemap.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/libsyntax/codemap.rs') 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 = 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, mut file_local_multibyte_chars: Vec) @@ -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), -- cgit 1.4.1-3-g733a5