summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2018-05-04 12:04:33 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2018-05-29 23:01:36 +0200
commit24abe6f363cd47d444e4cff1123da93817b980f8 (patch)
tree849e130d445bc81ee9a6fadeae611c0118e8e86c
parentDebug flag to bypass restriction of mutation in match guards. (diff)
downloadgrust-24abe6f363cd47d444e4cff1123da93817b980f8.tar.gz
grust-24abe6f363cd47d444e4cff1123da93817b980f8.tar.bz2
grust-24abe6f363cd47d444e4cff1123da93817b980f8.tar.xz
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.)
-rw-r--r--src/librustc/ich/impls_mir.rs3
-rw-r--r--src/librustc/mir/mod.rs6
-rw-r--r--src/librustc/mir/visit.rs5
-rw-r--r--src/librustc_codegen_llvm/mir/statement.rs1
-rw-r--r--src/librustc_mir/borrow_check/mod.rs9
-rw-r--r--src/librustc_mir/borrow_check/nll/invalidation.rs8
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/mod.rs3
-rw-r--r--src/librustc_mir/dataflow/impls/borrows.rs1
-rw-r--r--src/librustc_mir/dataflow/move_paths/builder.rs3
-rw-r--r--src/librustc_mir/interpret/step.rs5
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs1
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs1
-rw-r--r--src/librustc_mir/transform/remove_noop_landing_pads.rs1
-rw-r--r--src/librustc_mir/transform/rustc_peek.rs1
-rw-r--r--src/librustc_passes/mir_stats.rs1
15 files changed, 48 insertions, 1 deletions
diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs
index c71b10ce14..e77d38de58 100644
--- a/src/librustc/ich/impls_mir.rs
+++ b/src/librustc/ich/impls_mir.rs
@@ -241,6 +241,9 @@ for mir::StatementKind<'gcx> {
241 place.hash_stable(hcx, hasher); 241 place.hash_stable(hcx, hasher);
242 rvalue.hash_stable(hcx, hasher); 242 rvalue.hash_stable(hcx, hasher);
243 } 243 }
244 mir::StatementKind::ReadForMatch(ref place) => {
245 place.hash_stable(hcx, hasher);
246 }
244 mir::StatementKind::SetDiscriminant { ref place, variant_index } => { 247 mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
245 place.hash_stable(hcx, hasher); 248 place.hash_stable(hcx, hasher);
246 variant_index.hash_stable(hcx, hasher); 249 variant_index.hash_stable(hcx, hasher);
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs
index d35884ec78..a94e5e793b 100644
--- a/src/librustc/mir/mod.rs
+++ b/src/librustc/mir/mod.rs
@@ -1225,6 +1225,10 @@ pub enum StatementKind<'tcx> {
1225 /// Write the RHS Rvalue to the LHS Place. 1225 /// Write the RHS Rvalue to the LHS Place.
1226 Assign(Place<'tcx>, Rvalue<'tcx>), 1226 Assign(Place<'tcx>, Rvalue<'tcx>),
1227 1227
1228 /// This represents all the reading that a pattern match may do
1229 /// (e.g. inspecting constants and discriminant values).
1230 ReadForMatch(Place<'tcx>),
1231
1228 /// Write the discriminant for a variant to the enum Place. 1232 /// Write the discriminant for a variant to the enum Place.
1229 SetDiscriminant { place: Place<'tcx>, variant_index: usize }, 1233 SetDiscriminant { place: Place<'tcx>, variant_index: usize },
1230 1234
@@ -1327,6 +1331,7 @@ impl<'tcx> Debug for Statement<'tcx> {
1327 use self::StatementKind::*; 1331 use self::StatementKind::*;
1328 match self.kind { 1332 match self.kind {
1329 Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv), 1333 Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
1334 ReadForMatch(ref place) => write!(fmt, "ReadForMatch({:?})", place),
1330 // (reuse lifetime rendering policy from ppaux.) 1335 // (reuse lifetime rendering policy from ppaux.)
1331 EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)), 1336 EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)),
1332 Validate(ref op, ref places) => write!(fmt, "Validate({:?}, {:?})", op, places), 1337 Validate(ref op, ref places) => write!(fmt, "Validate({:?}, {:?})", op, places),
@@ -2212,6 +2217,7 @@ BraceStructTypeFoldableImpl! {
2212EnumTypeFoldableImpl! { 2217EnumTypeFoldableImpl! {
2213 impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> { 2218 impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
2214 (StatementKind::Assign)(a, b), 2219 (StatementKind::Assign)(a, b),
2220 (StatementKind::ReadForMatch)(place),
2215 (StatementKind::SetDiscriminant) { place, variant_index }, 2221 (StatementKind::SetDiscriminant) { place, variant_index },
2216 (StatementKind::StorageLive)(a), 2222 (StatementKind::StorageLive)(a),
2217 (StatementKind::StorageDead)(a), 2223 (StatementKind::StorageDead)(a),
diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs
index b647ba553d..9dd1432167 100644
--- a/src/librustc/mir/visit.rs
+++ b/src/librustc/mir/visit.rs
@@ -355,6 +355,11 @@ macro_rules! make_mir_visitor {
355 ref $($mutability)* rvalue) => { 355 ref $($mutability)* rvalue) => {
356 self.visit_assign(block, place, rvalue, location); 356 self.visit_assign(block, place, rvalue, location);
357 } 357 }
358 StatementKind::ReadForMatch(ref $($mutability)* place) => {
359 self.visit_place(place,
360 PlaceContext::Inspect,
361 location);
362 }
358 StatementKind::EndRegion(_) => {} 363 StatementKind::EndRegion(_) => {}
359 StatementKind::Validate(_, ref $($mutability)* places) => { 364 StatementKind::Validate(_, ref $($mutability)* places) => {
360 for operand in places { 365 for operand in places {
diff --git a/src/librustc_codegen_llvm/mir/statement.rs b/src/librustc_codegen_llvm/mir/statement.rs
index 578481df15..c0cce297ef 100644
--- a/src/librustc_codegen_llvm/mir/statement.rs
+++ b/src/librustc_codegen_llvm/mir/statement.rs
@@ -82,6 +82,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
82 asm::codegen_inline_asm(&bx, asm, outputs, input_vals); 82 asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
83 bx 83 bx
84 } 84 }
85 mir::StatementKind::ReadForMatch(_) |
85 mir::StatementKind::EndRegion(_) | 86 mir::StatementKind::EndRegion(_) |
86 mir::StatementKind::Validate(..) | 87 mir::StatementKind::Validate(..) |
87 mir::StatementKind::UserAssertTy(..) | 88 mir::StatementKind::UserAssertTy(..) |
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index 9bfba219cc..233974435f 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -423,6 +423,14 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
423 flow_state, 423 flow_state,
424 ); 424 );
425 } 425 }
426 StatementKind::ReadForMatch(ref place) => {
427 self.access_place(ContextKind::ReadForMatch.new(location),
428 (place, span),
429 (Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
430 LocalMutationIsAllowed::No,
431 flow_state,
432 );
433 }
426 StatementKind::SetDiscriminant { 434 StatementKind::SetDiscriminant {
427 ref place, 435 ref place,
428 variant_index: _, 436 variant_index: _,
@@ -2090,6 +2098,7 @@ enum ContextKind {
2090 CallDest, 2098 CallDest,
2091 Assert, 2099 Assert,
2092 Yield, 2100 Yield,
2101 ReadForMatch,
2093 StorageDead, 2102 StorageDead,
2094} 2103}
2095 2104
diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs
index 50aa1550fb..46026cdc94 100644
--- a/src/librustc_mir/borrow_check/nll/invalidation.rs
+++ b/src/librustc_mir/borrow_check/nll/invalidation.rs
@@ -93,6 +93,14 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
93 JustWrite 93 JustWrite
94 ); 94 );
95 } 95 }
96 StatementKind::ReadForMatch(ref place) => {
97 self.access_place(
98 ContextKind::ReadForMatch.new(location),
99 place,
100 (Deep, Read(ReadKind::Borrow(BorrowKind::Shared))),
101 LocalMutationIsAllowed::No,
102 );
103 }
96 StatementKind::SetDiscriminant { 104 StatementKind::SetDiscriminant {
97 ref place, 105 ref place,
98 variant_index: _, 106 variant_index: _,
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
index 456aa1aa66..04f5024b76 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs
@@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
836 ); 836 );
837 } 837 }
838 } 838 }
839 StatementKind::StorageLive(_) 839 StatementKind::ReadForMatch(_)
840 | StatementKind::StorageLive(_)
840 | StatementKind::StorageDead(_) 841 | StatementKind::StorageDead(_)
841 | StatementKind::InlineAsm { .. } 842 | StatementKind::InlineAsm { .. }
842 | StatementKind::EndRegion(_) 843 | StatementKind::EndRegion(_)
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs
index 04c62854c5..78886baf51 100644
--- a/src/librustc_mir/dataflow/impls/borrows.rs
+++ b/src/librustc_mir/dataflow/impls/borrows.rs
@@ -227,6 +227,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
227 } 227 }
228 } 228 }
229 229
230 mir::StatementKind::ReadForMatch(..) |
230 mir::StatementKind::SetDiscriminant { .. } | 231 mir::StatementKind::SetDiscriminant { .. } |
231 mir::StatementKind::StorageLive(..) | 232 mir::StatementKind::StorageLive(..) |
232 mir::StatementKind::Validate(..) | 233 mir::StatementKind::Validate(..) |
diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs
index cbf4c82276..2ff2284214 100644
--- a/src/librustc_mir/dataflow/move_paths/builder.rs
+++ b/src/librustc_mir/dataflow/move_paths/builder.rs
@@ -278,6 +278,9 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
278 } 278 }
279 self.gather_rvalue(rval); 279 self.gather_rvalue(rval);
280 } 280 }
281 StatementKind::ReadForMatch(ref place) => {
282 self.create_move_path(place);
283 }
281 StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => { 284 StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {
282 for (output, kind) in outputs.iter().zip(&asm.outputs) { 285 for (output, kind) in outputs.iter().zip(&asm.outputs) {
283 if !kind.is_indirect { 286 if !kind.is_indirect {
diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs
index 554d87a04e..b9edd2c07f 100644
--- a/src/librustc_mir/interpret/step.rs
+++ b/src/librustc_mir/interpret/step.rs
@@ -79,6 +79,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
79 self.deallocate_local(old_val)?; 79 self.deallocate_local(old_val)?;
80 } 80 }
81 81
82 // FIXME: is there some dynamic semantics we should attach to
83 // these? Or am I correct in thinking that the inerpreter
84 // is solely intended for borrowck'ed code?
85 ReadForMatch(..) => {}
86
82 // Validity checks. 87 // Validity checks.
83 Validate(op, ref places) => { 88 Validate(op, ref places) => {
84 for operand in places { 89 for operand in places {
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index fc3764e4f4..4081f827d4 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -100,6 +100,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
100 self.source_info = statement.source_info; 100 self.source_info = statement.source_info;
101 match statement.kind { 101 match statement.kind {
102 StatementKind::Assign(..) | 102 StatementKind::Assign(..) |
103 StatementKind::ReadForMatch(..) |
103 StatementKind::SetDiscriminant { .. } | 104 StatementKind::SetDiscriminant { .. } |
104 StatementKind::StorageLive(..) | 105 StatementKind::StorageLive(..) |
105 StatementKind::StorageDead(..) | 106 StatementKind::StorageDead(..) |
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index c249dc312f..7196301294 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -1135,6 +1135,7 @@ This does not pose a problem by itself because they can't be accessed directly."
1135 StatementKind::Assign(ref place, ref rvalue) => { 1135 StatementKind::Assign(ref place, ref rvalue) => {
1136 this.visit_assign(bb, place, rvalue, location); 1136 this.visit_assign(bb, place, rvalue, location);
1137 } 1137 }
1138 StatementKind::ReadForMatch(..) |
1138 StatementKind::SetDiscriminant { .. } | 1139 StatementKind::SetDiscriminant { .. } |
1139 StatementKind::StorageLive(_) | 1140 StatementKind::StorageLive(_) |
1140 StatementKind::StorageDead(_) | 1141 StatementKind::StorageDead(_) |
diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs
index bcc8fef18f..680b60b972 100644
--- a/src/librustc_mir/transform/remove_noop_landing_pads.rs
+++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs
@@ -47,6 +47,7 @@ impl RemoveNoopLandingPads {
47 { 47 {
48 for stmt in &mir[bb].statements { 48 for stmt in &mir[bb].statements {
49 match stmt.kind { 49 match stmt.kind {
50 StatementKind::ReadForMatch(_) |
50 StatementKind::StorageLive(_) | 51 StatementKind::StorageLive(_) |
51 StatementKind::StorageDead(_) | 52 StatementKind::StorageDead(_) |
52 StatementKind::EndRegion(_) | 53 StatementKind::EndRegion(_) |
diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs
index 8f67b9e7c3..b23f056801 100644
--- a/src/librustc_mir/transform/rustc_peek.rs
+++ b/src/librustc_mir/transform/rustc_peek.rs
@@ -158,6 +158,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
158 mir::StatementKind::Assign(ref place, ref rvalue) => { 158 mir::StatementKind::Assign(ref place, ref rvalue) => {
159 (place, rvalue) 159 (place, rvalue)
160 } 160 }
161 mir::StatementKind::ReadForMatch(_) |
161 mir::StatementKind::StorageLive(_) | 162 mir::StatementKind::StorageLive(_) |
162 mir::StatementKind::StorageDead(_) | 163 mir::StatementKind::StorageDead(_) |
163 mir::StatementKind::InlineAsm { .. } | 164 mir::StatementKind::InlineAsm { .. } |
diff --git a/src/librustc_passes/mir_stats.rs b/src/librustc_passes/mir_stats.rs
index 45c6e89321..f7c8f8f43f 100644
--- a/src/librustc_passes/mir_stats.rs
+++ b/src/librustc_passes/mir_stats.rs
@@ -85,6 +85,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
85 self.record("Statement", statement); 85 self.record("Statement", statement);
86 self.record(match statement.kind { 86 self.record(match statement.kind {
87 StatementKind::Assign(..) => "StatementKind::Assign", 87 StatementKind::Assign(..) => "StatementKind::Assign",
88 StatementKind::ReadForMatch(..) => "StatementKind::ReadForMatch",
88 StatementKind::EndRegion(..) => "StatementKind::EndRegion", 89 StatementKind::EndRegion(..) => "StatementKind::EndRegion",
89 StatementKind::Validate(..) => "StatementKind::Validate", 90 StatementKind::Validate(..) => "StatementKind::Validate",
90 StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant", 91 StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant",