Skip to content
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

Replace panic! with internal-error! in ast crate #4297

Closed
wants to merge 3 commits into from
Closed

Replace panic! with internal-error! in ast crate #4297

wants to merge 3 commits into from

Conversation

lucacervello
Copy link
Contributor

Hi,

I replaced panic! with internal_error!.
I started with only panic! and only inside the ast crate to keep this PR small.
Related to #2046

Copy link
Contributor

@bhansconnect bhansconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayazhafiz or @folkertdev, could you take a look at this? Some of these cases look like the might be user_error! instead of internal_error!. I just don't know this code well enough.

@@ -188,7 +189,7 @@ fn canonicalize_field<'a>(
}

Malformed(_string) => {
panic!("TODO canonicalize malformed record field");
internal_error!("TODO canonicalize malformed record field");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we making things that say TODO into todo!?

@@ -2064,7 +2065,7 @@ pub mod test_constrain {

assert_eq!(actual_str, expected_str);
}
Err(e) => panic!("syntax error {:?}", e),
Err(e) => internal_error!("syntax error {:?}", e),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very fimilare with this code, but I wonder if this is a user_error! that just doesn't have a pretty message yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using internal_error is still okay here, things that don't exit well to the user are internal errors to the compiler.

@@ -574,7 +574,7 @@ fn canonicalize_pending_def<'a>(
..
} => {
if arguments.len() != type_arguments.len() {
panic!("argument number mismatch");
internal_error!("argument number mismatch");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this and the errors below in this file. They might really be user_error!

self.0
.get_mut(rank.into_usize())
.unwrap_or_else(|| panic!("Compiler bug: could not find pool at rank {}", rank))
self.0.get_mut(rank.into_usize()).unwrap_or_else(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the Compiler bug: prefix here and below

@@ -20,14 +21,16 @@ pub fn load_module(src_file: &Path, threading: Threading) -> LoadedModule {
match loaded {
Ok(x) => x,
Err(roc_load::LoadingProblem::FormattedReport(report)) => {
panic!(
internal_error!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, here, not sure if this should technically be a user_error!

@bhansconnect
Copy link
Contributor

Thanks so much for doing this! These are the small steps to eventually getting a robust and fuzzable compiler. Makes it clear to the end users when they should to file bugs.

Copy link
Member

@ayazhafiz ayazhafiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after @bhansconnect 's comments are addressed

Copy link
Contributor

@bhansconnect bhansconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. 2 more minor changes.

@@ -188,7 +189,7 @@ fn canonicalize_field<'a>(
}

Malformed(_string) => {
panic!("TODO canonicalize malformed record field");
internal_error!("todo! canonicalize malformed record field");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this was a slight misunderstanding. I meant todo!("canonicalize malformed record field")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes of course.

.get(rank.into_usize())
.unwrap_or_else(|| panic!("Compiler bug: could not find pool at rank {}", rank))
self.0.get(rank.into_usize()).unwrap_or_else(|| {
internal_error!("Compiler bug: could not find pool at rank {}", rank)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove Compiler bug: here as well.

Copy link
Contributor

@bhansconnect bhansconnect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being so slow about this. The last few weeks have been quite hectic for me. Looks great!

@lucacervello lucacervello closed this by deleting the head repository Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants