Skip to content

Commit c656540

Browse files
committed
Auto merge of #161252 - jackh726:polonius-liveness-perf, r=lqd
Skip computing extra liveness info if borrow_set is empty With polonius alpha, we currently compute liveness for a larger set of locals than NLL. However, this extra liveness only matters if there are borrows; so we can skip the extra work if there aren't any. r? lqd
2 parents a872286 + ea0a481 commit c656540

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎compiler/rustc_borrowck/src/type_check/liveness/mod.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ pub(super) fn generate<'tcx>(
4646
// unlike NLLs.
4747
// We do record these regions in the polonius context, since they're used to differentiate
4848
// relevant and boring locals, which is a key distinction used later in diagnostics.
49-
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled() {
49+
// This additional liveness information is ultimately used for *loan* liveness,
50+
// so we don't need to compute it when there are no loans.
51+
// FIXME: this NLL optimization idea, to reduce work to relevant locals only, still makes sense
52+
// for polonius, and should be investigated to improve liveness performance.
53+
if typeck.tcx().sess.opts.unstable_opts.polonius.is_next_enabled()
54+
&& typeck.borrow_set.len() > 0
55+
{
5056
let (_, boring_locals) =
5157
compute_relevant_live_locals(typeck.tcx(), &free_regions, typeck.body);
5258
typeck.polonius_context.as_mut().unwrap().boring_nll_locals =

‎tests/ui/drop/dropck-normalize-errors.polonius.stderr‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ help: this trait has no implementations, consider adding one
7474
LL | trait NonImplementedTrait {
7575
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7676

77-
error: aborting due to 3 previous errors
77+
error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied
78+
--> $DIR/dropck-normalize-errors.rs:20:28
79+
|
80+
LL | fn make_a_decoder<'a>() -> ADecoder<'a> {
81+
| ^^^^^^^^^^^^ unsatisfied trait bound
82+
|
83+
help: the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct`
84+
--> $DIR/dropck-normalize-errors.rs:15:1
85+
|
86+
LL | struct NonImplementedStruct;
87+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
help: this trait has no implementations, consider adding one
89+
--> $DIR/dropck-normalize-errors.rs:12:1
90+
|
91+
LL | trait NonImplementedTrait {
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
93+
94+
error: aborting due to 4 previous errors
7895

7996
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/drop/dropck-normalize-errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct ADecoder<'a> {
1919
}
2020
fn make_a_decoder<'a>() -> ADecoder<'a> {
2121
//~^ ERROR the trait bound
22-
//[nll]~| ERROR the trait bound
22+
//~| ERROR the trait bound
2323
panic!()
2424
}
2525

‎tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ help: the trait `Iterator` is implemented for `&mut I`
3737
note: required by a bound in `Flatten`
3838
--> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL
3939

40-
error: aborting due to 3 previous errors
40+
error[E0277]: `&T` is not an iterator
41+
--> $DIR/hir-wf-check-erase-regions.rs:16:27
42+
|
43+
LL | fn into_iter(self) -> Self::IntoIter {
44+
| ^^^^^^^^^^^^^^ `&T` is not an iterator
45+
|
46+
= help: the trait `Iterator` is not implemented for `&T`
47+
help: the trait `Iterator` is implemented for `&mut I`
48+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
49+
= note: required for `&T` to implement `IntoIterator`
50+
51+
error: aborting due to 4 previous errors
4152

4253
For more information about this error, try `rustc --explain E0277`.

‎tests/ui/wf/hir-wf-check-erase-regions.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> {
1515

1616
fn into_iter(self) -> Self::IntoIter {
1717
//~^ ERROR `&'a T` is not an iterator
18-
//[nll]~| ERROR `&T` is not an iterator
18+
//~| ERROR `&T` is not an iterator
1919
unimplemented!()
2020
}
2121
}

0 commit comments

Comments
 (0)