updates all Filename variants to take a fingerprint
This commit is contained in:
parent
6ee4d3cafc
commit
88130f1796
@ -417,12 +417,12 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
|
||||
impl_stable_hash_for!(enum ::syntax_pos::FileName {
|
||||
Real(pb),
|
||||
Macros(s),
|
||||
QuoteExpansion,
|
||||
Anon,
|
||||
MacroExpansion,
|
||||
ProcMacroSourceCode,
|
||||
CliCrateAttr,
|
||||
CfgSpec,
|
||||
QuoteExpansion(s),
|
||||
Anon(s),
|
||||
MacroExpansion(s),
|
||||
ProcMacroSourceCode(s),
|
||||
CliCrateAttr(s),
|
||||
CfgSpec(s),
|
||||
Custom(s)
|
||||
});
|
||||
|
||||
|
@ -1756,8 +1756,8 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
||||
let mut parser =
|
||||
parse::new_parser_from_source_str(&sess, FileName::CfgSpec, s.to_string());
|
||||
let filename = FileName::cfg_spec_source_code(&s);
|
||||
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
|
||||
|
||||
macro_rules! error {($reason: expr) => {
|
||||
early_error(ErrorOutputType::default(),
|
||||
|
@ -594,7 +594,7 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>, Option
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Some((Input::Str { name: FileName::Anon, input: src },
|
||||
Some((Input::Str { name: FileName::anon_source_code(&src), input: src },
|
||||
None, err))
|
||||
} else {
|
||||
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());
|
||||
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
|
||||
let input = config::Input::Str {
|
||||
name: FileName::Anon,
|
||||
name: FileName::anon_source_code(&source_string),
|
||||
input: source_string.to_string(),
|
||||
};
|
||||
let krate =
|
||||
|
@ -3008,7 +3008,7 @@ pub struct Span {
|
||||
impl Span {
|
||||
pub fn empty() -> Span {
|
||||
Span {
|
||||
filename: FileName::Anon,
|
||||
filename: FileName::Anon(0),
|
||||
loline: 0, locol: 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 {
|
||||
let mut parser = parse::new_parser_from_source_str(
|
||||
parse_sess,
|
||||
FileName::CliCrateAttr,
|
||||
FileName::cli_crate_attr_source_code(&raw_attr),
|
||||
raw_attr.clone(),
|
||||
);
|
||||
|
||||
|
@ -353,27 +353,27 @@ pub trait ExtParseUtils {
|
||||
impl<'a> ExtParseUtils for ExtCtxt<'a> {
|
||||
fn parse_item(&self, s: String) -> P<ast::Item> {
|
||||
panictry!(parse::parse_item_from_source_str(
|
||||
FileName::QuoteExpansion,
|
||||
FileName::quote_expansion_source_code(&s),
|
||||
s,
|
||||
self.parse_sess())).expect("parse error")
|
||||
}
|
||||
|
||||
fn parse_stmt(&self, s: String) -> ast::Stmt {
|
||||
panictry!(parse::parse_stmt_from_source_str(
|
||||
FileName::QuoteExpansion,
|
||||
FileName::quote_expansion_source_code(&s),
|
||||
s,
|
||||
self.parse_sess())).expect("parse error")
|
||||
}
|
||||
|
||||
fn parse_expr(&self, s: String) -> P<ast::Expr> {
|
||||
panictry!(parse::parse_expr_from_source_str(
|
||||
FileName::QuoteExpansion,
|
||||
FileName::quote_expansion_source_code(&s),
|
||||
s,
|
||||
self.parse_sess()))
|
||||
}
|
||||
|
||||
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)
|
||||
.into_trees().collect()
|
||||
}
|
||||
|
@ -545,7 +545,8 @@ pub fn interpolated_to_tokenstream(&self, sess: &ParseSess, span: Span)
|
||||
let tokens_for_real = nt.1.force(|| {
|
||||
// FIXME(#43081): Avoid this pretty-print + reparse hack
|
||||
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
|
||||
@ -781,10 +782,12 @@ fn prepend_attrs(sess: &ParseSess,
|
||||
assert_eq!(attr.style, ast::AttrStyle::Outer,
|
||||
"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 {
|
||||
let stream = parse_stream_from_source_str(
|
||||
FileName::MacroExpansion,
|
||||
pprust::attr_to_string(attr),
|
||||
macro_filename,
|
||||
source,
|
||||
sess,
|
||||
Some(span),
|
||||
);
|
||||
@ -805,8 +808,8 @@ fn prepend_attrs(sess: &ParseSess,
|
||||
// should eventually be removed.
|
||||
} else {
|
||||
let stream = parse_stream_from_source_str(
|
||||
FileName::MacroExpansion,
|
||||
pprust::path_to_string(&attr.path),
|
||||
macro_filename,
|
||||
source,
|
||||
sess,
|
||||
Some(span),
|
||||
);
|
||||
|
@ -110,14 +110,14 @@ fn read_file(&self, path: &Path) -> io::Result<String> {
|
||||
|
||||
impl 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.unmapped_path.as_ref())
|
||||
}
|
||||
|
||||
pub fn new_from_pieces(name: &FileName,
|
||||
name_was_remapped: bool,
|
||||
unmapped_path: Option<&FileName>) -> StableFilemapId {
|
||||
unmapped_path: Option<&FileName>) -> StableSourceFileId {
|
||||
let mut hasher = StableHasher::new();
|
||||
|
||||
name.hash(&mut hasher);
|
||||
@ -236,7 +236,7 @@ pub fn new_source_file(&self, filename: FileName, src: String) -> Lrc<SourceFile
|
||||
other => (other, false),
|
||||
};
|
||||
|
||||
let file_id = StableFilemapId::new_from_pieces(&filename,
|
||||
let file_id = StableSourceFileId::new_from_pieces(&filename,
|
||||
was_remapped,
|
||||
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.
|
||||
Macros(String),
|
||||
/// call to `quote!`
|
||||
QuoteExpansion,
|
||||
QuoteExpansion(u64),
|
||||
/// Command line
|
||||
Anon,
|
||||
Anon(u64),
|
||||
/// Hack in src/libsyntax/parse.rs
|
||||
/// FIXME(jseyfried)
|
||||
MacroExpansion,
|
||||
ProcMacroSourceCode,
|
||||
MacroExpansion(u64),
|
||||
ProcMacroSourceCode(u64),
|
||||
/// Strings provided as --cfg [cfgspec] stored in a crate_cfg
|
||||
CfgSpec,
|
||||
CfgSpec(u64),
|
||||
/// Strings provided as crate attributes in the CLI
|
||||
CliCrateAttr,
|
||||
CliCrateAttr(u64),
|
||||
/// Custom sources for explicit parser calls from plugins and drivers
|
||||
Custom(String),
|
||||
}
|
||||
@ -111,12 +111,13 @@ fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match *self {
|
||||
Real(ref path) => write!(fmt, "{}", path.display()),
|
||||
Macros(ref name) => write!(fmt, "<{} macros>", name),
|
||||
QuoteExpansion => write!(fmt, "<quote expansion>"),
|
||||
MacroExpansion => write!(fmt, "<macro expansion>"),
|
||||
Anon => write!(fmt, "<anon>"),
|
||||
ProcMacroSourceCode => write!(fmt, "<proc-macro source code>"),
|
||||
CfgSpec => write!(fmt, "cfgspec"),
|
||||
CliCrateAttr => write!(fmt, "<crate attribute>"),
|
||||
QuoteExpansion(_) => write!(fmt, "<quote expansion>"),
|
||||
MacroExpansion(_) => write!(fmt, "<macro expansion>"),
|
||||
Anon(_) => write!(fmt, "<anon>"),
|
||||
ProcMacroSourceCode(_) =>
|
||||
write!(fmt, "<proc-macro source code>"),
|
||||
CfgSpec(_) => write!(fmt, "<cfgspec>"),
|
||||
CliCrateAttr(_) => write!(fmt, "<crate attribute>"),
|
||||
Custom(ref s) => write!(fmt, "<{}>", s),
|
||||
}
|
||||
}
|
||||
@ -135,13 +136,13 @@ pub fn is_real(&self) -> bool {
|
||||
match *self {
|
||||
Real(_) => true,
|
||||
Macros(_) |
|
||||
Anon |
|
||||
MacroExpansion |
|
||||
ProcMacroSourceCode |
|
||||
CfgSpec |
|
||||
CliCrateAttr |
|
||||
Anon(_) |
|
||||
MacroExpansion(_) |
|
||||
ProcMacroSourceCode(_) |
|
||||
CfgSpec(_) |
|
||||
CliCrateAttr(_) |
|
||||
Custom(_) |
|
||||
QuoteExpansion => false,
|
||||
QuoteExpansion(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,16 +150,52 @@ pub fn is_macros(&self) -> bool {
|
||||
use self::FileName::*;
|
||||
match *self {
|
||||
Real(_) |
|
||||
Anon |
|
||||
MacroExpansion |
|
||||
ProcMacroSourceCode |
|
||||
CfgSpec |
|
||||
CliCrateAttr |
|
||||
Anon(_) |
|
||||
MacroExpansion(_) |
|
||||
ProcMacroSourceCode(_) |
|
||||
CfgSpec(_) |
|
||||
CliCrateAttr(_) |
|
||||
Custom(_) |
|
||||
QuoteExpansion => false,
|
||||
QuoteExpansion(_) => false,
|
||||
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
|
||||
|
@ -33,7 +33,7 @@
|
||||
// Copied out of syntax::util::parser_testing
|
||||
|
||||
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
|
||||
|
@ -44,9 +44,11 @@
|
||||
|
||||
|
||||
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,
|
||||
FileName::Custom("expr".to_owned()),
|
||||
src.to_owned());
|
||||
FileName::Custom(src_as_string.clone()),
|
||||
src_as_string);
|
||||
p.parse_expr().unwrap()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user