feat(plugin): Enable bytecheck (#7280)

**Description:**

Second attempt to enable bytecheck. This PR does not have versioned struct yet, just enabling bytecheck wherever possible. Also, it is for the ast only yet, so transform metadata and others might need this later.

PR seems to be passing all the ci, but as we've experienced before, there might be some unexpected outcomes with the release. Maybe better to hold this until clear https://github.com/swc-project/swc/issues/7238, then land as a separate release.
This commit is contained in:
OJ Kwon 2023-05-05 20:54:25 -07:00 committed by GitHub
parent b60a33001a
commit d2c1f45f5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 156 additions and 71 deletions

39
Cargo.lock generated
View File

@ -2747,15 +2747,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a49a831dc1e13c9392b660b162333d4cb0033bbbdfe6a1687177e59e89037c86"
[[package]]
name = "rend"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79af64b4b6362ffba04eef3a4e10829718a4896dac19daa741851c86781edf95"
dependencies = [
"bytecheck",
]
[[package]]
name = "rend"
version = "0.4.0"
@ -2812,25 +2803,11 @@ dependencies = [
"hashbrown 0.12.3",
"indexmap",
"ptr_meta",
"rend 0.4.0",
"rend",
"rkyv_derive",
"seahash",
]
[[package]]
name = "rkyv-test"
version = "0.7.38-test.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddf47bca568385a5121422d265f8ea7ca2c8816141e29fd415498eabb150f14e"
dependencies = [
"bytecheck",
"hashbrown 0.12.3",
"ptr_meta",
"rend 0.3.6",
"rkyv_derive_test",
"seahash",
]
[[package]]
name = "rkyv_derive"
version = "0.7.41"
@ -2842,17 +2819,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "rkyv_derive_test"
version = "0.7.38-test.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e573710463b17b3cc3c5de19cc12118a788392b056ff097c6ee700920a4545ce"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
@ -3467,6 +3433,7 @@ dependencies = [
name = "swc_atoms"
version = "0.5.3"
dependencies = [
"bytecheck",
"once_cell",
"rkyv",
"rustc-hash",
@ -3543,6 +3510,7 @@ dependencies = [
"atty",
"better_scoped_tls",
"bitflags 2.1.0",
"bytecheck",
"cfg-if",
"criterion",
"either",
@ -3553,7 +3521,6 @@ dependencies = [
"parking_lot",
"rayon",
"rkyv",
"rkyv-test",
"rustc-hash",
"serde",
"serde_json",

View File

@ -207,6 +207,8 @@ pub fn ast_node(
feature = "rkyv-impl",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[cfg_attr(
feature = "rkyv-impl",
archive(bound(
@ -272,6 +274,8 @@ pub fn ast_node(
feature = "rkyv-impl",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[cfg_attr(
feature = "rkyv-impl",
archive(

View File

@ -14,9 +14,11 @@ bench = false
[features]
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv"]
rkyv-impl = ["__rkyv", "rkyv", "bytecheck"]
[dependencies]
# bytecheck version should be in sync with rkyv version. Do not bump individually.
bytecheck = { version = "0.6.10", optional = true }
once_cell = "1"
rkyv = { package = "rkyv", version = "=0.7.41", optional = true, features = [
"strict",

View File

@ -42,6 +42,8 @@ include!(concat!(env!("OUT_DIR"), "/js_word.rs"));
/// "longer than xx" as this is a type.
/// - Raw values.
#[derive(Clone)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct Atom(ThinArc<HeaderWithLength<()>, u8>);
fn _assert_size() {
@ -275,7 +277,7 @@ impl PartialEq<Atom> for str {
}
/// NOT A PUBLIC API
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl rkyv::Archive for Atom {
type Archived = rkyv::string::ArchivedString;
type Resolver = rkyv::string::StringResolver;
@ -287,7 +289,7 @@ impl rkyv::Archive for Atom {
}
/// NOT A PUBLIC API
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<S: rkyv::ser::Serializer + ?Sized> rkyv::Serialize<S> for Atom {
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
String::serialize(&self.to_string(), serializer)
@ -295,7 +297,7 @@ impl<S: rkyv::ser::Serializer + ?Sized> rkyv::Serialize<S> for Atom {
}
/// NOT A PUBLIC API
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::Deserialize<Atom, D> for rkyv::string::ArchivedString
where
D: ?Sized + rkyv::Fallible,
@ -310,11 +312,13 @@ where
/// NOT A PUBLIC API.
///
/// This type exists to allow serializing [JsWord] using `rkyv`.
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct EncodeJsWord;
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl rkyv::with::ArchiveWith<crate::JsWord> for EncodeJsWord {
type Archived = rkyv::Archived<String>;
type Resolver = rkyv::Resolver<String>;
@ -332,7 +336,7 @@ impl rkyv::with::ArchiveWith<crate::JsWord> for EncodeJsWord {
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<S> rkyv::with::SerializeWith<crate::JsWord, S> for EncodeJsWord
where
S: ?Sized + rkyv::ser::Serializer,
@ -345,7 +349,7 @@ where
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<String>, crate::JsWord, D> for EncodeJsWord
where
D: ?Sized + rkyv::Fallible,
@ -362,7 +366,7 @@ where
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl rkyv::with::ArchiveWith<Option<crate::JsWord>> for EncodeJsWord {
type Archived = rkyv::Archived<Option<String>>;
type Resolver = rkyv::Resolver<Option<String>>;
@ -380,7 +384,7 @@ impl rkyv::with::ArchiveWith<Option<crate::JsWord>> for EncodeJsWord {
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<S> rkyv::with::SerializeWith<Option<crate::JsWord>, S> for EncodeJsWord
where
S: ?Sized + rkyv::ser::Serializer,
@ -396,7 +400,7 @@ where
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<Option<String>>, Option<crate::JsWord>, D>
for EncodeJsWord
where

View File

@ -34,13 +34,15 @@ plugin_transform_schema_vtest = []
tty-emitter = ["atty", "termcolor"]
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl"]
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "bytecheck"]
[dependencies]
ahash = "0.7.4"
anyhow = { version = "1.0.45", optional = true }
ahash = "0.7.4"
anyhow = { version = "1.0.45", optional = true }
arbitrary = { version = "1", optional = true, features = ["derive"] }
atty = { version = "0.2", optional = true }
atty = { version = "0.2", optional = true }
# bytecheck version should be in sync with rkyv version. Do not bump individually.
bytecheck = { version = "0.6.10", optional = true }
cfg-if = "1.0.0"
either = "1.5"
new_debug_unreachable = "1.0.4"
@ -51,18 +53,15 @@ rkyv = { version = "=0.7.41", optional = true, features = [
"strict",
"validation",
] }
# This is to avoid cargo version selection conflict between rkyv=0.7.40 and other versions, as it is strictly pinned
# cannot be merged.
rkyv-latest = { package = "rkyv-test", version = "=0.7.38-test.2", optional = true }
rustc-hash = "1.1.0"
serde = { version = "1.0.119", features = ["derive"] }
siphasher = "0.3.9"
sourcemap = { version = "6", optional = true }
string_cache = "0.8.7"
termcolor = { version = "1.0", optional = true }
tracing = "0.1.32"
rustc-hash = "1.1.0"
serde = { version = "1.0.119", features = ["derive"] }
siphasher = "0.3.9"
sourcemap = { version = "6", optional = true }
string_cache = "0.8.7"
termcolor = { version = "1.0", optional = true }
tracing = "0.1.32"
unicode-width = "0.1.4"
url = "2.2.2"
url = "2.2.2"
ast_node = { version = "0.9.3", path = "../ast_node" }
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }

View File

@ -22,6 +22,8 @@ use crate::syntax_pos::{MultiSpan, Span};
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct Message(pub String, pub Style);
#[must_use]
@ -34,6 +36,8 @@ pub struct Message(pub String, pub Style);
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct Diagnostic {
pub level: Level,
pub message: Vec<Message>,
@ -52,6 +56,8 @@ pub struct Diagnostic {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum DiagnosticId {
Error(String),
Lint(String),
@ -67,6 +73,8 @@ pub enum DiagnosticId {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct SubDiagnostic {
pub level: Level,
pub message: Vec<Message>,

View File

@ -50,6 +50,8 @@ mod styled_buffer;
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum Applicability {
MachineApplicable,
HasPlaceholders,
@ -66,6 +68,8 @@ pub enum Applicability {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct CodeSuggestion {
/// Each substitute can have multiple variants due to multiple
/// applicable suggestions
@ -117,6 +121,8 @@ pub struct CodeSuggestion {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct Substitution {
pub parts: Vec<SubstitutionPart>,
}
@ -130,6 +136,8 @@ pub struct Substitution {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct SubstitutionPart {
pub span: Span,
pub snippet: String,
@ -877,6 +885,8 @@ impl Handler {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum Level {
Bug,
Fatal,

View File

@ -184,6 +184,8 @@ pub struct StyledString {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum Style {
MainHeaderMsg,
HeaderMsg,

View File

@ -7,6 +7,8 @@
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct PluginCorePkgDiagnostics {
pub pkg_version: String,
pub git_sha: String,

View File

@ -10,6 +10,8 @@ use rkyv::Deserialize;
feature = "__plugin",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "__plugin", archive(check_bytes))]
#[cfg_attr(feature = "__plugin", archive_attr(repr(u32)))]
/// Enum for possible errors while running transform via plugin.
/// This error indicates internal operation failure either in plugin_runner
/// or plugin_macro. Plugin's transform fn itself does not allow to return

View File

@ -34,6 +34,8 @@ pub mod hygiene;
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct Span {
#[serde(rename = "start")]
#[cfg_attr(feature = "__rkyv", omit_bounds)]
@ -120,6 +122,8 @@ better_scoped_tls::scoped_tls!(
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
pub enum FileName {
Real(#[cfg_attr(any(feature = "rkyv-impl"), with(crate::source_map::EncodePathBuf))] PathBuf),
@ -148,8 +152,10 @@ pub enum FileName {
/// There is built-in `AsString` supports PathBuf but it requires custom
/// serializer wrapper to handle conversion errors. This wrapper is simplified
/// version accepts errors
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct EncodePathBuf;
#[cfg(any(feature = "rkyv-impl"))]
@ -197,8 +203,10 @@ where
}
/// A wrapper that attempts to convert a Url to and from String.
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct EncodeUrl;
#[cfg(any(feature = "rkyv-impl"))]
@ -307,6 +315,8 @@ impl FileName {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct PrimarySpanLabel(pub Span, pub String);
/// A collection of spans. Spans have two orthogonal attributes:
@ -324,6 +334,8 @@ pub struct PrimarySpanLabel(pub Span, pub String);
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct MultiSpan {
primary_spans: Vec<Span>,
span_labels: Vec<PrimarySpanLabel>,
@ -726,6 +738,8 @@ pub const NO_EXPANSION: SyntaxContext = SyntaxContext::empty();
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct MultiByteChar {
/// The absolute offset of the character in the SourceMap
@ -754,6 +768,8 @@ impl MultiByteChar {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum NonNarrowChar {
/// Represents a zero-width character
@ -870,6 +886,8 @@ where
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[derive(Clone)]
pub struct SourceFile {
/// The name of the file that the source came from. Source that doesn't
@ -1090,6 +1108,8 @@ pub trait Pos {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct BytePos(#[cfg_attr(feature = "__rkyv", omit_bounds)] pub u32);
impl BytePos {
@ -1117,6 +1137,8 @@ impl BytePos {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
pub struct CharPos(pub usize);
@ -1230,6 +1252,8 @@ pub struct Loc {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug, Clone)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct PartialLoc {
pub source_file: Option<Lrc<SourceFile>>,
pub line: usize,
@ -1259,6 +1283,8 @@ pub struct SourceFileAndLine {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[derive(Debug)]
pub struct SourceFileAndBytePos {
pub sf: Lrc<SourceFile>,
@ -1270,6 +1296,8 @@ pub struct SourceFileAndBytePos {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct LineInfo {
/// Index of line, starting from 0.
pub line_index: usize,
@ -1306,6 +1334,8 @@ pub struct FileLines {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug, Clone)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct PartialFileLines {
pub file: Option<Lrc<SourceFile>>,
pub lines: Vec<LineInfo>,
@ -1325,6 +1355,8 @@ pub type PartialFileLinesResult = Result<PartialFileLines, Box<SpanLinesError>>;
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum SpanLinesError {
IllFormedSpan(Span),
DistinctSources(DistinctSources),
@ -1335,6 +1367,8 @@ pub enum SpanLinesError {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum SpanSnippetError {
DummyBytePos,
IllFormedSpan(Span),
@ -1348,6 +1382,8 @@ pub enum SpanSnippetError {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct FilePos(pub FileName, pub BytePos);
#[derive(Clone, PartialEq, Eq, Debug)]
@ -1355,6 +1391,8 @@ pub struct FilePos(pub FileName, pub BytePos);
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct DistinctSources {
pub begin: FilePos,
pub end: FilePos,
@ -1365,6 +1403,8 @@ pub struct DistinctSources {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct MalformedSourceMapPositions {
pub name: FileName,
pub source_len: usize,

View File

@ -34,6 +34,8 @@ use crate::collections::AHashMap;
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct SyntaxContext(#[cfg_attr(feature = "__rkyv", omit_bounds)] u32);
#[cfg(feature = "arbitrary")]
@ -70,6 +72,8 @@ pub(crate) struct MarkData {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct MutableMarkContext(pub u32, pub u32, pub u32);
// List of proxy calls injected by the host in the plugin's runtime context.

View File

@ -22,6 +22,8 @@ pub struct Tuple(#[span] HasSpan, usize, usize);
any(feature = "rkyv-impl"),
archive(bound(serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace"))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
pub struct HasSpan {
#[cfg_attr(feature = "__rkyv", omit_bounds)]
pub span: Span,

View File

@ -16,16 +16,23 @@ version = "0.103.5"
bench = false
[features]
__rkyv = []
default = []
fuzzing = ["arbitrary", "swc_common/arbitrary"]
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
__rkyv = []
default = []
fuzzing = ["arbitrary", "swc_common/arbitrary"]
rkyv-impl = [
"__rkyv",
"rkyv",
"bytecheck",
"swc_atoms/rkyv-impl",
"swc_common/rkyv-impl",
]
serde-impl = ["serde"]
[dependencies]
arbitrary = { version = "1", optional = true, features = ["derive"] }
bitflags = "2.1.0"
bytecheck = { version = "0.6.9", optional = true }
bitflags = "2.1.0"
# bytecheck version should be in sync with rkyv version. Do not bump individually.
bytecheck = { version = "0.6.10", optional = true }
is-macro = "0.2.1"
num-bigint = { version = "0.4", features = ["serde"] }
rkyv = { package = "rkyv", version = "=0.7.41", optional = true, features = [

View File

@ -251,6 +251,8 @@ pub struct Decorator {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum MethodKind {
#[cfg_attr(feature = "serde-impl", serde(rename = "method"))]

View File

@ -118,6 +118,8 @@ impl Take for VarDecl {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum VarDeclKind {
/// `var`
Var,

View File

@ -583,6 +583,8 @@ bridge_expr_from!(ClassExpr, Box<Class>);
deserialize = "__D: rkyv::de::SharedDeserializeRegistry"
))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[derive(Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize))]
@ -940,6 +942,8 @@ pub struct MetaPropExpr {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum MetaPropKind {
/// `new.target`
NewTarget,
@ -1129,6 +1133,8 @@ impl Take for Import {
deserialize = "__D: rkyv::de::SharedDeserializeRegistry"
))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub struct ExprOrSpread {
#[cfg_attr(feature = "serde-impl", serde(default))]

View File

@ -24,6 +24,8 @@ use crate::typescript::TsTypeAnn;
deserialize = "__D: rkyv::de::SharedDeserializeRegistry"
))
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(C)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub struct BindingIdent {
#[span]

View File

@ -80,8 +80,10 @@ impl EqIgnoreSpan for BigInt {
}
}
#[cfg(feature = "__rkyv")]
#[cfg(feature = "rkyv-impl")]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct EncodeBigInt;
#[cfg(any(feature = "rkyv-impl"))]

View File

@ -7,6 +7,8 @@ use swc_common::EqIgnoreSpan;
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum BinaryOp {
/// `==`
EqEq,
@ -116,6 +118,8 @@ impl BinaryOp {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum AssignOp {
/// `=`
Assign,
@ -189,6 +193,8 @@ impl AssignOp {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum UpdateOp {
/// `++`
PlusPlus,
@ -202,6 +208,8 @@ pub enum UpdateOp {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum UnaryOp {
/// `-`
Minus,

View File

@ -398,6 +398,8 @@ pub struct TsKeywordType {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum TsKeywordTypeKind {
#[cfg_attr(feature = "serde-impl", serde(rename = "any"))]
@ -680,6 +682,8 @@ pub struct TsTypeOperator {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum TsTypeOperatorOp {
/// `keyof`
KeyOf,
@ -706,6 +710,8 @@ pub struct TsIndexedAccessType {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
pub enum TruePlusMinus {
True,
Plus,
@ -1079,6 +1085,8 @@ pub struct TsSatisfiesExpr {
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "rkyv-impl", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-impl", archive_attr(repr(u32)))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
pub enum Accessibility {
#[cfg_attr(feature = "serde-impl", serde(rename = "public"))]

View File

@ -7,6 +7,8 @@ use swc_common::plugin::serialized::{deserialize_from_ptr, PluginSerializedBytes
feature = "__rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "__rkyv", archive(check_bytes))]
#[cfg_attr(feature = "__rkyv", archive_attr(repr(C)))]
pub struct AllocatedBytesPtr(pub u32, pub u32);
#[cfg(target_arch = "wasm32")]