From 5361b0e0df8863637361bec19a241f9c004d5db4 Mon Sep 17 00:00:00 2001 From: StunxFS Date: Wed, 29 Nov 2023 21:39:35 -0400 Subject: [PATCH] refact(rivetc.codegen): use `runtime_error` to attempt to access a `none` value --- lib/core/src/lib.ri | 16 ++++------------ rivetc/src/codegen/__init__.py | 10 +--------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/core/src/lib.ri b/lib/core/src/lib.ri index 8106a8883..a3b5b54e3 100644 --- a/lib/core/src/lib.ri +++ b/lib/core/src/lib.ri @@ -21,35 +21,27 @@ func runtime_error(s: string, args: ...Stringable) -> never { #[inline] func internal_alloc(size: uint) -> rawptr { return mem_alloc(size) catch { - runtime_error( - "internal error: cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif - ) + runtime_error("cannot allocate memory" #if _DEBUG_ " (size: {})", size #endif) }; } #[inline] func internal_zeroed(size: uint) -> rawptr { return mem_zeroed(size) catch { - runtime_error( - "internal error: cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif - ) + runtime_error("cannot allocate zeroed memory" #if _DEBUG_ " (size: {})", size #endif) }; } #[inline] func internal_dup(src: rawptr, sz: uint) -> rawptr { return mem_dup(src, sz) catch { - runtime_error( - "internal error: cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif - ) + runtime_error("cannot duplicate memory" #if _DEBUG_ " (size: {})", sz #endif) }; } #[inline] func internal_resize(ptr: ?rawptr, sz: uint) -> rawptr { return mem_resize(ptr, sz) catch { - runtime_error( - "internal error: cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif - ) + runtime_error("cannot resize memory" #if _DEBUG_ " (size: {})", sz #endif) }; } diff --git a/rivetc/src/codegen/__init__.py b/rivetc/src/codegen/__init__.py index 1ff0e3453..7bdc46360 100644 --- a/rivetc/src/codegen/__init__.py +++ b/rivetc/src/codegen/__init__.py @@ -1594,7 +1594,7 @@ def gen_expr(self, expr, custom_tmp = None): ) value = ir.Selector(ir_typ, left, ir.Name("value")) self.cur_fn.add_label(panic_l) - self.panic(f"attempt to use none value (`{expr.left}`)") + self.runtime_error(f"attempt to use none value (`{expr.left}`)") self.cur_fn.add_label(exit_l) return value elif isinstance(left, ir.StringLit): @@ -2628,14 +2628,6 @@ def runtime_error(self, msg): ] ) - def panic(self, msg): - self.cur_fn.add_call( - "_R4core13process_panicF", [ - self.gen_string_literal(utils.smart_quote(msg, False)), - self.empty_vec(self.comp.universe["[]core.Stringable"]) - ] - ) - def variadic_args(self, vargs, var_arg_typ_): if len(vargs) == 0: return self.empty_vec(var_arg_typ_.typ.symbol())