Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0a4176a

Browse files
committed
Revert "Rollup merge of rust-lang#124976 - petrochenkov:usedcrates, r=oli-obk"
This reverts commit eda4a35, reversing changes made to eb6b35b.
1 parent 2b6a342 commit 0a4176a

File tree

23 files changed

+47
-54
lines changed

23 files changed

+47
-54
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ fn upstream_monomorphizations_provider(
400400
tcx: TyCtxt<'_>,
401401
(): (),
402402
) -> DefIdMap<UnordMap<GenericArgsRef<'_>, CrateNum>> {
403-
let cnums = tcx.used_crates(());
403+
let cnums = tcx.crates(());
404404

405405
let mut instances: DefIdMap<UnordMap<_, _>> = Default::default();
406406

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ pub fn collect_debugger_visualizers_transitive(
541541
tcx.debugger_visualizers(LOCAL_CRATE)
542542
.iter()
543543
.chain(
544-
tcx.used_crates(())
544+
tcx.crates(())
545545
.iter()
546546
.filter(|&cnum| {
547547
let used_crate_source = tcx.used_crate_source(*cnum);
@@ -851,7 +851,7 @@ impl CrateInfo {
851851
// `compiler_builtins` are always placed last to ensure that they're linked correctly.
852852
used_crates.extend(compiler_builtins);
853853

854-
let crates = tcx.used_crates(());
854+
let crates = tcx.crates(());
855855
let n_crates = crates.len();
856856
let mut info = CrateInfo {
857857
target_cpu,

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
464464
}
465465
}
466466

467-
for &cnum in tcx.crates_including_speculative(()) {
467+
for &cnum in tcx.crates(()) {
468468
let source = tcx.used_crate_source(cnum);
469469
if let Some((path, _)) = &source.dylib {
470470
files.push(escape_dep_filename(&path.display().to_string()));

compiler/rustc_metadata/src/dependency_format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
144144
&& sess.crt_static(Some(ty))
145145
&& !sess.target.crt_static_allows_dylibs)
146146
{
147-
for &cnum in tcx.used_crates(()).iter() {
147+
for &cnum in tcx.crates(()).iter() {
148148
if tcx.dep_kind(cnum).macros_only() {
149149
continue;
150150
}
@@ -165,7 +165,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
165165
// Sweep all crates for found dylibs. Add all dylibs, as well as their
166166
// dependencies, ensuring there are no conflicts. The only valid case for a
167167
// dependency to be relied upon twice is for both cases to rely on a dylib.
168-
for &cnum in tcx.used_crates(()).iter() {
168+
for &cnum in tcx.crates(()).iter() {
169169
if tcx.dep_kind(cnum).macros_only() {
170170
continue;
171171
}
@@ -183,7 +183,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
183183
}
184184

185185
// Collect what we've got so far in the return vector.
186-
let last_crate = tcx.used_crates(()).len();
186+
let last_crate = tcx.crates(()).len();
187187
let mut ret = (1..last_crate + 1)
188188
.map(|cnum| match formats.get(&CrateNum::new(cnum)) {
189189
Some(&RequireDynamic) => Linkage::Dynamic,
@@ -197,7 +197,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
197197
//
198198
// If the crate hasn't been included yet and it's not actually required
199199
// (e.g., it's an allocator) then we skip it here as well.
200-
for &cnum in tcx.used_crates(()).iter() {
200+
for &cnum in tcx.crates(()).iter() {
201201
let src = tcx.used_crate_source(cnum);
202202
if src.dylib.is_none()
203203
&& !formats.contains_key(&cnum)
@@ -285,7 +285,7 @@ fn add_library(
285285

286286
fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<DependencyList> {
287287
let all_crates_available_as_rlib = tcx
288-
.used_crates(())
288+
.crates(())
289289
.iter()
290290
.copied()
291291
.filter_map(|cnum| {
@@ -306,7 +306,7 @@ fn attempt_static(tcx: TyCtxt<'_>, unavailable: &mut Vec<CrateNum>) -> Option<De
306306
// All crates are available in an rlib format, so we're just going to link
307307
// everything in explicitly so long as it's actually required.
308308
let mut ret = tcx
309-
.used_crates(())
309+
.crates(())
310310
.iter()
311311
.map(|&cnum| match tcx.dep_kind(cnum) {
312312
CrateDepKind::Explicit => Linkage::Static,

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
439439
// traversal, but not globally minimal across all crates.
440440
let bfs_queue = &mut VecDeque::new();
441441

442-
for &cnum in tcx.crates_including_speculative(()) {
442+
for &cnum in tcx.crates(()) {
443443
// Ignore crates without a corresponding local `extern crate` item.
444444
if tcx.missing_extern_crate_item(cnum) {
445445
continue;
@@ -509,7 +509,7 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
509509
tcx.arena
510510
.alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE))
511511
},
512-
crates_including_speculative: |tcx, ()| {
512+
crates: |tcx, ()| {
513513
// The list of loaded crates is now frozen in query cache,
514514
// so make sure cstore is not mutably accessed from here on.
515515
tcx.untracked().cstore.freeze();

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18991899

19001900
let deps = self
19011901
.tcx
1902-
.crates_including_speculative(())
1902+
.crates(())
19031903
.iter()
19041904
.map(|&cnum| {
19051905
let dep = CrateDep {

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
10401040
let krate = tcx.hir_crate(());
10411041
let hir_body_hash = krate.opt_hir_hash.expect("HIR hash missing while computing crate hash");
10421042

1043-
let upstream_crates = upstream_crates_for_hashing(tcx);
1043+
let upstream_crates = upstream_crates(tcx);
10441044

10451045
let resolutions = tcx.resolutions(());
10461046

@@ -1109,9 +1109,9 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
11091109
Svh::new(crate_hash)
11101110
}
11111111

1112-
fn upstream_crates_for_hashing(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
1112+
fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
11131113
let mut upstream_crates: Vec<_> = tcx
1114-
.crates_including_speculative(())
1114+
.crates(())
11151115
.iter()
11161116
.map(|&cnum| {
11171117
let stable_crate_id = tcx.stable_crate_id(cnum);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,22 +1861,13 @@ rustc_queries! {
18611861
eval_always
18621862
desc { "calculating the stability index for the local crate" }
18631863
}
1864-
/// All loaded crates, including those loaded purely for doc links or diagnostics.
1865-
/// (Diagnostics include lints, so speculatively loaded crates may occur in successful
1866-
/// compilation even without doc links.)
1867-
/// Should be used when encoding crate metadata (and therefore when generating crate hash,
1868-
/// depinfo and similar things), to avoid dangling crate references in other encoded data,
1869-
/// like source maps.
1870-
/// May also be used for diagnostics - if we are loading a crate anyway we can suggest some
1871-
/// items from it as well.
1872-
/// But otherwise, `used_crates` should generally be used.
1873-
query crates_including_speculative(_: ()) -> &'tcx [CrateNum] {
1864+
query crates(_: ()) -> &'tcx [CrateNum] {
18741865
eval_always
18751866
desc { "fetching all foreign CrateNum instances" }
18761867
}
1877-
/// Crates that are loaded non-speculatively (not for diagnostics or doc links).
1878-
/// Should be used to maintain observable language behavior, for example when collecting lang
1879-
/// items or impls from all crates, or collecting libraries to link.
1868+
// Crates that are loaded non-speculatively (not for diagnostics or doc links).
1869+
// FIXME: This is currently only used for collecting lang items, but should be used instead of
1870+
// `crates` in most other cases too.
18801871
query used_crates(_: ()) -> &'tcx [CrateNum] {
18811872
eval_always
18821873
desc { "fetching `CrateNum`s for all crates loaded non-speculatively" }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ impl<'tcx> TyCtxt<'tcx> {
16161616

16171617
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
16181618
iter::once(LOCAL_CRATE)
1619-
.chain(self.used_crates(()).iter().copied())
1619+
.chain(self.crates(()).iter().copied())
16201620
.flat_map(move |cnum| self.traits(cnum).iter().copied())
16211621
}
16221622

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
32323232
let queue = &mut Vec::new();
32333233
let mut seen_defs: DefIdSet = Default::default();
32343234

3235-
for &cnum in tcx.crates_including_speculative(()).iter() {
3235+
for &cnum in tcx.crates(()).iter() {
32363236
let def_id = cnum.as_def_id();
32373237

32383238
// Ignore crates that are not direct dependencies.

0 commit comments

Comments
 (0)