Skip to content

Commit 2fadb0a

Browse files
committed
Auto merge of #51487 - Zoxc:incr-passes, r=michaelwoerister
Make more passes incremental r? @michaelwoerister
2 parents 2cf736f + e69c2c7 commit 2fadb0a

29 files changed

+421
-70
lines changed

src/librustc/dep_graph/dep_node.rs

+6
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ define_dep_nodes!( <'tcx>
472472
[] UnsafetyCheckResult(DefId),
473473
[] UnsafeDeriveOnReprPacked(DefId),
474474

475+
[] CheckModAttrs(DefId),
476+
[] CheckModLoops(DefId),
477+
[] CheckModUnstableApiUsage(DefId),
478+
[] CheckModItemTypes(DefId),
479+
[] CollectModItemTypes(DefId),
480+
475481
[] Reachability,
476482
[] MirKeys,
477483
[eval_always] CrateVariances,

src/librustc/hir/check_attr.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7+
8+
use ty::TyCtxt;
9+
use ty::query::Providers;
10+
use ty::query::queries;
11+
712
use hir;
13+
use hir::def_id::DefId;
814
use hir::intravisit::{self, Visitor, NestedVisitorMap};
9-
use ty::TyCtxt;
1015
use std::fmt::{self, Display};
1116
use syntax_pos::Span;
1217

@@ -364,8 +369,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckAttrVisitor<'a, 'tcx> {
364369
}
365370

366371
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
367-
let mut checker = CheckAttrVisitor { tcx };
368-
tcx.hir().krate().visit_all_item_likes(&mut checker.as_deep_visitor());
372+
for &module in tcx.hir().krate().modules.keys() {
373+
queries::check_mod_attrs::ensure(tcx, tcx.hir().local_def_id(module));
374+
}
369375
}
370376

371377
fn is_c_like_enum(item: &hir::Item) -> bool {
@@ -381,3 +387,17 @@ fn is_c_like_enum(item: &hir::Item) -> bool {
381387
false
382388
}
383389
}
390+
391+
fn check_mod_attrs<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) {
392+
tcx.hir().visit_item_likes_in_module(
393+
module_def_id,
394+
&mut CheckAttrVisitor { tcx }.as_deep_visitor()
395+
);
396+
}
397+
398+
pub(crate) fn provide(providers: &mut Providers<'_>) {
399+
*providers = Providers {
400+
check_mod_attrs,
401+
..*providers
402+
};
403+
}

src/librustc/hir/def_id.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ty;
2+
use ty::TyCtxt;
23
use hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
34
use rustc_data_structures::indexed_vec::Idx;
45
use serialize;
@@ -243,6 +244,14 @@ impl DefId {
243244
pub fn to_local(self) -> LocalDefId {
244245
LocalDefId::from_def_id(self)
245246
}
247+
248+
pub fn describe_as_module(&self, tcx: TyCtxt<'_, '_, '_>) -> String {
249+
if self.is_local() && self.index == CRATE_DEF_INDEX {
250+
format!("top-level module")
251+
} else {
252+
format!("module `{}`", tcx.item_path_str(*self))
253+
}
254+
}
246255
}
247256

248257
impl serialize::UseSpecializedEncodable for DefId {}

src/librustc/hir/lowering.rs

+32-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use session::config::nightly_options;
4848
use util::common::FN_OUTPUT_NAME;
4949
use util::nodemap::{DefIdMap, NodeMap};
5050

51-
use std::collections::BTreeMap;
51+
use std::collections::{BTreeSet, BTreeMap};
5252
use std::fmt::Debug;
5353
use std::mem;
5454
use smallvec::SmallVec;
@@ -90,6 +90,8 @@ pub struct LoweringContext<'a> {
9090
trait_impls: BTreeMap<DefId, Vec<NodeId>>,
9191
trait_auto_impl: BTreeMap<DefId, NodeId>,
9292

93+
modules: BTreeMap<NodeId, hir::ModuleItems>,
94+
9395
is_generator: bool,
9496

9597
catch_scopes: Vec<NodeId>,
@@ -124,6 +126,8 @@ pub struct LoweringContext<'a> {
124126
// needs to be created for it.
125127
in_scope_lifetimes: Vec<Ident>,
126128

129+
current_module: NodeId,
130+
127131
type_def_lifetime_params: DefIdMap<usize>,
128132

129133
current_hir_id_owner: Vec<(DefIndex, u32)>,
@@ -228,12 +232,14 @@ pub fn lower_crate(
228232
bodies: BTreeMap::new(),
229233
trait_impls: BTreeMap::new(),
230234
trait_auto_impl: BTreeMap::new(),
235+
modules: BTreeMap::new(),
231236
exported_macros: Vec::new(),
232237
catch_scopes: Vec::new(),
233238
loop_scopes: Vec::new(),
234239
is_in_loop_condition: false,
235240
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
236241
type_def_lifetime_params: Default::default(),
242+
current_module: CRATE_NODE_ID,
237243
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
238244
item_local_id_counters: Default::default(),
239245
node_id_to_hir_id: IndexVec::new(),
@@ -414,11 +420,24 @@ impl<'a> LoweringContext<'a> {
414420
}
415421

416422
impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> {
423+
fn visit_mod(&mut self, m: &'lcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) {
424+
self.lctx.modules.insert(n, hir::ModuleItems {
425+
items: BTreeSet::new(),
426+
trait_items: BTreeSet::new(),
427+
impl_items: BTreeSet::new(),
428+
});
429+
430+
let old = self.lctx.current_module;
431+
self.lctx.current_module = n;
432+
visit::walk_mod(self, m);
433+
self.lctx.current_module = old;
434+
}
435+
417436
fn visit_item(&mut self, item: &'lcx Item) {
418437
let mut item_lowered = true;
419438
self.lctx.with_hir_id_owner(item.id, |lctx| {
420439
if let Some(hir_item) = lctx.lower_item(item) {
421-
lctx.items.insert(item.id, hir_item);
440+
lctx.insert_item(item.id, hir_item);
422441
} else {
423442
item_lowered = false;
424443
}
@@ -451,6 +470,7 @@ impl<'a> LoweringContext<'a> {
451470
let id = hir::TraitItemId { node_id: item.id };
452471
let hir_item = lctx.lower_trait_item(item);
453472
lctx.trait_items.insert(id, hir_item);
473+
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
454474
});
455475

456476
visit::walk_trait_item(self, item);
@@ -461,6 +481,7 @@ impl<'a> LoweringContext<'a> {
461481
let id = hir::ImplItemId { node_id: item.id };
462482
let hir_item = lctx.lower_impl_item(item);
463483
lctx.impl_items.insert(id, hir_item);
484+
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
464485
});
465486
visit::walk_impl_item(self, item);
466487
}
@@ -492,9 +513,15 @@ impl<'a> LoweringContext<'a> {
492513
body_ids,
493514
trait_impls: self.trait_impls,
494515
trait_auto_impl: self.trait_auto_impl,
516+
modules: self.modules,
495517
}
496518
}
497519

520+
fn insert_item(&mut self, id: NodeId, item: hir::Item) {
521+
self.items.insert(id, item);
522+
self.modules.get_mut(&self.current_module).unwrap().items.insert(id);
523+
}
524+
498525
fn allocate_hir_id_counter<T: Debug>(&mut self, owner: NodeId, debug: &T) -> LoweredNodeId {
499526
if self.item_local_id_counters.insert(owner, 0).is_some() {
500527
bug!(
@@ -1370,7 +1397,7 @@ impl<'a> LoweringContext<'a> {
13701397
// Insert the item into the global list. This usually happens
13711398
// automatically for all AST items. But this existential type item
13721399
// does not actually exist in the AST.
1373-
lctx.items.insert(exist_ty_id.node_id, exist_ty_item);
1400+
lctx.insert_item(exist_ty_id.node_id, exist_ty_item);
13741401

13751402
// `impl Trait` now just becomes `Foo<'a, 'b, ..>`.
13761403
hir::TyKind::Def(hir::ItemId { id: exist_ty_id.node_id }, lifetimes)
@@ -3026,7 +3053,7 @@ impl<'a> LoweringContext<'a> {
30263053
};
30273054
let vis = respan(vis.span, vis_kind);
30283055

3029-
this.items.insert(
3056+
this.insert_item(
30303057
new_id.node_id,
30313058
hir::Item {
30323059
id: new_id.node_id,
@@ -3133,7 +3160,7 @@ impl<'a> LoweringContext<'a> {
31333160
};
31343161
let vis = respan(vis.span, vis_kind);
31353162

3136-
this.items.insert(
3163+
this.insert_item(
31373164
new_id,
31383165
hir::Item {
31393166
id: new_id,

src/librustc/hir/map/collector.rs

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
119119
trait_impls: _,
120120
trait_auto_impl: _,
121121
body_ids: _,
122+
modules: _,
122123
} = *krate;
123124

124125
alloc_hir_dep_nodes(

src/librustc/hir/map/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use syntax::ext::base::MacroKind;
1717
use syntax_pos::{Span, DUMMY_SP};
1818

1919
use hir::*;
20+
use hir::itemlikevisit::ItemLikeVisitor;
2021
use hir::print::Nested;
2122
use util::nodemap::FxHashMap;
2223

@@ -506,6 +507,32 @@ impl<'hir> Map<'hir> {
506507
&self.forest.krate.attrs
507508
}
508509

510+
pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
511+
where V: ItemLikeVisitor<'hir>
512+
{
513+
let node_id = self.as_local_node_id(module).unwrap();
514+
515+
// Read the module so we'll be re-executed if new items
516+
// appear immediately under in the module. If some new item appears
517+
// in some nested item in the module, we'll be re-executed due to reads
518+
// in the expect_* calls the loops below
519+
self.read(node_id);
520+
521+
let module = &self.forest.krate.modules[&node_id];
522+
523+
for id in &module.items {
524+
visitor.visit_item(self.expect_item(*id));
525+
}
526+
527+
for id in &module.trait_items {
528+
visitor.visit_trait_item(self.expect_trait_item(id.node_id));
529+
}
530+
531+
for id in &module.impl_items {
532+
visitor.visit_impl_item(self.expect_impl_item(id.node_id));
533+
}
534+
}
535+
509536
/// Retrieve the Node corresponding to `id`, panicking if it cannot
510537
/// be found.
511538
pub fn get(&self, id: NodeId) -> Node<'hir> {

src/librustc/hir/mod.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope}
3333
use rustc_data_structures::thin_vec::ThinVec;
3434

3535
use serialize::{self, Encoder, Encodable, Decoder, Decodable};
36-
use std::collections::BTreeMap;
36+
use std::collections::{BTreeSet, BTreeMap};
3737
use std::fmt;
3838

3939
/// HIR doesn't commit to a concrete storage type and has its own alias for a vector.
@@ -676,6 +676,15 @@ pub struct WhereEqPredicate {
676676
pub rhs_ty: P<Ty>,
677677
}
678678

679+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
680+
pub struct ModuleItems {
681+
// Use BTreeSets here so items are in the same order as in the
682+
// list of all items in Crate
683+
pub items: BTreeSet<NodeId>,
684+
pub trait_items: BTreeSet<TraitItemId>,
685+
pub impl_items: BTreeSet<ImplItemId>,
686+
}
687+
679688
/// The top-level data structure that stores the entire contents of
680689
/// the crate currently being compiled.
681690
///
@@ -708,6 +717,10 @@ pub struct Crate {
708717
/// in the crate, you should iterate over this list rather than the keys
709718
/// of bodies.
710719
pub body_ids: Vec<BodyId>,
720+
721+
/// A list of modules written out in the order in which they
722+
/// appear in the crate. This includes the main crate module.
723+
pub modules: BTreeMap<NodeId, ModuleItems>,
711724
}
712725

713726
impl Crate {
@@ -2408,6 +2421,7 @@ pub type GlobMap = NodeMap<FxHashSet<Name>>;
24082421

24092422

24102423
pub fn provide(providers: &mut Providers<'_>) {
2424+
check_attr::provide(providers);
24112425
providers.describe_def = map::describe_def;
24122426
}
24132427

src/librustc/middle/stability.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use hir::{self, Item, Generics, StructField, Variant, HirId};
88
use hir::def::Def;
99
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
1010
use hir::intravisit::{self, Visitor, NestedVisitorMap};
11+
use ty::query::Providers;
12+
use ty::query::queries;
1113
use middle::privacy::AccessLevels;
1214
use session::{DiagnosticMessageId, Session};
1315
use syntax::symbol::Symbol;
@@ -454,11 +456,23 @@ impl<'a, 'tcx> Index<'tcx> {
454456
}
455457
}
456458

459+
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
460+
for &module in tcx.hir().krate().modules.keys() {
461+
queries::check_mod_unstable_api_usage::ensure(tcx, tcx.hir().local_def_id(module));
462+
}
463+
}
464+
457465
/// Cross-references the feature names of unstable APIs with enabled
458466
/// features and possibly prints errors.
459-
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
460-
let mut checker = Checker { tcx };
461-
tcx.hir().krate().visit_all_item_likes(&mut checker.as_deep_visitor());
467+
fn check_mod_unstable_api_usage<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) {
468+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx }.as_deep_visitor());
469+
}
470+
471+
pub fn provide(providers: &mut Providers<'_>) {
472+
*providers = Providers {
473+
check_mod_unstable_api_usage,
474+
..*providers
475+
};
462476
}
463477

464478
/// Check whether an item marked with `deprecated(since="X")` is currently

src/librustc/ty/query/config.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,56 @@ impl<'tcx, M: QueryAccessors<'tcx, Key=DefId>> QueryDescription<'tcx> for M {
6868
format!("processing `{}`", tcx.item_path_str(def_id)).into()
6969
} else {
7070
let name = unsafe { ::std::intrinsics::type_name::<M>() };
71-
format!("processing `{}` applied to `{:?}`", name, def_id).into()
71+
format!("processing {:?} with query `{}`", def_id, name).into()
7272
}
7373
}
7474
}
7575

76+
impl<'tcx> QueryDescription<'tcx> for queries::check_mod_attrs<'tcx> {
77+
fn describe(
78+
tcx: TyCtxt<'_, '_, '_>,
79+
key: DefId,
80+
) -> Cow<'static, str> {
81+
format!("checking attributes in {}", key.describe_as_module(tcx)).into()
82+
}
83+
}
84+
85+
impl<'tcx> QueryDescription<'tcx> for queries::check_mod_unstable_api_usage<'tcx> {
86+
fn describe(
87+
tcx: TyCtxt<'_, '_, '_>,
88+
key: DefId,
89+
) -> Cow<'static, str> {
90+
format!("checking for unstable API usage in {}", key.describe_as_module(tcx)).into()
91+
}
92+
}
93+
94+
impl<'tcx> QueryDescription<'tcx> for queries::check_mod_loops<'tcx> {
95+
fn describe(
96+
tcx: TyCtxt<'_, '_, '_>,
97+
key: DefId,
98+
) -> Cow<'static, str> {
99+
format!("checking loops in {}", key.describe_as_module(tcx)).into()
100+
}
101+
}
102+
103+
impl<'tcx> QueryDescription<'tcx> for queries::check_mod_item_types<'tcx> {
104+
fn describe(
105+
tcx: TyCtxt<'_, '_, '_>,
106+
key: DefId,
107+
) -> Cow<'static, str> {
108+
format!("checking item types in {}", key.describe_as_module(tcx)).into()
109+
}
110+
}
111+
112+
impl<'tcx> QueryDescription<'tcx> for queries::collect_mod_item_types<'tcx> {
113+
fn describe(
114+
tcx: TyCtxt<'_, '_, '_>,
115+
key: DefId,
116+
) -> Cow<'static, str> {
117+
format!("collecting item types in {}", key.describe_as_module(tcx)).into()
118+
}
119+
}
120+
76121
impl<'tcx> QueryDescription<'tcx> for queries::normalize_projection_ty<'tcx> {
77122
fn describe(
78123
_tcx: TyCtxt<'_, '_, '_>,

0 commit comments

Comments
 (0)