]> git.lizzy.rs Git - rust.git/commitdiff
Share `IndirectlyMutableLocals` results via reference
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 25 Sep 2019 19:02:56 +0000 (12:02 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Sat, 28 Sep 2019 14:06:52 +0000 (07:06 -0700)
src/librustc_mir/transform/check_consts/resolver.rs
src/librustc_mir/transform/check_consts/validation.rs
src/librustc_mir/transform/qualify_consts.rs

index 2350382e66390a59fdac0a13df1dce30463aab5b..52c471ad691e4ff134982ebd788ef6f143f09029 100644 (file)
@@ -4,7 +4,6 @@
 
 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 @@ fn contains(&mut self, local: Local) -> bool {
     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 @@ pub struct FlowSensitiveResolver<'a, 'mir, 'tcx, Q>
     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 @@ impl<Q> FlowSensitiveResolver<'a, 'mir, 'tcx, Q>
     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 {
index c61fdf5b970e10f227cbeca50c484fc8665822b3..74bf70f05e6871182beb1597cf5bc5505f29c053 100644 (file)
 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 @@ fn deref(&self) -> &Self::Target {
     }
 }
 
+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,
         );
 
index 5add7a64aabf658cc1c2c9c4b3d8b91d1fcc8498..387540655f07b72665109053a466d1a1e867d84a 100644 (file)
@@ -957,7 +957,8 @@ fn check_const(&mut self) -> (u8, &'tcx BitSet<Local>) {
         }
 
         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;