Skip to content

Commit d045a17

Browse files
Use MaybeMutBorrowedLocals for const-checking
1 parent 1d737fb commit d045a17

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/librustc_mir/transform/check_consts/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::dataflow::{self as old_dataflow, generic as dataflow};
1515
/// `FlowSensitiveAnalysis`.
1616
///
1717
/// This transfer does nothing when encountering an indirect assignment. Consumers should rely on
18-
/// the `IndirectlyMutableLocals` dataflow pass to see if a `Local` may have become qualified via
18+
/// the `MaybeMutBorrowedLocals` dataflow pass to see if a `Local` may have become qualified via
1919
/// an indirect assignment or function call.
2020
struct TransferFunction<'a, 'mir, 'tcx, Q> {
2121
item: &'a Item<'mir, 'tcx>,

src/librustc_mir/transform/check_consts/validation.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ use rustc_span::Span;
1515
use std::borrow::Cow;
1616
use std::ops::Deref;
1717

18-
use self::old_dataflow::IndirectlyMutableLocals;
1918
use super::ops::{self, NonConstOp};
2019
use super::qualifs::{self, HasMutInterior, NeedsDrop};
2120
use super::resolver::FlowSensitiveAnalysis;
2221
use super::{is_lang_panic_fn, ConstKind, Item, Qualif};
2322
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
24-
use crate::dataflow::{self as old_dataflow, generic as dataflow};
25-
use dataflow::Analysis;
23+
use crate::dataflow::generic::{self as dataflow, Analysis};
24+
use crate::dataflow::MaybeMutBorrowedLocals;
2625

26+
// We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated
27+
// through a pointer prior to the given point. This is okay even though `MaybeMutBorrowedLocals`
28+
// kills locals upon `StorageDead` because a local will never be used after a `StorageDead`.
2729
pub type IndirectlyMutableResults<'mir, 'tcx> =
28-
old_dataflow::DataflowResultsCursor<'mir, 'tcx, IndirectlyMutableLocals<'mir, 'tcx>>;
30+
dataflow::ResultsCursor<'mir, 'tcx, MaybeMutBorrowedLocals<'mir, 'tcx>>;
2931

3032
struct QualifCursor<'a, 'mir, 'tcx, Q: Qualif> {
3133
cursor: dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q>>,
@@ -58,7 +60,7 @@ pub struct Qualifs<'a, 'mir, 'tcx> {
5860

5961
impl Qualifs<'a, 'mir, 'tcx> {
6062
fn indirectly_mutable(&mut self, local: Local, location: Location) -> bool {
61-
self.indirectly_mutable.seek(location);
63+
self.indirectly_mutable.seek_before(location);
6264
self.indirectly_mutable.get().contains(local)
6365
}
6466

@@ -134,22 +136,15 @@ impl Deref for Validator<'_, 'mir, 'tcx> {
134136

135137
impl Validator<'a, 'mir, 'tcx> {
136138
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
139+
let Item { tcx, body, def_id, param_env, .. } = *item;
140+
137141
let needs_drop = QualifCursor::new(NeedsDrop, item);
138142
let has_mut_interior = QualifCursor::new(HasMutInterior, item);
139143

140-
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
141-
let indirectly_mutable = old_dataflow::do_dataflow(
142-
item.tcx,
143-
&*item.body,
144-
item.def_id,
145-
&item.tcx.get_attrs(item.def_id),
146-
&dead_unwinds,
147-
old_dataflow::IndirectlyMutableLocals::new(item.tcx, *item.body, item.param_env),
148-
|_, local| old_dataflow::DebugFormatted::new(&local),
149-
);
150-
151-
let indirectly_mutable =
152-
old_dataflow::DataflowResultsCursor::new(indirectly_mutable, *item.body);
144+
let indirectly_mutable = MaybeMutBorrowedLocals::new_mut_only(tcx, *body, param_env)
145+
.into_engine(tcx, *body, def_id)
146+
.iterate_to_fixpoint()
147+
.into_results_cursor(*body);
153148

154149
let qualifs = Qualifs { needs_drop, has_mut_interior, indirectly_mutable };
155150

0 commit comments

Comments
 (0)