Skip to content

Commit 2d2d70f

Browse files
committed
Remove dependency injection for the panic runtime
This used to be necessary for a correct linker order, but ever since the introduction of symbols.o adding the symbols in question to symbols.o would work just as well. We do still add dependencies on the panic runtime to the local crate, but not for #![needs_panic_runtime] crates. This also removes the runtime-depends-on-needs-runtime test. inject_dependency_if used to emit this error, but with symbols.o it is no longer important that there is no dependency and in fact it may be nice to have panic_abort and panic_unwind directly depend on libstd in the future for calling std::process::abort().
1 parent 1e10dfc commit 2d2d70f

File tree

5 files changed

+3
-97
lines changed

5 files changed

+3
-97
lines changed

compiler/rustc_metadata/src/creader.rs

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Validates all used crates and extern libraries and loads their metadata
22
33
use std::error::Error;
4-
use std::ops::Fn;
54
use std::path::Path;
65
use std::str::FromStr;
76
use std::time::Duration;
@@ -276,12 +275,6 @@ impl CStore {
276275
.filter_map(|(cnum, data)| data.as_deref().map(|data| (cnum, data)))
277276
}
278277

279-
fn iter_crate_data_mut(&mut self) -> impl Iterator<Item = (CrateNum, &mut CrateMetadata)> {
280-
self.metas
281-
.iter_enumerated_mut()
282-
.filter_map(|(cnum, data)| data.as_deref_mut().map(|data| (cnum, data)))
283-
}
284-
285278
fn push_dependencies_in_postorder(&self, deps: &mut IndexSet<CrateNum>, cnum: CrateNum) {
286279
if !deps.contains(&cnum) {
287280
let data = self.get_crate_data(cnum);
@@ -307,13 +300,6 @@ impl CStore {
307300
deps
308301
}
309302

310-
fn crate_dependencies_in_reverse_postorder(
311-
&self,
312-
cnum: CrateNum,
313-
) -> impl Iterator<Item = CrateNum> {
314-
self.crate_dependencies_in_postorder(cnum).into_iter().rev()
315-
}
316-
317303
pub(crate) fn injected_panic_runtime(&self) -> Option<CrateNum> {
318304
self.injected_panic_runtime
319305
}
@@ -966,27 +952,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
966952
// If we need a panic runtime, we try to find an existing one here. At
967953
// the same time we perform some general validation of the DAG we've got
968954
// going such as ensuring everything has a compatible panic strategy.
969-
//
970-
// The logic for finding the panic runtime here is pretty much the same
971-
// as the allocator case with the only addition that the panic strategy
972-
// compilation mode also comes into play.
973955
let desired_strategy = self.sess.panic_strategy();
974956
let mut runtime_found = false;
975957
let mut needs_panic_runtime = attr::contains_name(&krate.attrs, sym::needs_panic_runtime);
976958

977-
let mut panic_runtimes = Vec::new();
978-
for (cnum, data) in self.cstore.iter_crate_data() {
959+
for (_cnum, data) in self.cstore.iter_crate_data() {
979960
needs_panic_runtime = needs_panic_runtime || data.needs_panic_runtime();
980961
if data.is_panic_runtime() {
981-
// Inject a dependency from all #![needs_panic_runtime] to this
982-
// #![panic_runtime] crate.
983-
panic_runtimes.push(cnum);
984962
runtime_found = runtime_found || data.dep_kind() == CrateDepKind::Explicit;
985963
}
986964
}
987-
for cnum in panic_runtimes {
988-
self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime());
989-
}
990965

991966
// If an explicitly linked and matching panic runtime was found, or if
992967
// we just don't need one at all, then we're done here and there's
@@ -997,12 +972,10 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
997972

998973
// By this point we know that we (a) need a panic runtime and (b) no
999974
// panic runtime was explicitly linked. Here we just load an appropriate
1000-
// default runtime for our panic strategy and then inject the
1001-
// dependencies.
975+
// default runtime for our panic strategy.
1002976
//
1003977
// We may resolve to an already loaded crate (as the crate may not have
1004-
// been explicitly linked prior to this) and we may re-inject
1005-
// dependencies again, but both of those situations are fine.
978+
// been explicitly linked prior to this), but this is fine.
1006979
//
1007980
// Also note that we have yet to perform validation of the crate graph
1008981
// in terms of everyone has a compatible panic runtime format, that's
@@ -1031,7 +1004,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
10311004
}
10321005

10331006
self.cstore.injected_panic_runtime = Some(cnum);
1034-
self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime());
10351007
}
10361008

10371009
fn inject_profiler_runtime(&mut self) {
@@ -1212,45 +1184,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
12121184
}
12131185
}
12141186

1215-
fn inject_dependency_if(
1216-
&mut self,
1217-
krate: CrateNum,
1218-
what: &str,
1219-
needs_dep: &dyn Fn(&CrateMetadata) -> bool,
1220-
) {
1221-
// Don't perform this validation if the session has errors, as one of
1222-
// those errors may indicate a circular dependency which could cause
1223-
// this to stack overflow.
1224-
if self.dcx().has_errors().is_some() {
1225-
return;
1226-
}
1227-
1228-
// Before we inject any dependencies, make sure we don't inject a
1229-
// circular dependency by validating that this crate doesn't
1230-
// transitively depend on any crates satisfying `needs_dep`.
1231-
for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
1232-
let data = self.cstore.get_crate_data(dep);
1233-
if needs_dep(&data) {
1234-
self.dcx().emit_err(errors::NoTransitiveNeedsDep {
1235-
crate_name: self.cstore.get_crate_data(krate).name(),
1236-
needs_crate_name: what,
1237-
deps_crate_name: data.name(),
1238-
});
1239-
}
1240-
}
1241-
1242-
// All crates satisfying `needs_dep` do not explicitly depend on the
1243-
// crate provided for this compile, but in order for this compilation to
1244-
// be successfully linked we need to inject a dependency (to order the
1245-
// crates on the command line correctly).
1246-
for (cnum, data) in self.cstore.iter_crate_data_mut() {
1247-
if needs_dep(data) {
1248-
info!("injecting a dep from {} to {}", cnum, krate);
1249-
data.add_dependency(krate);
1250-
}
1251-
}
1252-
}
1253-
12541187
fn report_unused_deps(&mut self, krate: &ast::Crate) {
12551188
// Make a point span rather than covering the whole file
12561189
let span = krate.spans.inner_span.shrink_to_lo();

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,10 +1895,6 @@ impl CrateMetadata {
18951895
self.dependencies.iter().copied()
18961896
}
18971897

1898-
pub(crate) fn add_dependency(&mut self, cnum: CrateNum) {
1899-
self.dependencies.push(cnum);
1900-
}
1901-
19021898
pub(crate) fn target_modifiers(&self) -> TargetModifiers {
19031899
self.root.decode_target_modifiers(&self.blob).collect()
19041900
}

tests/ui/panic-runtime/auxiliary/depends.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/panic-runtime/auxiliary/needs-panic-runtime.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/ui/panic-runtime/runtime-depend-on-needs-runtime.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)