Skip to content

PS: Optimize ChildMapping using forward+reverse pruning#356

Merged
MathiasVP merged 1 commit intomainfrom
powershell-reverse-child-recurse-direction
May 5, 2026
Merged

PS: Optimize ChildMapping using forward+reverse pruning#356
MathiasVP merged 1 commit intomainfrom
powershell-reverse-child-recurse-direction

Conversation

@MathiasVP
Copy link
Copy Markdown
Collaborator

This is the final optimization I needed to make to make PowerShell analysis succeed on the Windows codebase.

The abstract ChildMapping class is used to convert parent/child relations from the AST layer to the parent/child relations in the CFG layer. Each AST class implements a subclass that extends ChildMapping and overrides relevantChild to mark which AST children are the children of this parent class. The ChildMapping logic then identifies the CFG nodes corresponding to those children so that we can implement "getter" predicates on the CFG classes (i.e., getLeft() and getRight() on CFG nodes corresponding to binary expressions).

On main the ChildMapping logic is pretty simple: we do a forward pass starting at the relevant children and then we recurse backwards or forwards (depending on whether the children occur "before" the parent or "after" the parent in the control-flow graph). However, this was blowing up on a large Windows repository.

So taking inspiration from Rust I extended this to perform a reverse pass after performing the existing forward pass. The reverse pass starts at the parent and proceeds along successor/predecessors from the forward pass.

@MathiasVP MathiasVP merged commit d52f413 into main May 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants