Skip to content

Commit

Permalink
Use MaybeMutBorrowedLocals for const-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Feb 12, 2020
1 parent 1d737fb commit d045a17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::dataflow::{self as old_dataflow, generic as dataflow};
/// `FlowSensitiveAnalysis`.
///
/// This transfer does nothing when encountering an indirect assignment. Consumers should rely on
/// the `IndirectlyMutableLocals` dataflow pass to see if a `Local` may have become qualified via
/// the `MaybeMutBorrowedLocals` dataflow pass to see if a `Local` may have become qualified via
/// an indirect assignment or function call.
struct TransferFunction<'a, 'mir, 'tcx, Q> {
item: &'a Item<'mir, 'tcx>,
Expand Down
31 changes: 13 additions & 18 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ use rustc_span::Span;
use std::borrow::Cow;
use std::ops::Deref;

use self::old_dataflow::IndirectlyMutableLocals;
use super::ops::{self, NonConstOp};
use super::qualifs::{self, HasMutInterior, NeedsDrop};
use super::resolver::FlowSensitiveAnalysis;
use super::{is_lang_panic_fn, ConstKind, Item, Qualif};
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
use crate::dataflow::{self as old_dataflow, generic as dataflow};
use dataflow::Analysis;
use crate::dataflow::generic::{self as dataflow, Analysis};
use crate::dataflow::MaybeMutBorrowedLocals;

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

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

impl Qualifs<'a, 'mir, 'tcx> {
fn indirectly_mutable(&mut self, local: Local, location: Location) -> bool {
self.indirectly_mutable.seek(location);
self.indirectly_mutable.seek_before(location);
self.indirectly_mutable.get().contains(local)
}

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

impl Validator<'a, 'mir, 'tcx> {
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
let Item { tcx, body, def_id, param_env, .. } = *item;

let needs_drop = QualifCursor::new(NeedsDrop, item);
let has_mut_interior = QualifCursor::new(HasMutInterior, item);

let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
let indirectly_mutable = old_dataflow::do_dataflow(
item.tcx,
&*item.body,
item.def_id,
&item.tcx.get_attrs(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 =
old_dataflow::DataflowResultsCursor::new(indirectly_mutable, *item.body);
let indirectly_mutable = MaybeMutBorrowedLocals::new_mut_only(tcx, *body, param_env)
.into_engine(tcx, *body, def_id)
.iterate_to_fixpoint()
.into_results_cursor(*body);

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

Expand Down

0 comments on commit d045a17

Please sign in to comment.