Commit 90c17993 authored by Matt Mastracci's avatar Matt Mastracci

Experiment: Wrap JsValue in Arc

parent 49e83f5d
use std::{borrow::Cow, collections::BTreeMap, fmt::Display}; use std::{borrow::Cow, collections::BTreeMap, fmt::Display, sync::Arc};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
...@@ -380,11 +380,11 @@ impl ImportMap { ...@@ -380,11 +380,11 @@ impl ImportMap {
if let Some((i, i_sym)) = self.imports.get(id) { if let Some((i, i_sym)) = self.imports.get(id) {
let r = &self.references[*i]; let r = &self.references[*i];
return Some(JsValue::member( return Some(JsValue::member(
Box::new(JsValue::Module(ModuleValue { Arc::new(JsValue::Module(ModuleValue {
module: r.module_path.clone(), module: r.module_path.clone(),
annotations: r.annotations.clone(), annotations: r.annotations.clone(),
})), })),
Box::new(i_sym.clone().into()), Arc::new(i_sym.clone().into()),
)); ));
} }
if let Some(i) = self.namespace_imports.get(id) { if let Some(i) = self.namespace_imports.get(id) {
......
use std::{collections::hash_map::Entry, fmt::Display, future::Future, mem::take}; use std::{collections::hash_map::Entry, fmt::Display, future::Future, mem::take, sync::Arc};
use anyhow::Result; use anyhow::Result;
use parking_lot::Mutex; use parking_lot::Mutex;
...@@ -178,11 +178,14 @@ where ...@@ -178,11 +178,14 @@ where
// Visit a function call // Visit a function call
// This need special handling, since we want to replace the function call and process // This need special handling, since we want to replace the function call and process
// the function return value after that. // the function return value after that.
Step::Visit(JsValue::Call( Step::Visit(JsValue::Call(_, callee, args))
_, if matches!(callee.as_ref(), JsValue::Function(..)) =>
box JsValue::Function(function_nodes, func_ident, return_value), {
args, let JsValue::Function(function_nodes, func_ident, return_value) =
)) => { Arc::unwrap_or_clone(callee)
else {
unreachable!()
};
total_nodes -= 2; // Call + Function total_nodes -= 2; // Call + Function
if let Entry::Vacant(entry) = fun_args_values.lock().entry(func_ident) { if let Entry::Vacant(entry) = fun_args_values.lock().entry(func_ident) {
// Return value will stay in total_nodes // Return value will stay in total_nodes
...@@ -192,7 +195,7 @@ where ...@@ -192,7 +195,7 @@ where
entry.insert(args); entry.insert(args);
fun_args_depth += 1; fun_args_depth += 1;
work_queue_stack.push(Step::LeaveCall(func_ident)); work_queue_stack.push(Step::LeaveCall(func_ident));
work_queue_stack.push(Step::Enter(*return_value)); work_queue_stack.push(Step::Enter(Arc::unwrap_or_clone(return_value)));
} else { } else {
total_nodes -= return_value.total_nodes(); total_nodes -= return_value.total_nodes();
for arg in args.iter() { for arg in args.iter() {
...@@ -201,7 +204,7 @@ where ...@@ -201,7 +204,7 @@ where
total_nodes += 1; total_nodes += 1;
done.push(JsValue::unknown( done.push(JsValue::unknown(
JsValue::call( JsValue::call(
Box::new(JsValue::Function(function_nodes, func_ident, return_value)), Arc::new(JsValue::Function(function_nodes, func_ident, return_value)),
args, args,
), ),
true, true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment