Skip to content

Commit

Permalink
fix: align bytes ptr address for cacheable::from_byte (web-infra-de…
Browse files Browse the repository at this point in the history
…v#8450)

* fix: cacheable::from_byte align bytes ptr address

* ci: miri test add env MIRIFLAGS
  • Loading branch information
jerrykingxyz authored Nov 15, 2024
1 parent d84e931 commit 425deee
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ jobs:
echo 'debug = false' >> Cargo.toml
- name: Run test
env:
MIRIFLAGS: -Zmiri-tree-borrows -Zmiri-disable-isolation
# reason for excluding https://github.com/napi-rs/napi-rs/issues/2200
run: cargo miri test --workspace --exclude rspack_binding_options --exclude rspack_node -- --nocapture

Expand Down
8 changes: 7 additions & 1 deletion crates/rspack_cacheable/src/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rkyv::{
bytecheck::CheckBytes,
de::Pool,
rancor::{BoxedError, Source, Strategy, Trace},
util::AlignedVec,
Archive, Deserialize,
};

Expand Down Expand Up @@ -79,8 +80,13 @@ where
let guard = ContextGuard::new(context);
let mut deserializer = Pool::default();
guard.add_to_pooling(&mut deserializer)?;
// The `bytes` ptr address in miri will throw UnalignedPointer error in rkyv.
// AlignedVec will force aligned the ptr address.
// Refer code: https://github.com/rkyv/rkyv/blob/dabbc1fcf5052f141403b84493bddb74c44f9ba9/rkyv/src/validation/archive/validator.rs#L135
let mut aligned_vec = AlignedVec::<16>::new();
aligned_vec.extend_from_slice(bytes);
deserialize_using(
access::<T::Archived, DeserializeError>(bytes)?,
access::<T::Archived, DeserializeError>(&aligned_vec)?,
&mut deserializer,
)
}
2 changes: 2 additions & 0 deletions crates/rspack_cacheable_test/tests/macro/cacheable_dyn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rspack_cacheable::{cacheable, cacheable_dyn, from_bytes, to_bytes};

#[test]
#[cfg_attr(miri, ignore)]
fn test_cacheable_dyn_macro() {
struct Context;

Expand Down Expand Up @@ -71,6 +72,7 @@ fn test_cacheable_dyn_macro() {
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_cacheable_dyn_macro_with_generics() {
struct Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rspack_cacheable::{cacheable, from_bytes, to_bytes};

#[test]
#[cfg_attr(miri, ignore)]
fn test_manual_cacheable_dyn_macro() {
struct Context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rspack_cacheable::{cacheable, from_bytes, to_bytes};

#[test]
#[cfg_attr(miri, ignore)]
fn test_manual_cacheable_dyn_macro_with_generics() {
struct Context;

Expand Down
1 change: 1 addition & 0 deletions crates/rspack_macros_test/tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[test]
#[cfg_attr(miri, ignore)]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/hook/*.rs");
Expand Down

0 comments on commit 425deee

Please sign in to comment.