updates all Filename variants to take a fingerprint
This commit is contained in:
parent
6ee4d3cafc
commit
88130f1796
12 changed files with 93 additions and 51 deletions
|
@ -417,12 +417,12 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
|
||||||
impl_stable_hash_for!(enum ::syntax_pos::FileName {
|
impl_stable_hash_for!(enum ::syntax_pos::FileName {
|
||||||
Real(pb),
|
Real(pb),
|
||||||
Macros(s),
|
Macros(s),
|
||||||
QuoteExpansion,
|
QuoteExpansion(s),
|
||||||
Anon,
|
Anon(s),
|
||||||
MacroExpansion,
|
MacroExpansion(s),
|
||||||
ProcMacroSourceCode,
|
ProcMacroSourceCode(s),
|
||||||
CliCrateAttr,
|
CliCrateAttr(s),
|
||||||
CfgSpec,
|
CfgSpec(s),
|
||||||
Custom(s)
|
Custom(s)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1756,8 +1756,8 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
||||||
let mut parser =
|
let filename = FileName::cfg_spec_source_code(&s);
|
||||||
parse::new_parser_from_source_str(&sess, FileName::CfgSpec, s.to_string());
|
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
|
||||||
|
|
||||||
macro_rules! error {($reason: expr) => {
|
macro_rules! error {($reason: expr) => {
|
||||||
early_error(ErrorOutputType::default(),
|
early_error(ErrorOutputType::default(),
|
||||||
|
|
|
@ -594,7 +594,7 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>, Option
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Some((Input::Str { name: FileName::Anon, input: src },
|
Some((Input::Str { name: FileName::anon_source_code(&src), input: src },
|
||||||
None, err))
|
None, err))
|
||||||
} else {
|
} else {
|
||||||
Some((Input::File(PathBuf::from(ifile)),
|
Some((Input::File(PathBuf::from(ifile)),
|
||||||
|
|
|
@ -129,7 +129,7 @@ fn test_env_with_pool<F>(
|
||||||
let cstore = CStore::new(::get_codegen_backend(&sess).metadata_loader());
|
let cstore = CStore::new(::get_codegen_backend(&sess).metadata_loader());
|
||||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||||
let input = config::Input::Str {
|
let input = config::Input::Str {
|
||||||
name: FileName::Anon,
|
name: FileName::anon_source_code(&source_string),
|
||||||
input: source_string.to_string(),
|
input: source_string.to_string(),
|
||||||
};
|
};
|
||||||
let krate =
|
let krate =
|
||||||
|
|
|
@ -3008,7 +3008,7 @@ pub struct Span {
|
||||||
impl Span {
|
impl Span {
|
||||||
pub fn empty() -> Span {
|
pub fn empty() -> Span {
|
||||||
Span {
|
Span {
|
||||||
filename: FileName::Anon,
|
filename: FileName::Anon(0),
|
||||||
loline: 0, locol: 0,
|
loline: 0, locol: 0,
|
||||||
hiline: 0, hicol: 0,
|
hiline: 0, hicol: 0,
|
||||||
}
|
}
|
||||||
|
|
|
@ -803,7 +803,7 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
|
||||||
for raw_attr in attrs {
|
for raw_attr in attrs {
|
||||||
let mut parser = parse::new_parser_from_source_str(
|
let mut parser = parse::new_parser_from_source_str(
|
||||||
parse_sess,
|
parse_sess,
|
||||||
FileName::CliCrateAttr,
|
FileName::cli_crate_attr_source_code(&raw_attr),
|
||||||
raw_attr.clone(),
|
raw_attr.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -353,27 +353,27 @@ pub mod rt {
|
||||||
impl<'a> ExtParseUtils for ExtCtxt<'a> {
|
impl<'a> ExtParseUtils for ExtCtxt<'a> {
|
||||||
fn parse_item(&self, s: String) -> P<ast::Item> {
|
fn parse_item(&self, s: String) -> P<ast::Item> {
|
||||||
panictry!(parse::parse_item_from_source_str(
|
panictry!(parse::parse_item_from_source_str(
|
||||||
FileName::QuoteExpansion,
|
FileName::quote_expansion_source_code(&s),
|
||||||
s,
|
s,
|
||||||
self.parse_sess())).expect("parse error")
|
self.parse_sess())).expect("parse error")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_stmt(&self, s: String) -> ast::Stmt {
|
fn parse_stmt(&self, s: String) -> ast::Stmt {
|
||||||
panictry!(parse::parse_stmt_from_source_str(
|
panictry!(parse::parse_stmt_from_source_str(
|
||||||
FileName::QuoteExpansion,
|
FileName::quote_expansion_source_code(&s),
|
||||||
s,
|
s,
|
||||||
self.parse_sess())).expect("parse error")
|
self.parse_sess())).expect("parse error")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_expr(&self, s: String) -> P<ast::Expr> {
|
fn parse_expr(&self, s: String) -> P<ast::Expr> {
|
||||||
panictry!(parse::parse_expr_from_source_str(
|
panictry!(parse::parse_expr_from_source_str(
|
||||||
FileName::QuoteExpansion,
|
FileName::quote_expansion_source_code(&s),
|
||||||
s,
|
s,
|
||||||
self.parse_sess()))
|
self.parse_sess()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_tts(&self, s: String) -> Vec<TokenTree> {
|
fn parse_tts(&self, s: String) -> Vec<TokenTree> {
|
||||||
let source_name = FileName::QuoteExpansion;
|
let source_name = FileName::quote_expansion_source_code(&s);
|
||||||
parse::parse_stream_from_source_str(source_name, s, self.parse_sess(), None)
|
parse::parse_stream_from_source_str(source_name, s, self.parse_sess(), None)
|
||||||
.into_trees().collect()
|
.into_trees().collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -545,7 +545,8 @@ impl Token {
|
||||||
let tokens_for_real = nt.1.force(|| {
|
let tokens_for_real = nt.1.force(|| {
|
||||||
// FIXME(#43081): Avoid this pretty-print + reparse hack
|
// FIXME(#43081): Avoid this pretty-print + reparse hack
|
||||||
let source = pprust::token_to_string(self);
|
let source = pprust::token_to_string(self);
|
||||||
parse_stream_from_source_str(FileName::MacroExpansion, source, sess, Some(span))
|
let filename = FileName::macro_expansion_source_code(&source);
|
||||||
|
parse_stream_from_source_str(filename, source, sess, Some(span))
|
||||||
});
|
});
|
||||||
|
|
||||||
// During early phases of the compiler the AST could get modified
|
// During early phases of the compiler the AST could get modified
|
||||||
|
@ -781,10 +782,12 @@ fn prepend_attrs(sess: &ParseSess,
|
||||||
assert_eq!(attr.style, ast::AttrStyle::Outer,
|
assert_eq!(attr.style, ast::AttrStyle::Outer,
|
||||||
"inner attributes should prevent cached tokens from existing");
|
"inner attributes should prevent cached tokens from existing");
|
||||||
|
|
||||||
|
let source = pprust::attr_to_string(attr);
|
||||||
|
let macro_filename = FileName::macro_expansion_source_code(&source);
|
||||||
if attr.is_sugared_doc {
|
if attr.is_sugared_doc {
|
||||||
let stream = parse_stream_from_source_str(
|
let stream = parse_stream_from_source_str(
|
||||||
FileName::MacroExpansion,
|
macro_filename,
|
||||||
pprust::attr_to_string(attr),
|
source,
|
||||||
sess,
|
sess,
|
||||||
Some(span),
|
Some(span),
|
||||||
);
|
);
|
||||||
|
@ -805,8 +808,8 @@ fn prepend_attrs(sess: &ParseSess,
|
||||||
// should eventually be removed.
|
// should eventually be removed.
|
||||||
} else {
|
} else {
|
||||||
let stream = parse_stream_from_source_str(
|
let stream = parse_stream_from_source_str(
|
||||||
FileName::MacroExpansion,
|
macro_filename,
|
||||||
pprust::path_to_string(&attr.path),
|
source,
|
||||||
sess,
|
sess,
|
||||||
Some(span),
|
Some(span),
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,14 +110,14 @@ pub struct StableSourceFileId(u128);
|
||||||
|
|
||||||
impl StableSourceFileId {
|
impl StableSourceFileId {
|
||||||
pub fn new(source_file: &SourceFile) -> StableSourceFileId {
|
pub fn new(source_file: &SourceFile) -> StableSourceFileId {
|
||||||
StableFilemapId::new_from_pieces(&source_file.name,
|
StableSourceFileId::new_from_pieces(&source_file.name,
|
||||||
source_file.name_was_remapped,
|
source_file.name_was_remapped,
|
||||||
source_file.unmapped_path.as_ref())
|
source_file.unmapped_path.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_pieces(name: &FileName,
|
pub fn new_from_pieces(name: &FileName,
|
||||||
name_was_remapped: bool,
|
name_was_remapped: bool,
|
||||||
unmapped_path: Option<&FileName>) -> StableFilemapId {
|
unmapped_path: Option<&FileName>) -> StableSourceFileId {
|
||||||
let mut hasher = StableHasher::new();
|
let mut hasher = StableHasher::new();
|
||||||
|
|
||||||
name.hash(&mut hasher);
|
name.hash(&mut hasher);
|
||||||
|
@ -236,7 +236,7 @@ impl SourceMap {
|
||||||
other => (other, false),
|
other => (other, false),
|
||||||
};
|
};
|
||||||
|
|
||||||
let file_id = StableFilemapId::new_from_pieces(&filename,
|
let file_id = StableSourceFileId::new_from_pieces(&filename,
|
||||||
was_remapped,
|
was_remapped,
|
||||||
Some(&unmapped_path));
|
Some(&unmapped_path));
|
||||||
|
|
||||||
|
|
|
@ -90,17 +90,17 @@ pub enum FileName {
|
||||||
/// A macro. This includes the full name of the macro, so that there are no clashes.
|
/// A macro. This includes the full name of the macro, so that there are no clashes.
|
||||||
Macros(String),
|
Macros(String),
|
||||||
/// call to `quote!`
|
/// call to `quote!`
|
||||||
QuoteExpansion,
|
QuoteExpansion(u64),
|
||||||
/// Command line
|
/// Command line
|
||||||
Anon,
|
Anon(u64),
|
||||||
/// Hack in src/libsyntax/parse.rs
|
/// Hack in src/libsyntax/parse.rs
|
||||||
/// FIXME(jseyfried)
|
/// FIXME(jseyfried)
|
||||||
MacroExpansion,
|
MacroExpansion(u64),
|
||||||
ProcMacroSourceCode,
|
ProcMacroSourceCode(u64),
|
||||||
/// Strings provided as --cfg [cfgspec] stored in a crate_cfg
|
/// Strings provided as --cfg [cfgspec] stored in a crate_cfg
|
||||||
CfgSpec,
|
CfgSpec(u64),
|
||||||
/// Strings provided as crate attributes in the CLI
|
/// Strings provided as crate attributes in the CLI
|
||||||
CliCrateAttr,
|
CliCrateAttr(u64),
|
||||||
/// Custom sources for explicit parser calls from plugins and drivers
|
/// Custom sources for explicit parser calls from plugins and drivers
|
||||||
Custom(String),
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
@ -111,12 +111,13 @@ impl std::fmt::Display for FileName {
|
||||||
match *self {
|
match *self {
|
||||||
Real(ref path) => write!(fmt, "{}", path.display()),
|
Real(ref path) => write!(fmt, "{}", path.display()),
|
||||||
Macros(ref name) => write!(fmt, "<{} macros>", name),
|
Macros(ref name) => write!(fmt, "<{} macros>", name),
|
||||||
QuoteExpansion => write!(fmt, "<quote expansion>"),
|
QuoteExpansion(_) => write!(fmt, "<quote expansion>"),
|
||||||
MacroExpansion => write!(fmt, "<macro expansion>"),
|
MacroExpansion(_) => write!(fmt, "<macro expansion>"),
|
||||||
Anon => write!(fmt, "<anon>"),
|
Anon(_) => write!(fmt, "<anon>"),
|
||||||
ProcMacroSourceCode => write!(fmt, "<proc-macro source code>"),
|
ProcMacroSourceCode(_) =>
|
||||||
CfgSpec => write!(fmt, "cfgspec"),
|
write!(fmt, "<proc-macro source code>"),
|
||||||
CliCrateAttr => write!(fmt, "<crate attribute>"),
|
CfgSpec(_) => write!(fmt, "<cfgspec>"),
|
||||||
|
CliCrateAttr(_) => write!(fmt, "<crate attribute>"),
|
||||||
Custom(ref s) => write!(fmt, "<{}>", s),
|
Custom(ref s) => write!(fmt, "<{}>", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,13 +136,13 @@ impl FileName {
|
||||||
match *self {
|
match *self {
|
||||||
Real(_) => true,
|
Real(_) => true,
|
||||||
Macros(_) |
|
Macros(_) |
|
||||||
Anon |
|
Anon(_) |
|
||||||
MacroExpansion |
|
MacroExpansion(_) |
|
||||||
ProcMacroSourceCode |
|
ProcMacroSourceCode(_) |
|
||||||
CfgSpec |
|
CfgSpec(_) |
|
||||||
CliCrateAttr |
|
CliCrateAttr(_) |
|
||||||
Custom(_) |
|
Custom(_) |
|
||||||
QuoteExpansion => false,
|
QuoteExpansion(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,16 +150,52 @@ impl FileName {
|
||||||
use self::FileName::*;
|
use self::FileName::*;
|
||||||
match *self {
|
match *self {
|
||||||
Real(_) |
|
Real(_) |
|
||||||
Anon |
|
Anon(_) |
|
||||||
MacroExpansion |
|
MacroExpansion(_) |
|
||||||
ProcMacroSourceCode |
|
ProcMacroSourceCode(_) |
|
||||||
CfgSpec |
|
CfgSpec(_) |
|
||||||
CliCrateAttr |
|
CliCrateAttr(_) |
|
||||||
Custom(_) |
|
Custom(_) |
|
||||||
QuoteExpansion => false,
|
QuoteExpansion(_) => false,
|
||||||
Macros(_) => true,
|
Macros(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn quote_expansion_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::QuoteExpansion(hasher.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn macro_expansion_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::MacroExpansion(hasher.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn anon_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::Anon(hasher.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn proc_macro_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::ProcMacroSourceCode(hasher.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cfg_spec_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::QuoteExpansion(hasher.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cli_crate_attr_source_code(src: &str) -> FileName {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
src.hash(&mut hasher);
|
||||||
|
FileName::CliCrateAttr(hasher.finish())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spans represent a region of code, used for error reporting. Positions in spans
|
/// Spans represent a region of code, used for error reporting. Positions in spans
|
||||||
|
|
|
@ -33,7 +33,7 @@ use std::fmt;
|
||||||
// Copied out of syntax::util::parser_testing
|
// Copied out of syntax::util::parser_testing
|
||||||
|
|
||||||
pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a> {
|
pub fn string_to_parser<'a>(ps: &'a ParseSess, source_str: String) -> Parser<'a> {
|
||||||
new_parser_from_source_str(ps, FileName::Custom("bogofile".to_owned()), source_str)
|
new_parser_from_source_str(ps, FileName::Custom(source_str.clone()), source_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> PResult<'a, T> where
|
fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> PResult<'a, T> where
|
||||||
|
|
|
@ -44,9 +44,11 @@ use syntax::ptr::P;
|
||||||
|
|
||||||
|
|
||||||
fn parse_expr(ps: &ParseSess, src: &str) -> P<Expr> {
|
fn parse_expr(ps: &ParseSess, src: &str) -> P<Expr> {
|
||||||
|
let src_as_string = src.to_string();
|
||||||
|
|
||||||
let mut p = parse::new_parser_from_source_str(ps,
|
let mut p = parse::new_parser_from_source_str(ps,
|
||||||
FileName::Custom("expr".to_owned()),
|
FileName::Custom(src_as_string.clone()),
|
||||||
src.to_owned());
|
src_as_string);
|
||||||
p.parse_expr().unwrap()
|
p.parse_expr().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue