diff --git a/.changeset/four-tips-impress.md b/.changeset/four-tips-impress.md new file mode 100644 index 00000000000..b569a04ffe2 --- /dev/null +++ b/.changeset/four-tips-impress.md @@ -0,0 +1,8 @@ +--- +ast_node: major +swc_atoms: major +swc_common: minor +swc_plugin_proxy: minor +--- + +fix(swc_common): don't panic when ast byte not match diff --git a/crates/ast_node/src/lib.rs b/crates/ast_node/src/lib.rs index 46cf23733c8..5f6662a098e 100644 --- a/crates/ast_node/src/lib.rs +++ b/crates/ast_node/src/lib.rs @@ -138,6 +138,8 @@ impl VisitMut for AddAttr { fn visit_field_mut(&mut self, f: &mut Field) { f.attrs .push(parse_quote!(#[cfg_attr(feature = "__rkyv", omit_bounds)])); + f.attrs + .push(parse_quote!(#[cfg_attr(feature = "__rkyv", archive_attr(omit_bounds))])); } } @@ -203,14 +205,13 @@ pub fn ast_node( derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) )] #[cfg_attr(feature = "rkyv-impl", archive(check_bytes))] + #[cfg_attr(feature = "rkyv-impl", archive_attr(check_bytes( + bound = "__C: rkyv::validation::ArchiveContext, <__C as rkyv::Fallible>::Error: std::error::Error" + )))] #[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))] - #[cfg_attr( - feature = "rkyv-impl", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) - )] + #[cfg_attr(feature = "rkyv-impl", archive( + bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer") + ))] #[cfg_attr( feature = "serde-impl", serde(untagged) @@ -267,16 +268,13 @@ pub fn ast_node( derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) )] #[cfg_attr(feature = "rkyv-impl", archive(check_bytes))] + #[cfg_attr(feature = "rkyv-impl", archive_attr(check_bytes( + bound = "__C: rkyv::validation::ArchiveContext, <__C as rkyv::Fallible>::Error: std::error::Error" + )))] #[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))] - #[cfg_attr( - feature = "rkyv-impl", - archive( - bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - ) - ) - )] + #[cfg_attr(feature = "rkyv-impl", archive( + bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer") + ))] #serde_tag #[cfg_attr( feature = "serde-impl", diff --git a/crates/swc_atoms/Cargo.toml b/crates/swc_atoms/Cargo.toml index 981b43ac1ad..de1f5af77ae 100644 --- a/crates/swc_atoms/Cargo.toml +++ b/crates/swc_atoms/Cargo.toml @@ -23,8 +23,4 @@ hstr = { workspace = true } once_cell = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true } - - [dependencies.rkyv] - features = ["strict", "validation"] - optional = true - workspace = true +rkyv = { workspace = true, features = ["validation"], optional = true } diff --git a/crates/swc_common/Cargo.toml b/crates/swc_common/Cargo.toml index 1cdd19b9e11..e5b2d1d84ac 100644 --- a/crates/swc_common/Cargo.toml +++ b/crates/swc_common/Cargo.toml @@ -48,10 +48,7 @@ new_debug_unreachable = { workspace = true } num-bigint = { workspace = true } once_cell = { workspace = true } parking_lot = { workspace = true, optional = true } -rkyv = { workspace = true, features = [ - "strict", - "validation", -], optional = true } +rkyv = { workspace = true, features = ["validation"], optional = true } rustc-hash = { workspace = true } serde = { workspace = true, features = ["derive"] } siphasher = { workspace = true } diff --git a/crates/swc_common/src/plugin/serialized.rs b/crates/swc_common/src/plugin/serialized.rs index 83e2a00b2c2..60552a8b4e9 100644 --- a/crates/swc_common/src/plugin/serialized.rs +++ b/crates/swc_common/src/plugin/serialized.rs @@ -103,11 +103,15 @@ impl PluginSerializedBytes { pub fn deserialize(&self) -> Result, Error> where W: rkyv::Archive, - W::Archived: rkyv::Deserialize, + W::Archived: rkyv::Deserialize + + for<'a> rkyv::CheckBytes>, { use anyhow::Context; - let archived = unsafe { rkyv::archived_root::>(&self.field[..]) }; + let archived = rkyv::check_archived_root::>(&self.field[..]) + .map_err(|err| { + anyhow::format_err!("wasm plugin bytecheck failed {:?}", err.to_string()) + })?; archived .deserialize(&mut rkyv::de::deserializers::SharedDeserializeMap::new()) diff --git a/crates/swc_css_ast/Cargo.toml b/crates/swc_css_ast/Cargo.toml index c749e54edc3..949de6e9dfc 100644 --- a/crates/swc_css_ast/Cargo.toml +++ b/crates/swc_css_ast/Cargo.toml @@ -25,7 +25,4 @@ string_enum = { version = "0.4.4", path = "../string_enum/" } swc_atoms = { version = "0.6.5", path = "../swc_atoms" } swc_common = { version = "0.38.0", path = "../swc_common" } - [dependencies.rkyv] - features = ["strict", "validation"] - optional = true - workspace = true +rkyv = { workspace = true, features = ["validation"], optional = true } diff --git a/crates/swc_css_ast/src/at_rule.rs b/crates/swc_css_ast/src/at_rule.rs index f1c940d948c..8d5125d0f25 100644 --- a/crates/swc_css_ast/src/at_rule.rs +++ b/crates/swc_css_ast/src/at_rule.rs @@ -453,11 +453,7 @@ pub struct MediaFeatureBoolean { #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] pub enum MediaFeatureRangeComparison { /// `<` @@ -783,11 +779,7 @@ pub struct SizeFeatureBoolean { #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] pub enum SizeFeatureRangeComparison { /// `<` diff --git a/crates/swc_css_ast/src/selector.rs b/crates/swc_css_ast/src/selector.rs index 956144288e0..6217fdb8d90 100644 --- a/crates/swc_css_ast/src/selector.rs +++ b/crates/swc_css_ast/src/selector.rs @@ -125,11 +125,7 @@ pub struct Combinator { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv", archive(check_bytes))] #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] @@ -270,11 +266,7 @@ pub struct AttributeSelector { #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] pub enum AttributeSelectorMatcherValue { /// `=` diff --git a/crates/swc_css_ast/src/token.rs b/crates/swc_css_ast/src/token.rs index 813d11f20c2..23848b84cac 100644 --- a/crates/swc_css_ast/src/token.rs +++ b/crates/swc_css_ast/src/token.rs @@ -44,11 +44,7 @@ pub struct UrlKeyValue(pub Atom, pub Atom); #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "serde-impl", derive(Serialize, Deserialize))] pub enum NumberType { @@ -86,11 +82,7 @@ pub struct DimensionToken { #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] pub enum Token { diff --git a/crates/swc_css_ast/src/value.rs b/crates/swc_css_ast/src/value.rs index f594743de2a..bf2130982df 100644 --- a/crates/swc_css_ast/src/value.rs +++ b/crates/swc_css_ast/src/value.rs @@ -121,11 +121,7 @@ impl EqIgnoreSpan for Str { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv", archive(check_bytes))] #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] @@ -401,11 +397,7 @@ pub struct Ratio { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv", archive(check_bytes))] #[cfg_attr(feature = "rkyv", archive_attr(repr(u32)))] @@ -511,11 +503,7 @@ pub struct CalcOperator { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv-impl", archive(check_bytes))] #[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))] diff --git a/crates/swc_ecma_ast/Cargo.toml b/crates/swc_ecma_ast/Cargo.toml index 7170efed8ed..1e6388005ef 100644 --- a/crates/swc_ecma_ast/Cargo.toml +++ b/crates/swc_ecma_ast/Cargo.toml @@ -36,10 +36,7 @@ bytecheck = { workspace = true, optional = true } is-macro = { workspace = true } num-bigint = { workspace = true, features = ["serde"] } phf = { workspace = true, features = ["macros"] } -rkyv = { workspace = true, features = [ - "strict", - "validation", -], optional = true } +rkyv = { workspace = true, features = ["validation"], optional = true } scoped-tls = { workspace = true } serde = { workspace = true, features = ["derive"], optional = true } string_enum = { version = "0.4.4", path = "../string_enum" } diff --git a/crates/swc_ecma_ast/src/expr.rs b/crates/swc_ecma_ast/src/expr.rs index 11563d040c7..aef159ae015 100644 --- a/crates/swc_ecma_ast/src/expr.rs +++ b/crates/swc_ecma_ast/src/expr.rs @@ -1273,12 +1273,8 @@ impl Take for Import { derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) )] #[cfg_attr( - any(feature = "rkyv-impl"), - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + feature = "rkyv", + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv-impl", archive(check_bytes))] #[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))] diff --git a/crates/swc_ecma_ast/src/ident.rs b/crates/swc_ecma_ast/src/ident.rs index 80f85b9b06b..d21de99f5b1 100644 --- a/crates/swc_ecma_ast/src/ident.rs +++ b/crates/swc_ecma_ast/src/ident.rs @@ -20,12 +20,8 @@ use crate::{typescript::TsTypeAnn, Expr}; derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) )] #[cfg_attr( - any(feature = "rkyv-impl"), - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + feature = "rkyv", + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "rkyv-impl", archive(check_bytes))] #[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))] diff --git a/crates/swc_html_ast/Cargo.toml b/crates/swc_html_ast/Cargo.toml index 7545c43f5be..cfca696162d 100644 --- a/crates/swc_html_ast/Cargo.toml +++ b/crates/swc_html_ast/Cargo.toml @@ -21,10 +21,7 @@ serde-impl = ["serde"] [dependencies] is-macro = { workspace = true } -rkyv = { workspace = true, features = [ - "strict", - "validation", -], optional = true } +rkyv = { workspace = true, features = ["validation"], optional = true } serde = { workspace = true, features = ["derive"], optional = true } string_enum = { version = "0.4.4", path = "../string_enum/" } diff --git a/crates/swc_html_ast/src/base.rs b/crates/swc_html_ast/src/base.rs index 5bc176f12fb..537372bc727 100644 --- a/crates/swc_html_ast/src/base.rs +++ b/crates/swc_html_ast/src/base.rs @@ -25,11 +25,7 @@ pub struct DocumentFragment { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] pub enum DocumentMode { /// `no-quirks` @@ -81,11 +77,7 @@ impl EqIgnoreSpan for DocumentType { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] pub enum Namespace { /// `http://www.w3.org/1999/xhtml` diff --git a/crates/swc_html_ast/src/token.rs b/crates/swc_html_ast/src/token.rs index d9d144d22fd..4cc0e504da0 100644 --- a/crates/swc_html_ast/src/token.rs +++ b/crates/swc_html_ast/src/token.rs @@ -27,11 +27,7 @@ pub struct AttributeToken { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] pub enum Raw { @@ -46,11 +42,7 @@ pub enum Raw { )] #[cfg_attr( feature = "rkyv", - archive(bound( - serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \ - rkyv::ser::SharedSerializeRegistry", - deserialize = "__D: rkyv::de::SharedDeserializeRegistry" - )) + archive(bound(serialize = "__S: rkyv::ser::ScratchSpace + rkyv::ser::Serializer")) )] #[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))] pub enum Token { diff --git a/crates/swc_plugin_proxy/Cargo.toml b/crates/swc_plugin_proxy/Cargo.toml index 4f30c519b2e..3ddb91c1a8b 100644 --- a/crates/swc_plugin_proxy/Cargo.toml +++ b/crates/swc_plugin_proxy/Cargo.toml @@ -22,10 +22,7 @@ plugin-rt = ["__plugin_rt", "swc_common/plugin-base", "rkyv-impl"] [dependencies] -rkyv = { workspace = true, features = [ - "strict", - "validation", -], optional = true } +rkyv = { workspace = true, features = ["validation"], optional = true } tracing = { workspace = true } better_scoped_tls = { version = "0.1.1", path = "../better_scoped_tls" } diff --git a/crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs b/crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs index 5285aae1bc4..386b3fd2560 100644 --- a/crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs +++ b/crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs @@ -92,7 +92,8 @@ pub fn read_returned_result_from_host(f: F) -> Option where F: FnOnce(u32) -> u32, R: rkyv::Archive, - R::Archived: rkyv::Deserialize, + R::Archived: rkyv::Deserialize + + for<'a> rkyv::CheckBytes>, { let allocated_returned_value_ptr = read_returned_result_from_host_inner(f);