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:
@@ -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, .. } = ¤t.kind {
|
||||
current = bound_expanded;
|
||||
}
|
||||
|
||||
if let BoundKind::Lambda { .. } = ¤t.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, .. } = ¤t.kind {
|
||||
current = bound_expanded;
|
||||
}
|
||||
|
||||
if let BoundKind::Lambda { .. } = ¤t.kind {
|
||||
self.registry
|
||||
.insert(*global_index, (*current).as_ref().clone());
|
||||
}
|
||||
}
|
||||
self.visit(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user