Skip to content

Commit c7a99e2

Browse files
committed
Rename variants of CrateDepKind to be more descriptive
Perhaps the old name used to be accurate in the past, but nowadays most injected dependencies are unconditionally linked too.
1 parent a0f8dff commit c7a99e2

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl CStore {
737737
.maybe_resolve_crate(
738738
tcx,
739739
sym::core,
740-
CrateDepKind::Explicit,
740+
CrateDepKind::Unconditional,
741741
CrateOrigin::Extern,
742742
)
743743
.is_err();
@@ -985,11 +985,15 @@ impl CStore {
985985
};
986986
info!("panic runtime not found -- loading {}", name);
987987

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

10191023
let name = Symbol::intern(&tcx.sess.opts.unstable_opts.profiler_runtime);
1020-
let Some(cnum) =
1021-
self.resolve_crate(tcx, name, DUMMY_SP, CrateDepKind::Explicit, CrateOrigin::Injected)
1022-
else {
1024+
let Some(cnum) = self.resolve_crate(
1025+
tcx,
1026+
name,
1027+
DUMMY_SP,
1028+
CrateDepKind::Unconditional,
1029+
CrateOrigin::Injected,
1030+
) else {
10231031
return;
10241032
};
10251033
let data = self.get_crate_data(cnum);
@@ -1139,7 +1147,7 @@ impl CStore {
11391147
tcx,
11401148
name_interned,
11411149
DUMMY_SP,
1142-
CrateDepKind::Explicit,
1150+
CrateDepKind::Unconditional,
11431151
CrateOrigin::Extern,
11441152
);
11451153
}
@@ -1171,7 +1179,7 @@ impl CStore {
11711179
tcx,
11721180
sym::compiler_builtins,
11731181
krate.spans.inner_span.shrink_to_lo(),
1174-
CrateDepKind::Explicit,
1182+
CrateDepKind::Unconditional,
11751183
CrateOrigin::Injected,
11761184
) else {
11771185
info!("`compiler_builtins` not resolved");
@@ -1288,7 +1296,7 @@ impl CStore {
12881296
let dep_kind = if attr::contains_name(&item.attrs, sym::no_link) {
12891297
CrateDepKind::MacrosOnly
12901298
} else {
1291-
CrateDepKind::Explicit
1299+
CrateDepKind::Unconditional
12921300
};
12931301

12941302
let cnum =
@@ -1318,7 +1326,7 @@ impl CStore {
13181326
span: Span,
13191327
) -> Option<CrateNum> {
13201328
let cnum =
1321-
self.resolve_crate(tcx, name, span, CrateDepKind::Explicit, CrateOrigin::Extern)?;
1329+
self.resolve_crate(tcx, name, span, CrateDepKind::Unconditional, CrateOrigin::Extern)?;
13221330

13231331
self.update_extern_crate(
13241332
cnum,
@@ -1336,7 +1344,7 @@ impl CStore {
13361344
}
13371345

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

compiler/rustc_metadata/src/dependency_format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
242242
let src = tcx.used_crate_source(cnum);
243243
if src.dylib.is_none()
244244
&& !formats.contains_key(&cnum)
245-
&& tcx.dep_kind(cnum) == CrateDepKind::Explicit
245+
&& tcx.dep_kind(cnum) == CrateDepKind::Unconditional
246246
{
247247
assert!(src.rlib.is_some() || src.rmeta.is_some());
248248
info!("adding staticlib: {}", tcx.crate_name(cnum));
@@ -355,8 +355,8 @@ fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<De
355355
for &cnum in tcx.crates(()) {
356356
assert_eq!(
357357
ret.push(match tcx.dep_kind(cnum) {
358-
CrateDepKind::Explicit => Linkage::Static,
359-
CrateDepKind::MacrosOnly | CrateDepKind::Implicit => Linkage::NotLinked,
358+
CrateDepKind::Unconditional => Linkage::Static,
359+
CrateDepKind::MacrosOnly | CrateDepKind::Conditional => Linkage::NotLinked,
360360
}),
361361
cnum
362362
);

compiler/rustc_session/src/cstore.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ impl CrateSource {
3939
pub enum CrateDepKind {
4040
/// A dependency that is only used for its macros.
4141
MacrosOnly,
42-
/// A dependency that is always injected into the dependency list and so
43-
/// doesn't need to be linked to an rlib, e.g., the injected panic runtime.
44-
Implicit,
42+
/// A dependency that is injected into the crate graph but which only
43+
/// sometimes needs to actually be linked in, e.g., the injected panic runtime.
44+
Conditional,
4545
/// A dependency that is required by an rlib version of this crate.
46-
/// Ordinary `extern crate`s result in `Explicit` dependencies.
47-
Explicit,
46+
/// Ordinary `extern crate`s as well as most injected dependencies result
47+
/// in `Unconditional` dependencies.
48+
Unconditional,
4849
}
4950

5051
impl CrateDepKind {
5152
#[inline]
5253
pub fn macros_only(self) -> bool {
5354
match self {
5455
CrateDepKind::MacrosOnly => true,
55-
CrateDepKind::Implicit | CrateDepKind::Explicit => false,
56+
CrateDepKind::Conditional | CrateDepKind::Unconditional => false,
5657
}
5758
}
5859
}

0 commit comments

Comments
 (0)