use crate::borrow_check::{JustWrite, WriteAndRead};
use crate::borrow_check::{AccessDepth, Deep, Shallow};
use crate::borrow_check::{ReadOrWrite, Activation, Read, Reservation, Write};
-use crate::borrow_check::{Context, ContextKind};
use crate::borrow_check::{LocalMutationIsAllowed, MutateMode};
use crate::borrow_check::ArtificialField;
use crate::borrow_check::{ReadKind, WriteKind};
use crate::dataflow::indexes::BorrowIndex;
use rustc::ty::TyCtxt;
use rustc::mir::visit::Visitor;
-use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue};
+use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue};
use rustc::mir::{Statement, StatementKind};
use rustc::mir::TerminatorKind;
use rustc::mir::{Operand, BorrowKind};
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
all_facts: &mut Option<AllFacts>,
location_table: &LocationTable,
- mir: &Mir<'tcx>,
+ mir: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
if all_facts.is_none() {
mir,
dominators,
};
- ig.visit_mir(mir);
+ ig.visit_body(mir);
}
}
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
all_facts: &'cx mut AllFacts,
location_table: &'cx LocationTable,
- mir: &'cx Mir<'tcx>,
+ mir: &'cx Body<'tcx>,
dominators: Dominators<BasicBlock>,
borrow_set: &'cx BorrowSet<'tcx>,
}
match statement.kind {
StatementKind::Assign(ref lhs, ref rhs) => {
self.consume_rvalue(
- ContextKind::AssignRhs.new(location),
+ location,
rhs,
);
self.mutate_place(
- ContextKind::AssignLhs.new(location),
+ location,
lhs,
Shallow(None),
JustWrite
variant_index: _,
} => {
self.mutate_place(
- ContextKind::SetDiscrim.new(location),
+ location,
place,
Shallow(None),
JustWrite,
);
}
StatementKind::InlineAsm(ref asm) => {
- let context = ContextKind::InlineAsm.new(location);
for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) {
if o.is_indirect {
// FIXME(eddyb) indirect inline asm outputs should
// be encoded through MIR place derefs instead.
self.access_place(
- context,
+ location,
output,
(Deep, Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
);
} else {
self.mutate_place(
- context,
+ location,
output,
if o.is_rw { Deep } else { Shallow(None) },
if o.is_rw { WriteAndRead } else { JustWrite },
}
}
for (_, input) in asm.inputs.iter() {
- self.consume_operand(context, input);
+ self.consume_operand(location, input);
}
}
StatementKind::Nop |
}
StatementKind::StorageDead(local) => {
self.access_place(
- ContextKind::StorageDead.new(location),
+ location,
&Place::Base(PlaceBase::Local(local)),
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes,
values: _,
targets: _,
} => {
- self.consume_operand(ContextKind::SwitchInt.new(location), discr);
+ self.consume_operand(location, discr);
}
TerminatorKind::Drop {
location: ref drop_place,
unwind: _,
} => {
self.access_place(
- ContextKind::Drop.new(location),
+ location,
drop_place,
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
LocalMutationIsAllowed::Yes,
unwind: _,
} => {
self.mutate_place(
- ContextKind::DropAndReplace.new(location),
+ location,
drop_place,
Deep,
JustWrite,
);
self.consume_operand(
- ContextKind::DropAndReplace.new(location),
+ location,
new_value,
);
}
cleanup: _,
from_hir_call: _,
} => {
- self.consume_operand(ContextKind::CallOperator.new(location), func);
+ self.consume_operand(location, func);
for arg in args {
- self.consume_operand(ContextKind::CallOperand.new(location), arg);
+ self.consume_operand(location, arg);
}
if let Some((ref dest, _ /*bb*/)) = *destination {
self.mutate_place(
- ContextKind::CallDest.new(location),
+ location,
dest,
Deep,
JustWrite,
target: _,
cleanup: _,
} => {
- self.consume_operand(ContextKind::Assert.new(location), cond);
+ self.consume_operand(location, cond);
use rustc::mir::interpret::InterpError::BoundsCheck;
if let BoundsCheck { ref len, ref index } = *msg {
- self.consume_operand(ContextKind::Assert.new(location), len);
- self.consume_operand(ContextKind::Assert.new(location), index);
+ self.consume_operand(location, len);
+ self.consume_operand(location, index);
}
}
TerminatorKind::Yield {
resume,
drop: _,
} => {
- self.consume_operand(ContextKind::Yield.new(location), value);
+ self.consume_operand(location, value);
// Invalidate all borrows of local places
let borrow_set = self.borrow_set.clone();
/// Simulates mutation of a place.
fn mutate_place(
&mut self,
- context: Context,
+ location: Location,
place: &Place<'tcx>,
kind: AccessDepth,
_mode: MutateMode,
) {
self.access_place(
- context,
+ location,
place,
(kind, Write(WriteKind::Mutate)),
LocalMutationIsAllowed::ExceptUpvars,
/// Simulates consumption of an operand.
fn consume_operand(
&mut self,
- context: Context,
+ location: Location,
operand: &Operand<'tcx>,
) {
match *operand {
Operand::Copy(ref place) => {
self.access_place(
- context,
+ location,
place,
(Deep, Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
}
Operand::Move(ref place) => {
self.access_place(
- context,
+ location,
place,
(Deep, Write(WriteKind::Move)),
LocalMutationIsAllowed::Yes,
// Simulates consumption of an rvalue
fn consume_rvalue(
&mut self,
- context: Context,
+ location: Location,
rvalue: &Rvalue<'tcx>,
) {
match *rvalue {
};
self.access_place(
- context,
+ location,
place,
access_kind,
LocalMutationIsAllowed::No,
| Rvalue::Repeat(ref operand, _)
| Rvalue::UnaryOp(_ /*un_op*/, ref operand)
| Rvalue::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => {
- self.consume_operand(context, operand)
+ self.consume_operand(location, operand)
}
Rvalue::Len(ref place) | Rvalue::Discriminant(ref place) => {
_ => unreachable!(),
};
self.access_place(
- context,
+ location,
place,
(Shallow(af), Read(ReadKind::Copy)),
LocalMutationIsAllowed::No,
Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2)
| Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => {
- self.consume_operand(context, operand1);
- self.consume_operand(context, operand2);
+ self.consume_operand(location, operand1);
+ self.consume_operand(location, operand2);
}
Rvalue::NullaryOp(_op, _ty) => {
Rvalue::Aggregate(_, ref operands) => {
for operand in operands {
- self.consume_operand(context, operand);
+ self.consume_operand(location, operand);
}
}
}
/// Simulates an access to a place.
fn access_place(
&mut self,
- context: Context,
+ location: Location,
place: &Place<'tcx>,
kind: (AccessDepth, ReadOrWrite),
_is_local_mutation_allowed: LocalMutationIsAllowed,
) {
let (sd, rw) = kind;
// note: not doing check_access_permissions checks because they don't generate invalidates
- self.check_access_for_conflict(context, place, sd, rw);
+ self.check_access_for_conflict(location, place, sd, rw);
}
fn check_access_for_conflict(
&mut self,
- context: Context,
+ location: Location,
place: &Place<'tcx>,
sd: AccessDepth,
rw: ReadOrWrite,
) {
debug!(
- "invalidation::check_access_for_conflict(context={:?}, place={:?}, sd={:?}, \
+ "invalidation::check_access_for_conflict(location={:?}, place={:?}, sd={:?}, \
rw={:?})",
- context,
+ location,
place,
sd,
rw,
self,
tcx,
mir,
- context,
+ location,
(sd, place),
&borrow_set.clone(),
indices,
(Read(_), BorrowKind::Unique) | (Read(_), BorrowKind::Mut { .. }) => {
// Reading from mere reservations of mutable-borrows is OK.
- if !is_active(&this.dominators, borrow, context.loc) {
+ if !is_active(&this.dominators, borrow, location) {
// If the borrow isn't active yet, reads don't invalidate it
assert!(allow_two_phase_borrow(borrow.kind));
return Control::Continue;
// Unique and mutable borrows are invalidated by reads from any
// involved path
- this.generate_invalidates(borrow_index, context.loc);
+ this.generate_invalidates(borrow_index, location);
}
(Reservation(_), _)
// Reservations count as writes since we need to check
// that activating the borrow will be OK
// FIXME(bob_twinkles) is this actually the right thing to do?
- this.generate_invalidates(borrow_index, context.loc);
+ this.generate_invalidates(borrow_index, location);
}
}
Control::Continue
});
self.access_place(
- ContextKind::Activation.new(location),
+ location,
&borrow.borrowed_place,
(
Deep,