-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update zig @panic
calls to roc_panic
for numeric errors
#6062
Changes from 1 commit
737d766
23e2269
191752e
5df2199
863ecd8
abc92de
14478c8
c9e1456
925cba4
38207cf
4fe4041
2a762f1
a5180be
d6f0709
d37dd44
298f93d
20bcd70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -252,7 +252,6 @@ pub const RocDec = extern struct { | |||||
|
||||||
if (answer.has_overflowed) { | ||||||
roc_panic("Decimal addition overflowed!", 0); | ||||||
unreachable; | ||||||
} else { | ||||||
return answer.value; | ||||||
} | ||||||
|
@@ -283,7 +282,6 @@ pub const RocDec = extern struct { | |||||
|
||||||
if (answer.has_overflowed) { | ||||||
roc_panic("Decimal subtraction overflowed!", 0); | ||||||
unreachable; | ||||||
} else { | ||||||
return answer.value; | ||||||
} | ||||||
|
@@ -347,7 +345,6 @@ pub const RocDec = extern struct { | |||||
|
||||||
if (answer.has_overflowed) { | ||||||
roc_panic("Decimal multiplication overflowed!", 0); | ||||||
unreachable; | ||||||
} else { | ||||||
return answer.value; | ||||||
} | ||||||
|
@@ -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)); | ||||||
|
@@ -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)); | ||||||
|
@@ -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 | ||||||
|
@@ -1211,7 +1206,6 @@ pub fn fromF64C(arg: f64) callconv(.C) i128 { | |||||
return dec.num; | ||||||
} else { | ||||||
roc_panic("Decimal conversion from f64!", 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
unreachable; | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -1221,7 +1215,6 @@ pub fn fromF32C(arg_f32: f32) callconv(.C) i128 { | |||||
return dec.num; | ||||||
} else { | ||||||
roc_panic("Decimal conversion from f32!", 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
unreachable; | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
unreachable; | ||||||
} else { | ||||||
return answer[0]; | ||||||
} | ||||||
|
@@ -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; | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be worth trying to convert these all back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ill give that a shot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did a bunch of find replace and made all the panics i found capitalize |
||
unreachable; | ||
}; | ||
} | ||
}.func; | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
@@ -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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
Comment on lines
+5
to
15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was having a weird error in CI were valgrind was crashing but was not happening locally My gut feeling is that us adding Looks like unreachable is undefined behavior when compiled with RelaseFast https://ziglang.org/documentation/master/#try which i think we do This return type lets you do
without zig type errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So glad this worked. Thanks for the find |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.