Skip to content

Commit 49082ae

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#40746 cc @cramertj @michaelwoerister
2 parents 1dca19a + 2e327a6 commit 49082ae

File tree

10 files changed

+42
-34
lines changed

10 files changed

+42
-34
lines changed

Diff for: src/librustc/dep_graph/dep_node.rs

-8
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@ pub enum DepNode<D: Clone + Debug> {
5757

5858
// Represents different phases in the compiler.
5959
CollectLanguageItems,
60-
CheckStaticRecursion,
6160
ResolveLifetimes,
6261
RegionResolveCrate,
63-
CheckLoops,
6462
PluginRegistrar,
6563
StabilityIndex,
6664
CollectItem(D),
6765
CollectItemSig(D),
6866
Coherence,
69-
EffectCheck,
70-
Liveness,
7167
Resolve,
7268
EntryPoint,
7369
CheckEntryFn,
@@ -216,15 +212,11 @@ impl<D: Clone + Debug> DepNode<D> {
216212
MirKrate => Some(MirKrate),
217213
TypeckBodiesKrate => Some(TypeckBodiesKrate),
218214
CollectLanguageItems => Some(CollectLanguageItems),
219-
CheckStaticRecursion => Some(CheckStaticRecursion),
220215
ResolveLifetimes => Some(ResolveLifetimes),
221216
RegionResolveCrate => Some(RegionResolveCrate),
222-
CheckLoops => Some(CheckLoops),
223217
PluginRegistrar => Some(PluginRegistrar),
224218
StabilityIndex => Some(StabilityIndex),
225219
Coherence => Some(Coherence),
226-
EffectCheck => Some(EffectCheck),
227-
Liveness => Some(Liveness),
228220
Resolve => Some(Resolve),
229221
EntryPoint => Some(EntryPoint),
230222
CheckEntryFn => Some(CheckEntryFn),

Diff for: src/librustc/hir/map/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,27 @@ impl<'hir> Map<'hir> {
442442
self.local_def_id(self.body_owner(id))
443443
}
444444

445+
/// Given a body owner's id, returns the `BodyId` associated with it.
446+
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
447+
if let Some(entry) = self.find_entry(id) {
448+
if let Some(body_id) = entry.associated_body() {
449+
// For item-like things and closures, the associated
450+
// body has its own distinct id, and that is returned
451+
// by `associated_body`.
452+
body_id
453+
} else {
454+
// For some expressions, the expression is its own body.
455+
if let EntryExpr(_, expr) = entry {
456+
BodyId { node_id: expr.id }
457+
} else {
458+
span_bug!(self.span(id), "id `{}` has no associated body", id);
459+
}
460+
}
461+
} else {
462+
bug!("no entry for id `{}`", id)
463+
}
464+
}
465+
445466
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
446467
match self.get(id) {
447468
NodeItem(&Item { node: ItemTrait(..), .. }) => id,

Diff for: src/librustc/middle/effect.rs

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! `unsafe`.
1313
use self::RootUnsafeContext::*;
1414

15-
use dep_graph::DepNode;
1615
use ty::{self, Ty, TyCtxt};
1716
use ty::MethodCall;
1817
use lint;
@@ -241,8 +240,6 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
241240
}
242241

243242
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
244-
let _task = tcx.dep_graph.in_task(DepNode::EffectCheck);
245-
246243
let mut visitor = EffectCheckVisitor {
247244
tcx: tcx,
248245
tables: &ty::TypeckTables::empty(),

Diff for: src/librustc/middle/liveness.rs

-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ use self::LoopKind::*;
109109
use self::LiveNodeKind::*;
110110
use self::VarKind::*;
111111

112-
use dep_graph::DepNode;
113112
use hir::def::*;
114113
use ty::{self, TyCtxt, ParameterEnvironment};
115114
use traits::{self, Reveal};
@@ -196,7 +195,6 @@ impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
196195
}
197196

198197
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
199-
let _task = tcx.dep_graph.in_task(DepNode::Liveness);
200198
tcx.hir.krate().visit_all_item_likes(&mut IrMaps::new(tcx).as_deep_visitor());
201199
tcx.sess.abort_if_errors();
202200
}

Diff for: src/librustc/ty/maps.rs

+2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ define_maps! { <'tcx>
429429

430430
pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
431431

432+
pub borrowck: BorrowCheck(DefId) -> (),
433+
432434
/// Gets a complete map from all types to their inherent impls.
433435
/// Not meant to be used directly outside of coherence.
434436
/// (Defined only for LOCAL_CRATE)

Diff for: src/librustc_borrowck/borrowck/mod.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub use self::mir::elaborate_drops::ElaborateDrops;
2222

2323
use self::InteriorKind::*;
2424

25-
use rustc::dep_graph::DepNode;
2625
use rustc::hir::map as hir_map;
2726
use rustc::hir::map::blocks::FnLikeNode;
2827
use rustc::cfg;
@@ -37,12 +36,13 @@ use rustc::middle::mem_categorization::Categorization;
3736
use rustc::middle::mem_categorization::ImmutabilityBlame;
3837
use rustc::middle::region;
3938
use rustc::ty::{self, TyCtxt};
39+
use rustc::ty::maps::Providers;
4040

4141
use std::fmt;
4242
use std::rc::Rc;
4343
use std::hash::{Hash, Hasher};
4444
use syntax::ast;
45-
use syntax_pos::{MultiSpan, Span};
45+
use syntax_pos::{DUMMY_SP, MultiSpan, Span};
4646
use errors::DiagnosticBuilder;
4747

4848
use rustc::hir;
@@ -62,16 +62,16 @@ pub struct LoanDataFlowOperator;
6262
pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
6363

6464
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
65-
tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, tcx, (), check_crate_task);
66-
67-
fn check_crate_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
68-
tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| {
69-
tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id),
70-
tcx,
71-
body_id,
72-
borrowck_fn);
73-
});
74-
}
65+
tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
66+
ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id);
67+
});
68+
}
69+
70+
pub fn provide(providers: &mut Providers) {
71+
*providers = Providers {
72+
borrowck,
73+
..*providers
74+
};
7575
}
7676

7777
/// Collection of conclusions determined via borrow checker analyses.
@@ -81,11 +81,11 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
8181
pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
8282
}
8383

84-
fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
85-
debug!("borrowck_fn(body_id={:?})", body_id);
84+
fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
85+
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
8686

87-
let owner_id = tcx.hir.body_owner(body_id);
88-
let owner_def_id = tcx.hir.local_def_id(owner_id);
87+
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
88+
let body_id = tcx.hir.body_owned_by(owner_id);
8989
let attributes = tcx.get_attrs(owner_def_id);
9090
let tables = tcx.item_tables(owner_def_id);
9191

Diff for: src/librustc_borrowck/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ mod borrowck;
5151

5252
pub mod graphviz;
5353

54+
pub use borrowck::provide;
55+
5456
__build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS }

Diff for: src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
891891
let mut local_providers = ty::maps::Providers::default();
892892
mir::provide(&mut local_providers);
893893
rustc_privacy::provide(&mut local_providers);
894+
borrowck::provide(&mut local_providers);
894895
typeck::provide(&mut local_providers);
895896
ty::provide(&mut local_providers);
896897
reachable::provide(&mut local_providers);

Diff for: src/librustc_passes/loops.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use self::Context::*;
1111

1212
use rustc::session::Session;
1313

14-
use rustc::dep_graph::DepNode;
1514
use rustc::hir::map::Map;
1615
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
1716
use rustc::hir;
@@ -50,7 +49,6 @@ struct CheckLoopVisitor<'a, 'hir: 'a> {
5049
}
5150

5251
pub fn check_crate(sess: &Session, map: &Map) {
53-
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
5452
let krate = map.krate();
5553
krate.visit_all_item_likes(&mut CheckLoopVisitor {
5654
sess: sess,

Diff for: src/librustc_passes/static_recursion.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// This compiler pass detects constants that refer to themselves
1212
// recursively.
1313

14-
use rustc::dep_graph::DepNode;
1514
use rustc::hir::map as hir_map;
1615
use rustc::session::{CompileResult, Session};
1716
use rustc::hir::def::{Def, CtorKind};
@@ -88,8 +87,6 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
8887
}
8988

9089
pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> CompileResult {
91-
let _task = hir_map.dep_graph.in_task(DepNode::CheckStaticRecursion);
92-
9390
let mut visitor = CheckCrateVisitor {
9491
sess: sess,
9592
hir_map: hir_map,

0 commit comments

Comments
 (0)