-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
Conversation
looking into failures. The apple-silicon failure looks like #5932 so possibly a flake? The valgrind error i'm having trouble reproducing locally. will investigate |
54ec0c8
to
9f78ab9
Compare
9f78ab9
to
4fe4041
Compare
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); | ||
} |
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.
I was having a weird error in CI were valgrind was crashing but was not happening locally
My gut feeling is that us adding unreachable
after a roc_panic
call is whats causing the issue.
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
if (some_cond) {
roc_panic(...)
} else {
return foo
}
without zig type errors
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.
So glad this worked. Thanks for the find
@@ -632,7 +629,7 @@ fn mul_and_decimalize(a: u128, b: u128) i128 { | |||
const d = answer[0]; | |||
|
|||
if (overflowed == 1) { | |||
@panic("TODO runtime exception for overflow!"); | |||
roc_panic("Decimal multiplication overflow22!", 0); |
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.
roc_panic("Decimal multiplication overflow22!", 0); | |
roc_panic("Decimal multiplication overflow!", 0); |
@@ -1208,7 +1205,7 @@ pub fn fromF64C(arg: f64) callconv(.C) i128 { | |||
if (@call(.always_inline, RocDec.fromF64, .{arg})) |dec| { | |||
return dec.num; | |||
} else { | |||
@panic("TODO runtime exception failing convert f64 to RocDec"); | |||
roc_panic("Decimal conversion from f64!", 0); |
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.
roc_panic("Decimal conversion from f64!", 0); | |
roc_panic("Decimal conversion from f64 failed!", 0); |
@@ -1217,7 +1214,7 @@ pub fn fromF32C(arg_f32: f32) callconv(.C) i128 { | |||
if (@call(.always_inline, RocDec.fromF64, .{arg_f64})) |dec| { | |||
return dec.num; | |||
} else { | |||
@panic("TODO runtime exception failing convert f64 to RocDec"); | |||
roc_panic("Decimal conversion from f32!", 0); |
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.
roc_panic("Decimal conversion from f32!", 0); | |
roc_panic("Decimal conversion from f32 failed!", 0); |
@@ -1232,7 +1229,7 @@ pub fn exportFromInt(comptime T: type, comptime name: []const u8) void { | |||
|
|||
const answer = @mulWithOverflow(this, RocDec.one_point_zero_i128); | |||
if (answer[1] == 1) { | |||
@panic("TODO runtime exception failing convert integer to RocDec"); | |||
roc_panic("Decimal conversion from integer!", 0); |
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.
roc_panic("Decimal conversion from integer!", 0); | |
roc_panic("Decimal conversion from integer failed!", 0); |
@@ -233,7 +233,9 @@ pub fn exportCeiling(comptime F: type, comptime T: type, comptime name: []const | |||
pub fn exportDivCeil(comptime T: type, comptime name: []const u8) void { | |||
comptime var f = struct { | |||
fn func(a: T, b: T) callconv(.C) T { | |||
return math.divCeil(T, a, b) catch @panic("TODO runtime exception for dividing by 0!"); | |||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Would be worth trying to convert these all back to Integer
. Probably will require update some tests. I assume most in cargo test-gen-llvm
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.
Ill give that a shot
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.
Did a bunch of find replace and made all the panics i found capitalize Integer
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); | ||
} |
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.
So glad this worked. Thanks for the find
@@ -1,4 +1,4 @@ | |||
#!/bin/bash |
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.
It looks like you have a number of unrelated changes in this file and below. Probably don't want those here?
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.
ahh yea this file is not related to this branch. I can remove
the readme/gitignore updates were useful when i was testing the wasm repl so i figured those were fine to leave in but can move out
crates/repl_wasm/README.md
Outdated
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.
Still a bit confused about the random repl and flake changes, but otherwise, this pr looks great.
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.
The docs here were out of date, linking to the public dir did not seem to hot reload for me
Do to some ci testing changes, I think this needs rebased or have main merged then tests should run fine and it should be good to merge. |
@bhansconnect you ok with merging this with the doc changes or do you want me to pull those out? |
fixes #6027
fyi I dont really know zig so please let me know if i did something wrong
The issue
calls to
@panic
in the zig bytecode generator would not bubble up the rest of the compiler so we would get nonsene numbers back instead of raise the error to the roc code that should have errored. For example1dec / 0
would give a giant number in wasm and 0 in llvmWhat I did
updated all the numeric related calls to
@panic
toroc_panic
. TBH not sure on the difference between the two but added some tests and they only fail when expected when usingroc_panic
Some errors I'm seeing
I posted some info in zulip
TLDR we still show "normal" output when a
panic
or call tocrash
happens.I could see the argument that its nice to display the type signature still but maybe we hid the value for crashes?
Misc changes
added node and zls to the dev shell since npx is needed for the site dev and zls is nice when editing zig.