Share IndirectlyMutableLocals results via reference

This commit is contained in:
Dylan MacKenzie 2019-09-25 12:02:56 -07:00
parent 1a14d17c4d
commit 713ec152fc
3 changed files with 35 additions and 26 deletions

View file

@ -4,7 +4,6 @@ use rustc_data_structures::bit_set::BitSet;
use std::cell::RefCell;
use std::marker::PhantomData;
use std::rc::Rc;
use crate::dataflow::{self as old_dataflow, generic as dataflow};
use super::{Item, Qualif};
@ -164,7 +163,7 @@ pub trait QualifResolver<Q> {
fn reset(&mut self);
}
type IndirectlyMutableResults<'mir, 'tcx> =
pub type IndirectlyMutableResults<'mir, 'tcx> =
old_dataflow::DataflowResultsCursor<'mir, 'tcx, IndirectlyMutableLocals<'mir, 'tcx>>;
/// A resolver for qualifs that works on arbitrarily complex CFGs.
@ -181,7 +180,7 @@ where
Q: Qualif,
{
location: Location,
indirectly_mutable_locals: Rc<RefCell<IndirectlyMutableResults<'mir, 'tcx>>>,
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
cursor: dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q>>,
qualifs_per_local: BitSet<Local>,
}
@ -193,7 +192,7 @@ where
pub fn new(
_: Q,
item: &'a Item<'mir, 'tcx>,
indirectly_mutable_locals: Rc<RefCell<IndirectlyMutableResults<'mir, 'tcx>>>,
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
dead_unwinds: &BitSet<BasicBlock>,
) -> Self {
let analysis = FlowSensitiveAnalysis {

View file

@ -11,11 +11,10 @@ use syntax_pos::Span;
use std::cell::RefCell;
use std::fmt;
use std::ops::Deref;
use std::rc::Rc;
use crate::dataflow as old_dataflow;
use super::{Item, Qualif, is_lang_panic_fn};
use super::resolver::{QualifResolver, FlowSensitiveResolver};
use super::resolver::{FlowSensitiveResolver, IndirectlyMutableResults, QualifResolver};
use super::qualifs::{HasMutInterior, NeedsDrop};
use super::ops::{self, NonConstOp};
@ -127,37 +126,47 @@ impl Deref for Validator<'_, 'mir, 'tcx> {
}
}
pub fn compute_indirectly_mutable_locals<'mir, 'tcx>(
item: &Item<'mir, 'tcx>,
) -> RefCell<IndirectlyMutableResults<'mir, 'tcx>> {
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
let indirectly_mutable_locals = old_dataflow::do_dataflow(
item.tcx,
item.body,
item.def_id,
&[],
&dead_unwinds,
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body, item.param_env),
|_, local| old_dataflow::DebugFormatted::new(&local),
);
let indirectly_mutable_locals = old_dataflow::DataflowResultsCursor::new(
indirectly_mutable_locals,
item.body,
);
RefCell::new(indirectly_mutable_locals)
}
impl Validator<'a, 'mir, 'tcx> {
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
pub fn new(
item: &'a Item<'mir, 'tcx>,
indirectly_mutable_locals: &'a RefCell<IndirectlyMutableResults<'mir, 'tcx>>,
) -> Self {
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
let indirectly_mutable_locals = old_dataflow::do_dataflow(
item.tcx,
item.body,
item.def_id,
&[],
&dead_unwinds,
old_dataflow::IndirectlyMutableLocals::new(item.tcx, item.body, item.param_env),
|_, local| old_dataflow::DebugFormatted::new(&local),
);
let indirectly_mutable_locals = old_dataflow::DataflowResultsCursor::new(
indirectly_mutable_locals,
item.body,
);
let indirectly_mutable_locals = Rc::new(RefCell::new(indirectly_mutable_locals));
let needs_drop = FlowSensitiveResolver::new(
NeedsDrop,
item,
indirectly_mutable_locals.clone(),
indirectly_mutable_locals,
&dead_unwinds,
);
let has_mut_interior = FlowSensitiveResolver::new(
HasMutInterior,
item,
indirectly_mutable_locals.clone(),
indirectly_mutable_locals,
&dead_unwinds,
);

View file

@ -957,7 +957,8 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
}
let item = new_checker::Item::new(self.tcx, self.def_id, self.body);
let mut validator = new_checker::validation::Validator::new(&item);
let mut_borrowed_locals = new_checker::validation::compute_indirectly_mutable_locals(&item);
let mut validator = new_checker::validation::Validator::new(&item, &mut_borrowed_locals);
validator.suppress_errors = !use_new_validator;
self.suppress_errors = use_new_validator;