]> git.lizzy.rs Git - rust.git/commitdiff
rust-lang/rust#27282: Add `StatementKind::ReadForMatch` to MIR.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 4 May 2018 10:04:33 +0000 (12:04 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 29 May 2018 21:01:36 +0000 (23:01 +0200)
(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.)

15 files changed:
src/librustc/ich/impls_mir.rs
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc_codegen_llvm/mir/statement.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/nll/invalidation.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs
src/librustc_mir/dataflow/impls/borrows.rs
src/librustc_mir/dataflow/move_paths/builder.rs
src/librustc_mir/interpret/step.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/qualify_consts.rs
src/librustc_mir/transform/remove_noop_landing_pads.rs
src/librustc_mir/transform/rustc_peek.rs
src/librustc_passes/mir_stats.rs

index c71b10ce142c56da1153841fbbd933dc141e6072..e77d38de582642585911fd518fcb23b373734f16 100644 (file)
@@ -241,6 +241,9 @@ fn hash_stable<W: StableHasherResult>(&self,
                 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);
index d35884ec78a82b5a37a4289ecc22eddc7fd1c377..a94e5e793b470efa700d0112cfc52cfd722ab24c 100644 (file)
@@ -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 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
         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 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
 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),
index b647ba553dd6c1f782f8d0d69ca16754bd35d53a..9dd1432167a9044115052025e0cdc4e71b7f53b5 100644 (file)
@@ -355,6 +355,11 @@ fn super_statement(&mut self,
                                           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 {
index 578481df157e8b231b1e863eb696430ff4a1949c..c0cce297ef6a98263db3e01b2a8ccaf8b03cc4d9 100644 (file)
@@ -82,6 +82,7 @@ pub fn codegen_statement(&mut self,
                 asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
                 bx
             }
+            mir::StatementKind::ReadForMatch(_) |
             mir::StatementKind::EndRegion(_) |
             mir::StatementKind::Validate(..) |
             mir::StatementKind::UserAssertTy(..) |
index 9bfba219ccd7116e820683cd70981b5e4290f593..233974435f3f835ba8c4316979703cb5573349c8 100644 (file)
@@ -423,6 +423,14 @@ fn visit_statement_entry(
                     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,
 }
 
index 50aa1550fb768c3539ad13d0484d99141997075a..46026cdc9412121ecef012b186f858f41f1226c6 100644 (file)
@@ -93,6 +93,14 @@ fn visit_statement(&mut self,
                     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: _,
index 456aa1aa66f112feaa3d25823c70083a121a33f4..04f5024b76946602cd2341f393ac30ba921fe7eb 100644 (file)
@@ -836,7 +836,8 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'tcx>, location: Loca
                     );
                 }
             }
-            StatementKind::StorageLive(_)
+            StatementKind::ReadForMatch(_)
+            | StatementKind::StorageLive(_)
             | StatementKind::StorageDead(_)
             | StatementKind::InlineAsm { .. }
             | StatementKind::EndRegion(_)
index 04c62854c5cbd5629749e48dd8878693a1095896..78886baf51476b1168727af735eab17af264265f 100644 (file)
@@ -227,6 +227,7 @@ fn statement_effect(&self, sets: &mut BlockSets<BorrowIndex>, location: Location
                 }
             }
 
+            mir::StatementKind::ReadForMatch(..) |
             mir::StatementKind::SetDiscriminant { .. } |
             mir::StatementKind::StorageLive(..) |
             mir::StatementKind::Validate(..) |
index cbf4c822769c616f38f87784ec7566fe3688299c..2ff22842141d9bfc806bff4ae7ca4b3f7f8b46c2 100644 (file)
@@ -278,6 +278,9 @@ fn gather_statement(&mut self, stmt: &Statement<'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 {
index 554d87a04e2f815f5da33775b42588d653602f7e..b9edd2c07f3813938fa17720791799a79bd54584 100644 (file)
@@ -79,6 +79,11 @@ fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx> {
                 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 {
index fc3764e4f49a5bbb8391ab4604b655c93340f9a5..4081f827d4b3da98ba8acad19f731cee89375d40 100644 (file)
@@ -100,6 +100,7 @@ fn visit_statement(&mut self,
         self.source_info = statement.source_info;
         match statement.kind {
             StatementKind::Assign(..) |
+            StatementKind::ReadForMatch(..) |
             StatementKind::SetDiscriminant { .. } |
             StatementKind::StorageLive(..) |
             StatementKind::StorageDead(..) |
index c249dc312f2f75fcfd3274b70511bf5acca714bd..719630129440a6defacbbe1cc3928914cb937e92 100644 (file)
@@ -1135,6 +1135,7 @@ fn visit_statement(&mut self, bb: BasicBlock, statement: &Statement<'tcx>, locat
                 StatementKind::Assign(ref place, ref rvalue) => {
                     this.visit_assign(bb, place, rvalue, location);
                 }
+                StatementKind::ReadForMatch(..) |
                 StatementKind::SetDiscriminant { .. } |
                 StatementKind::StorageLive(_) |
                 StatementKind::StorageDead(_) |
index bcc8fef18f013362135bb6b2162a00907215609d..680b60b97284121f58be6726b6d42ad3b401fa2a 100644 (file)
@@ -47,6 +47,7 @@ fn is_nop_landing_pad(&self, bb: BasicBlock, mir: &Mir, nop_landing_pads: &BitVe
     {
         for stmt in &mir[bb].statements {
             match stmt.kind {
+                StatementKind::ReadForMatch(_) |
                 StatementKind::StorageLive(_) |
                 StatementKind::StorageDead(_) |
                 StatementKind::EndRegion(_) |
index 8f67b9e7c3d9d406abee9929566035716b7c6f20..b23f05680121028dfd34f1f69dad8783215d9582 100644 (file)
@@ -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 { .. } |
index 45c6e89321d044934c0073ba092fbf951406e9ae..f7c8f8f43f178a2c2f81005a14b89b0642bb4c31 100644 (file)
@@ -85,6 +85,7 @@ fn visit_statement(&mut self,
         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",