Rollup merge of #41063 - nikomatsakis:issue-40746-always-exec-loops, r=eddyb
remove unnecessary tasks Remove various unnecessary tasks. All of these are "always execute" tasks that don't do any writes to tracked state (or else an assert would trigger, anyhow). In some cases, they issue lints or errors, but we''ll deal with that -- and anyway side-effects outside of a task don't cause problems for anything that I can see. The one non-trivial refactoring here is the borrowck conversion, which adds the requirement to go from a `DefId` to a `BodyId`. I tried to make a useful helper here. r? @eddyb cc #40746 cc @cramertj @michaelwoerister
This commit is contained in:
commit
49082ae9f2
|
@ -57,17 +57,13 @@ pub enum DepNode<D: Clone + Debug> {
|
||||||
|
|
||||||
// Represents different phases in the compiler.
|
// Represents different phases in the compiler.
|
||||||
CollectLanguageItems,
|
CollectLanguageItems,
|
||||||
CheckStaticRecursion,
|
|
||||||
ResolveLifetimes,
|
ResolveLifetimes,
|
||||||
RegionResolveCrate,
|
RegionResolveCrate,
|
||||||
CheckLoops,
|
|
||||||
PluginRegistrar,
|
PluginRegistrar,
|
||||||
StabilityIndex,
|
StabilityIndex,
|
||||||
CollectItem(D),
|
CollectItem(D),
|
||||||
CollectItemSig(D),
|
CollectItemSig(D),
|
||||||
Coherence,
|
Coherence,
|
||||||
EffectCheck,
|
|
||||||
Liveness,
|
|
||||||
Resolve,
|
Resolve,
|
||||||
EntryPoint,
|
EntryPoint,
|
||||||
CheckEntryFn,
|
CheckEntryFn,
|
||||||
|
@ -216,15 +212,11 @@ impl<D: Clone + Debug> DepNode<D> {
|
||||||
MirKrate => Some(MirKrate),
|
MirKrate => Some(MirKrate),
|
||||||
TypeckBodiesKrate => Some(TypeckBodiesKrate),
|
TypeckBodiesKrate => Some(TypeckBodiesKrate),
|
||||||
CollectLanguageItems => Some(CollectLanguageItems),
|
CollectLanguageItems => Some(CollectLanguageItems),
|
||||||
CheckStaticRecursion => Some(CheckStaticRecursion),
|
|
||||||
ResolveLifetimes => Some(ResolveLifetimes),
|
ResolveLifetimes => Some(ResolveLifetimes),
|
||||||
RegionResolveCrate => Some(RegionResolveCrate),
|
RegionResolveCrate => Some(RegionResolveCrate),
|
||||||
CheckLoops => Some(CheckLoops),
|
|
||||||
PluginRegistrar => Some(PluginRegistrar),
|
PluginRegistrar => Some(PluginRegistrar),
|
||||||
StabilityIndex => Some(StabilityIndex),
|
StabilityIndex => Some(StabilityIndex),
|
||||||
Coherence => Some(Coherence),
|
Coherence => Some(Coherence),
|
||||||
EffectCheck => Some(EffectCheck),
|
|
||||||
Liveness => Some(Liveness),
|
|
||||||
Resolve => Some(Resolve),
|
Resolve => Some(Resolve),
|
||||||
EntryPoint => Some(EntryPoint),
|
EntryPoint => Some(EntryPoint),
|
||||||
CheckEntryFn => Some(CheckEntryFn),
|
CheckEntryFn => Some(CheckEntryFn),
|
||||||
|
|
|
@ -442,6 +442,27 @@ impl<'hir> Map<'hir> {
|
||||||
self.local_def_id(self.body_owner(id))
|
self.local_def_id(self.body_owner(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Given a body owner's id, returns the `BodyId` associated with it.
|
||||||
|
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
|
||||||
|
if let Some(entry) = self.find_entry(id) {
|
||||||
|
if let Some(body_id) = entry.associated_body() {
|
||||||
|
// For item-like things and closures, the associated
|
||||||
|
// body has its own distinct id, and that is returned
|
||||||
|
// by `associated_body`.
|
||||||
|
body_id
|
||||||
|
} else {
|
||||||
|
// For some expressions, the expression is its own body.
|
||||||
|
if let EntryExpr(_, expr) = entry {
|
||||||
|
BodyId { node_id: expr.id }
|
||||||
|
} else {
|
||||||
|
span_bug!(self.span(id), "id `{}` has no associated body", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bug!("no entry for id `{}`", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
|
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
|
||||||
match self.get(id) {
|
match self.get(id) {
|
||||||
NodeItem(&Item { node: ItemTrait(..), .. }) => id,
|
NodeItem(&Item { node: ItemTrait(..), .. }) => id,
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
//! `unsafe`.
|
//! `unsafe`.
|
||||||
use self::RootUnsafeContext::*;
|
use self::RootUnsafeContext::*;
|
||||||
|
|
||||||
use dep_graph::DepNode;
|
|
||||||
use ty::{self, Ty, TyCtxt};
|
use ty::{self, Ty, TyCtxt};
|
||||||
use ty::MethodCall;
|
use ty::MethodCall;
|
||||||
use lint;
|
use lint;
|
||||||
|
@ -241,8 +240,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
let _task = tcx.dep_graph.in_task(DepNode::EffectCheck);
|
|
||||||
|
|
||||||
let mut visitor = EffectCheckVisitor {
|
let mut visitor = EffectCheckVisitor {
|
||||||
tcx: tcx,
|
tcx: tcx,
|
||||||
tables: &ty::TypeckTables::empty(),
|
tables: &ty::TypeckTables::empty(),
|
||||||
|
|
|
@ -109,7 +109,6 @@ use self::LoopKind::*;
|
||||||
use self::LiveNodeKind::*;
|
use self::LiveNodeKind::*;
|
||||||
use self::VarKind::*;
|
use self::VarKind::*;
|
||||||
|
|
||||||
use dep_graph::DepNode;
|
|
||||||
use hir::def::*;
|
use hir::def::*;
|
||||||
use ty::{self, TyCtxt, ParameterEnvironment};
|
use ty::{self, TyCtxt, ParameterEnvironment};
|
||||||
use traits::{self, Reveal};
|
use traits::{self, Reveal};
|
||||||
|
@ -196,7 +195,6 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
let _task = tcx.dep_graph.in_task(DepNode::Liveness);
|
|
||||||
tcx.hir.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor());
|
tcx.hir.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor());
|
||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
}
|
}
|
||||||
|
|
|
@ -429,6 +429,8 @@ define_maps! { <'tcx>
|
||||||
|
|
||||||
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
|
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
|
||||||
|
|
||||||
|
pub borrowck: BorrowCheck(DefId) -> (),
|
||||||
|
|
||||||
/// Gets a complete map from all types to their inherent impls.
|
/// Gets a complete map from all types to their inherent impls.
|
||||||
/// Not meant to be used directly outside of coherence.
|
/// Not meant to be used directly outside of coherence.
|
||||||
/// (Defined only for LOCAL_CRATE)
|
/// (Defined only for LOCAL_CRATE)
|
||||||
|
|
|
@ -22,7 +22,6 @@ pub use self::mir::elaborate_drops::ElaborateDrops;
|
||||||
|
|
||||||
use self::InteriorKind::*;
|
use self::InteriorKind::*;
|
||||||
|
|
||||||
use rustc::dep_graph::DepNode;
|
|
||||||
use rustc::hir::map as hir_map;
|
use rustc::hir::map as hir_map;
|
||||||
use rustc::hir::map::blocks::FnLikeNode;
|
use rustc::hir::map::blocks::FnLikeNode;
|
||||||
use rustc::cfg;
|
use rustc::cfg;
|
||||||
|
@ -37,12 +36,13 @@ use rustc::middle::mem_categorization::Categorization;
|
||||||
use rustc::middle::mem_categorization::ImmutabilityBlame;
|
use rustc::middle::mem_categorization::ImmutabilityBlame;
|
||||||
use rustc::middle::region;
|
use rustc::middle::region;
|
||||||
use rustc::ty::{self, TyCtxt};
|
use rustc::ty::{self, TyCtxt};
|
||||||
|
use rustc::ty::maps::Providers;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
|
||||||
use errors::DiagnosticBuilder;
|
use errors::DiagnosticBuilder;
|
||||||
|
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
|
@ -62,16 +62,16 @@ pub struct LoanDataFlowOperator;
|
||||||
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
|
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
|
||||||
|
|
||||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||||
tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, tcx, (), check_crate_task);
|
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
|
||||||
|
ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn check_crate_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| {
|
*providers = Providers {
|
||||||
tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id),
|
borrowck,
|
||||||
tcx,
|
..*providers
|
||||||
body_id,
|
};
|
||||||
borrowck_fn);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collection of conclusions determined via borrow checker analyses.
|
/// Collection of conclusions determined via borrow checker analyses.
|
||||||
|
@ -81,11 +81,11 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
|
||||||
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
|
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
|
fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
|
||||||
debug!("borrowck_fn(body_id={:?})", body_id);
|
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
|
||||||
|
|
||||||
let owner_id = tcx.hir.body_owner(body_id);
|
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
|
||||||
let owner_def_id = tcx.hir.local_def_id(owner_id);
|
let body_id = tcx.hir.body_owned_by(owner_id);
|
||||||
let attributes = tcx.get_attrs(owner_def_id);
|
let attributes = tcx.get_attrs(owner_def_id);
|
||||||
let tables = tcx.item_tables(owner_def_id);
|
let tables = tcx.item_tables(owner_def_id);
|
||||||
|
|
||||||
|
|
|
@ -51,4 +51,6 @@ mod borrowck;
|
||||||
|
|
||||||
pub mod graphviz;
|
pub mod graphviz;
|
||||||
|
|
||||||
|
pub use borrowck::provide;
|
||||||
|
|
||||||
__build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS }
|
__build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS }
|
||||||
|
|
|
@ -891,6 +891,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
|
||||||
let mut local_providers = ty::maps::Providers::default();
|
let mut local_providers = ty::maps::Providers::default();
|
||||||
mir::provide(&mut local_providers);
|
mir::provide(&mut local_providers);
|
||||||
rustc_privacy::provide(&mut local_providers);
|
rustc_privacy::provide(&mut local_providers);
|
||||||
|
borrowck::provide(&mut local_providers);
|
||||||
typeck::provide(&mut local_providers);
|
typeck::provide(&mut local_providers);
|
||||||
ty::provide(&mut local_providers);
|
ty::provide(&mut local_providers);
|
||||||
reachable::provide(&mut local_providers);
|
reachable::provide(&mut local_providers);
|
||||||
|
|
|
@ -11,7 +11,6 @@ use self::Context::*;
|
||||||
|
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
|
|
||||||
use rustc::dep_graph::DepNode;
|
|
||||||
use rustc::hir::map::Map;
|
use rustc::hir::map::Map;
|
||||||
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
|
@ -50,7 +49,6 @@ struct CheckLoopVisitor<'a, 'hir: 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate(sess: &Session, map: &Map) {
|
pub fn check_crate(sess: &Session, map: &Map) {
|
||||||
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
|
|
||||||
let krate = map.krate();
|
let krate = map.krate();
|
||||||
krate.visit_all_item_likes(&mut CheckLoopVisitor {
|
krate.visit_all_item_likes(&mut CheckLoopVisitor {
|
||||||
sess: sess,
|
sess: sess,
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
// This compiler pass detects constants that refer to themselves
|
// This compiler pass detects constants that refer to themselves
|
||||||
// recursively.
|
// recursively.
|
||||||
|
|
||||||
use rustc::dep_graph::DepNode;
|
|
||||||
use rustc::hir::map as hir_map;
|
use rustc::hir::map as hir_map;
|
||||||
use rustc::session::{CompileResult, Session};
|
use rustc::session::{CompileResult, Session};
|
||||||
use rustc::hir::def::{Def, CtorKind};
|
use rustc::hir::def::{Def, CtorKind};
|
||||||
|
@ -88,8 +87,6 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult {
|
pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult {
|
||||||
let _task = hir_map.dep_graph.in_task(DepNode::CheckStaticRecursion);
|
|
||||||
|
|
||||||
let mut visitor = CheckCrateVisitor {
|
let mut visitor = CheckCrateVisitor {
|
||||||
sess: sess,
|
sess: sess,
|
||||||
hir_map: hir_map,
|
hir_map: hir_map,
|
||||||
|
|
Loading…
Reference in New Issue