Skip to content

Commit d295e36

Browse files
committed
Auto merge of rust-lang#88538 - bjorn3:no_session_in_crate_loader, r=petrochenkov
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.
2 parents 065a372 + ff98cb6 commit d295e36

File tree

2 files changed

+77
-94
lines changed

2 files changed

+77
-94
lines changed

compiler/rustc_metadata/src/creader.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ impl<'a> CrateLoader<'a> {
450450
&self,
451451
locator: &mut CrateLocator<'b>,
452452
path_kind: PathKind,
453+
host_hash: Option<Svh>,
453454
) -> Result<Option<(LoadResult, Option<Library>)>, CrateError>
454455
where
455456
'a: 'b,
@@ -459,7 +460,7 @@ impl<'a> CrateLoader<'a> {
459460
let mut proc_macro_locator = locator.clone();
460461

461462
// Try to load a proc macro
462-
proc_macro_locator.is_proc_macro = Some(true);
463+
proc_macro_locator.is_proc_macro = true;
463464

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

484485
locator.reset();
485-
locator.is_proc_macro = Some(true);
486+
locator.is_proc_macro = true;
486487
locator.target = &self.sess.host;
487488
locator.triple = TargetTriple::from_triple(config::host_triple());
488489
locator.filesearch = self.sess.host_filesearch(path_kind);
@@ -510,12 +511,9 @@ impl<'a> CrateLoader<'a> {
510511
name: Symbol,
511512
span: Span,
512513
dep_kind: CrateDepKind,
513-
dep: Option<(&'b CratePaths, &'b CrateDep)>,
514514
) -> CrateNum {
515-
if dep.is_none() {
516-
self.used_extern_options.insert(name);
517-
}
518-
self.maybe_resolve_crate(name, dep_kind, dep).unwrap_or_else(|err| {
515+
self.used_extern_options.insert(name);
516+
self.maybe_resolve_crate(name, dep_kind, None).unwrap_or_else(|err| {
519517
let missing_core =
520518
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
521519
err.report(&self.sess, span, missing_core)
@@ -551,21 +549,18 @@ impl<'a> CrateLoader<'a> {
551549
&*self.metadata_loader,
552550
name,
553551
hash,
554-
host_hash,
555552
extra_filename,
556553
false, // is_host
557554
path_kind,
558-
root,
559-
Some(false), // is_proc_macro
560555
);
561556

562557
match self.load(&mut locator)? {
563558
Some(res) => (res, None),
564559
None => {
565560
dep_kind = CrateDepKind::MacrosOnly;
566-
match self.load_proc_macro(&mut locator, path_kind)? {
561+
match self.load_proc_macro(&mut locator, path_kind, host_hash)? {
567562
Some(res) => res,
568-
None => return Err(locator.into_error()),
563+
None => return Err(locator.into_error(root.cloned())),
569564
}
570565
}
571566
}
@@ -605,7 +600,7 @@ impl<'a> CrateLoader<'a> {
605600
// FIXME: why is this condition necessary? It was adding in #33625 but I
606601
// don't know why and the original author doesn't remember ...
607602
let can_reuse_cratenum =
608-
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro == Some(true);
603+
locator.triple == self.sess.opts.target_triple || locator.is_proc_macro;
609604
Ok(Some(if can_reuse_cratenum {
610605
let mut result = LoadResult::Loaded(library);
611606
self.cstore.iter_crate_data(|cnum, data| {
@@ -755,7 +750,7 @@ impl<'a> CrateLoader<'a> {
755750
};
756751
info!("panic runtime not found -- loading {}", name);
757752

758-
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
753+
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
759754
let data = self.cstore.get_crate_data(cnum);
760755

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

798-
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
793+
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit);
799794
let data = self.cstore.get_crate_data(cnum);
800795

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

1018-
let cnum = self.resolve_crate(name, item.span, dep_kind, None);
1013+
let cnum = self.resolve_crate(name, item.span, dep_kind);
10191014

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

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

10391034
self.update_extern_crate(
10401035
cnum,

0 commit comments

Comments
 (0)