fix(es/plugin/runner): Provide guest memory allocator for the sourcemap (#5517)

This commit is contained in:
OJ Kwon 2022-08-16 17:25:40 -07:00 committed by GitHub
parent 1a5b9792ef
commit 3bdb39c0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 46 deletions

26
Cargo.lock generated
View File

@ -2342,9 +2342,9 @@ checksum = "11000e6ba5020e53e7cc26f73b91ae7d5496b4977851479edb66b694c0675c21"
[[package]]
name = "rkyv"
version = "0.7.39"
version = "0.7.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cec2b3485b07d96ddfd3134767b8a447b45ea4eb91448d0a35180ec0ffd5ed15"
checksum = "517a3034eb2b1499714e9d1e49b2367ad567e07639b69776d35e259d9c27cca6"
dependencies = [
"bytecheck",
"hashbrown 0.12.0",
@ -2357,9 +2357,9 @@ dependencies = [
[[package]]
name = "rkyv_derive"
version = "0.7.39"
version = "0.7.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6eaedadc88b53e36dd32d940ed21ae4d850d5916f2581526921f553a72ac34c4"
checksum = "505c209ee04111a006431abf39696e640838364d67a107c559ababaf6fd8c9dd"
dependencies = [
"proc-macro2",
"quote",
@ -2815,7 +2815,7 @@ dependencies = [
[[package]]
name = "swc"
version = "0.214.7"
version = "0.214.8"
dependencies = [
"ahash",
"ansi_term",
@ -2871,7 +2871,7 @@ dependencies = [
[[package]]
name = "swc_atoms"
version = "0.4.6"
version = "0.4.7"
dependencies = [
"bytecheck",
"once_cell",
@ -2942,7 +2942,7 @@ dependencies = [
[[package]]
name = "swc_common"
version = "0.27.9"
version = "0.27.10"
dependencies = [
"ahash",
"anyhow",
@ -3000,7 +3000,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.7.16"
version = "0.7.18"
dependencies = [
"binding_macros",
"once_cell",
@ -3043,7 +3043,7 @@ dependencies = [
[[package]]
name = "swc_css_ast"
version = "0.107.1"
version = "0.107.2"
dependencies = [
"bytecheck",
"is-macro",
@ -3177,7 +3177,7 @@ dependencies = [
[[package]]
name = "swc_ecma_ast"
version = "0.90.8"
version = "0.90.9"
dependencies = [
"arbitrary",
"bitflags",
@ -3829,7 +3829,7 @@ dependencies = [
[[package]]
name = "swc_html_ast"
version = "0.24.5"
version = "0.24.6"
dependencies = [
"bytecheck",
"is-macro",
@ -4021,7 +4021,7 @@ dependencies = [
[[package]]
name = "swc_plugin_proxy"
version = "0.18.10"
version = "0.18.11"
dependencies = [
"better_scoped_tls",
"bytecheck",
@ -4034,7 +4034,7 @@ dependencies = [
[[package]]
name = "swc_plugin_runner"
version = "0.71.12"
version = "0.71.13"
dependencies = [
"anyhow",
"criterion",

View File

@ -9,7 +9,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.214.7"
version = "0.214.8"
[lib]
bench = false
@ -90,7 +90,7 @@ swc_ecma_visit = { version = "0.76.5", path = "../swc_ecma_visit" }
swc_error_reporters = { version = "0.11.4", path = "../swc_error_reporters" }
swc_node_comments = { version = "0.14.4", path = "../swc_node_comments" }
swc_plugin_proxy = { version = "0.18.7", path = "../swc_plugin_proxy", optional = true }
swc_plugin_runner = { version = "0.71.7", path = "../swc_plugin_runner", optional = true, default-features = false }
swc_plugin_runner = { version = "0.71.13", path = "../swc_plugin_runner", optional = true, default-features = false }
swc_timer = { version = "0.15.4", path = "../swc_timer" }
swc_visit = { version = "0.5.2", path = "../swc_visit" }
tracing = "0.1.32"

View File

@ -7,7 +7,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_atoms"
repository = "https://github.com/swc-project/swc.git"
version = "0.4.6"
version = "0.4.7"
[lib]
bench = false
@ -18,7 +18,7 @@ rkyv-impl = ["rkyv", "bytecheck"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
once_cell = "1"
rkyv = { version = "0.7.39", optional = true }
rkyv = { version = "=0.7.38", optional = true }
rustc-hash = "1.1.0"
serde = "1"
string_cache = "0.8.4"

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_common"
repository = "https://github.com/swc-project/swc.git"
version = "0.27.9"
version = "0.27.10"
[package.metadata.docs.rs]
all-features = true
@ -44,13 +44,13 @@ from_variant = { version = "0.1.3", path = "../from_variant" }
num-bigint = "0.4"
once_cell = "1.10.0"
parking_lot = { version = "0.12.0", optional = true }
rkyv = { version = "0.7.39", optional = true }
rkyv = { version = "=0.7.38", 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.4"
swc_atoms = { version = "0.4.5", path = "../swc_atoms" }
swc_atoms = { version = "0.4.6", path = "../swc_atoms" }
swc_eq_ignore_macros = { version = "0.1.1", path = "../swc_eq_ignore_macros" }
swc_visit = { version = "0.5.2", path = "../swc_visit" }
termcolor = { version = "1.0", optional = true }

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_core"
repository = "https://github.com/swc-project/swc.git"
version = "0.7.16"
version = "0.7.18"
[package.metadata.docs.rs]
features = [
"common_perf",
@ -225,10 +225,10 @@ wasmer-wasi = { optional = true, version = "3.0.0-beta", default-features = fals
# swc_* dependencies
binding_macros = { optional = true, version = "0.2.3", path = "../binding_macros" }
swc = { optional = true, version = "0.214.7", path = "../swc" }
swc_atoms = { optional = true, version = "0.4.6", path = "../swc_atoms" }
swc = { optional = true, version = "0.214.8", path = "../swc" }
swc_atoms = { optional = true, version = "0.4.7", path = "../swc_atoms" }
swc_bundler = { optional = true, version = "0.177.3", path = "../swc_bundler" }
swc_common = { optional = true, version = "0.27.9", path = "../swc_common" }
swc_common = { optional = true, version = "0.27.10", path = "../swc_common" }
swc_ecma_ast = { optional = true, version = "0.90.8", path = "../swc_ecma_ast" }
swc_ecma_loader = { optional = true, version = "0.39.4", path = "../swc_ecma_loader" }
swc_ecma_parser = { optional = true, version = "0.117.4", path = "../swc_ecma_parser" }
@ -242,10 +242,10 @@ swc_node_bundler = { optional = true, version = "0.0.2", path = "../s
swc_nodejs_common = { optional = true, version = "0.0.1", path = "../swc_nodejs_common" }
swc_plugin = { optional = true, version = "0.89.1", path = "../swc_plugin" }
swc_plugin_macro = { optional = true, version = "0.9.7", path = "../swc_plugin_macro" }
swc_plugin_proxy = { optional = true, version = "0.18.10", path = "../swc_plugin_proxy" }
swc_plugin_proxy = { optional = true, version = "0.18.11", path = "../swc_plugin_proxy" }
swc_trace_macro = { optional = true, version = "0.1.2", path = "../swc_trace_macro" }
# TODO: eventually swc_plugin_runner needs to remove default features
swc_plugin_runner = { optional = true, version = "0.71.12", path = "../swc_plugin_runner", default-features = false }
swc_plugin_runner = { optional = true, version = "0.71.13", path = "../swc_plugin_runner", default-features = false }
[dev-dependencies]
testing = { version = "0.29.4", path = "../testing" }

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_css_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.107.1"
version = "0.107.2"
[lib]
bench = false
@ -19,7 +19,7 @@ rkyv-impl = ["rkyv", "bytecheck", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.0"
rkyv = { version = "0.7.39", optional = true }
rkyv = { version = "=0.7.38", optional = true }
serde = { version = "1.0.127", features = ["derive"] }
string_enum = { version = "0.3.1", path = "../string_enum/" }
swc_atoms = { version = "0.4.5", path = "../swc_atoms" }

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_ecma_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.90.8"
version = "0.90.9"
[package.metadata.docs.rs]
all-features = true
@ -26,7 +26,7 @@ bitflags = "1"
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.0"
num-bigint = { version = "0.4", features = ["serde"] }
rkyv = { version = "0.7.39", optional = true }
rkyv = { version = "=0.7.38", optional = true }
scoped-tls = "1.0.0"
serde = { version = "1.0.133", features = ["derive"] }
string_enum = { version = "0.3.1", path = "../string_enum" }

View File

@ -9,7 +9,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_html_ast"
repository = "https://github.com/swc-project/swc.git"
version = "0.24.5"
version = "0.24.6"
[lib]
bench = false
@ -20,7 +20,7 @@ rkyv-impl = ["rkyv", "bytecheck", "swc_atoms/rkyv-impl", "swc_common/rkyv-impl"]
[dependencies]
bytecheck = { version = "0.6.9", optional = true }
is-macro = "0.2.0"
rkyv = { version = "0.7.39", optional = true }
rkyv = { version = "=0.7.38", optional = true }
serde = { version = "1.0.127", features = ["derive"] }
string_enum = { version = "0.3.1", path = "../string_enum/" }
swc_atoms = { version = "0.4.5", path = "../swc_atoms" }

View File

@ -5,7 +5,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_proxy"
repository = "https://github.com/swc-project/swc.git"
version = "0.18.10"
version = "0.18.11"
[lib]
bench = false
@ -19,7 +19,7 @@ plugin-mode = []
[dependencies]
better_scoped_tls = { version = "0.1.0", path = "../better_scoped_tls" }
bytecheck = "0.6.9"
rkyv = "0.7.39"
rkyv = "=0.7.38"
swc_common = { version = "0.27.7", path = "../swc_common", features = [
"plugin-base",
] }

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_plugin_runner"
repository = "https://github.com/swc-project/swc.git"
version = "0.71.12"
version = "0.71.13"
[lib]
bench = false

View File

@ -17,7 +17,7 @@ pub struct SourceMapHostEnvironment {
pub memory: Option<Memory>,
/// Attached imported fn `__alloc` to the hostenvironment to allow any other
/// imported fn can allocate guest's memory space from host runtime.
pub allocate_guest_memory: Option<TypedFunction<i32, i32>>,
pub alloc_guest_memory: Option<TypedFunction<i32, i32>>,
pub source_map: Arc<Mutex<Arc<SourceMap>>>,
/// A buffer to non-determined size of return value from the host.
pub mutable_source_map_buffer: Arc<Mutex<Vec<u8>>>,
@ -30,7 +30,7 @@ impl SourceMapHostEnvironment {
) -> SourceMapHostEnvironment {
SourceMapHostEnvironment {
memory: None,
allocate_guest_memory: None,
alloc_guest_memory: None,
source_map: source_map.clone(),
mutable_source_map_buffer: mutable_source_map_buffer.clone(),
}
@ -40,9 +40,6 @@ impl SourceMapHostEnvironment {
/// Returns `Loc` form given bytepos to the guest.
/// Returned `Loc` is partial, which excludes `SourceFile` from original struct
/// to avoid unnecessary data copying.
///
/// PluginSourceMapProxy::lookup_char_pos internally request separately if
/// `SourceFile` is needed.
#[tracing::instrument(level = "info", skip_all)]
pub fn lookup_char_pos_proxy(
mut env: FunctionEnvMut<SourceMapHostEnvironment>,
@ -66,7 +63,7 @@ pub fn lookup_char_pos_proxy(
let serialized_loc_bytes =
PluginSerializedBytes::try_serialize(&ret).expect("Should be serializable");
if let Some(alloc_guest_memory) = env.data().allocate_guest_memory.clone().as_ref() {
if let Some(alloc_guest_memory) = env.data().alloc_guest_memory.clone().as_ref() {
allocate_return_values_into_guest(
memory,
&mut env.as_store_mut(),
@ -162,7 +159,7 @@ pub fn span_to_lines_proxy(
let serialized_loc_bytes =
PluginSerializedBytes::try_serialize(&ret).expect("Should be serializable");
if let Some(alloc_guest_memory) = env.data().allocate_guest_memory.clone().as_ref() {
if let Some(alloc_guest_memory) = env.data().alloc_guest_memory.clone().as_ref() {
allocate_return_values_into_guest(
memory,
&mut env.as_store_mut(),
@ -192,7 +189,7 @@ pub fn lookup_byte_offset_proxy(
let serialized_loc_bytes =
PluginSerializedBytes::try_serialize(&ret).expect("Should be serializable");
if let Some(alloc_guest_memory) = env.data().allocate_guest_memory.clone().as_ref() {
if let Some(alloc_guest_memory) = env.data().alloc_guest_memory.clone().as_ref() {
allocate_return_values_into_guest(
memory,
&mut env.as_store_mut(),
@ -227,7 +224,7 @@ pub fn span_to_string_proxy(
let serialized_loc_bytes =
PluginSerializedBytes::try_serialize(&ret).expect("Should be serializable");
if let Some(alloc_guest_memory) = env.data().allocate_guest_memory.clone().as_ref() {
if let Some(alloc_guest_memory) = env.data().alloc_guest_memory.clone().as_ref() {
allocate_return_values_into_guest(
memory,
&mut env.as_store_mut(),
@ -262,7 +259,7 @@ pub fn span_to_filename_proxy(
let serialized_loc_bytes =
PluginSerializedBytes::try_serialize(&ret).expect("Should be serializable");
if let Some(alloc_guest_memory) = env.data().allocate_guest_memory.clone().as_ref() {
if let Some(alloc_guest_memory) = env.data().alloc_guest_memory.clone().as_ref() {
allocate_return_values_into_guest(
memory,
&mut env.as_store_mut(),

View File

@ -119,9 +119,10 @@ pub fn load_plugin(
base_env.as_mut(store).memory = Some(memory.clone());
comments_env.as_mut(store).memory = Some(memory.clone());
comments_env.as_mut(store).alloc_guest_memory = Some(alloc);
comments_env.as_mut(store).alloc_guest_memory = Some(alloc.clone());
source_map_host_env.as_mut(store).memory = Some(memory.clone());
source_map_host_env.as_mut(store).alloc_guest_memory = Some(alloc);
Ok(instance)
} else {