Skip to content

Move glob map use to query and get rid of CrateAnalysis #57476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ define_dep_nodes!( <'tcx>
[input] Freevars(DefId),
[input] MaybeUnusedTraitImport(DefId),
[input] MaybeUnusedExternCrates,
[input] NamesImportedByGlobUse(DefId),
[eval_always] StabilityIndex,
[eval_always] AllTraits,
[input] AllCrateNums,
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@ pub struct GlobalCtxt<'tcx> {

maybe_unused_trait_imports: FxHashSet<DefId>,
maybe_unused_extern_crates: Vec<(DefId, Span)>,
/// A map of glob use to a set of names it actually imports. Currently only
/// used in save-analysis.
glob_map: FxHashMap<DefId, FxHashSet<ast::Name>>,
/// Extern prelude entries. The value is `true` if the entry was introduced
/// via `extern crate` item and not `--extern` option or compiler built-in.
pub extern_prelude: FxHashMap<ast::Name, bool>,
Expand Down Expand Up @@ -1232,6 +1235,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
.into_iter()
.map(|(id, sp)| (hir.local_def_id(id), sp))
.collect(),
glob_map: resolutions.glob_map.into_iter().map(|(id, names)| {
(hir.local_def_id(id), names)
}).collect(),
extern_prelude: resolutions.extern_prelude,
hir_map: hir,
def_path_hash_to_def_id,
Expand Down Expand Up @@ -2972,6 +2978,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(cnum, LOCAL_CRATE);
Lrc::new(tcx.maybe_unused_extern_crates.clone())
};
providers.names_imported_by_glob_use = |tcx, id| {
assert_eq!(id.krate, LOCAL_CRATE);
Lrc::new(tcx.glob_map.get(&id).cloned().unwrap_or_default())
};

providers.stability_index = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
13 changes: 2 additions & 11 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::fold::TypeFoldable;

use hir::{map as hir_map, FreevarMap, TraitMap};
use hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
use hir::Node;
use hir::def::{Def, CtorKind, ExportMap};
use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
Expand Down Expand Up @@ -115,23 +115,14 @@ mod sty;

// Data types

/// The complete set of all analyses described in this module. This is
/// produced by the driver and fed to codegen and later passes.
///
/// N.B., these contents are being migrated into queries using the
/// *on-demand* infrastructure.
#[derive(Clone)]
pub struct CrateAnalysis {
pub glob_map: hir::GlobMap,
}

#[derive(Clone)]
pub struct Resolutions {
pub freevars: FreevarMap,
pub trait_map: TraitMap,
pub maybe_unused_trait_imports: NodeSet,
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
pub export_map: ExportMap,
pub glob_map: GlobMap,
/// Extern prelude entries. The value is `true` if the entry was introduced
/// via `extern crate` item and not `--extern` option or compiler built-in.
pub extern_prelude: FxHashMap<Name, bool>,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ define_queries! { <'tcx>
[] fn maybe_unused_trait_import: MaybeUnusedTraitImport(DefId) -> bool,
[] fn maybe_unused_extern_crates: maybe_unused_extern_crates_node(CrateNum)
-> Lrc<Vec<(DefId, Span)>>,
[] fn names_imported_by_glob_use: NamesImportedByGlobUse(DefId)
-> Lrc<FxHashSet<ast::Name>>,

[] fn stability_index: stability_index_node(CrateNum) -> Lrc<stability::Index<'tcx>>,
[] fn all_crate_nums: all_crate_nums_node(CrateNum) -> Lrc<Vec<CrateNum>>,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::MaybeUnusedTraitImport => {
force!(maybe_unused_trait_import, def_id!());
}
DepKind::NamesImportedByGlobUse => { force!(names_imported_by_glob_use, def_id!()); }
DepKind::MaybeUnusedExternCrates => { force!(maybe_unused_extern_crates, LOCAL_CRATE); }
DepKind::StabilityIndex => { force!(stability_index, LOCAL_CRATE); }
DepKind::AllTraits => { force!(all_traits, LOCAL_CRATE); }
Expand Down
26 changes: 5 additions & 21 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ pub fn compile_input(
let ExpansionResult {
expanded_crate,
defs,
analysis,
resolutions,
mut hir_forest,
} = {
Expand Down Expand Up @@ -251,7 +250,6 @@ pub fn compile_input(
output,
&cstore,
&hir_map,
&analysis,
&resolutions,
&expanded_crate,
&hir_map.krate(),
Expand All @@ -277,12 +275,11 @@ pub fn compile_input(
sess,
cstore,
hir_map,
analysis,
resolutions,
&mut arenas,
&crate_name,
&outputs,
|tcx, analysis, rx, result| {
|tcx, rx, result| {
{
// Eventually, we will want to track plugins.
tcx.dep_graph.with_ignore(|| {
Expand All @@ -293,7 +290,6 @@ pub fn compile_input(
output,
opt_crate,
tcx.hir().krate(),
&analysis,
tcx,
&crate_name,
);
Expand Down Expand Up @@ -527,7 +523,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
pub hir_crate: Option<&'a hir::Crate>,
pub hir_map: Option<&'a hir_map::Map<'tcx>>,
pub resolutions: Option<&'a Resolutions>,
pub analysis: Option<&'a ty::CrateAnalysis>,
pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
}

Expand All @@ -547,7 +542,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
hir_crate: None,
hir_map: None,
resolutions: None,
analysis: None,
tcx: None,
}
}
Expand Down Expand Up @@ -595,7 +589,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
out_file: &'a Option<PathBuf>,
cstore: &'tcx CStore,
hir_map: &'a hir_map::Map<'tcx>,
analysis: &'a ty::CrateAnalysis,
resolutions: &'a Resolutions,
krate: &'a ast::Crate,
hir_crate: &'a hir::Crate,
Expand All @@ -606,7 +599,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
crate_name: Some(crate_name),
cstore: Some(cstore),
hir_map: Some(hir_map),
analysis: Some(analysis),
resolutions: Some(resolutions),
expanded_crate: Some(krate),
hir_crate: Some(hir_crate),
Expand All @@ -623,12 +615,10 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
out_file: &'a Option<PathBuf>,
krate: Option<&'a ast::Crate>,
hir_crate: &'a hir::Crate,
analysis: &'a ty::CrateAnalysis,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
crate_name: &'a str,
) -> Self {
CompileState {
analysis: Some(analysis),
tcx: Some(tcx),
expanded_crate: krate,
hir_crate: Some(hir_crate),
Expand Down Expand Up @@ -711,7 +701,6 @@ fn count_nodes(krate: &ast::Crate) -> usize {
pub struct ExpansionResult {
pub expanded_crate: ast::Crate,
pub defs: hir_map::Definitions,
pub analysis: ty::CrateAnalysis,
pub resolutions: Resolutions,
pub hir_forest: hir_map::Forest,
}
Expand Down Expand Up @@ -772,16 +761,13 @@ where
freevars: resolver.freevars,
export_map: resolver.export_map,
trait_map: resolver.trait_map,
glob_map: resolver.glob_map,
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
maybe_unused_extern_crates: resolver.maybe_unused_extern_crates,
extern_prelude: resolver.extern_prelude.iter().map(|(ident, entry)| {
(ident.name, entry.introduced_by_item)
}).collect(),
},

analysis: ty::CrateAnalysis {
glob_map: resolver.glob_map
},
}),
Err(x) => Err(x),
}
Expand Down Expand Up @@ -1180,7 +1166,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
sess: &'tcx Session,
cstore: &'tcx CStore,
hir_map: hir_map::Map<'tcx>,
analysis: ty::CrateAnalysis,
resolutions: Resolutions,
arenas: &'tcx mut AllArenas<'tcx>,
name: &str,
Expand All @@ -1190,7 +1175,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(
where
F: for<'a> FnOnce(
TyCtxt<'a, 'tcx, 'tcx>,
ty::CrateAnalysis,
mpsc::Receiver<Box<dyn Any + Send>>,
CompileResult,
) -> R,
Expand Down Expand Up @@ -1254,7 +1238,7 @@ where
match typeck::check_crate(tcx) {
Ok(x) => x,
Err(x) => {
f(tcx, analysis, rx, Err(x));
f(tcx, rx, Err(x));
return Err(x);
}
}
Expand Down Expand Up @@ -1307,7 +1291,7 @@ where
// lint warnings and so on -- kindck used to do this abort, but
// kindck is gone now). -nmatsakis
if sess.err_count() > 0 {
return Ok(f(tcx, analysis, rx, sess.compile_status()));
return Ok(f(tcx, rx, sess.compile_status()));
}

time(sess, "death checking", || middle::dead::check_crate(tcx));
Expand All @@ -1318,7 +1302,7 @@ where

time(sess, "lint checking", || lint::check_crate(tcx));

return Ok(f(tcx, analysis, rx, tcx.sess.compile_status()));
return Ok(f(tcx, rx, tcx.sess.compile_status()));
},
)
}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
pretty::print_after_hir_lowering(state.session,
state.cstore.unwrap(),
state.hir_map.unwrap(),
state.analysis.unwrap(),
state.resolutions.unwrap(),
state.input,
&state.expanded_crate.take().unwrap(),
Expand Down Expand Up @@ -940,7 +939,6 @@ pub fn enable_save_analysis(control: &mut CompileController) {
time(state.session, "save analysis", || {
save::process_crate(state.tcx.unwrap(),
state.expanded_crate.unwrap(),
state.analysis.unwrap(),
state.crate_name.unwrap(),
state.input,
None,
Expand Down
16 changes: 3 additions & 13 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ impl PpSourceMode {
sess: &'tcx Session,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
output_filenames: &OutputFilenames,
id: &str,
Expand Down Expand Up @@ -223,12 +222,11 @@ impl PpSourceMode {
sess,
cstore,
hir_map.clone(),
analysis.clone(),
resolutions.clone(),
&mut arenas,
id,
output_filenames,
|tcx, _, _, _| {
|tcx, _, _| {
let empty_tables = ty::TypeckTables::empty(None);
let annotation = TypedAnnotation {
tcx,
Expand Down Expand Up @@ -959,7 +957,6 @@ pub fn print_after_parsing(sess: &Session,
pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'tcx CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
input: &Input,
krate: &ast::Crate,
Expand All @@ -972,7 +969,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
print_with_analysis(sess,
cstore,
hir_map,
analysis,
resolutions,
crate_name,
output_filenames,
Expand Down Expand Up @@ -1010,7 +1006,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
analysis,
resolutions,
output_filenames,
crate_name,
Expand All @@ -1033,7 +1028,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
analysis,
resolutions,
output_filenames,
crate_name,
Expand All @@ -1048,7 +1042,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
analysis,
resolutions,
output_filenames,
crate_name,
Expand Down Expand Up @@ -1081,7 +1074,6 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
s.call_with_pp_support_hir(sess,
cstore,
hir_map,
analysis,
resolutions,
output_filenames,
crate_name,
Expand All @@ -1103,13 +1095,12 @@ pub fn print_after_hir_lowering<'tcx, 'a: 'tcx>(sess: &'a Session,
}

// In an ideal world, this would be a public function called by the driver after
// analsysis is performed. However, we want to call `phase_3_run_analysis_passes`
// analysis is performed. However, we want to call `phase_3_run_analysis_passes`
// with a different callback than the standard driver, so that isn't easy.
// Instead, we call that function ourselves.
fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
cstore: &'a CStore,
hir_map: &hir_map::Map<'tcx>,
analysis: &ty::CrateAnalysis,
resolutions: &Resolutions,
crate_name: &str,
output_filenames: &OutputFilenames,
Expand All @@ -1134,12 +1125,11 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session,
sess,
cstore,
hir_map.clone(),
analysis.clone(),
resolutions.clone(),
&mut arenas,
crate_name,
output_filenames,
|tcx, _, _, _| {
|tcx, _, _| {
match ppm {
PpmMir | PpmMirCFG => {
if let Some(nodeid) = nodeid {
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
};

// Make a comma-separated list of names of imported modules.
let glob_map = &self.save_ctxt.analysis.glob_map;
let names = if glob_map.contains_key(&id) {
glob_map.get(&id).unwrap().iter().map(|n| n.to_string()).collect()
} else {
Vec::new()
};
let def_id = self.tcx.hir().local_def_id(id);
let names = self.tcx.names_imported_by_glob_use(def_id);
let names: Vec<_> = names.iter().map(|n| n.to_string()).collect();

// Otherwise it's a span with wrong macro expansion info, which
// we don't want to track anyway, since it's probably macro-internal `use`
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ pub struct SaveContext<'l, 'tcx: 'l> {
tcx: TyCtxt<'l, 'tcx, 'tcx>,
tables: &'l ty::TypeckTables<'tcx>,
access_levels: &'l AccessLevels,
analysis: &'l ty::CrateAnalysis,
span_utils: SpanUtils<'tcx>,
config: Config,
impl_counter: Cell<u32>,
Expand Down Expand Up @@ -1120,7 +1119,6 @@ impl<'b> SaveHandler for CallbackHandler<'b> {
pub fn process_crate<'l, 'tcx, H: SaveHandler>(
tcx: TyCtxt<'l, 'tcx, 'tcx>,
krate: &ast::Crate,
analysis: &'l ty::CrateAnalysis,
cratename: &str,
input: &'l Input,
config: Option<Config>,
Expand All @@ -1139,7 +1137,6 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
let save_ctxt = SaveContext {
tcx,
tables: &ty::TypeckTables::empty(None),
analysis,
access_levels: &access_levels,
span_utils: SpanUtils::new(&tcx.sess),
config: find_config(config),
Expand Down
Loading