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 rustc_hash::{FxHashMap, FxHashSet};
......@@ -380,11 +380,11 @@ impl ImportMap {
if let Some((i, i_sym)) = self.imports.get(id) {
let r = &self.references[*i];
return Some(JsValue::member(
Box::new(JsValue::Module(ModuleValue {
Arc::new(JsValue::Module(ModuleValue {
module: r.module_path.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) {
......
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 parking_lot::Mutex;
......@@ -178,11 +178,14 @@ where
// Visit a function call
// This need special handling, since we want to replace the function call and process
// the function return value after that.
Step::Visit(JsValue::Call(
_,
box JsValue::Function(function_nodes, func_ident, return_value),
args,
)) => {
Step::Visit(JsValue::Call(_, callee, args))
if matches!(callee.as_ref(), JsValue::Function(..)) =>
{
let JsValue::Function(function_nodes, func_ident, return_value) =
Arc::unwrap_or_clone(callee)
else {
unreachable!()
};
total_nodes -= 2; // Call + Function
if let Entry::Vacant(entry) = fun_args_values.lock().entry(func_ident) {
// Return value will stay in total_nodes
......@@ -192,7 +195,7 @@ where
entry.insert(args);
fun_args_depth += 1;
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 {
total_nodes -= return_value.total_nodes();
for arg in args.iter() {
......@@ -201,7 +204,7 @@ where
total_nodes += 1;
done.push(JsValue::unknown(
JsValue::call(
Box::new(JsValue::Function(function_nodes, func_ident, return_value)),
Arc::new(JsValue::Function(function_nodes, func_ident, return_value)),
args,
),
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