Skip to content

Commit f2c1468

Browse files
Add resume arg place to Yield MIR terminator
1 parent 2101a1f commit f2c1468

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

src/librustc/mir/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ pub enum TerminatorKind<'tcx> {
11201120
value: Operand<'tcx>,
11211121
/// Where to resume to.
11221122
resume: BasicBlock,
1123+
/// The place to store the resume argument in.
1124+
resume_arg: Place<'tcx>,
11231125
/// Cleanup to be done if the generator is dropped at this suspend point.
11241126
drop: Option<BasicBlock>,
11251127
},
@@ -2645,9 +2647,12 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
26452647
target,
26462648
unwind,
26472649
},
2648-
Yield { ref value, resume, drop } => {
2649-
Yield { value: value.fold_with(folder), resume: resume, drop: drop }
2650-
}
2650+
Yield { ref value, resume, ref resume_arg, drop } => Yield {
2651+
value: value.fold_with(folder),
2652+
resume,
2653+
resume_arg: resume_arg.fold_with(folder),
2654+
drop,
2655+
},
26512656
Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
26522657
let dest =
26532658
destination.as_ref().map(|&(ref loc, dest)| (loc.fold_with(folder), dest));

src/librustc/mir/visit.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,14 @@ macro_rules! make_mir_visitor {
516516
TerminatorKind::Yield {
517517
value,
518518
resume: _,
519+
resume_arg,
519520
drop: _,
520521
} => {
522+
self.visit_place(
523+
resume_arg,
524+
PlaceContext::MutatingUse(MutatingUseContext::Store),
525+
source_location,
526+
);
521527
self.visit_operand(value, source_location);
522528
}
523529

src/librustc_mir/borrow_check/invalidation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
159159
self.consume_operand(location, index);
160160
}
161161
}
162-
TerminatorKind::Yield { ref value, resume, drop: _ } => {
162+
TerminatorKind::Yield { ref value, resume, resume_arg, drop: _ } => {
163163
self.consume_operand(location, value);
164164

165165
// Invalidate all borrows of local places
@@ -170,6 +170,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
170170
self.all_facts.invalidates.push((resume, i));
171171
}
172172
}
173+
174+
self.mutate_place(location, resume_arg, Deep, JustWrite);
173175
}
174176
TerminatorKind::Resume | TerminatorKind::Return | TerminatorKind::GeneratorDrop => {
175177
// Invalidate all borrows of local places

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
684684
}
685685
}
686686

687-
TerminatorKind::Yield { ref value, resume: _, drop: _ } => {
687+
TerminatorKind::Yield { ref value, resume: _, ref resume_arg, drop: _ } => {
688688
self.consume_operand(loc, (value, span), flow_state);
689689

690690
if self.movable_generator {
@@ -697,6 +697,8 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
697697
}
698698
});
699699
}
700+
701+
self.mutate_place(loc, (resume_arg, span), Deep, JustWrite, flow_state);
700702
}
701703

702704
TerminatorKind::Resume | TerminatorKind::Return | TerminatorKind::GeneratorDrop => {

src/librustc_mir/borrow_check/universal_regions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
581581

582582
DefiningTy::Generator(def_id, substs, movability) => {
583583
assert_eq!(self.mir_def_id, def_id);
584+
let resume_ty = substs.as_generator().resume_ty(def_id, tcx);
584585
let output = substs.as_generator().return_ty(def_id, tcx);
585586
let generator_ty = tcx.mk_generator(def_id, substs, movability);
586-
let inputs_and_output = self.infcx.tcx.intern_type_list(&[generator_ty, output]);
587+
let inputs_and_output =
588+
self.infcx.tcx.intern_type_list(&[generator_ty, resume_ty, output]);
587589
ty::Binder::dummy(inputs_and_output)
588590
}
589591

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
380380
self.gather_operand(discr);
381381
}
382382

383-
TerminatorKind::Yield { ref value, .. } => {
383+
TerminatorKind::Yield { ref value, resume_arg: ref place, .. } => {
384+
self.create_move_path(place);
385+
self.gather_init(place.as_ref(), InitKind::Deep);
384386
self.gather_operand(value);
385387
}
386388

0 commit comments

Comments
 (0)