Skip to content

Commit f07d1b1

Browse files
committed
Make liveness checking more parallel
1 parent dfaed34 commit f07d1b1

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

src/librustc_interface/passes.rs

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

811811
sess.time("misc_checking_2", || {
812812
parallel!(
813+
{
814+
sess.time("liveness_checking", || {
815+
par_for_each(&tcx.hir().krate().modules, |(&module, _)| {
816+
// this must run before MIR dump, because
817+
// "not all control paths return a value" is reported here.
818+
//
819+
// maybe move the check to a MIR pass?
820+
let local_def_id = tcx.hir().local_def_id(module);
821+
822+
tcx.ensure().check_mod_liveness(local_def_id);
823+
});
824+
});
825+
},
813826
{
814827
sess.time("match_checking", || {
815828
tcx.par_body_owners(|def_id| {
@@ -818,15 +831,9 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
818831
});
819832
},
820833
{
821-
sess.time("liveness_and_intrinsic_checking", || {
834+
sess.time("intrinsic_checking", || {
822835
par_for_each(&tcx.hir().krate().modules, |(&module, _)| {
823-
// this must run before MIR dump, because
824-
// "not all control paths return a value" is reported here.
825-
//
826-
// maybe move the check to a MIR pass?
827836
let local_def_id = tcx.hir().local_def_id(module);
828-
829-
tcx.ensure().check_mod_liveness(local_def_id);
830837
tcx.ensure().check_mod_intrinsics(local_def_id);
831838
});
832839
});

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: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
1+
warning: unused variable: `Foo`
22
--> $DIR/lint-uppercase-variables.rs:22:9
33
|
44
LL | Foo => {}
5-
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
5+
| ^^^ help: consider prefixing with an underscore: `_Foo`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/lint-uppercase-variables.rs:1:9
9+
|
10+
LL | #![warn(unused)]
11+
| ^^^^^^
12+
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
813

9-
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
14+
warning: unused variable: `Foo`
1015
--> $DIR/lint-uppercase-variables.rs:28:9
1116
|
1217
LL | let Foo = foo::Foo::Foo;
13-
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
18+
| ^^^ help: consider prefixing with an underscore: `_Foo`
1419

15-
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
20+
warning: unused variable: `Foo`
1621
--> $DIR/lint-uppercase-variables.rs:33:17
1722
|
1823
LL | fn in_param(Foo: foo::Foo) {}
19-
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
24+
| ^^^ help: consider prefixing with an underscore: `_Foo`
2025

21-
warning: unused variable: `Foo`
26+
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
2227
--> $DIR/lint-uppercase-variables.rs:22:9
2328
|
2429
LL | Foo => {}
25-
| ^^^ help: consider prefixing with an underscore: `_Foo`
26-
|
27-
note: the lint level is defined here
28-
--> $DIR/lint-uppercase-variables.rs:1:9
30+
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
2931
|
30-
LL | #![warn(unused)]
31-
| ^^^^^^
32-
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
32+
= note: `#[warn(bindings_with_variant_name)]` on by default
3333

34-
warning: unused variable: `Foo`
34+
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
3535
--> $DIR/lint-uppercase-variables.rs:28:9
3636
|
3737
LL | let Foo = foo::Foo::Foo;
38-
| ^^^ help: consider prefixing with an underscore: `_Foo`
38+
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
3939

40-
warning: unused variable: `Foo`
40+
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
4141
--> $DIR/lint-uppercase-variables.rs:33:17
4242
|
4343
LL | fn in_param(Foo: foo::Foo) {}
44-
| ^^^ help: consider prefixing with an underscore: `_Foo`
44+
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
4545

4646
error: structure field `X` should have a snake case name
4747
--> $DIR/lint-uppercase-variables.rs:10:5

0 commit comments

Comments
 (0)