mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
Use custom macros for static assertions
This commit is contained in:
parent
d8b76b317b
commit
c61a18a200
8 changed files with 82 additions and 26 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -3592,6 +3592,7 @@ dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
|
"roc_error_macros",
|
||||||
"roc_ident",
|
"roc_ident",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"snafu",
|
"snafu",
|
||||||
|
@ -3608,6 +3609,7 @@ dependencies = [
|
||||||
"roc_builtins",
|
"roc_builtins",
|
||||||
"roc_can",
|
"roc_can",
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
|
"roc_error_macros",
|
||||||
"roc_module",
|
"roc_module",
|
||||||
"roc_problem",
|
"roc_problem",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
|
@ -3792,6 +3794,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bumpalo",
|
"bumpalo",
|
||||||
"roc_collections",
|
"roc_collections",
|
||||||
|
"roc_error_macros",
|
||||||
"roc_module",
|
"roc_module",
|
||||||
"roc_region",
|
"roc_region",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
|
|
|
@ -9,6 +9,7 @@ license = "UPL-1.0"
|
||||||
roc_region = { path = "../region" }
|
roc_region = { path = "../region" }
|
||||||
roc_ident = { path = "../ident" }
|
roc_ident = { path = "../ident" }
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
|
roc_error_macros = {path = "../../error_macros"}
|
||||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
|
|
|
@ -59,7 +59,9 @@ pub enum TagName {
|
||||||
Closure(Symbol),
|
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 {
|
impl TagName {
|
||||||
pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr {
|
pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr {
|
||||||
|
|
|
@ -17,6 +17,7 @@ roc_std = { path = "../../roc_std" }
|
||||||
roc_problem = { path = "../problem" }
|
roc_problem = { path = "../problem" }
|
||||||
roc_builtins = { path = "../builtins" }
|
roc_builtins = { path = "../builtins" }
|
||||||
roc_target = { path = "../roc_target" }
|
roc_target = { path = "../roc_target" }
|
||||||
|
roc_error_macros = {path="../../error_macros"}
|
||||||
ven_pretty = { path = "../../vendor/pretty" }
|
ven_pretty = { path = "../../vendor/pretty" }
|
||||||
morphic_lib = { path = "../../vendor/morphic_lib" }
|
morphic_lib = { path = "../../vendor/morphic_lib" }
|
||||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||||
|
|
|
@ -34,18 +34,26 @@ pub fn pretty_print_ir_symbols() -> bool {
|
||||||
// if it went up, maybe check that the change is really required
|
// if it went up, maybe check that the change is really required
|
||||||
|
|
||||||
// i128 alignment is different on arm
|
// i128 alignment is different on arm
|
||||||
#[cfg(target_arch = "aarch64")]
|
roc_error_macros::assert_sizeof_aarch64!(Literal, 4 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 4], Literal);
|
roc_error_macros::assert_sizeof_aarch64!(Expr, 10 * 8);
|
||||||
#[cfg(not(target_arch = "aarch64"))]
|
roc_error_macros::assert_sizeof_aarch64!(Stmt, 20 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 3], Literal);
|
roc_error_macros::assert_sizeof_aarch64!(ProcLayout, 6 * 8);
|
||||||
static_assertions::assert_eq_size!(([u64; 4], [usize; 6]), Expr);
|
roc_error_macros::assert_sizeof_aarch64!(Call, 7 * 8);
|
||||||
#[cfg(not(target_arch = "aarch64"))]
|
roc_error_macros::assert_sizeof_aarch64!(CallType, 5 * 8);
|
||||||
static_assertions::assert_eq_size!(([u64; 5], [usize; 14]), Stmt);
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
roc_error_macros::assert_sizeof_wasm!(Literal, 24);
|
||||||
static_assertions::assert_eq_size!([u64; 20], Stmt);
|
roc_error_macros::assert_sizeof_wasm!(Expr, 56);
|
||||||
static_assertions::assert_eq_size!([usize; 6], ProcLayout);
|
roc_error_macros::assert_sizeof_wasm!(Stmt, 96);
|
||||||
static_assertions::assert_eq_size!(([u64; 3], [usize; 4]), Call);
|
roc_error_macros::assert_sizeof_wasm!(ProcLayout, 24);
|
||||||
static_assertions::assert_eq_size!(([u64; 3], [usize; 2]), CallType);
|
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 {
|
macro_rules! return_on_layout_error {
|
||||||
($env:expr, $layout_result:expr) => {
|
($env:expr, $layout_result:expr) => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ edition = "2018"
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
roc_region = { path = "../region" }
|
roc_region = { path = "../region" }
|
||||||
roc_module = { path = "../module" }
|
roc_module = { path = "../module" }
|
||||||
|
roc_error_macros = {path="../../error_macros"}
|
||||||
ven_ena = { path = "../../vendor/ena" }
|
ven_ena = { path = "../../vendor/ena" }
|
||||||
bumpalo = { version = "3.8.0", features = ["collections"] }
|
bumpalo = { version = "3.8.0", features = ["collections"] }
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
|
|
|
@ -9,12 +9,15 @@ use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey};
|
||||||
// if your changes cause this number to go down, great!
|
// if your changes cause this number to go down, great!
|
||||||
// please change it to the lower number.
|
// please change it to the lower number.
|
||||||
// if it went up, maybe check that the change is really required
|
// if it went up, maybe check that the change is really required
|
||||||
static_assertions::assert_eq_size!([u64; 6], Descriptor);
|
roc_error_macros::assert_sizeof_all!(Descriptor, 6 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 4], Content);
|
roc_error_macros::assert_sizeof_all!(Content, 4 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 3], FlatType);
|
roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8);
|
||||||
static_assertions::assert_eq_size!(([usize; 4], [u64; 2]), Problem);
|
roc_error_macros::assert_sizeof_all!(UnionTags, 12);
|
||||||
static_assertions::assert_eq_size!([u8; 12], UnionTags);
|
roc_error_macros::assert_sizeof_all!(RecordFields, 2 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 2], RecordFields);
|
|
||||||
|
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)]
|
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
|
||||||
pub struct Mark(i32);
|
pub struct Mark(i32);
|
||||||
|
@ -1623,11 +1626,14 @@ impl From<Content> for Descriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assertions::assert_eq_size!([u64; 4], Content);
|
roc_error_macros::assert_sizeof_all!(Content, 4 * 8);
|
||||||
static_assertions::assert_eq_size!([usize; 4], (Variable, Option<Lowercase>));
|
roc_error_macros::assert_sizeof_all!((Symbol, AliasVariables, Variable), 3 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 3], (Symbol, AliasVariables, Variable));
|
roc_error_macros::assert_sizeof_all!(AliasVariables, 8);
|
||||||
static_assertions::assert_eq_size!([u8; 8], AliasVariables);
|
roc_error_macros::assert_sizeof_all!(FlatType, 3 * 8);
|
||||||
static_assertions::assert_eq_size!([u64; 3], FlatType);
|
|
||||||
|
roc_error_macros::assert_sizeof_aarch64!((Variable, Option<Lowercase>), 4 * 8);
|
||||||
|
roc_error_macros::assert_sizeof_wasm!((Variable, Option<Lowercase>), 4 * 4);
|
||||||
|
roc_error_macros::assert_sizeof_all!((Variable, Option<Lowercase>), 4 * 8);
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Content {
|
pub enum Content {
|
||||||
|
@ -1765,8 +1771,6 @@ impl Content {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assertions::assert_eq_size!([u64; 3], FlatType);
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum FlatType {
|
pub enum FlatType {
|
||||||
Apply(Symbol, VariableSubsSlice),
|
Apply(Symbol, VariableSubsSlice),
|
||||||
|
|
|
@ -29,3 +29,39 @@ macro_rules! user_error {
|
||||||
std::process::exit(1);
|
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]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue