refactor(plugin): Remove bytecheck flag (#7256)

This commit is contained in:
OJ Kwon 2023-04-12 22:49:58 -07:00 committed by GitHub
parent 604667d522
commit 6bd58cbcfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 105 additions and 347 deletions

View File

@ -232,7 +232,7 @@ jobs:
os: ubuntu-latest
runner: ubuntu-latest
check: |
cargo hack check --feature-powerset --no-dev-deps --exclude-features debug --exclude-features plugin --exclude-features plugin_transform_schema_v1 --exclude-features plugin_transform_schema_vtest --exclude-features plugin-bytecheck --exclude-features plugin_transform_host_js --exclude-features plugin_transform_host_native
cargo hack check --feature-powerset --no-dev-deps --exclude-features debug --exclude-features plugin --exclude-features plugin_transform_schema_v1 --exclude-features plugin_transform_schema_vtest --exclude-features plugin_transform_host_js --exclude-features plugin_transform_host_native
- crate: swc
os: windows-latest
runner: windows-latest
@ -251,7 +251,7 @@ jobs:
os: ubuntu-latest
runner: ubuntu-latest
check: |
cargo hack check --feature-powerset --no-dev-deps --exclude-features plugin_transform_schema_vtest --exclude-features __plugin --exclude-features __plugin_mode --exclude-features __plugin_rt --exclude-features __rkyv --exclude-features plugin-bytecheck-base --exclude-features plugin-bytecheck-mode --exclude-features plugin-bytecheck-rt --exclude-features rkyv-bytecheck-impl --exclude-features rkyv-impl
cargo hack check --feature-powerset --no-dev-deps --exclude-features plugin_transform_schema_vtest --exclude-features __plugin --exclude-features __plugin_mode --exclude-features __plugin_rt --exclude-features __rkyv --exclude-features rkyv-impl
- crate: swc_common
os: windows-latest
runner: windows-latest
@ -310,7 +310,7 @@ jobs:
os: ubuntu-latest
runner: ubuntu-latest
check: |
cargo hack check --feature-powerset --no-dev-deps --exclude-features __rkyv --exclude-features rkyv-bytecheck-impl
cargo hack check --feature-powerset --no-dev-deps --exclude-features __rkyv
- crate: swc_ecma_codegen
os: ubuntu-latest
runner: ubuntu-latest

8
Cargo.lock generated
View File

@ -3451,10 +3451,8 @@ dependencies = [
name = "swc_atoms"
version = "0.5.1"
dependencies = [
"bytecheck",
"once_cell",
"rkyv",
"rkyv-test",
"rustc-hash",
"serde",
"string_cache",
@ -3528,7 +3526,6 @@ dependencies = [
"ast_node",
"atty",
"better_scoped_tls",
"bytecheck",
"cfg-if",
"criterion",
"either",
@ -3646,7 +3643,6 @@ dependencies = [
name = "swc_css_ast"
version = "0.137.1"
dependencies = [
"bytecheck",
"is-macro",
"rkyv",
"serde",
@ -3820,11 +3816,9 @@ version = "0.103.1"
dependencies = [
"arbitrary",
"bitflags",
"bytecheck",
"is-macro",
"num-bigint",
"rkyv",
"rkyv-test",
"scoped-tls",
"serde",
"serde_json",
@ -4494,7 +4488,6 @@ dependencies = [
name = "swc_html_ast"
version = "0.31.1"
dependencies = [
"bytecheck",
"is-macro",
"rkyv",
"serde",
@ -4690,7 +4683,6 @@ version = "0.32.1"
dependencies = [
"better_scoped_tls",
"rkyv",
"rkyv-test",
"swc_common",
"swc_ecma_ast",
"swc_trace_macro",

View File

@ -18,14 +18,6 @@ plugin = ["swc_core/plugin_transform_host_native"]
swc_v1 = ["swc_core/bundler_node_v1"]
swc_v2 = ["swc_core/bundler_node_v2"]
# Experiemntal bytechecked plugin serialization / deserialization.
plugin_bytecheck = [
# We know what we're doing - enable internal features for the host plugin setup.
# "swc_core/__plugin_transform_host_bytecheck",
"swc_core/__plugin_transform_host_schema_v1",
"swc_core/__plugin_transform_env_native",
]
# Internal flag for testing purpose only.
__plugin_transform_vtest = [
# We know what we're doing - enable internal features for testing fixture setup.

View File

@ -207,10 +207,6 @@ pub fn ast_node(
feature = "rkyv-impl",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
feature = "rkyv-bytecheck-impl",
derive(rkyv_latest::Archive, rkyv_latest::Serialize, rkyv_latest::Deserialize)
)]
#[cfg_attr(
feature = "rkyv-impl",
archive(bound(
@ -218,13 +214,6 @@ pub fn ast_node(
deserialize = "__D: rkyv::de::SharedDeserializeRegistry"
))
)]
#[cfg_attr(
feature = "rkyv-bytecheck-impl",
archive(bound(
serialize = "__S: rkyv_latest::ser::Serializer + rkyv_latest::ser::ScratchSpace + rkyv_latest::ser::SharedSerializeRegistry",
deserialize = "__D: rkyv_latest::de::SharedDeserializeRegistry"
))
)]
#[cfg_attr(
feature = "serde-impl",
serde(untagged)
@ -283,10 +272,6 @@ pub fn ast_node(
feature = "rkyv-impl",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
feature = "rkyv-bytecheck-impl",
derive(rkyv_latest::Archive, rkyv_latest::Serialize, rkyv_latest::Deserialize)
)]
#[cfg_attr(
feature = "rkyv-impl",
archive(
@ -296,15 +281,6 @@ pub fn ast_node(
)
)
)]
#[cfg_attr(
feature = "rkyv-bytecheck-impl",
archive(
bound(
serialize = "__S: rkyv_latest::ser::Serializer + rkyv_latest::ser::ScratchSpace + rkyv_latest::ser::SharedSerializeRegistry",
deserialize = "__D: rkyv_latest::de::SharedDeserializeRegistry"
)
)
)]
serde_tag
#[cfg_attr(
feature = "serde-impl",

View File

@ -33,10 +33,6 @@ plugin = [
"swc_plugin_runner/rkyv-impl",
"swc_plugin_proxy/plugin-rt",
]
plugin-bytecheck = [
"swc_plugin_runner/rkyv-bytecheck-impl",
"swc_plugin_proxy/plugin-bytecheck-rt",
]
plugin_transform_schema_v1 = [
"swc_common/plugin_transform_schema_v1",
"swc_plugin_runner/plugin_transform_schema_v1",

View File

@ -1,8 +1,5 @@
#![cfg_attr(
any(
not(any(feature = "plugin", feature = "plugin-bytecheck")),
target_arch = "wasm32"
),
any(not(any(feature = "plugin")), target_arch = "wasm32"),
allow(unused)
)]
use std::{
@ -617,10 +614,7 @@ impl Options {
// Embedded runtime plugin target, based on assumption we have
// 1. filesystem access for the cache
// 2. embedded runtime can compiles & execute wasm
#[cfg(all(
any(feature = "plugin", feature = "plugin-bytecheck"),
not(target_arch = "wasm32")
))]
#[cfg(all(any(feature = "plugin"), not(target_arch = "wasm32")))]
let plugins = {
let plugin_resolver = CachingResolver::new(
40,
@ -659,10 +653,7 @@ impl Options {
// 1. no filesystem access, loading binary / cache management should be
// performed externally
// 2. native runtime compiles & execute wasm (i.e v8 on node, chrome)
#[cfg(all(
any(feature = "plugin", feature = "plugin-bytecheck"),
target_arch = "wasm32"
))]
#[cfg(all(any(feature = "plugin"), target_arch = "wasm32"))]
let plugins = {
let transform_filename = match base {
FileName::Real(path) => path.as_os_str().to_str().map(String::from),
@ -689,7 +680,7 @@ impl Options {
)
};
#[cfg(not(any(feature = "plugin", feature = "plugin-bytecheck")))]
#[cfg(not(any(feature = "plugin")))]
let plugins = crate::plugin::plugins();
let pass = chain!(

View File

@ -2,18 +2,15 @@
//! expressions at the moment.
#![cfg_attr(
any(
not(any(feature = "plugin", feature = "plugin-bytecheck")),
target_arch = "wasm32"
),
any(not(any(feature = "plugin")), target_arch = "wasm32"),
allow(unused)
)]
use serde::{Deserialize, Serialize};
#[cfg(any(feature = "plugin", feature = "plugin-bytecheck"))]
#[cfg(any(feature = "plugin"))]
use swc_ecma_ast::*;
use swc_ecma_loader::resolvers::{lru::CachingResolver, node::NodeModulesResolver};
#[cfg(not(any(feature = "plugin", feature = "plugin-bytecheck")))]
#[cfg(not(any(feature = "plugin")))]
use swc_ecma_transforms::pass::noop;
use swc_ecma_visit::{noop_fold_type, Fold};
@ -27,7 +24,7 @@ use swc_ecma_visit::{noop_fold_type, Fold};
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct PluginConfig(pub String, pub serde_json::Value);
#[cfg(any(feature = "plugin", feature = "plugin-bytecheck"))]
#[cfg(any(feature = "plugin"))]
pub fn plugins(
configured_plugins: Option<Vec<PluginConfig>>,
metadata_context: std::sync::Arc<swc_common::plugin::metadata::TransformPluginMetadataContext>,
@ -48,7 +45,7 @@ pub fn plugins(
}
}
#[cfg(not(any(feature = "plugin", feature = "plugin-bytecheck")))]
#[cfg(not(any(feature = "plugin")))]
pub fn plugins() -> impl Fold {
noop()
}
@ -63,7 +60,7 @@ struct RustPlugins {
}
impl RustPlugins {
#[cfg(any(feature = "plugin", feature = "plugin-bytecheck"))]
#[cfg(any(feature = "plugin"))]
fn apply(&mut self, n: Program) -> Result<Program, anyhow::Error> {
use anyhow::Context;
if self.plugins.is_none() || self.plugins.as_ref().unwrap().is_empty() {
@ -79,10 +76,7 @@ impl RustPlugins {
}
#[tracing::instrument(level = "info", skip_all, name = "apply_plugins")]
#[cfg(all(
any(feature = "plugin", feature = "plugin-bytecheck"),
not(target_arch = "wasm32")
))]
#[cfg(all(any(feature = "plugin"), not(target_arch = "wasm32")))]
fn apply_inner(&mut self, n: Program) -> Result<Program, anyhow::Error> {
use std::{path::PathBuf, sync::Arc};
@ -167,10 +161,7 @@ impl RustPlugins {
)
}
#[cfg(all(
any(feature = "plugin", feature = "plugin-bytecheck"),
target_arch = "wasm32"
))]
#[cfg(all(any(feature = "plugin"), target_arch = "wasm32"))]
#[tracing::instrument(level = "info", skip_all)]
fn apply_inner(&mut self, n: Program) -> Result<Program, anyhow::Error> {
use std::{path::PathBuf, sync::Arc};
@ -222,14 +213,14 @@ impl RustPlugins {
impl Fold for RustPlugins {
noop_fold_type!();
#[cfg(any(feature = "plugin", feature = "plugin-bytecheck"))]
#[cfg(any(feature = "plugin"))]
fn fold_module(&mut self, n: Module) -> Module {
self.apply(Program::Module(n))
.expect("failed to invoke plugin")
.expect_module()
}
#[cfg(any(feature = "plugin", feature = "plugin-bytecheck"))]
#[cfg(any(feature = "plugin"))]
fn fold_script(&mut self, n: Script) -> Script {
self.apply(Program::Script(n))
.expect("failed to invoke plugin")

View File

@ -13,24 +13,15 @@ version = "0.5.1"
bench = false
[features]
__rkyv = []
# Enably rkyv serialization with stable version of rkyv.
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv"]
# Enable rkyv serialization with updated version of rkyv, along with bytecheck.
rkyv-bytecheck-impl = ["__rkyv", "rkyv-latest"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
once_cell = "1"
rkyv = { package = "rkyv", version = "=0.7.40", 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, features = [
"strict",
] }
rustc-hash = "1.1.0"
serde = "1"
string_cache = "0.8.7"

View File

@ -1,8 +1,5 @@
use std::{env, path::Path};
#[cfg(all(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
compile_error!("Cannot enable bytechcked, non-bytechecked rkyv both");
fn main() {
let strs = include_str!("words.txt")
.lines()

View File

@ -14,8 +14,6 @@ use std::{
rc::Rc,
};
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use rustc_hash::FxHashSet;
use serde::Serializer;
use triomphe::{Arc, HeaderWithLength, ThinArc};

View File

@ -28,32 +28,19 @@ plugin-base = ["__plugin", "anyhow", "rkyv-impl", "diagnostic-serde"]
plugin-mode = ["__plugin_mode", "plugin-base"]
plugin-rt = ["__plugin_rt", "plugin-base"]
plugin-bytecheck-base = [
"__plugin",
"anyhow",
"rkyv-bytecheck-impl",
"diagnostic-serde",
]
plugin-bytecheck-mode = ["__plugin_mode", "plugin-bytecheck-base"]
plugin-bytecheck-rt = ["__plugin_rt", "plugin-bytecheck-base"]
plugin_transform_schema_v1 = []
plugin_transform_schema_vtest = []
tty-emitter = ["atty", "termcolor"]
__rkyv = []
# Enably rkyv serialization with stable version of rkyv.
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl"]
# Enable rkyv serialization with updated version of rkyv, along with bytecheck.
rkyv-bytecheck-impl = ["__rkyv", "rkyv-latest", "swc_atoms/rkyv-bytecheck-impl"]
[dependencies]
ahash = "0.7.4"
anyhow = { version = "1.0.45", optional = true }
arbitrary = { version = "1", optional = true, features = ["derive"] }
atty = { version = "0.2", optional = true }
bytecheck = { version = "0.6.9", optional = true }
cfg-if = "1.0.0"
either = "1.5"
new_debug_unreachable = "1.0.4"

View File

@ -4,8 +4,6 @@ use std::{
sync::Arc,
};
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use rustc_hash::FxHashMap;
use swc_atoms::{atom, Atom};
@ -545,7 +543,7 @@ impl SingleThreadedComments {
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct Comment {
@ -563,7 +561,7 @@ impl Spanned for Comment {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum CommentKind {

View File

@ -10,9 +10,6 @@
use std::fmt;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use super::{snippet::Style, Applicability, CodeSuggestion, Level, Substitution, SubstitutionPart};
use crate::syntax_pos::{MultiSpan, Span};
@ -22,7 +19,7 @@ use crate::syntax_pos::{MultiSpan, Span};
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct Message(pub String, pub Style);
@ -34,7 +31,7 @@ pub struct Message(pub String, pub Style);
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct Diagnostic {
@ -52,7 +49,7 @@ pub struct Diagnostic {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum DiagnosticId {
@ -67,7 +64,7 @@ pub enum DiagnosticId {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct SubDiagnostic {

View File

@ -17,8 +17,6 @@ use std::{
sync::atomic::{AtomicUsize, Ordering::SeqCst},
};
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[cfg(feature = "tty-emitter")]
use termcolor::{Color, ColorSpec};
@ -49,7 +47,7 @@ mod styled_buffer;
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum Applicability {
@ -65,7 +63,7 @@ pub enum Applicability {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct CodeSuggestion {
@ -116,7 +114,7 @@ pub struct CodeSuggestion {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct Substitution {
@ -129,7 +127,7 @@ pub struct Substitution {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct SubstitutionPart {
@ -876,7 +874,7 @@ impl Handler {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum Level {

View File

@ -10,9 +10,6 @@
// Code for annotating snippets.
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use super::Level;
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
@ -184,7 +181,7 @@ pub struct StyledString {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum Style {

View File

@ -79,19 +79,3 @@ pub mod util;
#[cfg(all(not(debug_assertions), feature = "plugin-rt", feature = "plugin-mode"))]
compile_error!("You can't enable `plugin-rt` and `plugin-mode` at the same time");
#[cfg(all(
not(debug_assertions),
feature = "plugin-bytecheck-rt",
feature = "plugin-bytecheck-mode"
))]
compile_error!(
"You can't enable `plugin-bytecheck-rt` and `plugin-bytecheck-mode` at the same time"
);
#[cfg(all(
not(debug_assertions),
feature = "plugin-base",
feature = "plugin-bytecheck-base"
))]
compile_error!("Bytecheck, non-bytecheck serialization cannot be enabled same time");

View File

@ -1,13 +1,10 @@
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
/// A serializable, wrapped struct for the diagnostics information
/// included in plugin binaries.
/// TODO: Must implement bytecheck with forward-compatible schema changes to
/// prevent handshake failure.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct PluginCorePkgDiagnostics {

View File

@ -3,8 +3,6 @@ use std::any::type_name;
use anyhow::Error;
#[cfg(feature = "__rkyv")]
use rkyv::Deserialize;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]

View File

@ -11,8 +11,6 @@ use std::{
#[cfg(feature = "parking_lot")]
use parking_lot::Mutex;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use serde::{Deserialize, Serialize};
use url::Url;
@ -33,7 +31,7 @@ pub mod hygiene;
/// `BytePos` range between files.
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct Span {
@ -119,18 +117,12 @@ better_scoped_tls::scoped_tls!(
);
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
pub enum FileName {
Real(
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
with(crate::source_map::EncodePathBuf)
)]
PathBuf,
),
Real(#[cfg_attr(any(feature = "rkyv-impl"), with(crate::source_map::EncodePathBuf))] PathBuf),
/// A macro. This includes the full name of the macro, so that there are no
/// clashes.
Macros(String),
@ -141,13 +133,7 @@ pub enum FileName {
/// Hack in src/libsyntax/parse.rs
MacroExpansion,
ProcMacroSourceCode,
Url(
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
with(crate::source_map::EncodeUrl)
)]
Url,
),
Url(#[cfg_attr(any(feature = "rkyv-impl"), with(crate::source_map::EncodeUrl))] Url),
Internal(String),
/// Custom sources for explicit parser calls from plugins and drivers
Custom(String),
@ -166,7 +152,7 @@ pub enum FileName {
#[derive(Debug, Clone, Copy)]
pub struct EncodePathBuf;
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl rkyv::with::ArchiveWith<PathBuf> for EncodePathBuf {
type Archived = rkyv::string::ArchivedString;
type Resolver = rkyv::string::StringResolver;
@ -184,7 +170,7 @@ impl rkyv::with::ArchiveWith<PathBuf> for EncodePathBuf {
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<S> rkyv::with::SerializeWith<PathBuf, S> for EncodePathBuf
where
S: ?Sized + rkyv::ser::Serializer,
@ -196,7 +182,7 @@ where
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<D> rkyv::with::DeserializeWith<rkyv::string::ArchivedString, PathBuf, D> for EncodePathBuf
where
D: ?Sized + rkyv::Fallible,
@ -215,7 +201,7 @@ where
#[derive(Debug, Clone, Copy)]
pub struct EncodeUrl;
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl rkyv::with::ArchiveWith<Url> for EncodeUrl {
type Archived = rkyv::string::ArchivedString;
type Resolver = rkyv::string::StringResolver;
@ -231,7 +217,7 @@ impl rkyv::with::ArchiveWith<Url> for EncodeUrl {
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<S> rkyv::with::SerializeWith<Url, S> for EncodeUrl
where
S: ?Sized + rkyv::ser::Serializer,
@ -243,7 +229,7 @@ where
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<String>, Url, D> for EncodeUrl
where
D: ?Sized + rkyv::Fallible,
@ -318,7 +304,7 @@ impl FileName {
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct PrimarySpanLabel(pub Span, pub String);
@ -335,7 +321,7 @@ pub struct PrimarySpanLabel(pub Span, pub String);
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct MultiSpan {
@ -737,7 +723,7 @@ pub const NO_EXPANSION: SyntaxContext = SyntaxContext::empty();
/// Identifies an offset of a multi-byte character in a SourceFile
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
@ -765,7 +751,7 @@ impl MultiByteChar {
/// Identifies an offset of a non-narrow character in a SourceFile
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
@ -832,7 +818,7 @@ impl Sub<BytePos> for NonNarrowChar {
/// A single source in the SourceMap.
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Clone)]
@ -1051,7 +1037,7 @@ pub trait Pos {
#[serde(transparent)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct BytePos(#[cfg_attr(feature = "__rkyv", omit_bounds)] pub u32);
@ -1078,7 +1064,7 @@ impl BytePos {
/// is not equivalent to a character offset. The SourceMap will convert BytePos
/// values to CharPos values as necessary.
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
@ -1191,7 +1177,7 @@ pub struct Loc {
/// A struct to exchange `Loc` with omitting SourceFile as needed.
/// This is internal struct between plugins to the host, not a public interface.
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug, Clone)
)]
pub struct PartialLoc {
@ -1220,7 +1206,7 @@ pub struct SourceFileAndLine {
}
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[derive(Debug)]
@ -1231,7 +1217,7 @@ pub struct SourceFileAndBytePos {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct LineInfo {
@ -1267,7 +1253,7 @@ pub struct FileLines {
/// A struct to exchange `FileLines` with omitting SourceFile as needed.
/// This is internal struct between plugins to the host, not a public interface.
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Debug, Clone)
)]
pub struct PartialFileLines {
@ -1286,7 +1272,7 @@ pub type PartialFileLinesResult = Result<PartialFileLines, Box<SpanLinesError>>;
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum SpanLinesError {
@ -1296,7 +1282,7 @@ pub enum SpanLinesError {
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum SpanSnippetError {
@ -1309,14 +1295,14 @@ pub enum SpanSnippetError {
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct FilePos(pub FileName, pub BytePos);
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct DistinctSources {
@ -1326,7 +1312,7 @@ pub struct DistinctSources {
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct MalformedSourceMapPositions {

View File

@ -21,8 +21,6 @@ use std::{
fmt,
};
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use serde::{Deserialize, Serialize};
use super::GLOBALS;
@ -33,7 +31,7 @@ use crate::collections::AHashMap;
#[derive(Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct SyntaxContext(#[cfg_attr(feature = "__rkyv", omit_bounds)] u32);
@ -69,7 +67,7 @@ pub(crate) struct MarkData {
}
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct MutableMarkContext(pub u32, pub u32, pub u32);

View File

@ -15,11 +15,11 @@ pub struct Tuple(#[span] HasSpan, usize, usize);
#[derive(Debug, Clone, PartialEq, Eq, Spanned, Serialize, Deserialize)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
archive(bound(serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace"))
)]
pub struct HasSpan {

View File

@ -257,20 +257,6 @@ __ecma_plugin_transform = [
"swc_ecma_ast/rkyv-impl",
]
__plugin_transform_bytecheck = [
# Dependent features
"ecma_visit",
"__common",
"ecma_ast",
"swc_ecma_ast/rkyv-bytecheck-impl",
"swc_atoms/rkyv-bytecheck-impl",
"swc_common/plugin-bytecheck-mode",
"swc_plugin_proxy/plugin-bytecheck-mode",
"swc_plugin_macro",
"swc_plugin",
"once_cell",
]
# Internal flags for any transform plugin host feature
__plugin_transform_host = [
# Dependent features
@ -283,16 +269,6 @@ __plugin_transform_host = [
"swc/plugin",
]
# Internal flags for the transform plugin host, if it needs to enable bytecheck
__plugin_transform_host_bytecheck = [
"__common",
"swc_atoms/rkyv-bytecheck-impl",
"swc_common/plugin-bytecheck-rt",
"swc_ecma_ast/rkyv-bytecheck-impl",
"swc_plugin_proxy/plugin-bytecheck-rt",
"swc/plugin-bytecheck",
]
# Internal flags to control plugin environment
__plugin_transform_env_native = [
"swc/plugin_transform_host_native",

View File

@ -15,13 +15,6 @@ plugin = ["swc_core/plugin_transform_host_native"]
swc_v1 = ["swc_core/bundler_node_v1"]
swc_v2 = ["swc_core/bundler_node_v2"]
# Experiemntal bytechecked plugin serialization / deserialization.
plugin_bytecheck = [
# "swc_core/__plugin_transform_host_bytecheck",
"swc_core/__plugin_transform_host_schema_v1",
"swc_core/__plugin_transform_env_native",
]
# Internal flag for testing purpose only.
__plugin_transform_vtest = [
"swc_core/__plugin_transform_host",

View File

@ -12,14 +12,12 @@ version = "0.137.1"
bench = false
[features]
__rkyv = []
default = []
rkyv-bytecheck-impl = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
serde-impl = ["serde"]
__rkyv = []
default = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
serde-impl = ["serde"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.0"
rkyv = { version = "=0.7.40", optional = true, features = [
"strict",

View File

@ -28,7 +28,7 @@ impl Take for TokenAndSpan {
#[derive(Debug, Clone, PartialEq, EqIgnoreSpan, Hash)]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct UrlKeyValue(pub Atom, pub Atom);

View File

@ -16,35 +16,21 @@ version = "0.103.1"
bench = false
[features]
__rkyv = []
default = []
fuzzing = ["arbitrary", "swc_common/arbitrary"]
# Enably rkyv serialization with stable version of rkyv.
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
# Enable rkyv serialization with updated version of rkyv, along with bytecheck.
rkyv-bytecheck-impl = [
"__rkyv",
"rkyv-latest",
"swc_atoms/rkyv-bytecheck-impl",
"swc_common/rkyv-bytecheck-impl",
]
__rkyv = []
default = []
fuzzing = ["arbitrary", "swc_common/arbitrary"]
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
serde-impl = ["serde"]
[dependencies]
arbitrary = { version = "1", optional = true, features = ["derive"] }
bitflags = "1"
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.1"
num-bigint = { version = "0.4", features = ["serde"] }
rkyv = { package = "rkyv", version = "=0.7.40", 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, features = [
"strict",
] }
scoped-tls = "1.0.0"
serde = { version = "1.0.133", features = ["derive"], optional = true }
unicode-id = "0.3"

View File

@ -1,6 +1,4 @@
use is_macro::Is;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};
use crate::{
@ -250,7 +248,7 @@ pub struct Decorator {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]

View File

@ -1,6 +1,4 @@
use is_macro::Is;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use string_enum::StringEnum;
use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};
@ -117,7 +115,7 @@ impl Take for VarDecl {
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum VarDeclKind {

View File

@ -1,7 +1,5 @@
#![allow(clippy::vec_box)]
use is_macro::Is;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[cfg(feature = "serde-impl")]
use serde::{
self,
@ -574,11 +572,11 @@ bridge_expr_from!(ClassExpr, Box<Class>);
#[derive(Spanned, Clone, Debug, PartialEq)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
archive(bound(
serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \
rkyv::ser::SharedSerializeRegistry",
@ -939,7 +937,7 @@ pub struct MetaPropExpr {
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum MetaPropKind {
@ -1120,11 +1118,11 @@ impl Take for Import {
#[derive(Clone, Debug, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
archive(bound(
serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \
rkyv::ser::SharedSerializeRegistry",

View File

@ -1,7 +1,5 @@
use std::fmt::Display;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use scoped_tls::scoped_thread_local;
use swc_atoms::{js_word, JsWord};
use swc_common::{
@ -15,11 +13,11 @@ use crate::typescript::TsTypeAnn;
#[derive(Spanned, Clone, Debug, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
archive(bound(
serialize = "__S: rkyv::ser::Serializer + rkyv::ser::ScratchSpace + \
rkyv::ser::SharedSerializeRegistry",
@ -115,10 +113,7 @@ bridge_from!(BindingIdent, Ident, Id);
pub struct Ident {
pub span: Span,
#[cfg_attr(feature = "serde-impl", serde(rename = "value"))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
with(swc_atoms::EncodeJsWord)
)]
#[cfg_attr(any(feature = "rkyv-impl"), with(swc_atoms::EncodeJsWord))]
pub sym: JsWord,
/// TypeScript only. Used in case of an optional parameter.

View File

@ -9,9 +9,6 @@
#![allow(clippy::clone_on_copy)]
#![recursion_limit = "1024"]
#[cfg(all(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
compile_error!("Cannot enable bytechcked, non-bytechecked rkyv both");
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use swc_common::{ast_node, EqIgnoreSpan, Span};

View File

@ -6,8 +6,6 @@ use std::{
};
use num_bigint::BigInt as BigIntValue;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use swc_atoms::{js_word, Atom, JsWord};
use swc_common::{ast_node, util::take::Take, EqIgnoreSpan, Span, DUMMY_SP};
@ -68,10 +66,7 @@ bridge_lit_from!(BigInt, BigIntValue);
#[derive(Eq, Hash)]
pub struct BigInt {
pub span: Span,
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
with(EncodeBigInt)
)]
#[cfg_attr(any(feature = "rkyv-impl"), with(EncodeBigInt))]
pub value: Box<BigIntValue>,
/// Use `None` value only for transformations to avoid recalculate
@ -89,7 +84,7 @@ impl EqIgnoreSpan for BigInt {
#[derive(Debug, Clone, Copy)]
pub struct EncodeBigInt;
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl rkyv::with::ArchiveWith<Box<BigIntValue>> for EncodeBigInt {
type Archived = rkyv::Archived<String>;
type Resolver = rkyv::Resolver<String>;
@ -107,7 +102,7 @@ impl rkyv::with::ArchiveWith<Box<BigIntValue>> for EncodeBigInt {
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<S> rkyv::with::SerializeWith<Box<BigIntValue>, S> for EncodeBigInt
where
S: ?Sized + rkyv::ser::Serializer,
@ -121,7 +116,7 @@ where
}
}
#[cfg(any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
#[cfg(any(feature = "rkyv-impl"))]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<String>, Box<BigIntValue>, D> for EncodeBigInt
where
D: ?Sized + rkyv::Fallible,
@ -167,10 +162,7 @@ impl From<BigIntValue> for BigInt {
pub struct Str {
pub span: Span,
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
with(swc_atoms::EncodeJsWord)
)]
#[cfg_attr(any(feature = "rkyv-impl"), with(swc_atoms::EncodeJsWord))]
pub value: JsWord,
/// Use `None` value only for transformations to avoid recalculate escaped

View File

@ -1,12 +1,10 @@
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
use string_enum::StringEnum;
use swc_common::EqIgnoreSpan;
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum BinaryOp {
@ -115,7 +113,7 @@ impl BinaryOp {
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum AssignOp {
@ -188,7 +186,7 @@ impl AssignOp {
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum UpdateOp {
@ -201,7 +199,7 @@ pub enum UpdateOp {
#[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum UnaryOp {

View File

@ -5,8 +5,6 @@
use std::fmt;
use is_macro::Is;
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[cfg(feature = "serde-impl")]
use serde::{
de::{self, Unexpected, Visitor},
@ -397,7 +395,7 @@ pub struct TsKeywordType {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
@ -679,7 +677,7 @@ pub struct TsTypeOperator {
#[derive(StringEnum, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum TsTypeOperatorOp {
@ -705,7 +703,7 @@ pub struct TsIndexedAccessType {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum TruePlusMinus {
@ -1078,7 +1076,7 @@ pub struct TsSatisfiesExpr {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
any(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"),
any(feature = "rkyv-impl"),
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]

View File

@ -15,13 +15,11 @@ version = "0.31.1"
bench = false
[features]
__rkyv = []
rkyv-bytecheck-impl = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
serde-impl = ["serde"]
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
serde-impl = ["serde"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.0"
rkyv = { version = "=0.7.40", optional = true, features = [
"strict",

View File

@ -11,29 +11,14 @@ version = "0.32.1"
bench = false
[features]
__rkyv = []
# Enably rkyv serialization with stable version of rkyv.
__rkyv = []
rkyv-impl = ["__rkyv", "rkyv"]
# Enable rkyv serialization with updated version of rkyv, along with bytecheck.
rkyv-bytecheck-impl = ["__rkyv", "rkyv-latest"]
__plugin_mode = []
__plugin_rt = []
# swc/core, which runs plugin
plugin-bytecheck-rt = [
"__plugin_rt",
"swc_common/plugin-bytecheck-base",
"rkyv-bytecheck-impl",
]
plugin-rt = ["__plugin_rt", "swc_common/plugin-base", "rkyv-impl"]
# actual wasm plugin binary
plugin-bytecheck-mode = [
"__plugin_mode",
"swc_common/plugin-bytecheck-base",
"rkyv-bytecheck-impl",
]
plugin-mode = ["__plugin_mode", "swc_common/plugin-base", "rkyv-impl"]
plugin-rt = ["__plugin_rt", "swc_common/plugin-base", "rkyv-impl"]
[dependencies]
@ -41,10 +26,7 @@ rkyv = { package = "rkyv", version = "=0.7.40", 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 }
tracing = "0.1.32"
tracing = "0.1.32"
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }
swc_common = { version = "0.31.1", path = "../swc_common" }

View File

@ -1,5 +1,3 @@
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[cfg(feature = "__plugin_mode")]
use swc_common::{
comments::{Comment, Comments},

View File

@ -1,8 +1,5 @@
#![cfg_attr(not(feature = "__rkyv"), allow(warnings))]
#[cfg(all(feature = "rkyv-impl", feature = "rkyv-bytecheck-impl"))]
compile_error!("Cannot enable bytechcked, non-bytechecked rkyv both");
mod comments;
mod memory_interop;
mod metadata;

View File

@ -1,5 +1,3 @@
#[cfg(feature = "rkyv-bytecheck-impl")]
use rkyv_latest as rkyv;
#[cfg_attr(not(target_arch = "wasm32"), allow(unused))]
#[cfg(any(feature = "__plugin_rt", feature = "__plugin_mode"))]
use swc_common::plugin::serialized::{deserialize_from_ptr, PluginSerializedBytes};

View File

@ -44,12 +44,7 @@ ecma = ["swc_ecma_ast/rkyv-impl"]
# Enable CSS support
css = ["swc_css_ast/rkyv-impl"]
__rkyv = []
rkyv-bytecheck-impl = [
"__rkyv",
"swc_common/plugin-bytecheck-rt",
"swc_plugin_proxy/plugin-bytecheck-rt",
]
__rkyv = []
rkyv-impl = ["__rkyv", "swc_common/plugin-rt", "swc_plugin_proxy/plugin-rt"]
[dependencies]

View File

@ -56,7 +56,6 @@
"build:wasm": "npm-run-all \"pack -- build ./bindings/binding_core_wasm --scope swc {1} -t {2} --features plugin\" --",
"build": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --cargo-cwd ./bindings -p binding_core_node --release",
"build:dev": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --cargo-cwd ./bindings -p binding_core_node",
"build:bytecheck": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --cargo-cwd ./bindings --features swc_v1,plugin_bytecheck -p binding_core_node --cargo-flags=--no-default-features --release",
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --config ./node-swc/jest.config.js",
"version": "napi version -p scripts/npm"
},
@ -178,4 +177,4 @@
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
],
"packageManager": "yarn@3.5.0"
}
}

View File

@ -26,13 +26,13 @@ os:
check:
swc:
# plugin feature is verified by other tasks
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features debug --exclude-features plugin --exclude-features plugin_transform_schema_v1 --exclude-features plugin_transform_schema_vtest --exclude-features plugin-bytecheck"
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features debug --exclude-features plugin --exclude-features plugin_transform_schema_v1 --exclude-features plugin_transform_schema_vtest"
swc_bundler:
- "cargo hack check --feature-powerset --no-dev-deps"
swc_common:
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features plugin_transform_schema_vtest --exclude-features __plugin --exclude-features __plugin_mode --exclude-features __plugin_rt --exclude-features __rkyv --exclude-features plugin-bytecheck-base --exclude-features plugin-bytecheck-mode --exclude-features plugin-bytecheck-rt --exclude-features rkyv-bytecheck-impl --exclude-features rkyv-impl"
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features plugin_transform_schema_vtest --exclude-features __plugin --exclude-features __plugin_mode --exclude-features __plugin_rt --exclude-features __rkyv --exclude-features rkyv-impl"
swc_ecma_ast:
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features __rkyv --exclude-features rkyv-bytecheck-impl"
- "cargo hack check --feature-powerset --no-dev-deps --exclude-features __rkyv"
swc_ecma_loader:
- "cargo hack check --feature-powerset --no-dev-deps"
swc_ecma_transforms: