Commit 5c9525be authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

tracing

parent 6d318d61
...@@ -245,6 +245,86 @@ impl Effect { ...@@ -245,6 +245,86 @@ impl Effect {
Effect::Unreachable { .. } => {} Effect::Unreachable { .. } => {}
} }
} }
/// Returns all JsValues referened by this effect. (Intended for debugging purposes.)
pub fn values(&self) -> Vec<&JsValue> {
match self {
Effect::Call { func, args, .. } => {
let mut result = vec![&**func];
result.extend(args.iter().flat_map(|arg| {
match arg {
EffectArg::Value(val) => vec![val],
EffectArg::Closure(func, block) => std::iter::once(func)
.chain(block.effects.iter().flat_map(|e| e.values()))
.collect(),
EffectArg::Spread => vec![],
}
}));
result
}
Effect::MemberCall {
obj, prop, args, ..
} => {
let mut result = vec![&**obj, &**prop];
result.extend(args.iter().flat_map(|arg| {
match arg {
EffectArg::Value(val) => vec![val],
EffectArg::Closure(func, block) => std::iter::once(func)
.chain(block.effects.iter().flat_map(|e| e.values()))
.collect(),
EffectArg::Spread => vec![],
}
}));
result
}
Effect::Conditional {
condition, kind, ..
} => {
let mut result = vec![&**condition];
match &**kind {
ConditionalKind::If { then: block }
| ConditionalKind::Else { r#else: block }
| ConditionalKind::And { expr: block, .. }
| ConditionalKind::Or { expr: block, .. }
| ConditionalKind::NullishCoalescing { expr: block, .. }
| ConditionalKind::Labeled { body: block } => {
result.extend(block.effects.iter().flat_map(|e| e.values()));
}
ConditionalKind::IfElse { then, r#else, .. }
| ConditionalKind::Ternary { then, r#else, .. } => {
result.extend(
then.effects
.iter()
.chain(r#else.effects.iter())
.flat_map(|e| e.values()),
);
}
ConditionalKind::IfElseMultiple { then, r#else, .. } => {
result.extend(
then.iter()
.flat_map(|b| b.effects.iter().flat_map(|e| e.values()))
.chain(
r#else
.iter()
.flat_map(|b| b.effects.iter().flat_map(|e| e.values())),
),
);
}
};
result
}
Effect::Member { obj, prop, .. } => {
vec![obj, prop]
}
Effect::TypeOf { arg, .. } => {
vec![arg]
}
Effect::FreeVar { .. }
| Effect::ImportedBinding { .. }
| Effect::ImportMeta { .. }
| Effect::Unreachable { .. } => vec![],
}
}
} }
pub enum AssignmentScope { pub enum AssignmentScope {
......
...@@ -22,16 +22,23 @@ where ...@@ -22,16 +22,23 @@ where
RF: 'a + Future<Output = Result<(JsValue, bool)>> + Send, RF: 'a + Future<Output = Result<(JsValue, bool)>> + Send,
F: 'a + Fn(JsValue) -> RF + Sync, F: 'a + Fn(JsValue) -> RF + Sync,
{ {
// use tracing::Instrument;
// let span = tracing::trace_span!("link", steps = tracing::field::Empty);
val.normalize(); val.normalize();
let (val, steps) = link_internal_iterative( let (val, steps) = async {
graph, link_internal_iterative(
val, graph,
early_visitor, val,
visitor, early_visitor,
fun_args_values, visitor,
var_cache, fun_args_values,
) var_cache,
)
.await
}
// .instrument(span.clone())
.await?; .await?;
// span.record("steps", steps);
Ok((val, steps)) Ok((val, steps))
} }
......
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