-
-
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
Remove all uses of panic!
, unwrap()
, expect(...)
, and unreachable!()
#2046
Comments
As an extra notes, in many cases, it may also be fine to replace |
Should we also add |
panic!
, unwrap()
, and expect(...)
panic!
, unwrap()
, expect(...)
, and unreachable!()
Yes, thanks for the catch. |
I suspect that this is a long way. |
I've applied the new panic macros in the main part of the compiler that I work on. But in other parts it's currently blocked by circular dependencies. The macros are defined in The same thing applies to all internal dependencies of
If we want to use the macros in these places then we will need to move them somewhere else. (Or maybe we're OK with that? I don't know.) I ran the command below to find Cargo.toml files that don't have lines beginning with $ for f in $(find . -name Cargo.toml)
do
if ! grep -q '^roc_' $f
then echo $f
fi
done
./roc_std/Cargo.toml
./Cargo.toml
./utils/Cargo.toml
./test_utils/Cargo.toml
./nightly_benches/Cargo.toml
./ci/bench-runner/Cargo.toml
./compiler/arena_pool/Cargo.toml
./compiler/parse/fuzz/Cargo.toml
./compiler/region/Cargo.toml
./compiler/test_mono_macros/Cargo.toml
./compiler/ident/Cargo.toml
./compiler/collections/Cargo.toml
./vendor/inkwell/Cargo.toml
./vendor/pretty/Cargo.toml
./vendor/ena/Cargo.toml
./vendor/morphic_lib/Cargo.toml |
We want to move them into their own crate to fix this. There is already an issue for it, just hasn't been done yet: #2130 |
#2130 is now fixed, and I thought I would try to help out with this one, but there are lots of places where panic/unwrap/expect/unreachable are still used, and I don't want to create unnecessary merge ambushes. Are there specific places in the code that are best avoided/left to those who actively work on them? |
I think these would be the least likely to have conflicts right now:
...and these would be more likely to have conflicts:
I'd also avoid anything in the |
Progress report
|
As a quick note, this should definitely be the preferred solution (even though it takes longer) whenever possible! A lot of the worst user experiences in Roc right now are due to compiler panics (e.g. because they block later steps in the compiler, such as error reporting, from running as normal), so anywhere we can replace a panic with telling the user what went wrong and then continuing, that's what we should do! |
This might be a crazy idea... but could we bulk add a Then the process of fixing this is a matter of replacing the |
Could this be simpler: we can execute the count command ( If we use |
I like that idea, Anton! We could also have a script which errors if the number decreases, so you can make sure to decrease the count. So the error messages could be:
Also, it's a bit unfortunately, but things like |
We want to use our new error macros instead of
panic!
,unwrap()
,expect(...)
, andunreachable!()
.The new error macros both live in
roc_reporting
and can be imported withuse roc_reporting:{internal_error, user_error}
.Essentially, all cases were the
panic!
/unwrap()
/expect(...)
would be a sign of a compiler bug, we want to useinternal_error!
instead.user_error!
should be used in cases where we eventually want to useroc_reporting
to print a pretty error message. It is essentially documentation that eventually better errors should be return there.todo!
should be used for cases were the feature is planned to be implemented but is not yet implemented.unimplemented!
should be used if the feature is not implemented, and there is not a current plan to implement the feature.Uses of
unreachable!()
should always be replaced withinternal_error!
. If possible, a message around why the statement is unreachable/what invariant was broken, should be added.This issue will be fixed when we can enable
clippy::panic
,clippy::unwrap_used
,clippy::expect_used
, andclippy::unreachable
on CI by default.This command can be used to track how many use cases are left:
At the date of creating this issue, we have 1283 cases to go.
The text was updated successfully, but these errors were encountered: