From 2dab9c81d1858a48b9d6444220ead7f48acecf66 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 23 Apr 2021 11:22:32 +0200 Subject: [PATCH] use invoke --- compiler/mono/src/inc_dec.rs | 12 ++++++++++-- compiler/mono/src/ir.rs | 16 ++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/compiler/mono/src/inc_dec.rs b/compiler/mono/src/inc_dec.rs index e3d7b86226..89405474a1 100644 --- a/compiler/mono/src/inc_dec.rs +++ b/compiler/mono/src/inc_dec.rs @@ -728,7 +728,13 @@ impl<'a> Context<'a> { // the result of an invoke should not be touched in the fail branch // but it should be present in the pass branch (otherwise it would be dead) - debug_assert!(case_live_vars.contains(symbol)); + // NOTE: we cheat a bit here to allow `invoke` when generating code for `expect` + let is_dead = !case_live_vars.contains(symbol); + + if is_dead && layout.is_refcounted() { + panic!("A variable of a reference-counted layout is dead; that's a bug!"); + } + case_live_vars.remove(symbol); let fail = { @@ -738,7 +744,9 @@ impl<'a> Context<'a> { ctx.add_dec_for_alt(&case_live_vars, &alt_live_vars, b) }; - case_live_vars.insert(*symbol); + if !is_dead { + case_live_vars.insert(*symbol); + } let pass = { // TODO should we use ctor info like Lean? diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 7a945e6953..a04da8c89d 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -3260,7 +3260,7 @@ pub fn with_hole<'a>( EmptyRecord => Stmt::Let(assigned, Expr::Struct(&[]), Layout::Struct(&[]), hole), - Expect(_, rest) => todo!(), + Expect(_, _) => unreachable!("I think this is unreachable"), If { cond_var, @@ -4307,14 +4307,14 @@ pub fn from_can<'a>( call_type, arguments, }; - let test = Expr::Call(call); - let rest = Stmt::Let( - env.unique_symbol(), - test, - bool_layout, - env.arena.alloc(rest), - ); + let rest = Stmt::Invoke { + symbol: env.unique_symbol(), + call, + layout: bool_layout, + pass: env.arena.alloc(rest), + fail: env.arena.alloc(Stmt::Rethrow), + }; with_hole( env,