Skip to content

Commit

Permalink
Rollup merge of rust-lang#104016 - Nilstrieb:query-descs-more, r=comp…
Browse files Browse the repository at this point in the history
…iler-errors

Add internal descriptions to a few queries

helps with rust-lang#104008
  • Loading branch information
matthiaskrgr authored Nov 6, 2022
2 parents 566868c + 27e0f03 commit 5731f00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
15 changes: 5 additions & 10 deletions compiler/rustc_interface/src/proc_macro_decls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym;

fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut finder = Finder { tcx, decls: None };
let mut decls = None;

for id in tcx.hir().items() {
let attrs = finder.tcx.hir().attrs(id.hir_id());
if finder.tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
finder.decls = Some(id.owner_id.def_id);
let attrs = tcx.hir().attrs(id.hir_id());
if tcx.sess.contains_name(attrs, sym::rustc_proc_macro_decls) {
decls = Some(id.owner_id.def_id);
}
}

finder.decls
}

struct Finder<'tcx> {
tcx: TyCtxt<'tcx>,
decls: Option<LocalDefId>,
decls
}

pub(crate) fn provide(providers: &mut Providers) {
Expand Down
18 changes: 17 additions & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ rustc_queries! {
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
}

/// Look up all native libraries this crate depends on.
/// These are assembled from the following places:
/// - `extern` blocks (depending on their `link` attributes)
/// - the `libs` (`-l`) option
query native_libraries(_: CrateNum) -> Vec<NativeLib> {
arena_cache
desc { "looking up the native libraries of a linked crate" }
Expand Down Expand Up @@ -1539,6 +1543,7 @@ rustc_queries! {
desc { "available upstream drop-glue for `{:?}`", substs }
}

/// Returns a list of all `extern` blocks of a crate.
query foreign_modules(_: CrateNum) -> FxHashMap<DefId, ForeignModule> {
arena_cache
desc { "looking up the foreign modules of a linked crate" }
Expand All @@ -1550,27 +1555,37 @@ rustc_queries! {
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
desc { "looking up the entry function of a crate" }
}

/// Finds the `rustc_proc_macro_decls` item of a crate.
query proc_macro_decls_static(_: ()) -> Option<LocalDefId> {
desc { "looking up the derive registrar for a crate" }
desc { "looking up the proc macro declarations for a crate" }
}

// The macro which defines `rustc_metadata::provide_extern` depends on this query's name.
// Changing the name should cause a compiler error, but in case that changes, be aware.
query crate_hash(_: CrateNum) -> Svh {
eval_always
desc { "looking up the hash a crate" }
separate_provide_extern
}

/// Gets the hash for the host proc macro. Used to support -Z dual-proc-macro.
query crate_host_hash(_: CrateNum) -> Option<Svh> {
eval_always
desc { "looking up the hash of a host version of a crate" }
separate_provide_extern
}

/// Gets the extra data to put in each output filename for a crate.
/// For example, compiling the `foo` crate with `extra-filename=-a` creates a `libfoo-b.rlib` file.
query extra_filename(_: CrateNum) -> String {
arena_cache
eval_always
desc { "looking up the extra filename for a crate" }
separate_provide_extern
}

/// Gets the paths where the crate came from in the file system.
query crate_extern_paths(_: CrateNum) -> Vec<PathBuf> {
arena_cache
eval_always
Expand All @@ -1594,6 +1609,7 @@ rustc_queries! {
separate_provide_extern
}

/// Get the corresponding native library from the `native_libraries` query
query native_library(def_id: DefId) -> Option<&'tcx NativeLib> {
desc { |tcx| "getting the native library for `{}`", tcx.def_path_str(def_id) }
}
Expand Down

0 comments on commit 5731f00

Please sign in to comment.