Skip to content

Commit 1716de0

Browse files
authored
Rollup merge of rust-lang#126068 - lqd:revert-124976, r=petrochenkov
Revert "use `tcx.used_crates(())` more" before it reaches beta There are more open issues caused by rust-lang#124976 than will be fixed by rust-lang#125493 alone. The beta cut is soon, so let's revert it and buy some time to analyze and fix these issues in our own time. fixes rust-lang#125474 fixes rust-lang#125484 fixes rust-lang#125646 fixes rust-lang#125707 fixes rust-lang#126066 fixes rust-lang#125934 fixes rust-lang#126021 r? `@petrochenkov` `@bors` p=1
2 parents 6a63bf8 + 9ddf572 commit 1716de0

File tree

26 files changed

+75
-54
lines changed

26 files changed

+75
-54
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+1-1
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

+2-2
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

+1-1
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

+6-6
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

+2-2
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

+1-1
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

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

1045-
let upstream_crates = upstream_crates_for_hashing(tcx);
1045+
let upstream_crates = upstream_crates(tcx);
10461046

10471047
let resolutions = tcx.resolutions(());
10481048

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

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

compiler/rustc_middle/src/query/mod.rs

+4-13
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

+1-1
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

+1-1
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.

compiler/rustc_middle/src/ty/trait_def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
206206
// Traits defined in the current crate can't have impls in upstream
207207
// crates, so we don't bother querying the cstore.
208208
if !trait_id.is_local() {
209-
for &cnum in tcx.used_crates(()).iter() {
209+
for &cnum in tcx.crates(()).iter() {
210210
for &(impl_def_id, simplified_self_ty) in
211211
tcx.implementations_of_trait((cnum, trait_id)).iter()
212212
{
@@ -248,7 +248,7 @@ pub(super) fn incoherent_impls_provider(
248248
let mut impls = Vec::new();
249249

250250
let mut res = Ok(());
251-
for cnum in iter::once(LOCAL_CRATE).chain(tcx.used_crates(()).iter().copied()) {
251+
for cnum in iter::once(LOCAL_CRATE).chain(tcx.crates(()).iter().copied()) {
252252
let incoherent_impls = match tcx.crate_incoherent_impls((cnum, simp)) {
253253
Ok(impls) => impls,
254254
Err(e) => {

compiler/rustc_passes/src/diagnostic_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn all_diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems {
8282
let mut items = DiagnosticItems::default();
8383

8484
// Collect diagnostic items in other crates.
85-
for &cnum in tcx.crates_including_speculative(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
85+
for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
8686
for (&name, &def_id) in &tcx.diagnostic_items(cnum).name_to_id {
8787
collect_item(tcx, &mut items, name, def_id);
8888
}

compiler/rustc_passes/src/stability.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10201020
// stabilization diagnostic, but it can be avoided when there are no
10211021
// `remaining_lib_features`.
10221022
let mut all_implications = remaining_implications.clone();
1023-
for &cnum in tcx.used_crates(()) {
1023+
for &cnum in tcx.crates(()) {
10241024
all_implications
10251025
.extend_unord(tcx.stability_implications(cnum).items().map(|(k, v)| (*k, *v)));
10261026
}
@@ -1033,7 +1033,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10331033
&all_implications,
10341034
);
10351035

1036-
for &cnum in tcx.used_crates(()) {
1036+
for &cnum in tcx.crates(()) {
10371037
if remaining_lib_features.is_empty() && remaining_implications.is_empty() {
10381038
break;
10391039
}

compiler/rustc_passes/src/weak_lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn verify(tcx: TyCtxt<'_>, items: &lang_items::LanguageItems) {
6868
}
6969

7070
let mut missing = FxHashSet::default();
71-
for &cnum in tcx.used_crates(()).iter() {
71+
for &cnum in tcx.crates(()).iter() {
7272
for &item in tcx.missing_lang_items(cnum).iter() {
7373
missing.insert(item);
7474
}

compiler/rustc_smir/src/rustc_smir/context.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
126126
let mut tables = self.0.borrow_mut();
127127
let tcx = tables.tcx;
128128
iter::once(LOCAL_CRATE)
129-
.chain(tables.tcx.used_crates(()).iter().copied())
129+
.chain(tables.tcx.crates(()).iter().copied())
130130
.flat_map(|cnum| tcx.trait_impls_in_crate(cnum).iter())
131131
.map(|impl_def_id| tables.impl_def(*impl_def_id))
132132
.collect()
@@ -201,19 +201,14 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
201201

202202
fn external_crates(&self) -> Vec<stable_mir::Crate> {
203203
let tables = self.0.borrow();
204-
tables
205-
.tcx
206-
.used_crates(())
207-
.iter()
208-
.map(|crate_num| smir_crate(tables.tcx, *crate_num))
209-
.collect()
204+
tables.tcx.crates(()).iter().map(|crate_num| smir_crate(tables.tcx, *crate_num)).collect()
210205
}
211206

212207
fn find_crates(&self, name: &str) -> Vec<stable_mir::Crate> {
213208
let tables = self.0.borrow();
214209
let crates: Vec<stable_mir::Crate> = [LOCAL_CRATE]
215210
.iter()
216-
.chain(tables.tcx.used_crates(()).iter())
211+
.chain(tables.tcx.crates(()).iter())
217212
.filter_map(|crate_num| {
218213
let crate_name = tables.tcx.crate_name(*crate_num).to_string();
219214
(name == crate_name).then(|| smir_crate(tables.tcx, *crate_num))

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ impl PrimitiveType {
19361936
let mut primitive_locations = FxHashMap::default();
19371937
// NOTE: technically this misses crates that are only passed with `--extern` and not loaded when checking the crate.
19381938
// This is a degenerate case that I don't plan to support.
1939-
for &crate_num in tcx.crates_including_speculative(()) {
1939+
for &crate_num in tcx.crates(()) {
19401940
let e = ExternalCrate { crate_num };
19411941
let crate_name = e.name(tcx);
19421942
debug!(?crate_num, ?crate_name);

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) fn run_global_ctxt(
347347
show_coverage,
348348
};
349349

350-
for cnum in tcx.crates_including_speculative(()) {
350+
for cnum in tcx.crates(()) {
351351
crate::visit_lib::lib_embargo_visit_item(&mut ctxt, cnum.as_def_id());
352352
}
353353

src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl Cache {
155155

156156
// Cache where all our extern crates are located
157157
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code
158-
for &crate_num in tcx.crates_including_speculative(()) {
158+
for &crate_num in tcx.crates(()) {
159159
let e = ExternalCrate { crate_num };
160160

161161
let name = e.name(tcx);

src/librustdoc/passes/collect_trait_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
4747
// External trait impls.
4848
{
4949
let _prof_timer = tcx.sess.prof.generic_activity("build_extern_trait_impls");
50-
for &cnum in tcx.crates_including_speculative(()) {
50+
for &cnum in tcx.crates(()) {
5151
for &impl_def_id in tcx.trait_impls_in_crate(cnum) {
5252
cx.with_param_env(impl_def_id, |cx| {
5353
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);

src/librustdoc/scrape_examples.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ pub(crate) fn run(
283283
// Collect CrateIds corresponding to provided target crates
284284
// If two different versions of the crate in the dependency tree, then examples will be collected from both.
285285
let all_crates = tcx
286-
.crates_including_speculative(())
286+
.crates(())
287287
.iter()
288288
.chain([&LOCAL_CRATE])
289289
.map(|crate_num| (crate_num, tcx.crate_name(*crate_num)))

src/tools/clippy/clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ fn item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Re
647647
/// This function is expensive and should be used sparingly.
648648
pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec<Res> {
649649
fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator<Item = DefId> + '_ {
650-
tcx.crates_including_speculative(())
650+
tcx.crates(())
651651
.iter()
652652
.copied()
653653
.filter(move |&num| tcx.crate_name(num) == name)

src/tools/miri/src/helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn try_resolve_did(tcx: TyCtxt<'_>, path: &[&str], namespace: Option<Namespace>)
126126
// the one in the sysroot and the one locally built by `cargo test`.)
127127
// FIXME: can we prefer the one from the sysroot?
128128
'crates: for krate in
129-
tcx.used_crates(()).iter().filter(|&&krate| tcx.crate_name(krate).as_str() == crate_name)
129+
tcx.crates(()).iter().filter(|&&krate| tcx.crate_name(krate).as_str() == crate_name)
130130
{
131131
let mut cur_item = DefId { krate: *krate, index: CRATE_DEF_INDEX };
132132
// Go over the modules.
@@ -1364,7 +1364,7 @@ pub fn get_local_crates(tcx: TyCtxt<'_>) -> Vec<CrateNum> {
13641364
.map(|crates| crates.split(',').map(|krate| krate.to_string()).collect::<Vec<_>>())
13651365
.unwrap_or_default();
13661366
let mut local_crates = Vec::new();
1367-
for &crate_num in tcx.crates_including_speculative(()) {
1367+
for &crate_num in tcx.crates(()) {
13681368
let name = tcx.crate_name(crate_num);
13691369
let name = name.as_str();
13701370
if local_crate_names.iter().any(|local_name| local_name == name) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub type Foo = something::same::Thing;
2+
3+
mod something {
4+
pub mod same {
5+
pub struct Thing;
6+
}
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Non-regression test for issues #125474, #125484, #125646, with the repro taken from #125484. Some
2+
// queries use "used dependencies" while others use "speculatively loaded dependencies", and an
3+
// indexing ICE appeared in some cases when these were unexpectedly used in the same context.
4+
5+
// FIXME: this should probably be a UI test instead of a run-make test, but I *cannot* find a way to
6+
// make compiletest annotations reproduce the ICE with the minimizations from issues #125474 and
7+
// #125484.
8+
9+
use run_make_support::{rustc, tmp_dir};
10+
11+
fn main() {
12+
// The dependency is not itself significant, apart from sharing a name with one of main's
13+
// modules.
14+
rustc().crate_name("same").crate_type("rlib").input("dependency.rs").run();
15+
16+
// Here, an ICE would happen when building the linker command.
17+
rustc().input("main.rs").extern_("same", tmp_dir().join("libsame.rlib")).run();
18+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
error: extern location for std does not exist:
22

3+
error: `#[panic_handler]` function required, but not found
4+
5+
error: unwinding panics are not supported without std
6+
|
7+
= help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
8+
= note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem
9+
310
error: requires `sized` lang_item
411

5-
error: aborting due to 2 previous errors
12+
error: aborting due to 4 previous errors
613

0 commit comments

Comments
 (0)