refactor(index): use static_assertions

This commit is contained in:
Boshen 2023-05-24 22:52:27 +08:00
parent c136fea535
commit a31c7ac77a
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
12 changed files with 68 additions and 84 deletions

1
Cargo.lock generated
View file

@ -1102,6 +1102,7 @@ name = "oxc_index"
version = "0.0.0"
dependencies = [
"index_vec",
"static_assertions",
]
[[package]]

View file

@ -36,45 +36,46 @@ oxc_semantic2 = { version = "0.0.0", path = "crates/oxc_semantic2" }
oxc_tasks_common = { path = "tasks/common" }
bitflags = { version = "2.2.1" }
bumpalo = { version = "3.12.2" }
clap = { version = "4.2.7", default-features = false, features = ["std"] }
compact_str = { version = "0.7.0" }
convert_case = { version = "0.6.0" }
criterion = { version = "0.4.0", default-features = false }
flate2 = { version = "1.0.26" }
glob = { version = "0.3.1" }
ignore = { version = "0.4.20" }
indextree = { version = "4.6.0" }
itertools = { version = "0.10.5" }
jemallocator = { version = "0.5.0" }
lazy_static = { version = "1.4.0" }
miette = { version = "5.8.0" }
mimalloc = { version = "0.1.37" }
num-bigint = { version = "0.4.3" }
num-traits = { version = "0.2.15" }
num_cpus = { version = "1.15.0" }
once_cell = { version = "1.17.1" }
phf = { version = "0.11" }
pico-args = { version = "0.5.0" }
proc-macro2 = { version = "1.0.56" }
project-root = { version = "0.2.2" }
quote = { version = "1.0.27" }
rayon = { version = "1.7.0" }
regex = { version = "1.8.1" }
rustc-hash = { version = "1.1.0", default-features = false, features = ["std"] }
ryu-js = { version = "0.2.2" }
serde = { version = "1.0.163" }
serde_json = { version = "1.0.96" }
syn = { version = "1.0.109" }
thiserror = { version = "1.0.40" }
tokio = { version = "1" }
unicode-id-start = { version = "1.1.0" }
ureq = { version = "2.6.2", default-features = false }
url = { version = "2.3.1" }
walkdir = { version = "2.3.3" }
indexmap = { version = "1.0.3" }
index_vec = { version = "0.1.3" }
bitflags = { version = "2.2.1" }
bumpalo = { version = "3.12.2" }
clap = { version = "4.2.7", default-features = false, features = ["std"] }
compact_str = { version = "0.7.0" }
convert_case = { version = "0.6.0" }
criterion = { version = "0.4.0", default-features = false }
flate2 = { version = "1.0.26" }
glob = { version = "0.3.1" }
ignore = { version = "0.4.20" }
indextree = { version = "4.6.0" }
itertools = { version = "0.10.5" }
jemallocator = { version = "0.5.0" }
lazy_static = { version = "1.4.0" }
miette = { version = "5.8.0" }
mimalloc = { version = "0.1.37" }
num-bigint = { version = "0.4.3" }
num-traits = { version = "0.2.15" }
num_cpus = { version = "1.15.0" }
once_cell = { version = "1.17.1" }
phf = { version = "0.11" }
pico-args = { version = "0.5.0" }
proc-macro2 = { version = "1.0.56" }
project-root = { version = "0.2.2" }
quote = { version = "1.0.27" }
rayon = { version = "1.7.0" }
regex = { version = "1.8.1" }
rustc-hash = { version = "1.1.0", default-features = false, features = ["std"] }
ryu-js = { version = "0.2.2" }
serde = { version = "1.0.163" }
serde_json = { version = "1.0.96" }
syn = { version = "1.0.109" }
thiserror = { version = "1.0.40" }
tokio = { version = "1" }
unicode-id-start = { version = "1.1.0" }
ureq = { version = "2.6.2", default-features = false }
url = { version = "2.3.1" }
walkdir = { version = "2.3.3" }
indexmap = { version = "1.0.3" }
index_vec = { version = "0.1.3" }
static_assertions = { version = "1.1.0" }
[workspace.metadata.workspaces]
allow_branch = "main"

View file

@ -19,9 +19,9 @@ oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
oxc_index = { workspace = true }
bitflags = { workspace = true }
rustc-hash = { workspace = true }
num-bigint = { workspace = true }
bitflags = { workspace = true }
rustc-hash = { workspace = true }
num-bigint = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }

View file

@ -52,21 +52,18 @@ pub use crate::{
// Read `https://nnethercote.github.io/perf-book/type-sizes.html` for more details.
#[cfg(target_pointer_width = "64")]
mod size_asserts {
use oxc_index::static_assert_size;
use oxc_index::assert_eq_size;
#[allow(clippy::wildcard_imports)]
use crate::ast::*;
static_assert_size!(Statement, 16);
static_assert_size!(Expression, 16);
static_assert_size!(Declaration, 16);
static_assert_size!(BindingPatternKind, 16);
static_assert_size!(ModuleDeclaration, 16);
static_assert_size!(ClassElement, 16);
static_assert_size!(ExportDefaultDeclarationKind, 16);
static_assert_size!(AssignmentTargetPattern, 16);
static_assert_size!(AssignmentTargetMaybeDefault, 24);
static_assert_size!(AssignmentTargetProperty, 16);
static_assert_size!(TSLiteral, 16);
static_assert_size!(TSType, 16);
assert_eq_size!(crate::ast::Statement, [u8; 16]);
assert_eq_size!(crate::ast::Expression, [u8; 16]);
assert_eq_size!(crate::ast::Declaration, [u8; 16]);
assert_eq_size!(crate::ast::BindingPatternKind, [u8; 16]);
assert_eq_size!(crate::ast::ModuleDeclaration, [u8; 16]);
assert_eq_size!(crate::ast::ClassElement, [u8; 16]);
assert_eq_size!(crate::ast::ExportDefaultDeclarationKind, [u8; 16]);
assert_eq_size!(crate::ast::AssignmentTargetPattern, [u8; 16]);
assert_eq_size!(crate::ast::AssignmentTargetMaybeDefault, [u8; 24]);
assert_eq_size!(crate::ast::AssignmentTargetProperty, [u8; 16]);
assert_eq_size!(crate::ast::TSLiteral, [u8; 16]);
assert_eq_size!(crate::ast::TSType, [u8; 16]);
}

View file

@ -21,8 +21,8 @@ oxc_syntax = { workspace = true }
oxc_index = { workspace = true }
oxc_semantic2 = { workspace = true }
bitflags = { workspace = true }
num-bigint = { workspace = true }
bitflags = { workspace = true }
num-bigint = { workspace = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }

View file

@ -11,4 +11,5 @@ license.workspace = true
repository.workspace = true
[dependencies]
index_vec = { workspace = true }
index_vec = { workspace = true }
static_assertions = { workspace = true }

View file

@ -3,13 +3,4 @@
//! <https://github.com/rust-lang/rust/tree/master/compiler/rustc_index>
pub use index_vec::{define_index_type, index_vec, IndexSlice, IndexVec};
/// Type size assertion. The first argument is a type and the second argument is its expected size.
///
/// <https://github.com/rust-lang/rust/blob/c86e7fb60f5343041fd0c27d4affaf3261115666/compiler/rustc_index/src/lib.rs#L30-L36>
#[macro_export]
macro_rules! static_assert_size {
($ty:ty, $size:expr) => {
const _: [(); $size] = [(); std::mem::size_of::<$ty>()];
};
}
pub use static_assertions::*;

View file

@ -21,7 +21,7 @@ oxc_semantic2 = { workspace = true }
oxc_syntax = { workspace = true }
[dev-dependencies]
walkdir = { workspace = true }
walkdir = { workspace = true }
pico-args = { workspace = true }
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]

View file

@ -28,11 +28,9 @@ pub struct Token<'a> {
#[cfg(target_pointer_width = "64")]
mod size_asserts {
use oxc_index::static_assert_size;
use oxc_index::assert_eq_size;
use super::Token;
static_assert_size!(Token, 48);
assert_eq_size!(super::Token, [u8; 48]);
}
impl<'a> Token<'a> {

View file

@ -35,8 +35,8 @@ pub struct Symbol {
#[cfg(target_pointer_width = "64")]
mod size_asserts {
use oxc_index::static_assert_size;
static_assert_size!(super::Symbol, 88);
use oxc_index::assert_eq_size;
assert_eq_size!(super::Symbol, [u8; 88]);
}
bitflags! {

View file

@ -13,11 +13,6 @@ define_index_type! {
pub struct SymbolId = u32;
}
#[cfg(target_pointer_width = "64")]
mod size_asserts {
oxc_index::static_assert_size!(Option<super::SymbolId>, 8);
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SymbolFlags: u16 {

View file

@ -13,4 +13,4 @@ oxc_tasks_common = { workspace = true }
flate2 = { workspace = true }
humansize = "2.1.3"
brotlic = "0.8.1"
brotlic = "0.8.1"