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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ast/src/canonicalization/canonicalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn canonicalize_field<'a>(
}

Malformed(_string) => {
panic!("TODO canonicalize malformed record field");
todo!("canonicalize malformed record field");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/ast/src/constrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ pub mod test_constrain {
use bumpalo::Bump;
use roc_can::expected::Expected;
use roc_collections::all::MutMap;
use roc_error_macros::internal_error;
use roc_module::{
ident::Lowercase,
symbol::{IdentIds, Interns, ModuleIds, Symbol},
Expand Down Expand Up @@ -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.

}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/ast/src/lang/core/def/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// use crate::pattern::{bindings_from_patterns, canonicalize_pattern, Pattern};
// use crate::procedure::References;
use roc_collections::all::{default_hasher, ImMap, MutMap, MutSet, SendMap};
use roc_error_macros::{internal_error, todo_abilities};
use roc_error_macros::{internal_error, todo_abilities, user_error};
use roc_module::ident::Lowercase;
use roc_module::symbol::Symbol;
use roc_parse::ast::{self, CommentOrNewline, Defs, TypeDef, TypeHeader, ValueDef as AstValueDef};
Expand Down Expand Up @@ -536,7 +536,7 @@ fn canonicalize_pending_def<'a>(
// remove its generated name from the closure map.
let references =
env.closures.remove(&closure_symbol).unwrap_or_else(|| {
panic!( r"Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_symbol, env.closures)
internal_error!( r"Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_symbol, env.closures)
});

// TODO should we re-insert this function into env.closures?
Expand Down Expand Up @@ -574,7 +574,7 @@ fn canonicalize_pending_def<'a>(
..
} => {
if arguments.len() != type_arguments.len() {
panic!("argument number mismatch");
user_error!("argument number mismatch");
}

let it: Vec<_> = closure_args
Expand Down Expand Up @@ -705,7 +705,7 @@ fn canonicalize_pending_def<'a>(
// remove its generated name from the closure map.
let references =
env.closures.remove(&closure_symbol).unwrap_or_else(|| {
panic!( r"Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_symbol, env.closures)
internal_error!( r"Tried to remove symbol {:?} from procedures, but it was not found: {:?}", closure_symbol, env.closures)
});

// TODO should we re-insert this function into env.closures?
Expand Down Expand Up @@ -1238,7 +1238,7 @@ pub fn sort_can_defs(
// )));
//
// declarations.push(Declaration::InvalidCycle(symbols_in_cycle, regions));
panic!("Invalid Cycle");
internal_error!("Invalid Cycle");
} else {
// slightly inefficient, because we know this becomes exactly one DeclareRec already
groups.push(cycle);
Expand Down
11 changes: 6 additions & 5 deletions crates/ast/src/lang/core/expr/expr_to_expr2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use roc_can::num::{
};
use roc_can::operator::desugar_expr;
use roc_collections::all::MutSet;
use roc_error_macros::internal_error;
use roc_module::symbol::Symbol;
use roc_parse::{ast::Expr, pattern::PatternType};
use roc_problem::can::{Problem, RuntimeError};
Expand Down Expand Up @@ -667,31 +668,31 @@ pub fn expr_to_expr2<'a>(
// Below this point, we shouln't see any of these nodes anymore because
// operator desugaring should have removed them!
bad_expr @ ParensAround(_) => {
panic!(
internal_error!(
"A ParensAround did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ SpaceBefore(_, _) => {
panic!(
internal_error!(
"A SpaceBefore did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ SpaceAfter(_, _) => {
panic!(
internal_error!(
"A SpaceAfter did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ BinOps { .. } => {
panic!(
internal_error!(
"A binary operator chain did not get desugared somehow: {:#?}",
bad_expr
);
}
bad_expr @ UnaryOp(_, _) => {
panic!(
internal_error!(
"A unary operator did not get desugared somehow: {:#?}",
bad_expr
);
Expand Down
11 changes: 7 additions & 4 deletions crates/ast/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bumpalo::Bump;
use roc_error_macros::{internal_error, user_error};
use roc_load::{ExecutionMode, LoadConfig, LoadedModule, Threading};
use roc_target::TargetInfo;
use std::path::Path;
Expand All @@ -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!(
user_error!(
"Failed to load module from src_file: {:?}. Report: {}",
src_file, report
src_file,
report
);
}
Err(e) => panic!(
Err(e) => internal_error!(
"Failed to load module from src_file {:?}: {:?}",
src_file, e
src_file,
e
),
}
}
10 changes: 5 additions & 5 deletions crates/ast/src/solve_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ impl Pools {
pub fn get_mut(&mut self, rank: Rank) -> &mut Vec<Variable> {
self.0
.get_mut(rank.into_usize())
.unwrap_or_else(|| panic!("Compiler bug: could not find pool at rank {}", rank))
.unwrap_or_else(|| internal_error!("could not find pool at rank {}", rank))
}

pub fn get(&self, rank: Rank) -> &Vec<Variable> {
self.0
.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!("could not find pool at rank {}", rank)
})
}

pub fn iter(&self) -> std::slice::Iter<'_, Vec<Variable>> {
Expand All @@ -131,7 +131,7 @@ impl Pools {
pub fn split_last(&self) -> (&Vec<Variable>, &[Vec<Variable>]) {
self.0
.split_last()
.unwrap_or_else(|| panic!("Attempted to split_last() on non-empty Pools"))
.unwrap_or_else(|| internal_error!("Attempted to split_last() on non-empty Pools"))
}

pub fn extend_to(&mut self, n: usize) {
Expand Down