Skip to content

Commit 7a6895f

Browse files
committed
Make liveness checking more parallel
1 parent ff125ff commit 7a6895f

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

src/librustc_interface/passes.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,19 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
813813

814814
sess.time("misc_checking_2", || {
815815
parallel!(
816+
{
817+
sess.time("liveness_checking", || {
818+
par_for_each(&tcx.hir().krate().modules, |(&module, _)| {
819+
// this must run before MIR dump, because
820+
// "not all control paths return a value" is reported here.
821+
//
822+
// maybe move the check to a MIR pass?
823+
let local_def_id = tcx.hir().local_def_id(module);
824+
825+
tcx.ensure().check_mod_liveness(local_def_id);
826+
});
827+
});
828+
},
816829
{
817830
sess.time("match_checking", || {
818831
tcx.par_body_owners(|def_id| {
@@ -821,15 +834,9 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
821834
});
822835
},
823836
{
824-
sess.time("liveness_and_intrinsic_checking", || {
837+
sess.time("intrinsic_checking", || {
825838
par_for_each(&tcx.hir().krate().modules, |(&module, _)| {
826-
// this must run before MIR dump, because
827-
// "not all control paths return a value" is reported here.
828-
//
829-
// maybe move the check to a MIR pass?
830839
let local_def_id = tcx.hir().local_def_id(module);
831-
832-
tcx.ensure().check_mod_liveness(local_def_id);
833840
tcx.ensure().check_mod_intrinsics(local_def_id);
834841
});
835842
});

src/librustc_passes/liveness.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ use rustc_hir as hir;
106106
use rustc_hir::def::*;
107107
use rustc_hir::def_id::DefId;
108108
use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor};
109+
use rustc_hir::itemlikevisit::ParItemLikeVisitor;
109110
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node};
110111
use rustc_span::symbol::sym;
111112
use rustc_span::Span;
@@ -182,11 +183,28 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
182183
}
183184
}
184185

186+
struct LivenessVisitor<'tcx> {
187+
tcx: TyCtxt<'tcx>,
188+
module_def_id: DefId,
189+
}
190+
191+
impl<'tcx> ParItemLikeVisitor<'tcx> for LivenessVisitor<'tcx> {
192+
fn visit_item(&self, item: &'tcx hir::Item<'tcx>) {
193+
IrMaps::new(self.tcx, self.module_def_id).visit_item(item);
194+
}
195+
196+
fn visit_trait_item(&self, trait_item: &'tcx hir::TraitItem<'tcx>) {
197+
IrMaps::new(self.tcx, self.module_def_id).visit_trait_item(trait_item);
198+
}
199+
200+
fn visit_impl_item(&self, impl_item: &'tcx hir::ImplItem<'tcx>) {
201+
IrMaps::new(self.tcx, self.module_def_id).visit_impl_item(impl_item);
202+
}
203+
}
204+
185205
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: DefId) {
186-
tcx.hir().visit_item_likes_in_module(
187-
module_def_id,
188-
&mut IrMaps::new(tcx, module_def_id).as_deep_visitor(),
189-
);
206+
tcx.hir()
207+
.par_visit_item_likes_in_module(module_def_id, &LivenessVisitor { tcx, module_def_id });
190208
}
191209

192210
pub fn provide(providers: &mut Providers<'_>) {

src/test/ui/lint/lint-uppercase-variables.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
2-
--> $DIR/lint-uppercase-variables.rs:22:9
3-
|
4-
LL | Foo => {}
5-
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
6-
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
8-
91
warning: unused variable: `Foo`
102
--> $DIR/lint-uppercase-variables.rs:22:9
113
|
@@ -19,6 +11,14 @@ LL | #![warn(unused)]
1911
| ^^^^^^
2012
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
2113

14+
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
15+
--> $DIR/lint-uppercase-variables.rs:22:9
16+
|
17+
LL | Foo => {}
18+
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
19+
|
20+
= note: `#[warn(bindings_with_variant_name)]` on by default
21+
2222
error: structure field `X` should have a snake case name
2323
--> $DIR/lint-uppercase-variables.rs:10:5
2424
|

0 commit comments

Comments
 (0)