Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 22 additions & 14 deletions compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl CStore {
.maybe_resolve_crate(
tcx,
sym::core,
CrateDepKind::Explicit,
CrateDepKind::Unconditional,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: okay I was about to ask what's the distinction between Explicit/Implicit, but this commit answers my question 😆

CrateOrigin::Extern,
)
.is_err();
Expand Down Expand Up @@ -985,11 +985,15 @@ impl CStore {
};
info!("panic runtime not found -- loading {}", name);

// This has to be implicit as both panic_unwind and panic_abort may be present in the crate
// graph at the same time. One of them will later be activated in dependency_formats.
let Some(cnum) =
self.resolve_crate(tcx, name, DUMMY_SP, CrateDepKind::Implicit, CrateOrigin::Injected)
else {
// This has to be conditional as both panic_unwind and panic_abort may be present in the
// crate graph at the same time. One of them will later be activated in dependency_formats.
let Some(cnum) = self.resolve_crate(
tcx,
name,
DUMMY_SP,
CrateDepKind::Conditional,
CrateOrigin::Injected,
) else {
return;
};
let data = self.get_crate_data(cnum);
Expand Down Expand Up @@ -1017,9 +1021,13 @@ impl CStore {
info!("loading profiler");

let name = Symbol::intern(&tcx.sess.opts.unstable_opts.profiler_runtime);
let Some(cnum) =
self.resolve_crate(tcx, name, DUMMY_SP, CrateDepKind::Explicit, CrateOrigin::Injected)
else {
let Some(cnum) = self.resolve_crate(
tcx,
name,
DUMMY_SP,
CrateDepKind::Unconditional,
CrateOrigin::Injected,
) else {
return;
};
let data = self.get_crate_data(cnum);
Expand Down Expand Up @@ -1139,7 +1147,7 @@ impl CStore {
tcx,
name_interned,
DUMMY_SP,
CrateDepKind::Explicit,
CrateDepKind::Unconditional,
CrateOrigin::Extern,
);
}
Expand Down Expand Up @@ -1171,7 +1179,7 @@ impl CStore {
tcx,
sym::compiler_builtins,
krate.spans.inner_span.shrink_to_lo(),
CrateDepKind::Explicit,
CrateDepKind::Unconditional,
CrateOrigin::Injected,
) else {
info!("`compiler_builtins` not resolved");
Expand Down Expand Up @@ -1288,7 +1296,7 @@ impl CStore {
let dep_kind = if attr::contains_name(&item.attrs, sym::no_link) {
CrateDepKind::MacrosOnly
} else {
CrateDepKind::Explicit
CrateDepKind::Unconditional
};

let cnum =
Expand Down Expand Up @@ -1318,7 +1326,7 @@ impl CStore {
span: Span,
) -> Option<CrateNum> {
let cnum =
self.resolve_crate(tcx, name, span, CrateDepKind::Explicit, CrateOrigin::Extern)?;
self.resolve_crate(tcx, name, span, CrateDepKind::Unconditional, CrateOrigin::Extern)?;

self.update_extern_crate(
cnum,
Expand All @@ -1336,7 +1344,7 @@ impl CStore {
}

pub fn maybe_process_path_extern(&mut self, tcx: TyCtxt<'_>, name: Symbol) -> Option<CrateNum> {
self.maybe_resolve_crate(tcx, name, CrateDepKind::Explicit, CrateOrigin::Extern).ok()
self.maybe_resolve_crate(tcx, name, CrateDepKind::Unconditional, CrateOrigin::Extern).ok()
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
let src = tcx.used_crate_source(cnum);
if src.dylib.is_none()
&& !formats.contains_key(&cnum)
&& tcx.dep_kind(cnum) == CrateDepKind::Explicit
&& tcx.dep_kind(cnum) == CrateDepKind::Unconditional
{
assert!(src.rlib.is_some() || src.rmeta.is_some());
info!("adding staticlib: {}", tcx.crate_name(cnum));
Expand Down Expand Up @@ -355,8 +355,8 @@ fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<De
for &cnum in tcx.crates(()) {
assert_eq!(
ret.push(match tcx.dep_kind(cnum) {
CrateDepKind::Explicit => Linkage::Static,
CrateDepKind::MacrosOnly | CrateDepKind::Implicit => Linkage::NotLinked,
CrateDepKind::Unconditional => Linkage::Static,
CrateDepKind::MacrosOnly | CrateDepKind::Conditional => Linkage::NotLinked,
}),
cnum
);
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_session/src/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ impl CrateSource {
pub enum CrateDepKind {
/// A dependency that is only used for its macros.
MacrosOnly,
/// A dependency that is always injected into the dependency list and so
/// doesn't need to be linked to an rlib, e.g., the injected panic runtime.
Implicit,
/// A dependency that is injected into the crate graph but which only
/// sometimes needs to actually be linked in, e.g., the injected panic runtime.
Conditional,
/// A dependency that is required by an rlib version of this crate.
/// Ordinary `extern crate`s result in `Explicit` dependencies.
Explicit,
/// Ordinary `extern crate`s as well as most injected dependencies result
/// in `Unconditional` dependencies.
Unconditional,
}

impl CrateDepKind {
#[inline]
pub fn macros_only(self) -> bool {
match self {
CrateDepKind::MacrosOnly => true,
CrateDepKind::Implicit | CrateDepKind::Explicit => false,
CrateDepKind::Conditional | CrateDepKind::Unconditional => false,
}
}
}
Expand Down