Skip to content

CrateLocator refactorings #88538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ impl<'a> CrateLoader<'a> {
&self,
locator: &mut CrateLocator<'b>,
path_kind: PathKind,
host_hash: Option<Svh>,
) -> Result<Option<(LoadResult, Option<Library>)>, CrateError>
where
'a: 'b,
Expand All @@ -459,7 +460,7 @@ impl<'a> CrateLoader<'a> {
let mut proc_macro_locator = locator.clone();

// Try to load a proc macro
proc_macro_locator.is_proc_macro = Some(true);
proc_macro_locator.is_proc_macro = true;

// Load the proc macro crate for the target
let (locator, target_result) = if self.sess.opts.debugging_opts.dual_proc_macros {
Expand All @@ -471,7 +472,7 @@ impl<'a> CrateLoader<'a> {
Some(LoadResult::Loaded(library)) => Some(LoadResult::Loaded(library)),
None => return Ok(None),
};
locator.hash = locator.host_hash;
locator.hash = host_hash;
// Use the locator when looking for the host proc macro crate, as that is required
// so we want it to affect the error message
(locator, result)
Expand All @@ -482,7 +483,7 @@ impl<'a> CrateLoader<'a> {
// Load the proc macro crate for the host

locator.reset();
locator.is_proc_macro = Some(true);
locator.is_proc_macro = true;
locator.target = &self.sess.host;
locator.triple = TargetTriple::from_triple(config::host_triple());
locator.filesearch = self.sess.host_filesearch(path_kind);
Expand Down Expand Up @@ -510,12 +511,9 @@ impl<'a> CrateLoader<'a> {
name: Symbol,
span: Span,
dep_kind: CrateDepKind,
dep: Option<(&'b CratePaths, &'b CrateDep)>,
) -> CrateNum {
if dep.is_none() {
self.used_extern_options.insert(name);
}
self.maybe_resolve_crate(name, dep_kind, dep).unwrap_or_else(|err| {
self.used_extern_options.insert(name);
self.maybe_resolve_crate(name, dep_kind, None).unwrap_or_else(|err| {
let missing_core =
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
err.report(&self.sess, span, missing_core)
Expand Down Expand Up @@ -551,21 +549,18 @@ impl<'a> CrateLoader<'a> {
&*self.metadata_loader,
name,
hash,
host_hash,
extra_filename,
false, // is_host
path_kind,
root,
Some(false), // is_proc_macro
);

match self.load(&mut locator)? {
Some(res) => (res, None),
None => {
dep_kind = CrateDepKind::MacrosOnly;
match self.load_proc_macro(&mut locator, path_kind)? {
match self.load_proc_macro(&mut locator, path_kind, host_hash)? {
Some(res) => res,
None => return Err(locator.into_error()),
None => return Err(locator.into_error(root.cloned())),
}
}
}
Expand Down Expand Up @@ -605,7 +600,7 @@ impl<'a> CrateLoader<'a> {
// FIXME: why is this condition necessary? It was adding in #33625 but I
// don't know why and the original author doesn't remember ...
let can_reuse_cratenum =
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro == Some(true);
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro;
Ok(Some(if can_reuse_cratenum {
let mut result = LoadResult::Loaded(library);
self.cstore.iter_crate_data(|cnum, data| {
Expand Down Expand Up @@ -755,7 +750,7 @@ impl<'a> CrateLoader<'a> {
};
info!("panic runtime not found -- loading {}", name);

let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
let data = self.cstore.get_crate_data(cnum);

// Sanity check the loaded crate to ensure it is indeed a panic runtime
Expand Down Expand Up @@ -795,7 +790,7 @@ impl<'a> CrateLoader<'a> {
);
}

let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
let data = self.cstore.get_crate_data(cnum);

// Sanity check the loaded crate to ensure it is indeed a profiler runtime
Expand Down Expand Up @@ -1015,7 +1010,7 @@ impl<'a> CrateLoader<'a> {
CrateDepKind::Explicit
};

let cnum = self.resolve_crate(name, item.span, dep_kind, None);
let cnum = self.resolve_crate(name, item.span, dep_kind);

let path_len = definitions.def_path(def_id).data.len();
self.update_extern_crate(
Expand All @@ -1034,7 +1029,7 @@ impl<'a> CrateLoader<'a> {
}

pub fn process_path_extern(&mut self, name: Symbol, span: Span) -> CrateNum {
let cnum = self.resolve_crate(name, span, CrateDepKind::Explicit, None);
let cnum = self.resolve_crate(name, span, CrateDepKind::Explicit);

self.update_extern_crate(
cnum,
Expand Down
Loading