feat: Add stack size to runtime metadata
Store the pre-calculated stack size of lambda bodies in the RuntimeMetadata. This allows the VM to directly access this information without recalculating it.
This commit is contained in:
@@ -10,6 +10,7 @@ pub struct RuntimeMetadata {
|
||||
pub is_tail: bool,
|
||||
/// The analyzed node, containing metrics and a link to the original TypedNode.
|
||||
pub original: Rc<AnalyzedNode>,
|
||||
pub stack_size: u32,
|
||||
}
|
||||
|
||||
impl Debug for RuntimeMetadata {
|
||||
@@ -17,6 +18,7 @@ impl Debug for RuntimeMetadata {
|
||||
f.debug_struct("Metadata")
|
||||
.field("ty", &self.ty)
|
||||
.field("is_tail", &self.is_tail)
|
||||
.field("stack_size", &self.stack_size)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
@@ -174,6 +176,16 @@ impl TCO {
|
||||
BoundKind::Error => BoundKind::Error,
|
||||
};
|
||||
|
||||
let stack_size = match &new_kind {
|
||||
BoundKind::Lambda { .. } => {
|
||||
// Pre-calculate stack size for the lambda body.
|
||||
// Note: 'node' here is AnalyzedNode (Node<BoundKind<NodeMetrics>, NodeMetrics>)
|
||||
// 'calculate_stack_size' works for any T.
|
||||
node.calculate_stack_size()
|
||||
}
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
Node {
|
||||
identity: node.identity.clone(),
|
||||
kind: new_kind,
|
||||
@@ -181,6 +193,7 @@ impl TCO {
|
||||
ty: node.ty.original.ty.clone(),
|
||||
is_tail: is_tail_position,
|
||||
original: node_rc,
|
||||
stack_size,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -508,7 +508,7 @@ impl VM {
|
||||
for addr in upvalues {
|
||||
captured.push(self.capture_upvalue(*addr)?);
|
||||
}
|
||||
let stack_size = body.calculate_stack_size();
|
||||
let stack_size = node.ty.stack_size;
|
||||
let closure = Closure::new(
|
||||
params.ty.original.clone(),
|
||||
body.ty.original.clone(),
|
||||
|
||||
Reference in New Issue
Block a user