Skip to content

Commit ff12d78

Browse files
Switch TerminatorKind::Call to StatementKind.
1 parent 49b486b commit ff12d78

25 files changed

+655
-620
lines changed

src/librustc/mir/mod.rs

+63-63
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,6 @@ pub enum TerminatorKind<'tcx> {
515515
target: Block,
516516
unwind: Option<Block>,
517517
},
518-
519-
/// Block ends with a call of a converging function
520-
Call {
521-
/// The function that’s being called
522-
func: Operand<'tcx>,
523-
/// Arguments the function is called with
524-
args: Vec<Operand<'tcx>>,
525-
/// Destination for the return value. If some, the call is converging.
526-
destination: Option<(Lvalue<'tcx>, Block)>,
527-
/// Cleanups to be done if the call unwinds.
528-
cleanup: Option<Block>
529-
},
530518
}
531519

532520
impl<'tcx> Terminator<'tcx> {
@@ -559,11 +547,6 @@ impl<'tcx> TerminatorKind<'tcx> {
559547
Resume => (&[]).into_cow(),
560548
Return => (&[]).into_cow(),
561549
Unreachable => (&[]).into_cow(),
562-
Call { destination: Some((_, t)), cleanup: Some(c), .. } => vec![t, c].into_cow(),
563-
Call { destination: Some((_, ref t)), cleanup: None, .. } =>
564-
slice::ref_slice(t).into_cow(),
565-
Call { destination: None, cleanup: Some(ref c), .. } => slice::ref_slice(c).into_cow(),
566-
Call { destination: None, cleanup: None, .. } => (&[]).into_cow(),
567550
DropAndReplace { target, unwind: Some(unwind), .. } |
568551
Drop { target, unwind: Some(unwind), .. } => {
569552
vec![target, unwind].into_cow()
@@ -585,10 +568,6 @@ impl<'tcx> TerminatorKind<'tcx> {
585568
Resume => Vec::new(),
586569
Return => Vec::new(),
587570
Unreachable => Vec::new(),
588-
Call { destination: Some((_, ref mut t)), cleanup: Some(ref mut c), .. } => vec![t, c],
589-
Call { destination: Some((_, ref mut t)), cleanup: None, .. } => vec![t],
590-
Call { destination: None, cleanup: Some(ref mut c), .. } => vec![c],
591-
Call { destination: None, cleanup: None, .. } => vec![],
592571
DropAndReplace { ref mut target, unwind: Some(ref mut unwind), .. } |
593572
Drop { ref mut target, unwind: Some(ref mut unwind), .. } => vec![target, unwind],
594573
DropAndReplace { ref mut target, unwind: None, .. } |
@@ -663,19 +642,6 @@ impl<'tcx> TerminatorKind<'tcx> {
663642
Drop { ref location, .. } => write!(fmt, "drop({:?})", location),
664643
DropAndReplace { ref location, ref value, .. } =>
665644
write!(fmt, "replace({:?} <- {:?})", location, value),
666-
Call { ref func, ref args, ref destination, .. } => {
667-
if let Some((ref destination, _)) = *destination {
668-
write!(fmt, "{:?} = ", destination)?;
669-
}
670-
write!(fmt, "{:?}(", func)?;
671-
for (index, arg) in args.iter().enumerate() {
672-
if index > 0 {
673-
write!(fmt, ", ")?;
674-
}
675-
write!(fmt, "{:?}", arg)?;
676-
}
677-
write!(fmt, ")")
678-
}
679645
}
680646
}
681647

@@ -695,11 +661,6 @@ impl<'tcx> TerminatorKind<'tcx> {
695661
.chain(iter::once(String::from("otherwise").into()))
696662
.collect()
697663
}
698-
Call { destination: Some(_), cleanup: Some(_), .. } =>
699-
vec!["return".into_cow(), "unwind".into_cow()],
700-
Call { destination: Some(_), cleanup: None, .. } => vec!["return".into_cow()],
701-
Call { destination: None, cleanup: Some(_), .. } => vec!["unwind".into_cow()],
702-
Call { destination: None, cleanup: None, .. } => vec![],
703664
DropAndReplace { unwind: None, .. } |
704665
Drop { unwind: None, .. } => vec!["return".into_cow()],
705666
DropAndReplace { unwind: Some(_), .. } |
@@ -737,19 +698,39 @@ impl<'tcx> Statement<'tcx> {
737698

738699
pub fn cleanup_target(&self) -> Option<Block> {
739700
match self.kind {
740-
StatementKind::Assert { cleanup: Some(unwind), .. } => {
741-
Some(unwind)
701+
StatementKind::Assign(..) |
702+
StatementKind::SetDiscriminant { .. } |
703+
StatementKind::StorageLive(..) |
704+
StatementKind::StorageDead(..) |
705+
StatementKind::InlineAsm { .. } |
706+
StatementKind::Nop => None,
707+
StatementKind::Assert { cleanup: unwind, .. } |
708+
StatementKind::Call { cleanup: unwind, .. } => {
709+
if let Some(unwind) = unwind {
710+
Some(unwind)
711+
} else {
712+
None
713+
}
742714
}
743-
_ => None
744715
}
745716
}
746717

747718
pub fn cleanup_target_mut(&mut self) -> Option<&mut Block> {
748719
match self.kind {
749-
StatementKind::Assert { cleanup: Some(ref mut unwind), .. } => {
750-
Some(unwind)
720+
StatementKind::Assign(..) |
721+
StatementKind::SetDiscriminant { .. } |
722+
StatementKind::StorageLive(..) |
723+
StatementKind::StorageDead(..) |
724+
StatementKind::InlineAsm { .. } |
725+
StatementKind::Nop => None,
726+
StatementKind::Assert { cleanup: ref mut unwind, .. } |
727+
StatementKind::Call { cleanup: ref mut unwind, .. } => {
728+
if let Some(ref mut unwind) = *unwind {
729+
Some(unwind)
730+
} else {
731+
None
732+
}
751733
}
752-
_ => None
753734
}
754735
}
755736
}
@@ -783,6 +764,18 @@ pub enum StatementKind<'tcx> {
783764
cleanup: Option<Block>
784765
},
785766

767+
/// Block ends with a call of a converging function
768+
Call {
769+
/// The function that’s being called
770+
func: Operand<'tcx>,
771+
/// Arguments the function is called with
772+
args: Vec<Operand<'tcx>>,
773+
/// Destination for the return value.
774+
destination: Lvalue<'tcx>,
775+
/// Cleanups to be done if the call unwinds.
776+
cleanup: Option<Block>
777+
},
778+
786779
/// No-op. Useful for deleting instructions without affecting statement indices.
787780
Nop,
788781
}
@@ -820,6 +813,17 @@ impl<'tcx> Debug for Statement<'tcx> {
820813

821814
write!(fmt, ")")
822815
},
816+
Call { ref func, ref args, ref destination, .. } => {
817+
write!(fmt, "{:?} = ", destination)?;
818+
write!(fmt, "{:?}(", func)?;
819+
for (index, arg) in args.iter().enumerate() {
820+
if index > 0 {
821+
write!(fmt, ", ")?;
822+
}
823+
write!(fmt, "{:?}", arg)?;
824+
}
825+
write!(fmt, ")")
826+
},
823827
Nop => write!(fmt, "nop"),
824828
}
825829
}
@@ -1459,6 +1463,16 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
14591463
cleanup: cleanup
14601464
}
14611465
},
1466+
Call { ref func, ref args, ref destination, cleanup } => {
1467+
let dest = destination.fold_with(folder);
1468+
1469+
Call {
1470+
func: func.fold_with(folder),
1471+
args: args.fold_with(folder),
1472+
destination: dest,
1473+
cleanup: cleanup
1474+
}
1475+
},
14621476
Nop => Nop,
14631477
};
14641478
Statement {
@@ -1488,6 +1502,10 @@ impl<'tcx> TypeFoldable<'tcx> for Statement<'tcx> {
14881502
false
14891503
}
14901504
},
1505+
Call { ref func, ref args, ref destination, .. } => {
1506+
destination.visit_with(visitor) || func.visit_with(visitor) ||
1507+
args.visit_with(visitor)
1508+
},
14911509
Nop => false,
14921510
}
14931511
}
@@ -1516,18 +1534,6 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
15161534
target: target,
15171535
unwind: unwind
15181536
},
1519-
Call { ref func, ref args, ref destination, cleanup } => {
1520-
let dest = destination.as_ref().map(|&(ref loc, dest)| {
1521-
(loc.fold_with(folder), dest)
1522-
});
1523-
1524-
Call {
1525-
func: func.fold_with(folder),
1526-
args: args.fold_with(folder),
1527-
destination: dest,
1528-
cleanup: cleanup
1529-
}
1530-
},
15311537
Resume => Resume,
15321538
Return => Return,
15331539
Unreachable => Unreachable,
@@ -1547,12 +1553,6 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
15471553
Drop { ref location, ..} => location.visit_with(visitor),
15481554
DropAndReplace { ref location, ref value, ..} =>
15491555
location.visit_with(visitor) || value.visit_with(visitor),
1550-
Call { ref func, ref args, ref destination, .. } => {
1551-
let dest = if let Some((ref loc, _)) = *destination {
1552-
loc.visit_with(visitor)
1553-
} else { false };
1554-
dest || func.visit_with(visitor) || args.visit_with(visitor)
1555-
},
15561556
Goto { .. } |
15571557
Resume |
15581558
Return |

src/librustc/mir/visit.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,17 @@ macro_rules! make_mir_visitor {
352352
self.visit_assert_message(msg, location);
353353
cleanup.map(|t| self.visit_branch(block, t));
354354
}
355+
StatementKind::Call { ref $($mutability)* func,
356+
ref $($mutability)* args,
357+
ref $($mutability)* destination,
358+
cleanup } => {
359+
self.visit_operand(func, location);
360+
for arg in args {
361+
self.visit_operand(arg, location);
362+
}
363+
self.visit_lvalue(destination, LvalueContext::Call, location);
364+
cleanup.map(|t| self.visit_branch(block, t));
365+
}
355366
StatementKind::Nop => {}
356367
}
357368
}
@@ -423,21 +434,6 @@ macro_rules! make_mir_visitor {
423434
self.visit_branch(block, target);
424435
unwind.map(|t| self.visit_branch(block, t));
425436
}
426-
427-
TerminatorKind::Call { ref $($mutability)* func,
428-
ref $($mutability)* args,
429-
ref $($mutability)* destination,
430-
cleanup } => {
431-
self.visit_operand(func, source_location);
432-
for arg in args {
433-
self.visit_operand(arg, source_location);
434-
}
435-
if let Some((ref $($mutability)* destination, target)) = *destination {
436-
self.visit_lvalue(destination, LvalueContext::Call, source_location);
437-
self.visit_branch(block, target);
438-
}
439-
cleanup.map(|t| self.visit_branch(block, t));
440-
}
441437
}
442438
}
443439

src/librustc_borrowck/borrowck/mir/dataflow/impls.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
300300
fn propagate_call_return(&self,
301301
in_out: &mut IdxSet<MovePathIndex>,
302302
_call_bb: mir::Block,
303-
_dest_bb: mir::Block,
304303
dest_lval: &mir::Lvalue) {
305304
// when a call returns successfully, that means we need to set
306305
// the bits for that dest_lval to 1 (initialized).
@@ -357,7 +356,6 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
357356
fn propagate_call_return(&self,
358357
in_out: &mut IdxSet<MovePathIndex>,
359358
_call_bb: mir::Block,
360-
_dest_bb: mir::Block,
361359
dest_lval: &mir::Lvalue) {
362360
// when a call returns successfully, that means we need to set
363361
// the bits for that dest_lval to 0 (initialized).
@@ -413,7 +411,6 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
413411
fn propagate_call_return(&self,
414412
in_out: &mut IdxSet<MovePathIndex>,
415413
_call_bb: mir::Block,
416-
_dest_bb: mir::Block,
417414
dest_lval: &mir::Lvalue) {
418415
// when a call returns successfully, that means we need to set
419416
// the bits for that dest_lval to 1 (initialized).
@@ -475,6 +472,7 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
475472
mir::StatementKind::StorageDead(_) |
476473
mir::StatementKind::InlineAsm { .. } |
477474
mir::StatementKind::Assert { .. } |
475+
mir::StatementKind::Call { .. } |
478476
mir::StatementKind::Nop => {}
479477
}
480478
}
@@ -500,7 +498,6 @@ impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
500498
fn propagate_call_return(&self,
501499
in_out: &mut IdxSet<MoveOutIndex>,
502500
_call_bb: mir::Block,
503-
_dest_bb: mir::Block,
504501
dest_lval: &mir::Lvalue) {
505502
let move_data = self.move_data();
506503
let bits_per_block = self.bits_per_block();

src/librustc_borrowck/borrowck/mir/dataflow/mod.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ pub trait BitDenotation {
368368
fn propagate_call_return(&self,
369369
in_out: &mut IdxSet<Self::Idx>,
370370
call_bb: mir::Block,
371-
dest_bb: mir::Block,
372371
dest_lval: &mir::Lvalue);
373372
}
374373

@@ -457,16 +456,24 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
457456
self.propagate_bits_into_entry_set_for(in_out, changed, target);
458457
}
459458
}
460-
mir::TerminatorKind::Call { ref cleanup, ref destination, func: _, args: _ } => {
461-
if let Some(ref unwind) = *cleanup {
462-
self.propagate_bits_into_entry_set_for(in_out, changed, unwind);
463-
}
464-
if let Some((ref dest_lval, ref dest_bb)) = *destination {
459+
}
460+
461+
for stmt in bb_data.statements.iter() {
462+
match stmt.kind {
463+
mir::StatementKind::Assign(..) |
464+
mir::StatementKind::SetDiscriminant { .. } |
465+
mir::StatementKind::StorageLive(..) |
466+
mir::StatementKind::StorageDead(..) |
467+
mir::StatementKind::InlineAsm { .. } |
468+
mir::StatementKind::Assert { .. } |
469+
mir::StatementKind::Nop => {},
470+
mir::StatementKind::Call { ref cleanup, ref destination, func: _, args: _ } => {
471+
if let Some(ref unwind) = *cleanup {
472+
self.propagate_bits_into_entry_set_for(in_out, changed, unwind);
473+
}
465474
// N.B.: This must be done *last*, after all other
466475
// propagation, as documented in comment above.
467-
self.flow_state.operator.propagate_call_return(
468-
in_out, bb, *dest_bb, dest_lval);
469-
self.propagate_bits_into_entry_set_for(in_out, changed, dest_bb);
476+
self.flow_state.operator.propagate_call_return(in_out, bb, destination);
470477
}
471478
}
472479
}

0 commit comments

Comments
 (0)