diff --git a/Cargo.lock b/Cargo.lock index 7500ac6277..b530153d8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3592,6 +3592,7 @@ dependencies = [ "bumpalo", "lazy_static", "roc_collections", + "roc_error_macros", "roc_ident", "roc_region", "snafu", @@ -3608,6 +3609,7 @@ dependencies = [ "roc_builtins", "roc_can", "roc_collections", + "roc_error_macros", "roc_module", "roc_problem", "roc_region", @@ -3792,6 +3794,7 @@ version = "0.1.0" dependencies = [ "bumpalo", "roc_collections", + "roc_error_macros", "roc_module", "roc_region", "static_assertions", diff --git a/compiler/module/Cargo.toml b/compiler/module/Cargo.toml index c05ca69ed1..9b8c272d54 100644 --- a/compiler/module/Cargo.toml +++ b/compiler/module/Cargo.toml @@ -9,6 +9,7 @@ license = "UPL-1.0" roc_region = { path = "../region" } roc_ident = { path = "../ident" } roc_collections = { path = "../collections" } +roc_error_macros = {path = "../../error_macros"} bumpalo = { version = "3.8.0", features = ["collections"] } lazy_static = "1.4.0" static_assertions = "1.1.0" diff --git a/compiler/module/src/ident.rs b/compiler/module/src/ident.rs index 4f4cb22196..73a5fc9737 100644 --- a/compiler/module/src/ident.rs +++ b/compiler/module/src/ident.rs @@ -59,7 +59,9 @@ pub enum TagName { Closure(Symbol), } -static_assertions::assert_eq_size!((usize, usize, u64), TagName); +roc_error_macros::assert_sizeof_aarch64!(TagName, 24); +roc_error_macros::assert_sizeof_wasm!(TagName, 16); +roc_error_macros::assert_sizeof_default!(TagName, 24); impl TagName { pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr { diff --git a/compiler/mono/Cargo.toml b/compiler/mono/Cargo.toml index 969bd4e256..5bdf3723fa 100644 --- a/compiler/mono/Cargo.toml +++ b/compiler/mono/Cargo.toml @@ -17,6 +17,7 @@ roc_std = { path = "../../roc_std" } roc_problem = { path = "../problem" } roc_builtins = { path = "../builtins" } roc_target = { path = "../roc_target" } +roc_error_macros = {path="../../error_macros"} ven_pretty = { path = "../../vendor/pretty" } morphic_lib = { path = "../../vendor/morphic_lib" } bumpalo = { version = "3.8.0", features = ["collections"] } diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 01b0a78389..0e0c39019a 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -34,18 +34,26 @@ pub fn pretty_print_ir_symbols() -> bool { // if it went up, maybe check that the change is really required // i128 alignment is different on arm -#[cfg(target_arch = "aarch64")] -static_assertions::assert_eq_size!([u64; 4], Literal); -#[cfg(not(target_arch = "aarch64"))] -static_assertions::assert_eq_size!([u64; 3], Literal); -static_assertions::assert_eq_size!(([u64; 4], [usize; 6]), Expr); -#[cfg(not(target_arch = "aarch64"))] -static_assertions::assert_eq_size!(([u64; 5], [usize; 14]), Stmt); -#[cfg(target_arch = "aarch64")] -static_assertions::assert_eq_size!([u64; 20], Stmt); -static_assertions::assert_eq_size!([usize; 6], ProcLayout); -static_assertions::assert_eq_size!(([u64; 3], [usize; 4]), Call); -static_assertions::assert_eq_size!(([u64; 3], [usize; 2]), CallType); +roc_error_macros::assert_sizeof_aarch64!(Literal, 4 * 8); +roc_error_macros::assert_sizeof_aarch64!(Expr, 10 * 8); +roc_error_macros::assert_sizeof_aarch64!(Stmt, 20 * 8); +roc_error_macros::assert_sizeof_aarch64!(ProcLayout, 6 * 8); +roc_error_macros::assert_sizeof_aarch64!(Call, 7 * 8); +roc_error_macros::assert_sizeof_aarch64!(CallType, 5 * 8); + +roc_error_macros::assert_sizeof_wasm!(Literal, 24); +roc_error_macros::assert_sizeof_wasm!(Expr, 56); +roc_error_macros::assert_sizeof_wasm!(Stmt, 96); +roc_error_macros::assert_sizeof_wasm!(ProcLayout, 24); +roc_error_macros::assert_sizeof_wasm!(Call, 40); +roc_error_macros::assert_sizeof_wasm!(CallType, 32); + +roc_error_macros::assert_sizeof_default!(Literal, 3 * 8); +roc_error_macros::assert_sizeof_default!(Expr, 10 * 8); +roc_error_macros::assert_sizeof_default!(Stmt, 19 * 8); +roc_error_macros::assert_sizeof_default!(ProcLayout, 6 * 8); +roc_error_macros::assert_sizeof_default!(Call, 7 * 8); +roc_error_macros::assert_sizeof_default!(CallType, 5 * 8); macro_rules! return_on_layout_error { ($env:expr, $layout_result:expr) => { diff --git a/compiler/types/Cargo.toml b/compiler/types/Cargo.toml index 97cd23ac45..550cb5f333 100644 --- a/compiler/types/Cargo.toml +++ b/compiler/types/Cargo.toml @@ -9,6 +9,7 @@ edition = "2018" roc_collections = { path = "../collections" } roc_region = { path = "../region" } roc_module = { path = "../module" } +roc_error_macros = {path="../../error_macros"} ven_ena = { path = "../../vendor/ena" } bumpalo = { version = "3.8.0", features = ["collections"] } static_assertions = "1.1.0" diff --git a/compiler/types/src/subs.rs b/compiler/types/src/subs.rs index 051845d03b..7dac3c50c7 100644 --- a/compiler/types/src/subs.rs +++ b/compiler/types/src/subs.rs @@ -9,12 +9,15 @@ use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey}; // if your changes cause this number to go down, great! // please change it to the lower number. // if it went up, maybe check that the change is really required -static_assertions::assert_eq_size!([u64; 6], Descriptor); -static_assertions::assert_eq_size!([u64; 4], Content); -static_assertions::assert_eq_size!([u64; 3], FlatType); -static_assertions::assert_eq_size!(([usize; 4], [u64; 2]), Problem); -static_assertions::assert_eq_size!([u8; 12], UnionTags); -static_assertions::assert_eq_size!([u64; 2], RecordFields); +roc_error_macros::assert_sizeof_all!(Descriptor, 6 * 8); +roc_error_macros::assert_sizeof_all!(Content, 4 * 8); +roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8); +roc_error_macros::assert_sizeof_all!(UnionTags, 12); +roc_error_macros::assert_sizeof_all!(RecordFields, 2 * 8); + +roc_error_macros::assert_sizeof_aarch64!(Problem, 6 * 8); +roc_error_macros::assert_sizeof_wasm!(Problem, 32); +roc_error_macros::assert_sizeof_default!(Problem, 6 * 8); #[derive(Clone, Copy, Hash, PartialEq, Eq)] pub struct Mark(i32); @@ -1623,11 +1626,14 @@ impl From for Descriptor { } } -static_assertions::assert_eq_size!([u64; 4], Content); -static_assertions::assert_eq_size!([usize; 4], (Variable, Option)); -static_assertions::assert_eq_size!([u64; 3], (Symbol, AliasVariables, Variable)); -static_assertions::assert_eq_size!([u8; 8], AliasVariables); -static_assertions::assert_eq_size!([u64; 3], FlatType); +roc_error_macros::assert_sizeof_all!(Content, 4 * 8); +roc_error_macros::assert_sizeof_all!((Symbol, AliasVariables, Variable), 3 * 8); +roc_error_macros::assert_sizeof_all!(AliasVariables, 8); +roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8); + +roc_error_macros::assert_sizeof_aarch64!((Variable, Option), 4 * 8); +roc_error_macros::assert_sizeof_wasm!((Variable, Option), 4 * 4); +roc_error_macros::assert_sizeof_all!((Variable, Option), 4 * 8); #[derive(Clone, Debug)] pub enum Content { @@ -1765,8 +1771,6 @@ impl Content { } } -static_assertions::assert_eq_size!([u64; 3], FlatType); - #[derive(Clone, Debug)] pub enum FlatType { Apply(Symbol, VariableSubsSlice), diff --git a/error_macros/src/lib.rs b/error_macros/src/lib.rs index d9b2e0e9a3..39aeca5aa0 100644 --- a/error_macros/src/lib.rs +++ b/error_macros/src/lib.rs @@ -29,3 +29,39 @@ macro_rules! user_error { std::process::exit(1); }) } + +/// Assert that a type has the expected size on ARM +#[macro_export] +macro_rules! assert_sizeof_aarch64 { + ($t: ty, $expected_size: expr) => { + #[cfg(target_arch = "aarch64")] + static_assertions::assert_eq_size!($t, [u8; $expected_size]); + }; +} + +/// Assert that a type has the expected size in Wasm +#[macro_export] +macro_rules! assert_sizeof_wasm { + ($t: ty, $expected_size: expr) => { + #[cfg(target_family = "wasm")] + static_assertions::assert_eq_size!($t, [u8; $expected_size]); + }; +} + +/// Assert that a type has the expected size on any target not covered above +/// In practice we use this for x86_64, and add specific macros for other platforms +#[macro_export] +macro_rules! assert_sizeof_default { + ($t: ty, $expected_size: expr) => { + #[cfg(not(any(target_family = "wasm", target_arch = "aarch64")))] + static_assertions::assert_eq_size!($t, [u8; $expected_size]); + }; +} + +/// Assert that a type has the expected size on all targets +#[macro_export] +macro_rules! assert_sizeof_all { + ($t: ty, $expected_size: expr) => { + static_assertions::assert_eq_size!($t, [u8; $expected_size]); + }; +}