diff --git a/compiler/gen/src/llvm/build.rs b/compiler/gen/src/llvm/build.rs index d1bd40ee29..20fc3d5ec0 100644 --- a/compiler/gen/src/llvm/build.rs +++ b/compiler/gen/src/llvm/build.rs @@ -1366,6 +1366,13 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>( value } + Unreachable => { + // used in exception handling + env.builder.build_unreachable(); + + env.context.i64_type().const_zero().into() + } + Switch { branches, default_branch, diff --git a/compiler/gen_dev/src/lib.rs b/compiler/gen_dev/src/lib.rs index 967cec574a..82958feb84 100644 --- a/compiler/gen_dev/src/lib.rs +++ b/compiler/gen_dev/src/lib.rs @@ -335,6 +335,7 @@ where Stmt::Ret(sym) => { self.set_last_seen(*sym, stmt); } + Stmt::Unreachable => {} Stmt::Inc(sym, following) => { self.set_last_seen(*sym, stmt); self.scan_ast(following); diff --git a/compiler/mono/src/borrow.rs b/compiler/mono/src/borrow.rs index ea6c9cfede..651877097e 100644 --- a/compiler/mono/src/borrow.rs +++ b/compiler/mono/src/borrow.rs @@ -166,7 +166,7 @@ impl<'a> ParamMap<'a> { } Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"), - Ret(_) | Jump(_, _) | RuntimeError(_) => { + Ret(_) | Unreachable | Jump(_, _) | RuntimeError(_) => { // these are terminal, do nothing } } @@ -470,7 +470,7 @@ impl<'a> BorrowInfState<'a> { } Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"), - Ret(_) | RuntimeError(_) => { + Ret(_) | RuntimeError(_) | Unreachable => { // these are terminal, do nothing } } diff --git a/compiler/mono/src/inc_dec.rs b/compiler/mono/src/inc_dec.rs index 12d989e4e8..15ecda7e82 100644 --- a/compiler/mono/src/inc_dec.rs +++ b/compiler/mono/src/inc_dec.rs @@ -35,6 +35,8 @@ pub fn occuring_variables(stmt: &Stmt<'_>) -> (MutSet, MutSet) { result.insert(*symbol); } + Unreachable => {} + Inc(symbol, cont) | Dec(symbol, cont) => { result.insert(*symbol); stack.push(cont); @@ -673,6 +675,8 @@ impl<'a> Context<'a> { } } + Unreachable => (stmt, MutSet::default()), + Jump(j, xs) => { let empty = MutSet::default(); let j_live_vars = match self.jp_live_vars.get(j) { @@ -813,6 +817,8 @@ pub fn collect_stmt( vars } + Unreachable => vars, + RuntimeError(_) => vars, } } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index de3d9398ee..89150ac3b9 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -754,6 +754,7 @@ pub enum Stmt<'a> { ret_layout: Layout<'a>, }, Ret(Symbol), + Unreachable, Inc(Symbol, &'a Stmt<'a>), Dec(Symbol, &'a Stmt<'a>), Join { @@ -1103,6 +1104,8 @@ impl<'a> Stmt<'a> { .append(symbol_to_doc(alloc, *symbol)) .append(";"), + Unreachable => alloc.text("unreachable;"), + Switch { cond_symbol, branches, @@ -4436,6 +4439,8 @@ fn substitute_in_stmt_help<'a>( } } + Unreachable => None, + RuntimeError(_) => None, } } diff --git a/compiler/mono/src/tail_recursion.rs b/compiler/mono/src/tail_recursion.rs index 193624d4a6..36be4b0835 100644 --- a/compiler/mono/src/tail_recursion.rs +++ b/compiler/mono/src/tail_recursion.rs @@ -187,6 +187,7 @@ fn insert_jumps<'a>( None => None, }, + Unreachable => None, Ret(_) => None, Jump(_, _) => None, RuntimeError(_) => None,