Skip to content

Commit

Permalink
replace panic
Browse files Browse the repository at this point in the history
  • Loading branch information
eiei114 committed Jun 24, 2023
1 parent fb6ec34 commit 6d16652
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
8 changes: 3 additions & 5 deletions crates/repl_cli/src/cli_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use roc_target::TargetInfo;
use roc_types::pretty_print::{name_and_print_var, DebugPrint};
use roc_types::subs::Subs;
use target_lexicon::Triple;
use roc_error_macros::internal_error;

pub fn gen_and_eval_llvm<'a, I: Iterator<Item = &'a str>>(
defs: I,
Expand Down Expand Up @@ -263,7 +264,7 @@ fn mono_module_to_dylib<'a>(
if main_fn.verify(true) {
function_pass.run_on(&main_fn);
} else {
panic!("Main function {} failed LLVM verification in build. Uncomment things nearby to see more details.", main_fn_name);
internal_error!("Main function {} failed LLVM verification in build. Uncomment things nearby to see more details.", main_fn_name);
}

module_pass.run_on(env.module);
Expand All @@ -273,10 +274,7 @@ fn mono_module_to_dylib<'a>(

// Verify the module
if let Err(errors) = env.module.verify() {
panic!(
"Errors defining module:\n{}\n\nUncomment things nearby to see more details.",
errors.to_string()
);
internal_error!("Errors defining module:\n{}", errors.to_string());
}

llvm_module_to_dylib(env.module, &target, opt_level)
Expand Down
5 changes: 3 additions & 2 deletions crates/repl_expect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mod test {
use roc_packaging::cache::RocCacheDir;
use roc_reporting::report::{RenderTarget, DEFAULT_PALETTE};
use target_lexicon::Triple;
use roc_error_macros::internal_error;

use crate::run::expect_mono_module_to_dylib;

Expand Down Expand Up @@ -136,9 +137,9 @@ mod test {
) {
Ok(m) => m,
Err(LoadMonomorphizedError::ErrorModule(m)) => {
panic!("{:?}", (m.can_problems, m.type_problems))
internal_error!("{:?}", (m.can_problems, m.type_problems))
}
Err(e) => panic!("{e:?}"),
Err(e) => internal_error!("{e:?}"),
};

let mut loaded = loaded;
Expand Down
10 changes: 5 additions & 5 deletions crates/repl_expect/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn run_expect_fx<'a, W: std::io::Write>(
try_run_jit_function!(lib, expect.name, (), |v: ()| v);

if let Err((msg, _)) = result {
panic!("roc panic {}", msg);
internal_error!("roc panic {}", msg);
}

if sequence.count_failures() > 0 {
Expand Down Expand Up @@ -518,7 +518,7 @@ fn render_dbg_failure<'a>(
let data = expectations.get_mut(&module_id).unwrap();

let current = match data.dbgs.get(&dbg_symbol) {
None => panic!("region {failure_region:?} not in list of dbgs"),
None => internal_error!("region {failure_region:?} not in list of dbgs"),
Some(current) => current,
};
let failure_region = current.region;
Expand Down Expand Up @@ -565,7 +565,7 @@ fn render_expect_failure<'a>(
let data = expectations.get_mut(&module_id).unwrap();

let current = match data.expectations.get(&failure_region) {
None => panic!("region {failure_region:?} not in list of expects"),
None => internal_error!("region {failure_region:?} not in list of expects"),
Some(current) => current,
};

Expand Down Expand Up @@ -638,7 +638,7 @@ impl ExpectSequence {
0 => std::hint::spin_loop(),
1 => break ChildProcessMsg::Expect,
2 => break ChildProcessMsg::Dbg,
n => panic!("invalid atomic value set by the child: {:#x}", n),
n => internal_error!("invalid atomic value set by the child: {:#x}", n),
}
}
}
Expand Down Expand Up @@ -815,7 +815,7 @@ pub fn expect_mono_module_to_dylib<'a>(
if let Err(errors) = env.module.verify() {
let path = std::env::temp_dir().join("test.ll");
env.module.print_to_file(&path).unwrap();
panic!(
internal_error!(
"Errors defining module:\n{}\n\nUncomment things nearby to see more details. IR written to `{:?}`",
errors.to_string(), path,
);
Expand Down

0 comments on commit 6d16652

Please sign in to comment.