Skip to content

Commit

Permalink
Implement liveness passes for if-let guards
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Dec 6, 2020
1 parent f9cc626 commit cfaaa21
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions compiler/rustc_passes/src/liveness.rs
Expand Up @@ -358,6 +358,9 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {

fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) {
self.add_from_pat(&arm.pat);
if let Some(hir::Guard::IfLet(ref pat, _)) = arm.guard {
self.add_from_pat(pat);
}
intravisit::walk_arm(self, arm);
}

Expand Down Expand Up @@ -1029,10 +1032,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
for arm in arms {
let body_succ = self.propagate_through_expr(&arm.body, succ);

let guard_succ = self.propagate_through_opt_expr(
arm.guard.as_ref().map(|hir::Guard::If(e)| *e),
body_succ,
);
let guard_succ = arm.guard.as_ref().map_or(body_succ, |g| match g {
hir::Guard::If(e) => self.propagate_through_expr(e, body_succ),
hir::Guard::IfLet(pat, e) => {
let let_bind = self.define_bindings_in_pat(pat, body_succ);
self.propagate_through_expr(e, let_bind)
}
});
let arm_succ = self.define_bindings_in_pat(&arm.pat, guard_succ);
self.merge_from_succ(ln, arm_succ, first_merge);
first_merge = false;
Expand Down

0 comments on commit cfaaa21

Please sign in to comment.