Skip to content

Commit 24abe6f

Browse files
committed
rust-lang#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.)
1 parent 47bb3fd commit 24abe6f

File tree

15 files changed

+48
-1
lines changed

15 files changed

+48
-1
lines changed

src/librustc/ich/impls_mir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ for mir::StatementKind<'gcx> {
241241
place.hash_stable(hcx, hasher);
242242
rvalue.hash_stable(hcx, hasher);
243243
}
244+
mir::StatementKind::ReadForMatch(ref place) => {
245+
place.hash_stable(hcx, hasher);
246+
}
244247
mir::StatementKind::SetDiscriminant { ref place, variant_index } => {
245248
place.hash_stable(hcx, hasher);
246249
variant_index.hash_stable(hcx, hasher);

src/librustc/mir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,10 @@ pub enum StatementKind<'tcx> {
12251225
/// Write the RHS Rvalue to the LHS Place.
12261226
Assign(Place<'tcx>, Rvalue<'tcx>),
12271227

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+
12281232
/// Write the discriminant for a variant to the enum Place.
12291233
SetDiscriminant { place: Place<'tcx>, variant_index: usize },
12301234

@@ -1327,6 +1331,7 @@ impl<'tcx> Debug for Statement<'tcx> {
13271331
use self::StatementKind::*;
13281332
match self.kind {
13291333
Assign(ref place, ref rv) => write!(fmt, "{:?} = {:?}", place, rv),
1334+
ReadForMatch(ref place) => write!(fmt, "ReadForMatch({:?})", place),
13301335
// (reuse lifetime rendering policy from ppaux.)
13311336
EndRegion(ref ce) => write!(fmt, "EndRegion({})", ty::ReScope(*ce)),
13321337
Validate(ref op, ref places) => write!(fmt, "Validate({:?}, {:?})", op, places),
@@ -2212,6 +2217,7 @@ BraceStructTypeFoldableImpl! {
22122217
EnumTypeFoldableImpl! {
22132218
impl<'tcx> TypeFoldable<'tcx> for StatementKind<'tcx> {
22142219
(StatementKind::Assign)(a, b),
2220+
(StatementKind::ReadForMatch)(place),
22152221
(StatementKind::SetDiscriminant) { place, variant_index },
22162222
(StatementKind::StorageLive)(a),
22172223
(StatementKind::StorageDead)(a),

src/librustc/mir/visit.rs

+5
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ macro_rules! make_mir_visitor {
355355
ref $($mutability)* rvalue) => {
356356
self.visit_assign(block, place, rvalue, location);
357357
}
358+
StatementKind::ReadForMatch(ref $($mutability)* place) => {
359+
self.visit_place(place,
360+
PlaceContext::Inspect,
361+
location);
362+
}
358363
StatementKind::EndRegion(_) => {}
359364
StatementKind::Validate(_, ref $($mutability)* places) => {
360365
for operand in places {

src/librustc_codegen_llvm/mir/statement.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
8282
asm::codegen_inline_asm(&bx, asm, outputs, input_vals);
8383
bx
8484
}
85+
mir::StatementKind::ReadForMatch(_) |
8586
mir::StatementKind::EndRegion(_) |
8687
mir::StatementKind::Validate(..) |
8788
mir::StatementKind::UserAssertTy(..) |

src/librustc_mir/borrow_check/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
423423
flow_state,
424424
);
425425
}
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+
}
426434
StatementKind::SetDiscriminant {
427435
ref place,
428436
variant_index: _,
@@ -2090,6 +2098,7 @@ enum ContextKind {
20902098
CallDest,
20912099
Assert,
20922100
Yield,
2101+
ReadForMatch,
20932102
StorageDead,
20942103
}
20952104

src/librustc_mir/borrow_check/nll/invalidation.rs

+8
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ impl<'cg, 'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cg, 'cx, 'tc
9393
JustWrite
9494
);
9595
}
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+
}
96104
StatementKind::SetDiscriminant {
97105
ref place,
98106
variant_index: _,

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
836836
);
837837
}
838838
}
839-
StatementKind::StorageLive(_)
839+
StatementKind::ReadForMatch(_)
840+
| StatementKind::StorageLive(_)
840841
| StatementKind::StorageDead(_)
841842
| StatementKind::InlineAsm { .. }
842843
| StatementKind::EndRegion(_)

src/librustc_mir/dataflow/impls/borrows.rs

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
227227
}
228228
}
229229

230+
mir::StatementKind::ReadForMatch(..) |
230231
mir::StatementKind::SetDiscriminant { .. } |
231232
mir::StatementKind::StorageLive(..) |
232233
mir::StatementKind::Validate(..) |

src/librustc_mir/dataflow/move_paths/builder.rs

+3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
278278
}
279279
self.gather_rvalue(rval);
280280
}
281+
StatementKind::ReadForMatch(ref place) => {
282+
self.create_move_path(place);
283+
}
281284
StatementKind::InlineAsm { ref outputs, ref inputs, ref asm } => {
282285
for (output, kind) in outputs.iter().zip(&asm.outputs) {
283286
if !kind.is_indirect {

src/librustc_mir/interpret/step.rs

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
7979
self.deallocate_local(old_val)?;
8080
}
8181

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+
8287
// Validity checks.
8388
Validate(op, ref places) => {
8489
for operand in places {

src/librustc_mir/transform/check_unsafety.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
100100
self.source_info = statement.source_info;
101101
match statement.kind {
102102
StatementKind::Assign(..) |
103+
StatementKind::ReadForMatch(..) |
103104
StatementKind::SetDiscriminant { .. } |
104105
StatementKind::StorageLive(..) |
105106
StatementKind::StorageDead(..) |

src/librustc_mir/transform/qualify_consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ This does not pose a problem by itself because they can't be accessed directly."
11351135
StatementKind::Assign(ref place, ref rvalue) => {
11361136
this.visit_assign(bb, place, rvalue, location);
11371137
}
1138+
StatementKind::ReadForMatch(..) |
11381139
StatementKind::SetDiscriminant { .. } |
11391140
StatementKind::StorageLive(_) |
11401141
StatementKind::StorageDead(_) |

src/librustc_mir/transform/remove_noop_landing_pads.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl RemoveNoopLandingPads {
4747
{
4848
for stmt in &mir[bb].statements {
4949
match stmt.kind {
50+
StatementKind::ReadForMatch(_) |
5051
StatementKind::StorageLive(_) |
5152
StatementKind::StorageDead(_) |
5253
StatementKind::EndRegion(_) |

src/librustc_mir/transform/rustc_peek.rs

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
158158
mir::StatementKind::Assign(ref place, ref rvalue) => {
159159
(place, rvalue)
160160
}
161+
mir::StatementKind::ReadForMatch(_) |
161162
mir::StatementKind::StorageLive(_) |
162163
mir::StatementKind::StorageDead(_) |
163164
mir::StatementKind::InlineAsm { .. } |

src/librustc_passes/mir_stats.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl<'a, 'tcx> mir_visit::Visitor<'tcx> for StatCollector<'a, 'tcx> {
8585
self.record("Statement", statement);
8686
self.record(match statement.kind {
8787
StatementKind::Assign(..) => "StatementKind::Assign",
88+
StatementKind::ReadForMatch(..) => "StatementKind::ReadForMatch",
8889
StatementKind::EndRegion(..) => "StatementKind::EndRegion",
8990
StatementKind::Validate(..) => "StatementKind::Validate",
9091
StatementKind::SetDiscriminant { .. } => "StatementKind::SetDiscriminant",

0 commit comments

Comments
 (0)