PS: Optimize ChildMapping using forward+reverse pruning#356
Merged
Conversation
LWSimpkins
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the final optimization I needed to make to make PowerShell analysis succeed on the Windows codebase.
The abstract
ChildMappingclass 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 extendsChildMappingand overridesrelevantChildto mark which AST children are the children of this parent class. TheChildMappinglogic then identifies the CFG nodes corresponding to those children so that we can implement "getter" predicates on the CFG classes (i.e.,getLeft()andgetRight()on CFG nodes corresponding to binary expressions).On
maintheChildMappinglogic 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.