Skip to content

Commit

Permalink
make zig roc_panic return type be noreturn and remove some `unrea…
Browse files Browse the repository at this point in the history
…chable` calls
  • Loading branch information
JRMurr committed Nov 28, 2023
1 parent 2a762f1 commit a5180be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
12 changes: 1 addition & 11 deletions crates/compiler/builtins/bitcode/src/dec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ pub const RocDec = extern struct {

if (answer.has_overflowed) {
roc_panic("Decimal addition overflowed!", 0);
unreachable;
} else {
return answer.value;
}
Expand Down Expand Up @@ -283,7 +282,6 @@ pub const RocDec = extern struct {

if (answer.has_overflowed) {
roc_panic("Decimal subtraction overflowed!", 0);
unreachable;
} else {
return answer.value;
}
Expand Down Expand Up @@ -347,7 +345,6 @@ pub const RocDec = extern struct {

if (answer.has_overflowed) {
roc_panic("Decimal multiplication overflowed!", 0);
unreachable;
} else {
return answer.value;
}
Expand Down Expand Up @@ -398,7 +395,6 @@ pub const RocDec = extern struct {
return self;
} else {
roc_panic("Decimal division overflow in numerator!", 0);
unreachable;
}
};
const numerator_u128 = @as(u128, @intCast(numerator_abs_i128));
Expand All @@ -412,7 +408,6 @@ pub const RocDec = extern struct {
return other;
} else {
roc_panic("Decimal division overflow in denominator!", 0);
unreachable;
}
};
const denominator_u128 = @as(u128, @intCast(denominator_abs_i128));
Expand Down Expand Up @@ -634,7 +629,7 @@ fn mul_and_decimalize(a: u128, b: u128) i128 {
const d = answer[0];

if (overflowed == 1) {
roc_panic("Decimal multiplication overflow!", 0);
roc_panic("Decimal multiplication overflow22!", 0);
}

// Final 512bit value is d, c, b, a
Expand Down Expand Up @@ -1211,7 +1206,6 @@ pub fn fromF64C(arg: f64) callconv(.C) i128 {
return dec.num;
} else {
roc_panic("Decimal conversion from f64!", 0);
unreachable;
}
}

Expand All @@ -1221,7 +1215,6 @@ pub fn fromF32C(arg_f32: f32) callconv(.C) i128 {
return dec.num;
} else {
roc_panic("Decimal conversion from f32!", 0);
unreachable;
}
}

Expand All @@ -1237,7 +1230,6 @@ pub fn exportFromInt(comptime T: type, comptime name: []const u8) void {
const answer = @mulWithOverflow(this, RocDec.one_point_zero_i128);
if (answer[1] == 1) {
roc_panic("Decimal conversion from integer!", 0);
unreachable;
} else {
return answer[0];
}
Expand Down Expand Up @@ -1265,14 +1257,12 @@ pub fn neqC(arg1: RocDec, arg2: RocDec) callconv(.C) bool {
pub fn negateC(arg: RocDec) callconv(.C) i128 {
return if (@call(.always_inline, RocDec.negate, .{arg})) |dec| dec.num else {
roc_panic("Decimal negation overflow!", 0);
unreachable;
};
}

pub fn absC(arg: RocDec) callconv(.C) i128 {
const result = @call(.always_inline, RocDec.abs, .{arg}) catch {
roc_panic("Decimal absolute value overflow!", 0);
unreachable;
};
return result.num;
}
Expand Down
4 changes: 0 additions & 4 deletions crates/compiler/builtins/bitcode/src/num.zig
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void {
fn func(a: T, b: T) callconv(.C) T {
return math.divCeil(T, a, b) catch {
roc_panic("integer division by 0!", 0);
unreachable;
};
}
}.func;
Expand Down Expand Up @@ -383,7 +382,6 @@ pub fn exportAddOrPanic(comptime T: type, comptime name: []const u8) void {
const result = addWithOverflow(T, self, other);
if (result.has_overflowed) {
roc_panic("integer addition overflowed!", 0);
unreachable;
} else {
return result.value;
}
Expand Down Expand Up @@ -441,7 +439,6 @@ pub fn exportSubOrPanic(comptime T: type, comptime name: []const u8) void {
const result = subWithOverflow(T, self, other);
if (result.has_overflowed) {
roc_panic("integer subtraction overflowed!", 0);
unreachable;
} else {
return result.value;
}
Expand Down Expand Up @@ -626,7 +623,6 @@ pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []con
const result = @call(.always_inline, mulWithOverflow, .{ T, W, self, other });
if (result.has_overflowed) {
roc_panic("integer multiplication overflowed!", 0);
unreachable;
} else {
return result.value;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/builtins/bitcode/src/panic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const std = @import("std");
const RocStr = @import("str.zig").RocStr;

// Signals to the host that the program has panicked
extern fn roc_panic(msg: *const RocStr, tag_id: u32) callconv(.C) void;
extern fn roc_panic(msg: *const RocStr, tag_id: u32) callconv(.C) noreturn;

pub fn panic_help(msg: []const u8, tag_id: u32) void {
pub fn panic_help(msg: []const u8, tag_id: u32) noreturn {
var str = RocStr.init(msg.ptr, msg.len);
roc_panic(&str, tag_id);
}

// must export this explicitly because right now it is not used from zig code
pub fn panic(msg: *const RocStr, alignment: u32) callconv(.C) void {
pub fn panic(msg: *const RocStr, alignment: u32) callconv(.C) noreturn {
return roc_panic(msg, alignment);
}

0 comments on commit a5180be

Please sign in to comment.