Handle macro expansion in lambda collection

Recursively traverse through `BoundKind::Expansion` nodes when
collecting lambdas to ensure that macros correctly expanded into lambdas
are registered. This also updates assignments to global variables to
correctly track lambdas that have been assigned after macro expansion.

Added a new integration test to verify that macro-wrapped function calls
are correctly inlined and optimized, and that unused definitions are
removed by dead code elimination.
This commit is contained in:
Michael Schimmel
2026-02-25 13:47:50 +01:00
parent b12b85f54a
commit 11f6115fc1
2 changed files with 52 additions and 10 deletions
+20 -10
View File
@@ -24,22 +24,32 @@ impl<'a, T: Clone> LambdaCollector<'a, T> {
BoundKind::Define { addr, value, .. } => {
// Register global function definitions (lambdas)
if let Address::Global(global_index) = addr
&& let BoundKind::Lambda { .. } = &value.kind
{
self.registry
.insert(*global_index, (*value).as_ref().clone());
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).as_ref().clone());
}
}
self.visit(value);
}
BoundKind::Set { addr, value } => {
// Also track assignments to globals if they hold lambdas.
if let Address::Global(global_index) = addr
&& let BoundKind::Lambda { .. } = &value.kind
{
self.registry
.insert(*global_index, (*value).as_ref().clone());
if let Address::Global(global_index) = addr {
let mut current = value;
while let BoundKind::Expansion { bound_expanded, .. } = &current.kind {
current = bound_expanded;
}
if let BoundKind::Lambda { .. } = &current.kind {
self.registry
.insert(*global_index, (*current).as_ref().clone());
}
}
self.visit(value);
}