1
Fork 0

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

View file

@ -11,11 +11,10 @@ use syntax_pos::Span;
use std::cell::RefCell; use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc;
use crate::dataflow as old_dataflow; use crate::dataflow as old_dataflow;
use super::{Item, Qualif, is_lang_panic_fn}; 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::qualifs::{HasMutInterior, NeedsDrop};
use super::ops::{self, NonConstOp}; use super::ops::{self, NonConstOp};
@ -127,8 +126,9 @@ impl Deref for Validator<'_, 'mir, 'tcx> {
} }
} }
impl Validator<'a, 'mir, 'tcx> { pub fn compute_indirectly_mutable_locals<'mir, 'tcx>(
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self { item: &Item<'mir, 'tcx>,
) -> RefCell<IndirectlyMutableResults<'mir, 'tcx>> {
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len()); let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
let indirectly_mutable_locals = old_dataflow::do_dataflow( let indirectly_mutable_locals = old_dataflow::do_dataflow(
@ -145,19 +145,28 @@ impl Validator<'a, 'mir, 'tcx> {
indirectly_mutable_locals, indirectly_mutable_locals,
item.body, item.body,
); );
let indirectly_mutable_locals = Rc::new(RefCell::new(indirectly_mutable_locals));
RefCell::new(indirectly_mutable_locals)
}
impl Validator<'a, 'mir, 'tcx> {
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 needs_drop = FlowSensitiveResolver::new( let needs_drop = FlowSensitiveResolver::new(
NeedsDrop, NeedsDrop,
item, item,
indirectly_mutable_locals.clone(), indirectly_mutable_locals,
&dead_unwinds, &dead_unwinds,
); );
let has_mut_interior = FlowSensitiveResolver::new( let has_mut_interior = FlowSensitiveResolver::new(
HasMutInterior, HasMutInterior,
item, item,
indirectly_mutable_locals.clone(), indirectly_mutable_locals,
&dead_unwinds, &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 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; validator.suppress_errors = !use_new_validator;
self.suppress_errors = use_new_validator; self.suppress_errors = use_new_validator;