Skip to content

Commit

Permalink
Auto merge of #88538 - bjorn3:no_session_in_crate_loader, r=petrochenkov
Browse files Browse the repository at this point in the history
CrateLocator refactorings

This makes the `CrateLocator` a lot cleaner IMHO and much more self-contained. The last commit removes `extra_filename` from the crate metadata. This is an **insta-stable** change as it allows a crate like `libfoo-abc.rlib` to be used as dependency and then be renamed as `libfoo-bcd.rlib` while still being found as indirect dependency. This may reduce performance when there are a lot of versions of the same crate available as the extra filename won't be used to do an early rejection of crates before trying to load metadata, but it makes the logic to find the right filename a lot cleaner.
  • Loading branch information
bors committed Sep 4, 2021
2 parents 065a372 + ff98cb6 commit d295e36
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 94 deletions.
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

0 comments on commit d295e36

Please sign in to comment.