mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
Move macros from roc_reporting to new roc_error_macros module
The `internal_error!` and `user_error!´ macros can't be used everywhere when they live in `roc_reporting` due to circular dependencies.
This commit is contained in:
parent
2b3f347eec
commit
71f359fbdc
27 changed files with 71 additions and 57 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -3248,12 +3248,12 @@ dependencies = [
|
|||
"roc_builtins",
|
||||
"roc_can",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_load",
|
||||
"roc_module",
|
||||
"roc_parse",
|
||||
"roc_problem",
|
||||
"roc_region",
|
||||
"roc_reporting",
|
||||
"roc_types",
|
||||
"roc_unify",
|
||||
"snafu",
|
||||
|
@ -3338,6 +3338,7 @@ dependencies = [
|
|||
"roc_constrain",
|
||||
"roc_docs",
|
||||
"roc_editor",
|
||||
"roc_error_macros",
|
||||
"roc_fmt",
|
||||
"roc_gen_llvm",
|
||||
"roc_linker",
|
||||
|
@ -3470,6 +3471,10 @@ dependencies = [
|
|||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "roc_error_macros"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "roc_fmt"
|
||||
version = "0.1.0"
|
||||
|
@ -3495,12 +3500,12 @@ dependencies = [
|
|||
"roc_builtins",
|
||||
"roc_can",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_mono",
|
||||
"roc_parse",
|
||||
"roc_problem",
|
||||
"roc_region",
|
||||
"roc_reporting",
|
||||
"roc_solve",
|
||||
"roc_std",
|
||||
"roc_types",
|
||||
|
@ -3517,9 +3522,9 @@ dependencies = [
|
|||
"morphic_lib",
|
||||
"roc_builtins",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_mono",
|
||||
"roc_reporting",
|
||||
"roc_std",
|
||||
"target-lexicon",
|
||||
]
|
||||
|
@ -3531,9 +3536,9 @@ dependencies = [
|
|||
"bumpalo",
|
||||
"roc_builtins",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_mono",
|
||||
"roc_reporting",
|
||||
"roc_std",
|
||||
]
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ members = [
|
|||
"ast",
|
||||
"cli",
|
||||
"code_markup",
|
||||
"error_macros",
|
||||
"reporting",
|
||||
"roc_std",
|
||||
"test_utils",
|
||||
|
|
|
@ -47,7 +47,7 @@ install-zig-llvm-valgrind-clippy-rustfmt:
|
|||
|
||||
copy-dirs:
|
||||
FROM +install-zig-llvm-valgrind-clippy-rustfmt
|
||||
COPY --dir cli cli_utils compiler docs editor ast code_markup utils test_utils reporting roc_std vendor examples linker Cargo.toml Cargo.lock version.txt ./
|
||||
COPY --dir cli cli_utils compiler docs editor ast code_markup error_macros utils test_utils reporting roc_std vendor examples linker Cargo.toml Cargo.lock version.txt ./
|
||||
|
||||
test-zig:
|
||||
FROM +install-zig-llvm-valgrind-clippy-rustfmt
|
||||
|
|
|
@ -17,7 +17,7 @@ roc_problem = { path = "../compiler/problem" }
|
|||
roc_types = { path = "../compiler/types" }
|
||||
roc_unify = { path = "../compiler/unify"}
|
||||
roc_load = { path = "../compiler/load" }
|
||||
roc_reporting = { path = "../reporting" }
|
||||
roc_error_macros = { path = "../error_macros" }
|
||||
arrayvec = "0.7.2"
|
||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||
libc = "0.2.106"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use roc_error_macros::internal_error;
|
||||
use roc_module::{called_via::CalledVia, symbol::Symbol};
|
||||
use roc_parse::ast::StrLiteral;
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
use crate::{
|
||||
ast_error::{ASTResult, UnexpectedASTNode},
|
||||
|
|
|
@ -62,6 +62,7 @@ roc_gen_llvm = { path = "../compiler/gen_llvm", optional = true }
|
|||
roc_build = { path = "../compiler/build", default-features = false }
|
||||
roc_fmt = { path = "../compiler/fmt" }
|
||||
roc_reporting = { path = "../reporting" }
|
||||
roc_error_macros = { path = "../error_macros" }
|
||||
roc_editor = { path = "../editor", optional = true }
|
||||
roc_linker = { path = "../linker" }
|
||||
clap = { version = "= 3.0.0-beta.5", default-features = false, features = ["std", "color", "suggestions"] }
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::path::PathBuf;
|
|||
|
||||
use bumpalo::collections::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_error_macros::{internal_error, user_error};
|
||||
use roc_fmt::def::fmt_def;
|
||||
use roc_fmt::module::fmt_module;
|
||||
use roc_fmt::Buf;
|
||||
|
@ -21,7 +22,6 @@ use roc_parse::{
|
|||
state::State,
|
||||
};
|
||||
use roc_region::all::{Loc, Region};
|
||||
use roc_reporting::{internal_error, user_error};
|
||||
|
||||
pub fn format(files: std::vec::Vec<PathBuf>) {
|
||||
for file in files {
|
||||
|
|
|
@ -16,7 +16,7 @@ roc_builtins = { path = "../builtins" }
|
|||
roc_unify = { path = "../unify" }
|
||||
roc_solve = { path = "../solve" }
|
||||
roc_mono = { path = "../mono" }
|
||||
roc_reporting = { path = "../../reporting" }
|
||||
roc_error_macros = { path = "../../error_macros" }
|
||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||
target-lexicon = "0.12.2"
|
||||
# TODO: Deal with the update of object to 0.27.
|
||||
|
|
|
@ -3,9 +3,9 @@ use crate::Relocation;
|
|||
use bumpalo::collections::Vec;
|
||||
use packed_struct::prelude::*;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::Layout;
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
#[allow(dead_code)]
|
||||
|
|
|
@ -2,11 +2,11 @@ use crate::{Backend, Env, Relocation};
|
|||
use bumpalo::collections::Vec;
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use roc_mono::code_gen_help::CodeGenHelp;
|
||||
use roc_mono::ir::{BranchInfo, JoinPointId, Literal, Param, ProcLayout, SelfRecursive, Stmt};
|
||||
use roc_mono::layout::{Builtin, Layout};
|
||||
use roc_reporting::internal_error;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub mod aarch64;
|
||||
|
|
|
@ -5,9 +5,9 @@ use crate::{
|
|||
use bumpalo::collections::Vec;
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{Builtin, Layout};
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
// Not sure exactly how I want to represent registers.
|
||||
// If we want max speed, we would likely make them structs that impl the same trait to avoid ifs.
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use bumpalo::{collections::Vec, Bump};
|
||||
use roc_builtins::bitcode::{self, FloatWidth, IntWidth};
|
||||
use roc_collections::all::{MutMap, MutSet};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::ident::{ModuleName, TagName};
|
||||
use roc_module::low_level::{LowLevel, LowLevelWrapperType};
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
|
@ -14,7 +15,6 @@ use roc_mono::ir::{
|
|||
SelfRecursive, Stmt,
|
||||
};
|
||||
use roc_mono::layout::{Builtin, Layout, LayoutId, LayoutIds};
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
mod generic64;
|
||||
mod object_builder;
|
||||
|
|
|
@ -8,11 +8,11 @@ use object::{
|
|||
SymbolFlags, SymbolKind, SymbolScope,
|
||||
};
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol;
|
||||
use roc_module::symbol::Interns;
|
||||
use roc_mono::ir::{Proc, ProcLayout};
|
||||
use roc_mono::layout::LayoutIds;
|
||||
use roc_reporting::internal_error;
|
||||
use target_lexicon::{Architecture as TargetArch, BinaryFormat as TargetBF, Triple};
|
||||
|
||||
// This is used by some code below which is currently commented out.
|
||||
|
|
|
@ -10,7 +10,7 @@ edition = "2018"
|
|||
roc_collections = { path = "../collections" }
|
||||
roc_module = { path = "../module" }
|
||||
roc_builtins = { path = "../builtins" }
|
||||
roc_reporting = { path = "../../reporting" }
|
||||
roc_error_macros = { path = "../../error_macros" }
|
||||
roc_mono = { path = "../mono" }
|
||||
roc_std = { path = "../../roc_std" }
|
||||
morphic_lib = { path = "../../vendor/morphic_lib" }
|
||||
|
|
|
@ -55,6 +55,7 @@ use morphic_lib::{
|
|||
use roc_builtins::bitcode::{self, FloatWidth, IntWidth, IntrinsicName};
|
||||
use roc_builtins::{float_intrinsic, int_intrinsic};
|
||||
use roc_collections::all::{ImMap, MutMap, MutSet};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::low_level::LowLevel;
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
use roc_mono::ir::{
|
||||
|
@ -62,7 +63,6 @@ use roc_mono::ir::{
|
|||
ModifyRc, OptLevel, ProcLayout,
|
||||
};
|
||||
use roc_mono::layout::{Builtin, LambdaSet, Layout, LayoutIds, TagIdIntType, UnionLayout};
|
||||
use roc_reporting::internal_error;
|
||||
use target_lexicon::{Architecture, OperatingSystem, Triple};
|
||||
|
||||
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
|
||||
|
|
|
@ -12,4 +12,4 @@ roc_collections = { path = "../collections" }
|
|||
roc_module = { path = "../module" }
|
||||
roc_mono = { path = "../mono" }
|
||||
roc_std = { path = "../../roc_std" }
|
||||
roc_reporting = { path = "../../reporting" }
|
||||
roc_error_macros = { path = "../../error_macros" }
|
||||
|
|
|
@ -12,8 +12,8 @@ use roc_mono::ir::{
|
|||
ProcLayout, Stmt,
|
||||
};
|
||||
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_mono::layout::{Builtin, Layout, LayoutIds, TagIdIntType, UnionLayout};
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
use crate::layout::{CallConv, ReturnMethod, WasmLayout};
|
||||
use crate::low_level::LowLevelCall;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use bumpalo::collections::Vec;
|
||||
use roc_builtins::bitcode::{self, FloatWidth, IntWidth};
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::low_level::{LowLevel, LowLevel::*};
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
use crate::backend::WasmBackend;
|
||||
use crate::layout::CallConv;
|
||||
|
|
|
@ -2,9 +2,9 @@ use bumpalo::collections::Vec;
|
|||
use bumpalo::Bump;
|
||||
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::Symbol;
|
||||
use roc_mono::layout::Layout;
|
||||
use roc_reporting::internal_error;
|
||||
|
||||
use crate::layout::{
|
||||
CallConv, ReturnMethod, StackMemoryFormat, WasmLayout, ZigVersion, BUILTINS_ZIG_VERSION,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
use core::panic;
|
||||
use roc_reporting::internal_error;
|
||||
use roc_error_macros::internal_error;
|
||||
|
||||
use roc_module::symbol::Symbol;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ pub mod serialize;
|
|||
use bumpalo::Bump;
|
||||
pub use code_builder::{Align, CodeBuilder, LocalId, ValueType, VmSymbolState};
|
||||
pub use linking::SymInfo;
|
||||
use roc_reporting::internal_error;
|
||||
use roc_error_macros::internal_error;
|
||||
pub use sections::{ConstExpr, Export, ExportType, Global, GlobalType, Signature};
|
||||
|
||||
use crate::wasm_module::serialize::SkipBytes;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use roc_reporting::internal_error;
|
||||
use roc_error_macros::internal_error;
|
||||
|
||||
use super::serialize::{parse_u32_or_panic, SkipBytes};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bumpalo::collections::vec::Vec;
|
||||
use bumpalo::Bump;
|
||||
use roc_collections::all::MutMap;
|
||||
use roc_reporting::internal_error;
|
||||
use roc_error_macros::internal_error;
|
||||
|
||||
use super::dead_code::{
|
||||
copy_preloads_shrinking_dead_fns, parse_preloads_call_graph, trace_call_graph,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{fmt::Debug, iter::FromIterator};
|
||||
|
||||
use bumpalo::collections::vec::Vec;
|
||||
use roc_reporting::internal_error;
|
||||
use roc_error_macros::internal_error;
|
||||
|
||||
/// In the WebAssembly binary format, all integers are variable-length encoded (using LEB-128)
|
||||
/// A small value like 3 or 100 is encoded as 1 byte. The value 128 needs 2 bytes, etc.
|
||||
|
|
8
error_macros/Cargo.toml
Normal file
8
error_macros/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "roc_error_macros"
|
||||
version = "0.1.0"
|
||||
authors = ["The Roc Contributors"]
|
||||
license = "UPL-1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
31
error_macros/src/lib.rs
Normal file
31
error_macros/src/lib.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
/// `internal_error!` should be used whenever a compiler invariant is broken.
|
||||
/// It is a wrapper around panic that tells the user to file a bug.
|
||||
/// This should only be used in cases where there would be a compiler bug and the user can't fix it.
|
||||
/// If there is simply an unimplemented feature, please use `unimplemented!`
|
||||
/// If there is a user error, please use roc_reporting to print a nice error message.
|
||||
#[macro_export]
|
||||
macro_rules! internal_error {
|
||||
($($arg:tt)*) => ({
|
||||
eprintln!("An internal compiler expectation was broken.");
|
||||
eprintln!("This is definitely a compiler bug.");
|
||||
// TODO: update this to the new bug template.
|
||||
eprintln!("Please file an issue here: https://github.com/rtfeldman/roc/issues/new/choose");
|
||||
#[allow(clippy::panic)] {
|
||||
panic!($($arg)*);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// `user_error!` should only ever be used temporarily.
|
||||
/// It is a way to document locations where we do not yet have nice error reporting.
|
||||
/// All cases of `user_error!` should eventually be replaced with pretty error printing using roc_reporting.
|
||||
#[macro_export]
|
||||
macro_rules! user_error {
|
||||
($($arg:tt)*) => ({
|
||||
eprintln!("We ran into an issue while compiling your code.");
|
||||
eprintln!("Sadly, we don't havs a pretty error message for this case yet.");
|
||||
eprintln!("If you can't figure out the problem from the context below, please reach out at: https://roc.zulipchat.com/");
|
||||
eprintln!($($arg)*);
|
||||
std::process::exit(1);
|
||||
})
|
||||
}
|
|
@ -4,35 +4,3 @@
|
|||
|
||||
pub mod error;
|
||||
pub mod report;
|
||||
|
||||
/// `internal_error!` should be used whenever a compiler invariant is broken.
|
||||
/// It is a wrapper around panic that tells the user to file a bug.
|
||||
/// This should only be used in cases where there would be a compiler bug and the user can't fix it.
|
||||
/// If there is simply an unimplemented feature, please use `unimplemented!`
|
||||
/// If there is a user error, please use roc_reporting to print a nice error message.
|
||||
#[macro_export]
|
||||
macro_rules! internal_error {
|
||||
($($arg:tt)*) => ({
|
||||
eprintln!("An internal compiler expectation was broken.");
|
||||
eprintln!("This is definitely a compiler bug.");
|
||||
// TODO: update this to the new bug template.
|
||||
eprintln!("Please file an issue here: https://github.com/rtfeldman/roc/issues/new/choose");
|
||||
#[allow(clippy::panic)] {
|
||||
panic!($($arg)*);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// `user_error!` should only ever be used temporarily.
|
||||
/// It is a way to document locations where we do not yet have nice error reporting.
|
||||
/// All cases of `user_error!` should eventually be replaced with pretty error printing using roc_reporting.
|
||||
#[macro_export]
|
||||
macro_rules! user_error {
|
||||
($($arg:tt)*) => ({
|
||||
eprintln!("We ran into an issue while compiling your code.");
|
||||
eprintln!("Sadly, we don't havs a pretty error message for this case yet.");
|
||||
eprintln!("If you can't figure out the problem from the context below, please reach out at: https://roc.zulipchat.com/");
|
||||
eprintln!($($arg)*);
|
||||
std::process::exit(1);
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue