rust-lang/rust#27282: Add StatementKind::ReadForMatch to MIR.
(This is just the data structure changes and some boilerplate match code that followed from it; the actual emission of these statements comes in a follow-up commit.)
This commit is contained in:
parent
47bb3fd505
commit
24abe6f363
15 changed files with 48 additions and 1 deletions
|
|
@ -241,6 +241,9 @@ for mir::StatementKind<'gcx> {
|
|||
place.hash_stable(hcx, hasher);
|
||||
rvalue.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::StatementKind::ReadForMatch(ref place) => {
|
||||
place.hash_stable(hcx, hasher);
|
||||
}
|
||||
mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
|
||||
place.hash_stable(hcx, hasher);
|
||||
variant_index.hash_stable(hcx, hasher);
|
||||
|
|
|
|||
|
|
@ -1225,6 +1225,10 @@ pub enum StatementKind<'tcx> {
|
|||
/// Write the RHS Rvalue to the LHS Place.
|
||||
Assign(Place<'tcx>, Rvalue<'tcx>),
|
||||
|
||||
/// This represents all the reading that a pattern match may do
|
||||
/// (e.g. inspecting constants and discriminant values).
|
||||
ReadForMatch(Place<'tcx>),
|
||||
|
||||
/// Write the discriminant for a variant to the enum Place.
|
||||
SetDiscriminant { place: Place<'tcx>, variant_index: usize },
|
||||
|
||||
|
|
@ -1327,6 +1331,7 @@ impl<'tcx> Debug for Statement<'tcx> {
|
|||
use self::StatementKind::*;
|
||||
match self.kind {
|
||||
Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
|
||||
ReadForMatch(ref place) => write!(fmt, "ReadForMatch({:?})", place),
|
||||
// (reuse lifetime rendering policy from ppaux.)
|
||||
EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)),
|
||||
Validate(ref op, ref places) => write!(fmt, "Validate({:?}, {:?})", op, places),
|
||||
|
|
@ -2212,6 +2217,7 @@ BraceStructTypeFoldableImpl! {
|
|||
EnumTypeFoldableImpl! {
|
||||
impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
|
||||
(StatementKind::Assign)(a, b),
|
||||
(StatementKind::ReadForMatch)(place),
|
||||
(StatementKind::SetDiscriminant) { place, variant_index },
|
||||
(StatementKind::StorageLive)(a),
|
||||
(StatementKind::StorageDead)(a),
|
||||
|
|
|
|||
|
|
@ -355,6 +355,11 @@ macro_rules! make_mir_visitor {
|
|||
ref $($mutability)* rvalue) => {
|
||||
self.visit_assign(block, place, rvalue, location);
|
||||
}
|
||||
StatementKind::ReadForMatch(ref $($mutability)* place) => {
|
||||
self.visit_place(place,
|
||||
PlaceContext::Inspect,
|
||||
location);
|
||||
}
|
||||
StatementKind::EndRegion(_) => {}
|
||||
StatementKind::Validate(_, ref $($mutability)* places) => {
|
||||
for operand in places {
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
|
|||
asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
|
||||
bx
|
||||
}
|
||||
mir::StatementKind::ReadForMatch(_) |
|
||||
mir::StatementKind::EndRegion(_) |
|
||||
mir::StatementKind::Validate(..) |
|
||||
mir::StatementKind::UserAssertTy(..) |
|
||||
|
|
|
|||
|
|
@ -423,6 +423,14 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
|
|||
flow_state,
|
||||
);
|
||||
}
|
||||
StatementKind::ReadForMatch(ref place) => {
|
||||
self.access_place(ContextKind::ReadForMatch.new(location),
|
||||
(place, span),
|
||||
(Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
|
||||
LocalMutationIsAllowed::No,
|
||||
flow_state,
|
||||
);
|
||||
}
|
||||
StatementKind::SetDiscriminant {
|
||||
ref place,
|
||||
variant_index: _,
|
||||
|
|
@ -2090,6 +2098,7 @@ enum ContextKind {
|
|||
CallDest,
|
||||
Assert,
|
||||
Yield,
|
||||
ReadForMatch,
|
||||
StorageDead,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,14 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
|
|||
JustWrite
|
||||
);
|
||||
}
|
||||
StatementKind::ReadForMatch(ref place) => {
|
||||
self.access_place(
|
||||
ContextKind::ReadForMatch.new(location),
|
||||
place,
|
||||
(Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
|
||||
LocalMutationIsAllowed::No,
|
||||
);
|
||||
}
|
||||
StatementKind::SetDiscriminant {
|
||||
ref place,
|
||||
variant_index: _,
|
||||
|
|
|
|||
|
|
@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
StatementKind::StorageLive(_)
|
||||
StatementKind::ReadForMatch(_)
|
||||
| StatementKind::StorageLive(_)
|
||||
| StatementKind::StorageDead(_)
|
||||
| StatementKind::InlineAsm { .. }
|
||||
| StatementKind::EndRegion(_)
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
mir::StatementKind::ReadForMatch(..) |
|
||||
mir::StatementKind::SetDiscriminant { .. } |
|
||||
mir::StatementKind::StorageLive(..) |
|
||||
mir::StatementKind::Validate(..) |
|
||||
|
|
|
|||
|
|
@ -278,6 +278,9 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
|
|||
}
|
||||
self.gather_rvalue(rval);
|
||||
}
|
||||
StatementKind::ReadForMatch(ref place) => {
|
||||
self.create_move_path(place);
|
||||
}
|
||||
StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {
|
||||
for (output, kind) in outputs.iter().zip(&asm.outputs) {
|
||||
if !kind.is_indirect {
|
||||
|
|
|
|||
|
|
@ -79,6 +79,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
|||
self.deallocate_local(old_val)?;
|
||||
}
|
||||
|
||||
// FIXME: is there some dynamic semantics we should attach to
|
||||
// these? Or am I correct in thinking that the inerpreter
|
||||
// is solely intended for borrowck'ed code?
|
||||
ReadForMatch(..) => {}
|
||||
|
||||
// Validity checks.
|
||||
Validate(op, ref places) => {
|
||||
for operand in places {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
|
|||
self.source_info = statement.source_info;
|
||||
match statement.kind {
|
||||
StatementKind::Assign(..) |
|
||||
StatementKind::ReadForMatch(..) |
|
||||
StatementKind::SetDiscriminant { .. } |
|
||||
StatementKind::StorageLive(..) |
|
||||
StatementKind::StorageDead(..) |
|
||||
|
|
|
|||
|
|
@ -1135,6 +1135,7 @@ This does not pose a problem by itself because they can't be accessed directly."
|
|||
StatementKind::Assign(ref place, ref rvalue) => {
|
||||
this.visit_assign(bb, place, rvalue, location);
|
||||
}
|
||||
StatementKind::ReadForMatch(..) |
|
||||
StatementKind::SetDiscriminant { .. } |
|
||||
StatementKind::StorageLive(_) |
|
||||
StatementKind::StorageDead(_) |
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ impl RemoveNoopLandingPads {
|
|||
{
|
||||
for stmt in &mir[bb].statements {
|
||||
match stmt.kind {
|
||||
StatementKind::ReadForMatch(_) |
|
||||
StatementKind::StorageLive(_) |
|
||||
StatementKind::StorageDead(_) |
|
||||
StatementKind::EndRegion(_) |
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
mir::StatementKind::Assign(ref place, ref rvalue) => {
|
||||
(place, rvalue)
|
||||
}
|
||||
mir::StatementKind::ReadForMatch(_) |
|
||||
mir::StatementKind::StorageLive(_) |
|
||||
mir::StatementKind::StorageDead(_) |
|
||||
mir::StatementKind::InlineAsm { .. } |
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
|
|||
self.record("Statement", statement);
|
||||
self.record(match statement.kind {
|
||||
StatementKind::Assign(..) => "StatementKind::Assign",
|
||||
StatementKind::ReadForMatch(..) => "StatementKind::ReadForMatch",
|
||||
StatementKind::EndRegion(..) => "StatementKind::EndRegion",
|
||||
StatementKind::Validate(..) => "StatementKind::Validate",
|
||||
StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue