From 39b5bffb75364635651f99fced06ff926646ad4e Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Wed, 29 Jan 2025 19:49:26 +0800 Subject: [PATCH 1/3] bump inventory 0.1 -> 0.3 --- Cargo.lock | 44 +++---------------- Cargo.toml | 2 +- crates/rspack_cacheable/Cargo.toml | 1 + crates/rspack_cacheable/src/dyn/mod.rs | 36 ++++++++------- crates/rspack_cacheable/src/dyn/validation.rs | 7 +-- crates/rspack_cacheable/src/dyn/vtable_ptr.rs | 16 +++++++ crates/rspack_cacheable/src/lib.rs | 1 + crates/rspack_cacheable_test/Cargo.toml | 1 + .../tests/macro/manual_cacheable_dyn.rs | 38 ++++++---------- .../manual_cacheable_dyn_with_generics.rs | 38 ++++++---------- crates/rspack_macros/src/cacheable_dyn.rs | 22 ++++------ 11 files changed, 86 insertions(+), 120 deletions(-) create mode 100644 crates/rspack_cacheable/src/dyn/vtable_ptr.rs diff --git a/Cargo.lock b/Cargo.lock index d8b5a4c3a514..13db92f0e150 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1145,16 +1145,6 @@ dependencies = [ "syn 2.0.95", ] -[[package]] -name = "ctor" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" -dependencies = [ - "quote", - "syn 1.0.109", -] - [[package]] name = "ctor" version = "0.2.9" @@ -1886,17 +1876,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "ghost" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39b697dbd8bfcc35d0ee91698aaa379af096368ba8837d279cc097b276edda45" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.95", -] - [[package]] name = "gimli" version = "0.28.1" @@ -2487,24 +2466,11 @@ dependencies = [ [[package]] name = "inventory" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4" -dependencies = [ - "ctor 0.1.26", - "ghost", - "inventory-impl", -] - -[[package]] -name = "inventory-impl" -version = "0.1.11" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548" +checksum = "3b31349d02fe60f80bbbab1a9402364cad7460626d6030494b08ac4a2075bf81" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "rustversion", ] [[package]] @@ -3045,7 +3011,7 @@ checksum = "5de0beff58a431b3bd6568b690bcf55d72d8dd7f8e0e613a0193a8a9a8eef26b" dependencies = [ "anyhow", "bitflags 2.6.0", - "ctor 0.2.9", + "ctor", "napi-build", "napi-sys", "serde", @@ -4320,6 +4286,7 @@ dependencies = [ "smol_str", "swc_core", "ustr-fxhash", + "xxhash-rust", ] [[package]] @@ -4338,6 +4305,7 @@ dependencies = [ "serde_json", "swc_core", "ustr-fxhash", + "xxhash-rust", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index cf6cbe431412..0168784d51b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,7 @@ napi-build = { version = "2.1.4" } napi-derive = { version = "3.0.0-alpha.22" } # Serialize and Deserialize -inventory = { version = "=0.1" } +inventory = { version = "0.3.17" } rkyv = { version = "=0.8.8" } # Must be pinned with the same swc versions diff --git a/crates/rspack_cacheable/Cargo.toml b/crates/rspack_cacheable/Cargo.toml index 9dee325c149a..e7a9f69b6009 100644 --- a/crates/rspack_cacheable/Cargo.toml +++ b/crates/rspack_cacheable/Cargo.toml @@ -26,3 +26,4 @@ serde_json = { workspace = true } smol_str = { workspace = true } swc_core = { workspace = true, features = ["ecma_ast"] } ustr = { workspace = true } +xxhash-rust = { workspace = true, features = ["const_xxh64"] } diff --git a/crates/rspack_cacheable/src/dyn/mod.rs b/crates/rspack_cacheable/src/dyn/mod.rs index 1e0f49c8dd45..41a519bf9dd3 100644 --- a/crates/rspack_cacheable/src/dyn/mod.rs +++ b/crates/rspack_cacheable/src/dyn/mod.rs @@ -14,6 +14,10 @@ use rkyv::{ }; pub mod validation; +mod vtable_ptr; + +pub use vtable_ptr::VTablePtr; + use crate::{DeserializeError, Deserializer, SerializeError, Serializer}; /// A trait object that can be archived. @@ -140,35 +144,35 @@ impl ArchivedDynMetadata { /// Returns the pointer metadata for the trait object this metadata refers to. pub fn lookup_metadata(&self) -> DynMetadata { unsafe { - std::mem::transmute( - *DYN_REGISTRY - .get(&self.dyn_id.to_native()) - .expect("attempted to get vtable for an unregistered impl"), - ) + DYN_REGISTRY + .get(&self.dyn_id.to_native()) + .expect("attempted to get vtable for an unregistered impl") + .cast() } } } pub struct DynEntry { dyn_id: u64, - vtable: usize, + vtable: VTablePtr, } impl DynEntry { - pub fn new(dyn_id: u64, vtable: usize) -> Self { + pub const fn new(dyn_id: u64, vtable: VTablePtr) -> Self { Self { dyn_id, vtable } } } inventory::collect!(DynEntry); -static DYN_REGISTRY: std::sync::LazyLock> = std::sync::LazyLock::new(|| { - let mut result = HashMap::default(); - for entry in inventory::iter:: { - let old_value = result.insert(entry.dyn_id, entry.vtable); - if old_value.is_some() { - panic!("cacheable_dyn init global REGISTRY error, duplicate implementation.") +static DYN_REGISTRY: std::sync::LazyLock> = + std::sync::LazyLock::new(|| { + let mut result = HashMap::default(); + for entry in inventory::iter:: { + let old_value = result.insert(entry.dyn_id, entry.vtable); + if old_value.is_some() { + panic!("cacheable_dyn init global REGISTRY error, duplicate implementation.") + } } - } - result -}); + result + }); diff --git a/crates/rspack_cacheable/src/dyn/validation.rs b/crates/rspack_cacheable/src/dyn/validation.rs index 157b47aeadf7..c5986e3e8452 100644 --- a/crates/rspack_cacheable/src/dyn/validation.rs +++ b/crates/rspack_cacheable/src/dyn/validation.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use rkyv::bytecheck::CheckBytes; +use super::VTablePtr; use crate::{DeserializeError, Validator}; type CheckBytesDyn = unsafe fn(*const u8, &mut Validator<'_>) -> Result<(), DeserializeError>; @@ -20,13 +21,13 @@ where } pub struct CheckBytesEntry { - vtable: usize, + vtable: VTablePtr, check_bytes_dyn: CheckBytesDyn, } impl CheckBytesEntry { #[doc(hidden)] - pub fn new(vtable: usize, check_bytes_dyn: CheckBytesDyn) -> Self { + pub const fn new(vtable: VTablePtr, check_bytes_dyn: CheckBytesDyn) -> Self { Self { vtable, check_bytes_dyn, @@ -36,7 +37,7 @@ impl CheckBytesEntry { inventory::collect!(CheckBytesEntry); -pub static CHECK_BYTES_REGISTRY: std::sync::LazyLock> = +pub static CHECK_BYTES_REGISTRY: std::sync::LazyLock> = std::sync::LazyLock::new(|| { let mut result = HashMap::default(); for entry in inventory::iter:: { diff --git a/crates/rspack_cacheable/src/dyn/vtable_ptr.rs b/crates/rspack_cacheable/src/dyn/vtable_ptr.rs new file mode 100644 index 000000000000..8d64388fdcdf --- /dev/null +++ b/crates/rspack_cacheable/src/dyn/vtable_ptr.rs @@ -0,0 +1,16 @@ +use rkyv::ptr_meta::DynMetadata; + +/// A untyped wrapper for vtable +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +pub struct VTablePtr(DynMetadata<()>); + +impl VTablePtr { + pub const unsafe fn new(vtable: DynMetadata) -> Self { + Self(core::mem::transmute(vtable)) + } + pub const unsafe fn cast(self) -> DynMetadata { + core::mem::transmute(self.0) + } +} +unsafe impl Send for VTablePtr {} +unsafe impl Sync for VTablePtr {} diff --git a/crates/rspack_cacheable/src/lib.rs b/crates/rspack_cacheable/src/lib.rs index 9d09d29b261c..154acf916336 100644 --- a/crates/rspack_cacheable/src/lib.rs +++ b/crates/rspack_cacheable/src/lib.rs @@ -19,3 +19,4 @@ pub mod __private { pub use deserialize::{from_bytes, DeserializeError, Deserializer, Validator}; pub use serialize::{to_bytes, SerializeError, Serializer}; +pub use xxhash_rust; diff --git a/crates/rspack_cacheable_test/Cargo.toml b/crates/rspack_cacheable_test/Cargo.toml index 04b383675714..6a48b76c271a 100644 --- a/crates/rspack_cacheable_test/Cargo.toml +++ b/crates/rspack_cacheable_test/Cargo.toml @@ -21,3 +21,4 @@ rustc-hash = { workspace = true } serde_json = { workspace = true } swc_core = { workspace = true, features = ["ecma_ast"] } ustr = { workspace = true } +xxhash-rust = { workspace = true, features = ["const_xxh64"] } diff --git a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs index cac51e1ac587..316c0ebeedf0 100644 --- a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs +++ b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs @@ -1,4 +1,4 @@ -use rspack_cacheable::{cacheable, from_bytes, to_bytes}; +use rspack_cacheable::{cacheable, from_bytes, r#dyn::VTablePtr, to_bytes}; #[test] #[cfg_attr(miri, ignore)] @@ -99,7 +99,7 @@ fn test_manual_cacheable_dyn_macro() { value: *const Self, context: &mut Validator, ) -> Result<(), DeserializeError> { - let vtable: usize = std::mem::transmute(ptr_meta::metadata(value)); + let vtable = VTablePtr::new(ptr_meta::metadata(value)); if let Some(check_bytes_dyn) = CHECK_BYTES_REGISTRY.get(&vtable) { check_bytes_dyn(value.cast(), context)?; Ok(()) @@ -115,13 +115,8 @@ fn test_manual_cacheable_dyn_macro() { color: String, } - static __DYN_ID_DOG_ANIMAL: std::sync::LazyLock = std::sync::LazyLock::new(|| { - use std::hash::{DefaultHasher, Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - module_path!().hash(&mut hasher); - line!().hash(&mut hasher); - hasher.finish() - }); + const __DYN_ID_DOG_ANIMAL: u64 = + xxhash_rust::const_xxh64::xxh64(concat!(module_path!(), ":", line!()).as_bytes(), 0); impl Animal for Dog { fn color(&self) -> &str { @@ -132,7 +127,7 @@ fn test_manual_cacheable_dyn_macro() { } fn __dyn_id(&self) -> u64 { - *__DYN_ID_DOG_ANIMAL + __DYN_ID_DOG_ANIMAL } } @@ -149,14 +144,14 @@ fn test_manual_cacheable_dyn_macro() { DeserializeError, Deserializer, }; - fn get_vtable() -> usize { + const fn get_vtable() -> VTablePtr { unsafe { - core::mem::transmute(ptr_meta::metadata( + VTablePtr::new(ptr_meta::metadata( core::ptr::null::>() as *const ::Archived )) } } - inventory::submit! { DynEntry::new(*__DYN_ID_DOG_ANIMAL, get_vtable()) } + inventory::submit! { DynEntry::new(__DYN_ID_DOG_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } impl DeserializeDyn for ArchivedDog @@ -184,13 +179,8 @@ fn test_manual_cacheable_dyn_macro() { color: String, } - static __DYN_ID_CAT_ANIMAL: std::sync::LazyLock = std::sync::LazyLock::new(|| { - use std::hash::{DefaultHasher, Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - module_path!().hash(&mut hasher); - line!().hash(&mut hasher); - hasher.finish() - }); + const __DYN_ID_CAT_ANIMAL: u64 = + xxhash_rust::const_xxh64::xxh64(concat!(module_path!(), ":", line!()).as_bytes(), 0); impl Animal for Cat { fn color(&self) -> &str { @@ -201,7 +191,7 @@ fn test_manual_cacheable_dyn_macro() { } fn __dyn_id(&self) -> u64 { - *__DYN_ID_CAT_ANIMAL + __DYN_ID_CAT_ANIMAL } } @@ -218,14 +208,14 @@ fn test_manual_cacheable_dyn_macro() { DeserializeError, Deserializer, }; - fn get_vtable() -> usize { + const fn get_vtable() -> VTablePtr { unsafe { - core::mem::transmute(ptr_meta::metadata( + VTablePtr::new(ptr_meta::metadata( core::ptr::null::>() as *const ::Archived )) } } - inventory::submit! { DynEntry::new(*__DYN_ID_CAT_ANIMAL, get_vtable()) } + inventory::submit! { DynEntry::new(__DYN_ID_CAT_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } impl DeserializeDyn for ArchivedCat diff --git a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs index 26ae3577a471..003566af3438 100644 --- a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs +++ b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs @@ -1,4 +1,4 @@ -use rspack_cacheable::{cacheable, from_bytes, to_bytes}; +use rspack_cacheable::{cacheable, from_bytes, r#dyn::VTablePtr, to_bytes}; #[test] #[cfg_attr(miri, ignore)] @@ -99,7 +99,7 @@ fn test_manual_cacheable_dyn_macro_with_generics() { value: *const Self, context: &mut Validator, ) -> Result<(), DeserializeError> { - let vtable: usize = std::mem::transmute(ptr_meta::metadata(value)); + let vtable = VTablePtr::new(ptr_meta::metadata(value)); if let Some(check_bytes_dyn) = CHECK_BYTES_REGISTRY.get(&vtable) { check_bytes_dyn(value.cast(), context)?; Ok(()) @@ -115,13 +115,8 @@ fn test_manual_cacheable_dyn_macro_with_generics() { color: String, } - static __DYN_ID_DOG_ANIMAL: std::sync::LazyLock = std::sync::LazyLock::new(|| { - use std::hash::{DefaultHasher, Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - module_path!().hash(&mut hasher); - line!().hash(&mut hasher); - hasher.finish() - }); + const __DYN_ID_DOG_ANIMAL: u64 = + xxhash_rust::const_xxh64::xxh64(concat!(module_path!(), ":", line!()).as_bytes(), 0); impl Animal<&'static str> for Dog { fn color(&self) -> &str { @@ -131,7 +126,7 @@ fn test_manual_cacheable_dyn_macro_with_generics() { "dog" } fn __dyn_id(&self) -> u64 { - *__DYN_ID_DOG_ANIMAL + __DYN_ID_DOG_ANIMAL } } @@ -148,13 +143,13 @@ fn test_manual_cacheable_dyn_macro_with_generics() { DeserializeError, Deserializer, }; - fn get_vtable() -> usize { + const fn get_vtable() -> VTablePtr { unsafe { - core::mem::transmute(ptr_meta::metadata(core::ptr::null::>() + VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() as *const as ArchiveUnsized>::Archived)) } } - inventory::submit! { DynEntry::new(*__DYN_ID_DOG_ANIMAL, get_vtable()) } + inventory::submit! { DynEntry::new(__DYN_ID_DOG_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } impl DeserializeDyn> for ArchivedDog @@ -182,13 +177,8 @@ fn test_manual_cacheable_dyn_macro_with_generics() { color: String, } - static __DYN_ID_CAT_ANIMAL: std::sync::LazyLock = std::sync::LazyLock::new(|| { - use std::hash::{DefaultHasher, Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - module_path!().hash(&mut hasher); - line!().hash(&mut hasher); - hasher.finish() - }); + const __DYN_ID_CAT_ANIMAL: u64 = + xxhash_rust::const_xxh64::xxh64(concat!(module_path!(), ":", line!()).as_bytes(), 0); impl Animal for Cat { fn color(&self) -> &str { @@ -198,7 +188,7 @@ fn test_manual_cacheable_dyn_macro_with_generics() { String::from("cat") } fn __dyn_id(&self) -> u64 { - *__DYN_ID_CAT_ANIMAL + __DYN_ID_CAT_ANIMAL } } @@ -215,13 +205,13 @@ fn test_manual_cacheable_dyn_macro_with_generics() { DeserializeError, Deserializer, }; - fn get_vtable() -> usize { + const fn get_vtable() -> VTablePtr { unsafe { - core::mem::transmute(ptr_meta::metadata(core::ptr::null::>() + VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() as *const as ArchiveUnsized>::Archived)) } } - inventory::submit! { DynEntry::new(*__DYN_ID_CAT_ANIMAL, get_vtable()) } + inventory::submit! { DynEntry::new(__DYN_ID_CAT_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>)} impl DeserializeDyn> for ArchivedCat diff --git a/crates/rspack_macros/src/cacheable_dyn.rs b/crates/rspack_macros/src/cacheable_dyn.rs index 6e8b31ff1b17..fb82eb7d5733 100644 --- a/crates/rspack_macros/src/cacheable_dyn.rs +++ b/crates/rspack_macros/src/cacheable_dyn.rs @@ -42,7 +42,7 @@ pub fn impl_trait(mut input: ItemTrait) -> TokenStream { ArchiveUnsized, ArchivedMetadata, DeserializeUnsized, Portable, SerializeUnsized, }; use rspack_cacheable::{ - r#dyn::{validation::CHECK_BYTES_REGISTRY, ArchivedDynMetadata, DeserializeDyn}, + r#dyn::{validation::CHECK_BYTES_REGISTRY, ArchivedDynMetadata, DeserializeDyn, VTablePtr}, DeserializeError, Deserializer, SerializeError, Serializer, Validator, }; @@ -122,7 +122,7 @@ pub fn impl_trait(mut input: ItemTrait) -> TokenStream { value: *const Self, context: &mut Validator, ) -> Result<(), DeserializeError> { - let vtable: usize = std::mem::transmute(ptr_meta::metadata(value)); + let vtable = VTablePtr::new(ptr_meta::metadata(value)); if let Some(check_bytes_dyn) = CHECK_BYTES_REGISTRY.get(&vtable) { check_bytes_dyn(value.cast(), context)?; Ok(()) @@ -181,18 +181,12 @@ pub fn impl_impl(mut input: ItemImpl) -> TokenStream { input.items.push(parse_quote! { fn __dyn_id(&self) -> u64 { - *#dyn_id_ident + #dyn_id_ident } }); quote! { - static #dyn_id_ident: std::sync::LazyLock = std::sync::LazyLock::new(|| { - use std::hash::{DefaultHasher, Hash, Hasher}; - let mut hasher = DefaultHasher::new(); - module_path!().hash(&mut hasher); - line!().hash(&mut hasher); - hasher.finish() - }); + const #dyn_id_ident: u64 = rspack_cacheable::xxhash_rust::const_xxh64::xxh64(concat!(module_path!(), ":", line!()).as_bytes(), 0); #input @@ -204,19 +198,19 @@ pub fn impl_impl(mut input: ItemImpl) -> TokenStream { use rspack_cacheable::{ r#dyn::{ validation::{default_check_bytes_dyn, CheckBytesEntry}, - DeserializeDyn, DynEntry, + DeserializeDyn, DynEntry, VTablePtr, }, DeserializeError, Deserializer, }; - fn get_vtable() -> usize { + const fn get_vtable() -> VTablePtr { unsafe { - core::mem::transmute(ptr_meta::metadata( + VTablePtr::new(ptr_meta::metadata( core::ptr::null::>() as *const ::Archived )) } } - inventory::submit! { DynEntry::new(*#dyn_id_ident, get_vtable()) } + inventory::submit! { DynEntry::new(#dyn_id_ident, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } impl DeserializeDyn for #archived_target_ident From a3fc80e09de749bff68cc64404cecde5d4ef00f3 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Wed, 5 Feb 2025 18:08:22 +0800 Subject: [PATCH 2/3] Fix clippy --- crates/rspack_cacheable/src/dyn/vtable_ptr.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/rspack_cacheable/src/dyn/vtable_ptr.rs b/crates/rspack_cacheable/src/dyn/vtable_ptr.rs index 8d64388fdcdf..84ccc900565b 100644 --- a/crates/rspack_cacheable/src/dyn/vtable_ptr.rs +++ b/crates/rspack_cacheable/src/dyn/vtable_ptr.rs @@ -5,9 +5,14 @@ use rkyv::ptr_meta::DynMetadata; pub struct VTablePtr(DynMetadata<()>); impl VTablePtr { - pub const unsafe fn new(vtable: DynMetadata) -> Self { - Self(core::mem::transmute(vtable)) + pub const fn new(vtable: DynMetadata) -> Self { + // Creating VTablePtr is safe while using it is unsafe, just like raw pointers in rust. + Self(unsafe { core::mem::transmute::, DynMetadata<()>>(vtable) }) } + + /// # Safety + /// The casting target `T` must be consistent with the `T` in VTablePtr::new + /// Currently it is implemented by store VTablePtr as values in HashMap to associate the types with __DYN_ID pub const unsafe fn cast(self) -> DynMetadata { core::mem::transmute(self.0) } From fb425ceef58203ac4867449d3dd02c22d6369a19 Mon Sep 17 00:00:00 2001 From: CPunisher <1343316114@qq.com> Date: Wed, 5 Feb 2025 18:57:21 +0800 Subject: [PATCH 3/3] Remove unnecessary unsafe --- .../tests/macro/manual_cacheable_dyn.rs | 16 ++++++---------- .../macro/manual_cacheable_dyn_with_generics.rs | 12 ++++-------- crates/rspack_macros/src/cacheable_dyn.rs | 8 +++----- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs index 316c0ebeedf0..5c0d94ec6914 100644 --- a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs +++ b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn.rs @@ -145,11 +145,9 @@ fn test_manual_cacheable_dyn_macro() { }; const fn get_vtable() -> VTablePtr { - unsafe { - VTablePtr::new(ptr_meta::metadata( - core::ptr::null::>() as *const ::Archived - )) - } + VTablePtr::new(ptr_meta::metadata( + core::ptr::null::>() as *const ::Archived + )) } inventory::submit! { DynEntry::new(__DYN_ID_DOG_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } @@ -209,11 +207,9 @@ fn test_manual_cacheable_dyn_macro() { }; const fn get_vtable() -> VTablePtr { - unsafe { - VTablePtr::new(ptr_meta::metadata( - core::ptr::null::>() as *const ::Archived - )) - } + VTablePtr::new(ptr_meta::metadata( + core::ptr::null::>() as *const ::Archived + )) } inventory::submit! { DynEntry::new(__DYN_ID_CAT_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } diff --git a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs index 003566af3438..2a3f267c406f 100644 --- a/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs +++ b/crates/rspack_cacheable_test/tests/macro/manual_cacheable_dyn_with_generics.rs @@ -144,10 +144,8 @@ fn test_manual_cacheable_dyn_macro_with_generics() { }; const fn get_vtable() -> VTablePtr { - unsafe { - VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() - as *const as ArchiveUnsized>::Archived)) - } + VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() + as *const as ArchiveUnsized>::Archived)) } inventory::submit! { DynEntry::new(__DYN_ID_DOG_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) } @@ -206,10 +204,8 @@ fn test_manual_cacheable_dyn_macro_with_generics() { }; const fn get_vtable() -> VTablePtr { - unsafe { - VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() - as *const as ArchiveUnsized>::Archived)) - } + VTablePtr::new(ptr_meta::metadata(core::ptr::null::>() + as *const as ArchiveUnsized>::Archived)) } inventory::submit! { DynEntry::new(__DYN_ID_CAT_ANIMAL, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>)} diff --git a/crates/rspack_macros/src/cacheable_dyn.rs b/crates/rspack_macros/src/cacheable_dyn.rs index fb82eb7d5733..64487939ede4 100644 --- a/crates/rspack_macros/src/cacheable_dyn.rs +++ b/crates/rspack_macros/src/cacheable_dyn.rs @@ -204,11 +204,9 @@ pub fn impl_impl(mut input: ItemImpl) -> TokenStream { }; const fn get_vtable() -> VTablePtr { - unsafe { - VTablePtr::new(ptr_meta::metadata( - core::ptr::null::>() as *const ::Archived - )) - } + VTablePtr::new(ptr_meta::metadata( + core::ptr::null::>() as *const ::Archived + )) } inventory::submit! { DynEntry::new(#dyn_id_ident, get_vtable()) } inventory::submit! { CheckBytesEntry::new(get_vtable(), default_check_bytes_dyn::>) }