feat: Implement closure cracking and inlining
Introduces a new optimizer pass that can "crack" closures, allowing for more aggressive specialization. It also enables inlining of upvalues that point to immutable global variables. This removes overhead for higher-order functions and currying when arguments are statically resolvable.
This commit is contained in:
@@ -23,10 +23,9 @@ impl<'a> LambdaCollector<'a> {
|
||||
}
|
||||
|
||||
BoundKind::DefGlobal { global_index, value, .. } => {
|
||||
// If we define a global that is a lambda, register its BODY as the template.
|
||||
// This allows the VM to skip the Lambda/Parameter nodes during execution.
|
||||
if let BoundKind::Lambda { body, .. } = &value.kind {
|
||||
self.registry.insert(*global_index, (**body).clone());
|
||||
// Register the full Lambda node as the template.
|
||||
if let BoundKind::Lambda { .. } = &value.kind {
|
||||
self.registry.insert(*global_index, (**value).clone());
|
||||
}
|
||||
self.visit(value);
|
||||
}
|
||||
@@ -34,9 +33,9 @@ impl<'a> LambdaCollector<'a> {
|
||||
BoundKind::Set { addr, value } => {
|
||||
// Also track assignments to globals if they hold lambdas.
|
||||
if let Address::Global(global_index) = addr
|
||||
&& let BoundKind::Lambda { body, .. } = &value.kind
|
||||
&& let BoundKind::Lambda { .. } = &value.kind
|
||||
{
|
||||
self.registry.insert(*global_index, (**body).clone());
|
||||
self.registry.insert(*global_index, (**value).clone());
|
||||
}
|
||||
self.visit(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user