提交 c6bcf601 编写于 作者: V Vadim Petrochenkov

rustc_metadata: `locator::Context` -> `CrateLocator`

上级 68985c76
//! Validates all used crates and extern libraries and loads their metadata //! Validates all used crates and extern libraries and loads their metadata
use crate::cstore::{self, CStore}; use crate::cstore::{self, CStore};
use crate::locator::{self, CratePaths}; use crate::locator::{CrateLocator, CratePaths};
use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob}; use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob};
use rustc_data_structures::sync::{Lock, Once, AtomicCell}; use rustc_data_structures::sync::{Lock, Once, AtomicCell};
...@@ -68,13 +68,13 @@ enum LoadResult { ...@@ -68,13 +68,13 @@ enum LoadResult {
} }
enum LoadError<'a> { enum LoadError<'a> {
LocatorError(locator::Context<'a>), LocatorError(CrateLocator<'a>),
} }
impl<'a> LoadError<'a> { impl<'a> LoadError<'a> {
fn report(self) -> ! { fn report(self) -> ! {
match self { match self {
LoadError::LocatorError(locate_ctxt) => locate_ctxt.report_errs(), LoadError::LocatorError(locator) => locator.report_errs(),
} }
} }
} }
...@@ -267,15 +267,15 @@ fn register_crate( ...@@ -267,15 +267,15 @@ fn register_crate(
fn load_proc_macro<'b>( fn load_proc_macro<'b>(
&self, &self,
locate_ctxt: &mut locator::Context<'b>, locator: &mut CrateLocator<'b>,
path_kind: PathKind, path_kind: PathKind,
) -> Option<(LoadResult, Option<Library>)> ) -> Option<(LoadResult, Option<Library>)>
where where
'a: 'b, 'a: 'b,
{ {
// Use a new locator Context so trying to load a proc macro doesn't affect the error // Use a new crate locator so trying to load a proc macro doesn't affect the error
// message we emit // message we emit
let mut proc_macro_locator = locate_ctxt.clone(); let mut proc_macro_locator = locator.clone();
// Try to load a proc macro // Try to load a proc macro
proc_macro_locator.is_proc_macro = Some(true); proc_macro_locator.is_proc_macro = Some(true);
...@@ -287,10 +287,10 @@ fn load_proc_macro<'b>( ...@@ -287,10 +287,10 @@ fn load_proc_macro<'b>(
LoadResult::Previous(cnum) => return Some((LoadResult::Previous(cnum), None)), LoadResult::Previous(cnum) => return Some((LoadResult::Previous(cnum), None)),
LoadResult::Loaded(library) => Some(LoadResult::Loaded(library)) LoadResult::Loaded(library) => Some(LoadResult::Loaded(library))
}; };
locate_ctxt.hash = locate_ctxt.host_hash; locator.hash = locator.host_hash;
// Use the locate_ctxt when looking for the host proc macro crate, as that is required // Use the locator when looking for the host proc macro crate, as that is required
// so we want it to affect the error message // so we want it to affect the error message
(locate_ctxt, result) (locator, result)
} else { } else {
(&mut proc_macro_locator, None) (&mut proc_macro_locator, None)
}; };
...@@ -350,7 +350,7 @@ fn maybe_resolve_crate<'b>( ...@@ -350,7 +350,7 @@ fn maybe_resolve_crate<'b>(
(LoadResult::Previous(cnum), None) (LoadResult::Previous(cnum), None)
} else { } else {
info!("falling back to a load"); info!("falling back to a load");
let mut locate_ctxt = locator::Context { let mut locator = CrateLocator {
sess: self.sess, sess: self.sess,
span, span,
crate_name: name, crate_name: name,
...@@ -371,10 +371,10 @@ fn maybe_resolve_crate<'b>( ...@@ -371,10 +371,10 @@ fn maybe_resolve_crate<'b>(
metadata_loader: self.metadata_loader, metadata_loader: self.metadata_loader,
}; };
self.load(&mut locate_ctxt).map(|r| (r, None)).or_else(|| { self.load(&mut locator).map(|r| (r, None)).or_else(|| {
dep_kind = DepKind::UnexportedMacrosOnly; dep_kind = DepKind::UnexportedMacrosOnly;
self.load_proc_macro(&mut locate_ctxt, path_kind) self.load_proc_macro(&mut locator, path_kind)
}).ok_or_else(move || LoadError::LocatorError(locate_ctxt))? }).ok_or_else(move || LoadError::LocatorError(locator))?
}; };
match result { match result {
...@@ -395,8 +395,8 @@ fn maybe_resolve_crate<'b>( ...@@ -395,8 +395,8 @@ fn maybe_resolve_crate<'b>(
} }
} }
fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> { fn load(&self, locator: &mut CrateLocator<'_>) -> Option<LoadResult> {
let library = locate_ctxt.maybe_load_library_crate()?; let library = locator.maybe_load_library_crate()?;
// In the case that we're loading a crate, but not matching // In the case that we're loading a crate, but not matching
// against a hash, we could load a crate which has the same hash // against a hash, we could load a crate which has the same hash
...@@ -407,11 +407,11 @@ fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> { ...@@ -407,11 +407,11 @@ fn load(&self, locate_ctxt: &mut locator::Context<'_>) -> Option<LoadResult> {
// don't want to match a host crate against an equivalent target one // don't want to match a host crate against an equivalent target one
// already loaded. // already loaded.
let root = library.metadata.get_root(); let root = library.metadata.get_root();
if locate_ctxt.triple == self.sess.opts.target_triple { if locator.triple == self.sess.opts.target_triple {
let mut result = LoadResult::Loaded(library); let mut result = LoadResult::Loaded(library);
self.cstore.iter_crate_data(|cnum, data| { self.cstore.iter_crate_data(|cnum, data| {
if data.root.name == root.name && root.hash == data.root.hash { if data.root.name == root.name && root.hash == data.root.hash {
assert!(locate_ctxt.hash.is_none()); assert!(locator.hash.is_none());
info!("load success, going to previous cnum: {}", cnum); info!("load success, going to previous cnum: {}", cnum);
result = LoadResult::Previous(cnum); result = LoadResult::Previous(cnum);
} }
......
...@@ -254,7 +254,7 @@ ...@@ -254,7 +254,7 @@
} }
#[derive(Clone)] #[derive(Clone)]
crate struct Context<'a> { crate struct CrateLocator<'a> {
pub sess: &'a Session, pub sess: &'a Session,
pub span: Span, pub span: Span,
pub crate_name: Symbol, pub crate_name: Symbol,
...@@ -298,7 +298,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ...@@ -298,7 +298,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
} }
} }
impl<'a> Context<'a> { impl<'a> CrateLocator<'a> {
crate fn reset(&mut self) { crate fn reset(&mut self) {
self.rejected_via_hash.clear(); self.rejected_via_hash.clear();
self.rejected_via_triple.clear(); self.rejected_via_triple.clear();
...@@ -926,7 +926,7 @@ pub fn find_plugin_registrar( ...@@ -926,7 +926,7 @@ pub fn find_plugin_registrar(
let host_triple = TargetTriple::from_triple(config::host_triple()); let host_triple = TargetTriple::from_triple(config::host_triple());
let is_cross = target_triple != host_triple; let is_cross = target_triple != host_triple;
let mut target_only = false; let mut target_only = false;
let mut locate_ctxt = Context { let mut locator = CrateLocator {
sess, sess,
span, span,
crate_name: name, crate_name: name,
...@@ -947,7 +947,7 @@ pub fn find_plugin_registrar( ...@@ -947,7 +947,7 @@ pub fn find_plugin_registrar(
metadata_loader, metadata_loader,
}; };
let library = locate_ctxt.maybe_load_library_crate().or_else(|| { let library = locator.maybe_load_library_crate().or_else(|| {
if !is_cross { if !is_cross {
return None return None
} }
...@@ -955,15 +955,15 @@ pub fn find_plugin_registrar( ...@@ -955,15 +955,15 @@ pub fn find_plugin_registrar(
// try to load a plugin registrar function, // try to load a plugin registrar function,
target_only = true; target_only = true;
locate_ctxt.target = &sess.target.target; locator.target = &sess.target.target;
locate_ctxt.triple = target_triple; locator.triple = target_triple;
locate_ctxt.filesearch = sess.target_filesearch(PathKind::Crate); locator.filesearch = sess.target_filesearch(PathKind::Crate);
locate_ctxt.maybe_load_library_crate() locator.maybe_load_library_crate()
}); });
let library = match library { let library = match library {
Some(l) => l, Some(l) => l,
None => locate_ctxt.report_errs(), None => locator.report_errs(),
}; };
if target_only { if target_only {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册