Skip to content

Commit 17a6b1f

Browse files
committed
Always execute crates.
This commit stops `crates` from being a query so that it will always execute. This is required as speculative loading of crates for diagnostic purposes will add new crate numbers that `crates` would not include when cached.
1 parent 6cd311e commit 17a6b1f

File tree

10 files changed

+15
-36
lines changed

10 files changed

+15
-36
lines changed

src/librustc/dep_graph/dep_node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ define_dep_nodes!( <'tcx>
639639
[input] NamesImportedByGlobUse(DefId),
640640
[eval_always] StabilityIndex,
641641
[eval_always] AllSuggestibleTraits,
642-
[input] AllCrateNums,
643642
[] ExportedSymbols(CrateNum),
644643
[eval_always] CollectAndPartitionMonoItems,
645644
[] IsCodegenedItem(DefId),

src/librustc/ty/context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13341334
self.stability_index(LOCAL_CRATE)
13351335
}
13361336

1337-
pub fn crates(self) -> Lrc<Vec<CrateNum>> {
1338-
self.all_crate_nums(LOCAL_CRATE)
1337+
pub fn crates(self) -> Vec<CrateNum> {
1338+
self.cstore.crates_untracked()
13391339
}
13401340

13411341
pub fn features(self) -> Lrc<feature_gate::Features> {
@@ -3031,10 +3031,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30313031
let id = tcx.hir().as_local_node_id(id).unwrap();
30323032
tcx.cstore.extern_mod_stmt_cnum_untracked(id)
30333033
};
3034-
providers.all_crate_nums = |tcx, cnum| {
3035-
assert_eq!(cnum, LOCAL_CRATE);
3036-
Lrc::new(tcx.cstore.crates_untracked())
3037-
};
30383034
providers.postorder_cnums = |tcx, cnum| {
30393035
assert_eq!(cnum, LOCAL_CRATE);
30403036
Lrc::new(tcx.cstore.postorder_cnums_untracked())

src/librustc/ty/query/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::all_suggestible_traits<'tcx> {
844844
}
845845
}
846846

847-
impl<'tcx> QueryDescription<'tcx> for queries::all_crate_nums<'tcx> {
848-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
849-
"fetching all foreign CrateNum instances".into()
850-
}
851-
}
852-
853847
impl<'tcx> QueryDescription<'tcx> for queries::exported_symbols<'tcx> {
854848
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> {
855849
"exported_symbols".into()

src/librustc/ty/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,6 @@ define_queries! { <'tcx>
558558
-> Lrc<FxHashSet<ast::Name>>,
559559

560560
[] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
561-
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
562561

563562
/// A vector of every trait accessible in the whole crate
564563
/// (i.e., including those from subcrates). This is used only for
@@ -895,10 +894,6 @@ fn stability_index_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
895894
DepConstructor::StabilityIndex
896895
}
897896

898-
fn all_crate_nums_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
899-
DepConstructor::AllCrateNums
900-
}
901-
902897
fn all_suggestible_traits_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {
903898
DepConstructor::AllSuggestibleTraits
904899
}

src/librustc/ty/query/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'sess> OnDiskCache<'sess> {
429429
-> IndexVec<CrateNum, Option<CrateNum>>
430430
{
431431
tcx.dep_graph.with_ignore(|| {
432-
let current_cnums = tcx.all_crate_nums(LOCAL_CRATE).iter().map(|&cnum| {
432+
let current_cnums = tcx.crates().iter().map(|&cnum| {
433433
let crate_name = tcx.original_crate_name(cnum)
434434
.to_string();
435435
let crate_disambiguator = tcx.crate_disambiguator(cnum);

src/librustc/ty/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
14171417
DepKind::MaybeUnusedExternCrates => { force!(maybe_unused_extern_crates, LOCAL_CRATE); }
14181418
DepKind::StabilityIndex => { force!(stability_index, LOCAL_CRATE); }
14191419
DepKind::AllSuggestibleTraits => { force!(all_suggestible_traits, LOCAL_CRATE); }
1420-
DepKind::AllCrateNums => { force!(all_crate_nums, LOCAL_CRATE); }
14211420
DepKind::ExportedSymbols => { force!(exported_symbols, krate!()); }
14221421
DepKind::CollectAndPartitionMonoItems => {
14231422
force!(collect_and_partition_mono_items, LOCAL_CRATE);

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn upstream_monomorphizations_provider<'a, 'tcx>(
286286
{
287287
debug_assert!(cnum == LOCAL_CRATE);
288288

289-
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
289+
let cnums = tcx.crates();
290290

291291
let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();
292292

src/librustc_metadata/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub fn provide<'tcx>(providers: &mut Providers<'tcx>) {
329329
// which is to say, its not deterministic in general. But
330330
// we believe that libstd is consistently assigned crate
331331
// num 1, so it should be enough to resolve #46112.
332-
let mut crates: Vec<CrateNum> = (*tcx.crates()).clone();
332+
let mut crates = tcx.crates();
333333
crates.sort();
334334

335335
for &cnum in crates.iter() {

src/librustc_typeck/check/method/suggest.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use errors::{Applicability, DiagnosticBuilder};
99
use rustc_data_structures::sync::Lrc;
1010
use rustc::hir::{self, ExprKind, Node, QPath};
1111
use rustc::hir::def::Def;
12-
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, CrateNum, DefId};
12+
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
1313
use rustc::hir::map as hir_map;
1414
use rustc::hir::print;
1515
use rustc::infer::type_variable::TypeVariableOrigin;
@@ -775,29 +775,19 @@ fn compute_all_traits<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Vec<DefId>
775775
}
776776
}
777777

778-
let mut cnums: FxHashSet<CrateNum> = FxHashSet::default();
779-
780778
// Attempt to load all crates that we have `--extern` flags for, this means
781779
// we will be able to make suggestions for traits they define. Particularly useful
782780
// in Rust 2018 as there aren't `extern crate` lines that import a crate even if it isn't
783781
// otherwise used.
784782
for name in tcx.extern_prelude.keys() {
785783
let cnum = tcx.maybe_load_extern_crate(*name);
786784
debug!("compute_all_traits: (attempt load) name={:?} cnum={:?}", name, cnum);
787-
if let Some(cnum) = cnum {
788-
let _ = cnums.insert(cnum);
789-
}
790-
}
791-
792-
// Add all crates that we already know about.
793-
for &cnum in tcx.crates().iter() {
794-
let _ = cnums.insert(cnum);
795785
}
796786

797-
for cnum in cnums {
798-
debug!("compute_all_traits: cnum={:?} name={:?}", cnum, tcx.crate_name(cnum));
787+
for cnum in tcx.crates().iter() {
788+
debug!("compute_all_traits: cnum={:?} name={:?}", cnum, tcx.crate_name(*cnum));
799789
let def_id = DefId {
800-
krate: cnum,
790+
krate: *cnum,
801791
index: CRATE_DEF_INDEX,
802792
};
803793
handle_external_def(tcx, &mut traits, &mut external_mods, Def::Mod(def_id));

src/test/ui/rust-2018/trait-import-suggestions.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ error[E0599]: no method named `extern_baz` found for type `u32` in the current s
2525
|
2626
LL | x.extern_baz(); //~ ERROR no method named `extern_baz`
2727
| ^^^^^^^^^^
28+
|
29+
= help: items from traits can only be used if the trait is in scope
30+
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
31+
|
32+
LL | use baz::BazTrait;
33+
|
2834

2935
error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope
3036
--> $DIR/trait-import-suggestions.rs:33:18

0 commit comments

Comments
 (0)