Skip to content

Commit

Permalink
#27282: Add StatementKind::ReadForMatch to MIR.
Browse files Browse the repository at this point in the history
(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.)
  • Loading branch information
pnkfelix committed May 29, 2018
1 parent 47bb3fd commit 24abe6f
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/librustc/ich/impls_mir.rs
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/mir/mod.rs
Expand Up @@ -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 },

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/mir/visit.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/mir/statement.rs
Expand Up @@ -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(..) |
Expand Down
9 changes: 9 additions & 0 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -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: _,
Expand Down Expand Up @@ -2090,6 +2098,7 @@ enum ContextKind {
CallDest,
Assert,
Yield,
ReadForMatch,
StorageDead,
}

Expand Down
8 changes: 8 additions & 0 deletions src/librustc_mir/borrow_check/nll/invalidation.rs
Expand Up @@ -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: _,
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/nll/type_check/mod.rs
Expand Up @@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
);
}
}
StatementKind::StorageLive(_)
StatementKind::ReadForMatch(_)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::InlineAsm { .. }
| StatementKind::EndRegion(_)
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/dataflow/impls/borrows.rs
Expand Up @@ -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(..) |
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_mir/dataflow/move_paths/builder.rs
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_mir/interpret/step.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/transform/check_unsafety.rs
Expand Up @@ -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(..) |
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -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(_) |
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/transform/remove_noop_landing_pads.rs
Expand Up @@ -47,6 +47,7 @@ impl RemoveNoopLandingPads {
{
for stmt in &mir[bb].statements {
match stmt.kind {
StatementKind::ReadForMatch(_) |
StatementKind::StorageLive(_) |
StatementKind::StorageDead(_) |
StatementKind::EndRegion(_) |
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/transform/rustc_peek.rs
Expand Up @@ -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 { .. } |
Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/mir_stats.rs
Expand Up @@ -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",
Expand Down

0 comments on commit 24abe6f

Please sign in to comment.