Skip to content

Commit

Permalink
Merge pull request #5322 from jarlah/replace-panic!-with-internal-err…
Browse files Browse the repository at this point in the history
…or!-in-compiler-parse-create

Replace panic! with internal_error! in `compiler/parse` and `compiler/can`
  • Loading branch information
folkertdev authored Apr 26, 2023
2 parents 6d7e3dd + 8bf888a commit 8a76937
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions crates/compiler/can/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,31 +1378,31 @@ pub fn canonicalize_expr<'a>(
// Below this point, we shouln't see any of these nodes anymore because
// operator desugaring should have removed them!
bad_expr @ ast::Expr::ParensAround(_) => {
panic!(
internal_error!(
"A ParensAround did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ ast::Expr::SpaceBefore(_, _) => {
panic!(
internal_error!(
"A SpaceBefore did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ ast::Expr::SpaceAfter(_, _) => {
panic!(
internal_error!(
"A SpaceAfter did not get removed during operator desugaring somehow: {:#?}",
bad_expr
);
}
bad_expr @ ast::Expr::BinOps { .. } => {
panic!(
internal_error!(
"A binary operator chain did not get desugared somehow: {:#?}",
bad_expr
);
}
bad_expr @ ast::Expr::UnaryOp(_, _) => {
panic!(
internal_error!(
"A unary operator did not get desugared somehow: {:#?}",
bad_expr
);
Expand Down Expand Up @@ -1814,15 +1814,15 @@ fn canonicalize_field<'a>(

// A label with no value, e.g. `{ name }` (this is sugar for { name: name })
LabelOnly(_) => {
panic!("Somehow a LabelOnly record field was not desugared!");
internal_error!("Somehow a LabelOnly record field was not desugared!");
}

SpaceBefore(sub_field, _) | SpaceAfter(sub_field, _) => {
canonicalize_field(env, var_store, scope, sub_field)
}

Malformed(_string) => {
panic!("TODO canonicalize malformed record field");
internal_error!("TODO canonicalize malformed record field");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/compiler/can/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub fn canonicalize_module_defs<'a>(
can_exposed_imports.insert(symbol, region);
}
Err((_shadowed_symbol, _region)) => {
panic!("TODO gracefully handle shadowing in imports.")
internal_error!("TODO gracefully handle shadowing in imports.")
}
}
} else {
Expand All @@ -359,7 +359,7 @@ pub fn canonicalize_module_defs<'a>(
// here we do nothing special
}
Err((shadowed_symbol, _region)) => {
panic!(
internal_error!(
"TODO gracefully handle shadowing in imports, {:?} is shadowed.",
shadowed_symbol
)
Expand Down Expand Up @@ -523,7 +523,7 @@ pub fn canonicalize_module_defs<'a>(
GeneratedInfo::Builtin => {
match crate::builtins::builtin_defs_map(*symbol, var_store) {
None => {
panic!("A builtin module contains a signature without implementation for {:?}", symbol)
internal_error!("A builtin module contains a signature without implementation for {:?}", symbol)
}
Some(replacement_def) => {
declarations.update_builtin_def(index, replacement_def);
Expand Down Expand Up @@ -581,7 +581,7 @@ pub fn canonicalize_module_defs<'a>(
GeneratedInfo::Builtin => {
match crate::builtins::builtin_defs_map(*symbol, var_store) {
None => {
panic!("A builtin module contains a signature without implementation for {:?}", symbol)
internal_error!("A builtin module contains a signature without implementation for {:?}", symbol)
}
Some(replacement_def) => {
declarations.update_builtin_def(index, replacement_def);
Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/can/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_error_macros::internal_error;
use roc_module::called_via::BinOp::Pizza;
use roc_module::called_via::{BinOp, CalledVia};
use roc_module::ident::ModuleName;
Expand Down Expand Up @@ -592,7 +593,7 @@ fn binop_step<'a>(
//
// By design, Roc neither allows custom operators nor has any built-in operators with
// the same precedence and different associativity, so this should never happen!
panic!("BinOps had the same associativity, but different precedence. This should never happen!");
internal_error!("BinOps had the same associativity, but different precedence. This should never happen!");
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/compiler/can/src/scope.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use roc_collections::{VecMap, VecSet};
use roc_error_macros::internal_error;
use roc_module::ident::Ident;
use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol};
use roc_problem::can::RuntimeError;
Expand Down Expand Up @@ -470,9 +471,13 @@ pub fn create_alias(
}

if !hidden.is_empty() {
panic!(
internal_error!(
"Found unbound type variables {:?} \n in type alias {:?} {:?} {:?} : {:?}",
hidden, name, &vars, &infer_ext_in_output_variables, &typ
hidden,
name,
&vars,
&infer_ext_in_output_variables,
&typ
)
}

Expand Down
3 changes: 2 additions & 1 deletion crates/compiler/can/src/string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// use bumpalo::collections::string::String;
// use bumpalo::collections::vec::Vec;
use bumpalo::Bump;
use roc_error_macros::internal_error;
use roc_parse::ast::Expr;
// use roc_parse::ast::{Attempting, Expr};
// use roc_parse::ident;
Expand All @@ -12,7 +13,7 @@ use roc_region::all::Region;
// use std::iter::Peekable;

pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Region) -> Expr<'a> {
panic!("TODO restore canonicalization");
internal_error!("TODO restore canonicalization");
}
// let mut problems = std::vec::Vec::new();

Expand Down
1 change: 1 addition & 0 deletions crates/compiler/parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ version.workspace = true
roc_collections = { path = "../collections" }
roc_module = { path = "../module" }
roc_region = { path = "../region" }
roc_error_macros = { path = "../../error_macros" }

bumpalo.workspace = true
encode_unicode.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/compiler/parse/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::type_annotation;
use bumpalo::collections::Vec;
use bumpalo::Bump;
use roc_collections::soa::Slice;
use roc_error_macros::internal_error;
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
use roc_region::all::{Loc, Position, Region};

Expand Down Expand Up @@ -2479,10 +2480,10 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
// TODO: make this state impossible to represent in Ident::Access,
// by splitting out parts[0] into a separate field with a type of `&'a str`,
// rather than a `&'a [Accessor<'a>]`.
panic!("Parsed an Ident::Access with a first part of a tuple index");
internal_error!("Parsed an Ident::Access with a first part of a tuple index");
}
None => {
panic!("Parsed an Ident::Access with no parts");
internal_error!("Parsed an Ident::Access with no parts");
}
};

Expand Down

0 comments on commit 8a76937

Please sign in to comment.