Use MaybeMutBorrowedLocals
for const-checking
This commit is contained in:
parent
1d737fb032
commit
d045a17c4b
2 changed files with 14 additions and 19 deletions
|
@ -15,7 +15,7 @@ use crate::dataflow::{self as old_dataflow, generic as dataflow};
|
||||||
/// `FlowSensitiveAnalysis`.
|
/// `FlowSensitiveAnalysis`.
|
||||||
///
|
///
|
||||||
/// This transfer does nothing when encountering an indirect assignment. Consumers should rely on
|
/// 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.
|
/// an indirect assignment or function call.
|
||||||
struct TransferFunction<'a, 'mir, 'tcx, Q> {
|
struct TransferFunction<'a, 'mir, 'tcx, Q> {
|
||||||
item: &'a Item<'mir, 'tcx>,
|
item: &'a Item<'mir, 'tcx>,
|
||||||
|
|
|
@ -15,17 +15,19 @@ use rustc_span::Span;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use self::old_dataflow::IndirectlyMutableLocals;
|
|
||||||
use super::ops::{self, NonConstOp};
|
use super::ops::{self, NonConstOp};
|
||||||
use super::qualifs::{self, HasMutInterior, NeedsDrop};
|
use super::qualifs::{self, HasMutInterior, NeedsDrop};
|
||||||
use super::resolver::FlowSensitiveAnalysis;
|
use super::resolver::FlowSensitiveAnalysis;
|
||||||
use super::{is_lang_panic_fn, ConstKind, Item, Qualif};
|
use super::{is_lang_panic_fn, ConstKind, Item, Qualif};
|
||||||
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
|
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
|
||||||
use crate::dataflow::{self as old_dataflow, generic as dataflow};
|
use crate::dataflow::generic::{self as dataflow, Analysis};
|
||||||
use 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> =
|
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> {
|
struct QualifCursor<'a, 'mir, 'tcx, Q: Qualif> {
|
||||||
cursor: dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q>>,
|
cursor: dataflow::ResultsCursor<'mir, 'tcx, FlowSensitiveAnalysis<'a, 'mir, 'tcx, Q>>,
|
||||||
|
@ -58,7 +60,7 @@ pub struct Qualifs<'a, 'mir, 'tcx> {
|
||||||
|
|
||||||
impl Qualifs<'a, 'mir, 'tcx> {
|
impl Qualifs<'a, 'mir, 'tcx> {
|
||||||
fn indirectly_mutable(&mut self, local: Local, location: Location) -> bool {
|
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)
|
self.indirectly_mutable.get().contains(local)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,22 +136,15 @@ impl Deref for Validator<'_, 'mir, 'tcx> {
|
||||||
|
|
||||||
impl Validator<'a, 'mir, 'tcx> {
|
impl Validator<'a, 'mir, 'tcx> {
|
||||||
pub fn new(item: &'a Item<'mir, 'tcx>) -> Self {
|
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 needs_drop = QualifCursor::new(NeedsDrop, item);
|
||||||
let has_mut_interior = QualifCursor::new(HasMutInterior, item);
|
let has_mut_interior = QualifCursor::new(HasMutInterior, item);
|
||||||
|
|
||||||
let dead_unwinds = BitSet::new_empty(item.body.basic_blocks().len());
|
let indirectly_mutable = MaybeMutBorrowedLocals::new_mut_only(tcx, *body, param_env)
|
||||||
let indirectly_mutable = old_dataflow::do_dataflow(
|
.into_engine(tcx, *body, def_id)
|
||||||
item.tcx,
|
.iterate_to_fixpoint()
|
||||||
&*item.body,
|
.into_results_cursor(*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 qualifs = Qualifs { needs_drop, has_mut_interior, indirectly_mutable };
|
let qualifs = Qualifs { needs_drop, has_mut_interior, indirectly_mutable };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue