assert type sizes

This commit is contained in:
Folkert 2021-08-03 22:16:27 +02:00
parent d4896d3ed2
commit f301de5576
9 changed files with 17 additions and 21 deletions

2
Cargo.lock generated
View File

@ -3329,6 +3329,7 @@ dependencies = [
"roc_collections",
"roc_ident",
"roc_region",
"static_assertions",
]
[[package]]
@ -3461,6 +3462,7 @@ dependencies = [
"roc_collections",
"roc_module",
"roc_region",
"static_assertions",
"ven_ena",
]

View File

@ -1,5 +1,4 @@
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;

View File

@ -2,7 +2,6 @@
extern crate pretty_assertions;
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;

View File

@ -6,7 +6,6 @@ extern crate pretty_assertions;
extern crate maplit;
extern crate bumpalo;
extern crate inlinable_string;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;

View File

@ -11,6 +11,7 @@ roc_ident = { path = "../ident" }
roc_collections = { path = "../collections" }
bumpalo = { version = "3.6.1", features = ["collections"] }
lazy_static = "1.4"
static_assertions = "1.1.0"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -59,6 +59,8 @@ pub enum TagName {
Closure(Symbol),
}
static_assertions::assert_eq_size!([u8; 24], TagName);
impl TagName {
pub fn as_ident_str(&self, interns: &Interns, home: ModuleId) -> IdentStr {
match self {

View File

@ -4488,18 +4488,4 @@ mod solve_expr {
"RBTree {}",
);
}
#[test]
fn sizes() {
let query = (
std::mem::size_of::<roc_module::ident::TagName>(),
std::mem::size_of::<roc_types::subs::Descriptor>(),
std::mem::size_of::<roc_types::subs::Content>(),
std::mem::size_of::<roc_types::subs::FlatType>(),
std::mem::size_of::<roc_types::types::Problem>(),
);
// without RecordFields in FlatType assert_eq!((40, 72, 56, 48, 64), query)
assert_eq!((24, 104, 88, 80, 48), query)
}
}

View File

@ -10,6 +10,7 @@ roc_collections = { path = "../collections" }
roc_region = { path = "../region" }
roc_module = { path = "../module" }
ven_ena = { path = "../../vendor/ena" }
static_assertions = "1.1.0"
[dev-dependencies]
pretty_assertions = "0.5.1"

View File

@ -7,6 +7,13 @@ use std::fmt;
use std::iter::{once, Extend, FromIterator, Iterator, Map, Zip};
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!([u8; 104], Descriptor);
static_assertions::assert_eq_size!([u8; 88], Content);
static_assertions::assert_eq_size!([u8; 80], FlatType);
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct Mark(i32);
@ -494,7 +501,7 @@ fn unnamed_flex_var() -> Content {
}
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Rank(usize);
pub struct Rank(u32);
impl Rank {
pub const NONE: Rank = Rank(0);
@ -508,7 +515,7 @@ impl Rank {
}
pub fn into_usize(self) -> usize {
self.0
self.0 as usize
}
}
@ -526,13 +533,13 @@ impl fmt::Debug for Rank {
impl From<Rank> for usize {
fn from(rank: Rank) -> Self {
rank.0
rank.0 as usize
}
}
impl From<usize> for Rank {
fn from(index: usize) -> Self {
Rank(index)
Rank(index as u32)
}
}