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.
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()),
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>)
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),
#![feature(const_fn)]
#![feature(custom_attribute)]
+#![feature(i128_type)]
#![feature(optin_builtin_traits)]
#![allow(unused_attributes)]
#![feature(specialization)]
use std::ops::{Add, Sub};
use std::rc::Rc;
use std::cmp;
-
use std::fmt;
use serialize::{Encodable, Decodable, Encoder, Decoder};
pub crate_of_origin: u32,
/// The complete source code
pub src: Option<Rc<String>>,
+ /// The source code's hash
+ pub src_hash: u128,
/// The start position of this source in the CodeMap
pub start_pos: BytePos,
/// The end position of this source in the CodeMap
impl Encodable for FileMap {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
- s.emit_struct("FileMap", 6, |s| {
+ s.emit_struct("FileMap", 7, |s| {
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
+ s.emit_struct_field("src_hash", 6, |s| self.src_hash.encode(s))?;
s.emit_struct_field("start_pos", 2, |s| self.start_pos.encode(s))?;
s.emit_struct_field("end_pos", 3, |s| self.end_pos.encode(s))?;
s.emit_struct_field("lines", 4, |s| {
let name: String = d.read_struct_field("name", 0, |d| Decodable::decode(d))?;
let name_was_remapped: bool =
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
- let start_pos: BytePos = d.read_struct_field("start_pos", 2, |d| Decodable::decode(d))?;
+ let src_hash: u128 =
+ d.read_struct_field("src_hash", 6, |d| Decodable::decode(d))?;
+ let start_pos: BytePos =
+ d.read_struct_field("start_pos", 2, |d| Decodable::decode(d))?;
let end_pos: BytePos = d.read_struct_field("end_pos", 3, |d| Decodable::decode(d))?;
let lines: Vec<BytePos> = d.read_struct_field("lines", 4, |d| {
let num_lines: u32 = Decodable::decode(d)?;
start_pos: start_pos,
end_pos: end_pos,
src: None,
+ src_hash: src_hash,
lines: RefCell::new(lines),
multibyte_chars: RefCell::new(multibyte_chars)
})