Skip to content

Commit 713ec15

Browse files
Share IndirectlyMutableLocals results via reference
1 parent 1a14d17 commit 713ec15

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

src/librustc_mir/transform/check_consts/resolver.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_data_structures::bit_set::BitSet;
44

55
use std::cell::RefCell;
66
use std::marker::PhantomData;
7-
use std::rc::Rc;
87

98
use crate::dataflow::{self as old_dataflow, generic as dataflow};
109
use super::{Item, Qualif};
@@ -164,7 +163,7 @@ pub trait QualifResolver<Q> {
164163
fn reset(&mut self);
165164
}
166165

167-
type IndirectlyMutableResults<'mir, 'tcx> =
166+
pub type IndirectlyMutableResults<'mir, 'tcx> =
168167
old_dataflow::DataflowResultsCursor<'mir, 'tcx, IndirectlyMutableLocals<'mir, 'tcx>>;
169168

170169
/// A resolver for qualifs that works on arbitrarily complex CFGs.
@@ -181,7 +180,7 @@ where
181180
Q: Qualif,
182181
{
183182
location: Location,
184-
indirectly_mutable_locals: Rc<RefCell<IndirectlyMutableResults<'mir, 'tcx>>>,
183+
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
185184
cursor: dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q>>,
186185
qualifs_per_local: BitSet<Local>,
187186
}
@@ -193,7 +192,7 @@ where
193192
pub fn new(
194193
_: Q,
195194
item: &'a Item<'mir, 'tcx>,
196-
indirectly_mutable_locals: Rc<RefCell<IndirectlyMutableResults<'mir, 'tcx>>>,
195+
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
197196
dead_unwinds: &BitSet<BasicBlock>,
198197
) -> Self {
199198
let analysis = FlowSensitiveAnalysis {

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ use syntax_pos::Span;
1111
use std::cell::RefCell;
1212
use std::fmt;
1313
use std::ops::Deref;
14-
use std::rc::Rc;
1514

1615
use crate::dataflow as old_dataflow;
1716
use super::{Item, Qualif, is_lang_panic_fn};
18-
use super::resolver::{QualifResolver, FlowSensitiveResolver};
17+
use super::resolver::{FlowSensitiveResolver, IndirectlyMutableResults, QualifResolver};
1918
use super::qualifs::{HasMutInterior, NeedsDrop};
2019
use super::ops::{self, NonConstOp};
2120

@@ -127,37 +126,47 @@ impl Deref for Validator<'_, 'mir, 'tcx> {
127126
}
128127
}
129128

129+
pub fn compute_indirectly_mutable_locals<'mir, 'tcx>(
130+
item: &Item<'mir, 'tcx>,
131+
) -> RefCell<IndirectlyMutableResults<'mir, 'tcx>> {
132+
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
133+
134+
let indirectly_mutable_locals = old_dataflow::do_dataflow(
135+
item.tcx,
136+
item.body,
137+
item.def_id,
138+
&[],
139+
&dead_unwinds,
140+
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body, item.param_env),
141+
|_, local| old_dataflow::DebugFormatted::new(&local),
142+
);
143+
144+
let indirectly_mutable_locals = old_dataflow::DataflowResultsCursor::new(
145+
indirectly_mutable_locals,
146+
item.body,
147+
);
148+
149+
RefCell::new(indirectly_mutable_locals)
150+
}
151+
130152
impl Validator<'a, 'mir, 'tcx> {
131-
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
153+
pub fn new(
154+
item: &'a Item<'mir, 'tcx>,
155+
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
156+
) -> Self {
132157
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
133158

134-
let indirectly_mutable_locals = old_dataflow::do_dataflow(
135-
item.tcx,
136-
item.body,
137-
item.def_id,
138-
&[],
139-
&dead_unwinds,
140-
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body, item.param_env),
141-
|_, local| old_dataflow::DebugFormatted::new(&local),
142-
);
143-
144-
let indirectly_mutable_locals = old_dataflow::DataflowResultsCursor::new(
145-
indirectly_mutable_locals,
146-
item.body,
147-
);
148-
let indirectly_mutable_locals = Rc::new(RefCell::new(indirectly_mutable_locals));
149-
150159
let needs_drop = FlowSensitiveResolver::new(
151160
NeedsDrop,
152161
item,
153-
indirectly_mutable_locals.clone(),
162+
indirectly_mutable_locals,
154163
&dead_unwinds,
155164
);
156165

157166
let has_mut_interior = FlowSensitiveResolver::new(
158167
HasMutInterior,
159168
item,
160-
indirectly_mutable_locals.clone(),
169+
indirectly_mutable_locals,
161170
&dead_unwinds,
162171
);
163172

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
957957
}
958958

959959
let item = new_checker::Item::new(self.tcx, self.def_id, self.body);
960-
let mut validator = new_checker::validation::Validator::new(&item);
960+
let mut_borrowed_locals = new_checker::validation::compute_indirectly_mutable_locals(&item);
961+
let mut validator = new_checker::validation::Validator::new(&item, &mut_borrowed_locals);
961962

962963
validator.suppress_errors = !use_new_validator;
963964
self.suppress_errors = use_new_validator;

0 commit comments

Comments
 (0)