Merge pull request #4298 from lucacervello/replace-panic!-with-internal-error!-in-compiler-crates

Replace panic! with internal_error! in `compiler/build`, `compiler/alias_analysis` and `compiler/arena_pool`
This commit is contained in:
Anton-4 2022-10-15 17:05:25 +02:00 committed by GitHub
commit 2f8dcb7e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 27 deletions

4
Cargo.lock generated
View file

@ -96,6 +96,9 @@ dependencies = [
[[package]]
name = "arena-pool"
version = "0.0.1"
dependencies = [
"roc_error_macros",
]
[[package]]
name = "arrayvec"
@ -3285,6 +3288,7 @@ dependencies = [
"morphic_lib",
"roc_collections",
"roc_debug_flags",
"roc_error_macros",
"roc_module",
"roc_mono",
]

View file

@ -11,3 +11,4 @@ roc_collections = {path = "../collections"}
roc_module = {path = "../module"}
roc_mono = {path = "../mono"}
roc_debug_flags = {path = "../debug_flags"}
roc_error_macros = { path = "../../error_macros" }

View file

@ -16,6 +16,8 @@ use roc_mono::layout::{
Builtin, CapturesNiche, Layout, RawFunctionLayout, STLayoutInterner, UnionLayout,
};
use roc_error_macros::internal_error;
// just using one module for now
pub const MOD_APP: ModName = ModName(b"UserApp");
@ -603,9 +605,10 @@ fn build_tuple_value(
for field in symbols.iter() {
let value_id = match env.symbols.get(field) {
None => panic!(
None => internal_error!(
"Symbol {:?} is not defined in environment {:?}",
field, &env.symbols
field,
&env.symbols
),
Some(x) => *x,
};

View file

@ -6,3 +6,6 @@ license = "UPL-1.0"
repository = "https://github.com/roc-lang/roc"
edition = "2021"
description = "A CLI for Roc"
[dependencies]
roc_error_macros = { path = "../../error_macros" }

View file

@ -1,3 +1,4 @@
use roc_error_macros::internal_error;
use std::marker::PhantomPinned;
use std::ptr::{copy_nonoverlapping, NonNull};
@ -391,6 +392,6 @@ fn verify_ownership<T>(
// The address wasn't within any of our chunks' bounds.
// Panic to avoid use-after-free errors!
panic!("Pointer ownership verification failed.");
internal_error!("Pointer ownership verification failed.");
}
}

View file

@ -61,7 +61,7 @@ pub fn link(
operating_system: OperatingSystem::Windows,
..
} => link_windows(target, output_path, input_paths, link_type),
_ => panic!("TODO gracefully handle unsupported target: {:?}", target),
_ => internal_error!("TODO gracefully handle unsupported target: {:?}", target),
}
}
@ -89,7 +89,7 @@ fn find_zig_str_path() -> PathBuf {
return zig_str_path;
}
panic!("cannot find `str.zig`. Check the source code in find_zig_str_path() to show all the paths I tried.")
internal_error!("cannot find `str.zig`. Check the source code in find_zig_str_path() to show all the paths I tried.")
}
fn find_wasi_libc_path() -> PathBuf {
@ -99,7 +99,7 @@ fn find_wasi_libc_path() -> PathBuf {
return wasi_libc_pathbuf;
}
panic!("cannot find `wasi-libc.a`")
internal_error!("cannot find `wasi-libc.a`")
}
#[cfg(all(unix, not(target_os = "macos")))]
@ -258,15 +258,15 @@ pub fn build_zig_host_native(
let zig_env_json = if zig_env_output.status.success() {
std::str::from_utf8(&zig_env_output.stdout).unwrap_or_else(|utf8_err| {
panic!(
internal_error!(
"`zig env` failed; its stderr output was invalid utf8 ({:?})",
utf8_err
);
})
} else {
match std::str::from_utf8(&zig_env_output.stderr) {
Ok(stderr) => panic!("`zig env` failed - stderr output was: {:?}", stderr),
Err(utf8_err) => panic!(
Ok(stderr) => internal_error!("`zig env` failed - stderr output was: {:?}", stderr),
Err(utf8_err) => internal_error!(
"`zig env` failed; its stderr output was invalid utf8 ({:?})",
utf8_err
),
@ -277,11 +277,11 @@ pub fn build_zig_host_native(
Ok(Value::Object(map)) => match map.get("std_dir") {
Some(Value::String(std_dir)) => PathBuf::from(Path::new(std_dir)),
_ => {
panic!("Expected JSON containing a `std_dir` String field from `zig env`, but got: {:?}", zig_env_json);
internal_error!("Expected JSON containing a `std_dir` String field from `zig env`, but got: {:?}", zig_env_json);
}
},
_ => {
panic!(
internal_error!(
"Expected JSON containing a `std_dir` field from `zig env`, but got: {:?}",
zig_env_json
);
@ -628,7 +628,7 @@ pub fn rebuild_host(
shared_lib_path,
)
}
_ => panic!("Unsupported architecture {:?}", target.architecture),
_ => internal_error!("Unsupported architecture {:?}", target.architecture),
};
validate_output("host.zig", &zig_executable(), output)
@ -962,7 +962,7 @@ fn link_linux(
}
}
Architecture::Aarch64(_) => library_path(["/lib", "ld-linux-aarch64.so.1"]),
_ => panic!(
_ => internal_error!(
"TODO gracefully handle unsupported linux architecture: {:?}",
target.architecture
),
@ -1370,13 +1370,17 @@ pub fn preprocess_host_wasm32(host_input_path: &Path, preprocessed_host_path: &P
fn validate_output(file_name: &str, cmd_name: &str, output: Output) {
if !output.status.success() {
match std::str::from_utf8(&output.stderr) {
Ok(stderr) => panic!(
Ok(stderr) => internal_error!(
"Failed to rebuild {} - stderr of the `{}` command was:\n{}",
file_name, cmd_name, stderr
file_name,
cmd_name,
stderr
),
Err(utf8_err) => panic!(
Err(utf8_err) => internal_error!(
"Failed to rebuild {} - stderr of the `{}` command was invalid utf8 ({:?})",
file_name, cmd_name, utf8_err
file_name,
cmd_name,
utf8_err
),
}
}

View file

@ -1,4 +1,5 @@
use inkwell::memory_buffer::MemoryBuffer;
use roc_error_macros::internal_error;
pub use roc_gen_llvm::llvm::build::FunctionIterator;
use roc_gen_llvm::llvm::build::{module_from_builtins, LlvmBackendMode};
use roc_gen_llvm::llvm::externs::add_default_roc_externs;
@ -315,7 +316,7 @@ fn gen_from_mono_module_llvm(
// write the ll code to a file, so we can modify it
env.module.print_to_file(&app_ll_file).unwrap();
panic!(
internal_error!(
"😱 LLVM errors when defining module; I wrote the full LLVM IR to {:?}\n\n {}",
app_ll_file,
errors.to_string(),
@ -353,10 +354,10 @@ fn gen_from_mono_module_llvm(
Err(error) => {
use std::io::ErrorKind;
match error.kind() {
ErrorKind::NotFound => panic!(
ErrorKind::NotFound => internal_error!(
r"I could not find the `debugir` tool on the PATH, install it from https://github.com/vaivaswatha/debugir"
),
_ => panic!("{:?}", error),
_ => internal_error!("{:?}", error),
}
}
}
@ -417,7 +418,7 @@ fn gen_from_mono_module_llvm(
// module.print_to_file(app_ll_file);
module.write_bitcode_to_memory()
}
_ => panic!(
_ => internal_error!(
"TODO gracefully handle unsupported architecture: {:?}",
target.architecture
),
@ -506,14 +507,14 @@ fn gen_from_mono_module_dev_wasm32(
};
let host_bytes = std::fs::read(preprocessed_host_path).unwrap_or_else(|_| {
panic!(
internal_error!(
"Failed to read host object file {}! Try setting --prebuilt-platform=false",
preprocessed_host_path.display()
)
});
let host_module = roc_gen_wasm::parse_host(arena, &host_bytes).unwrap_or_else(|e| {
panic!(
internal_error!(
"I ran into a problem with the host object file, {} at offset 0x{:x}:\n{}",
preprocessed_host_path.display(),
e.offset,

View file

@ -2,6 +2,7 @@ use inkwell::{
targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetMachine, TargetTriple},
OptimizationLevel,
};
use roc_error_macros::internal_error;
use roc_mono::ir::OptLevel;
use target_lexicon::{Architecture, Environment, OperatingSystem, Triple};
@ -44,7 +45,7 @@ pub fn target_triple_str(target: &Triple) -> &'static str {
operating_system: OperatingSystem::Windows,
..
} => "x86_64-pc-windows-gnu",
_ => panic!("TODO gracefully handle unsupported target: {:?}", target),
_ => internal_error!("TODO gracefully handle unsupported target: {:?}", target),
}
}
@ -92,7 +93,7 @@ pub fn target_zig_str(target: &Triple) -> &'static str {
operating_system: OperatingSystem::Darwin,
..
} => "aarch64-apple-darwin",
_ => panic!("TODO gracefully handle unsupported target: {:?}", target),
_ => internal_error!("TODO gracefully handle unsupported target: {:?}", target),
}
}
@ -112,7 +113,7 @@ pub fn init_arch(target: &Triple) {
Architecture::Wasm32 if cfg!(feature = "target-wasm32") => {
Target::initialize_webassembly(&InitializationConfig::default());
}
_ => panic!(
_ => internal_error!(
"TODO gracefully handle unsupported target architecture: {:?}",
target.architecture
),
@ -132,7 +133,7 @@ pub fn arch_str(target: &Triple) -> &'static str {
Architecture::Aarch64(_) if cfg!(feature = "target-aarch64") => "aarch64",
Architecture::Arm(_) if cfg!(feature = "target-arm") => "arm",
Architecture::Wasm32 if cfg!(feature = "target-webassembly") => "wasm32",
_ => panic!(
_ => internal_error!(
"TODO gracefully handle unsupported target architecture: {:?}",
target.architecture
),