Skip to content

Commit 3aa236c

Browse files
committed
Change how always_live_locals is stored.
In `MaybeStorage{Live,Dead}` just store a reference. No need for a `Cow`.
1 parent 481b5fa commit 3aa236c

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
22
33
use std::assert_matches::assert_matches;
4-
use std::borrow::Cow;
54
use std::mem;
65
use std::num::NonZero;
76
use std::ops::Deref;
@@ -236,10 +235,9 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
236235
// A local is "transient" if it is guaranteed dead at all `Return`.
237236
// So first compute the say of "maybe live" locals at each program point.
238237
let always_live_locals = &always_storage_live_locals(&ccx.body);
239-
let mut maybe_storage_live =
240-
MaybeStorageLive::new(Cow::Borrowed(always_live_locals))
241-
.iterate_to_fixpoint(ccx.tcx, &ccx.body, None)
242-
.into_results_cursor(&ccx.body);
238+
let mut maybe_storage_live = MaybeStorageLive::new(&always_live_locals)
239+
.iterate_to_fixpoint(ccx.tcx, &ccx.body, None)
240+
.into_results_cursor(&ccx.body);
243241

244242
// And then check all `Return` in the MIR, and if a local is "maybe live" at a
245243
// `Return` then it is definitely not transient.

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::borrow::Cow;
2-
31
use rustc_index::bit_set::BitSet;
42
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
53
use rustc_middle::mir::*;
@@ -8,11 +6,11 @@ use super::MaybeBorrowedLocals;
86
use crate::{Analysis, GenKill, ResultsCursor};
97

108
pub struct MaybeStorageLive<'a> {
11-
always_live_locals: Cow<'a, BitSet<Local>>,
9+
always_live_locals: &'a BitSet<Local>,
1210
}
1311

1412
impl<'a> MaybeStorageLive<'a> {
15-
pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
13+
pub fn new(always_live_locals: &'a BitSet<Local>) -> Self {
1614
MaybeStorageLive { always_live_locals }
1715
}
1816
}
@@ -53,11 +51,11 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeStorageLive<'a> {
5351
}
5452

5553
pub struct MaybeStorageDead<'a> {
56-
always_live_locals: Cow<'a, BitSet<Local>>,
54+
always_live_locals: &'a BitSet<Local>,
5755
}
5856

5957
impl<'a> MaybeStorageDead<'a> {
60-
pub fn new(always_live_locals: Cow<'a, BitSet<Local>>) -> Self {
58+
pub fn new(always_live_locals: &'a BitSet<Local>) -> Self {
6159
MaybeStorageDead { always_live_locals }
6260
}
6361
}

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ fn locals_live_across_suspend_points<'tcx>(
665665
) -> LivenessInfo {
666666
// Calculate when MIR locals have live storage. This gives us an upper bound of their
667667
// lifetimes.
668-
let mut storage_live = MaybeStorageLive::new(std::borrow::Cow::Borrowed(always_live_locals))
668+
let mut storage_live = MaybeStorageLive::new(always_live_locals)
669669
.iterate_to_fixpoint(tcx, body, None)
670670
.into_results_cursor(body);
671671

compiler/rustc_mir_transform/src/lint.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//! It can be used to locate problems in MIR building or optimizations. It assumes that all code
33
//! can be executed, so it has false positives.
44
5-
use std::borrow::Cow;
6-
75
use rustc_data_structures::fx::FxHashSet;
86
use rustc_index::bit_set::BitSet;
97
use rustc_middle::mir::visit::{PlaceContext, Visitor};
@@ -16,11 +14,11 @@ use rustc_mir_dataflow::{Analysis, ResultsCursor};
1614
pub(super) fn lint_body<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, when: String) {
1715
let always_live_locals = &always_storage_live_locals(body);
1816

19-
let maybe_storage_live = MaybeStorageLive::new(Cow::Borrowed(always_live_locals))
17+
let maybe_storage_live = MaybeStorageLive::new(always_live_locals)
2018
.iterate_to_fixpoint(tcx, body, None)
2119
.into_results_cursor(body);
2220

23-
let maybe_storage_dead = MaybeStorageDead::new(Cow::Borrowed(always_live_locals))
21+
let maybe_storage_dead = MaybeStorageDead::new(always_live_locals)
2422
.iterate_to_fixpoint(tcx, body, None)
2523
.into_results_cursor(body);
2624

compiler/rustc_mir_transform/src/ref_prop.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::borrow::Cow;
2-
31
use rustc_data_structures::fx::FxHashSet;
42
use rustc_index::IndexVec;
53
use rustc_index::bit_set::BitSet;
@@ -125,7 +123,7 @@ fn compute_replacement<'tcx>(
125123

126124
// Compute `MaybeStorageDead` dataflow to check that we only replace when the pointee is
127125
// definitely live.
128-
let mut maybe_dead = MaybeStorageDead::new(Cow::Owned(always_live_locals))
126+
let mut maybe_dead = MaybeStorageDead::new(&always_live_locals)
129127
.iterate_to_fixpoint(tcx, body, None)
130128
.into_results_cursor(body);
131129

0 commit comments

Comments
 (0)