Skip to content

Conversation

natecook1000
Copy link
Member

The shared DSLTree type that is used to store the pre-compilation regex pattern is an indirect enumeration that has arbitrary nesting/recursion. This design makes it challenging both to reference different parts of the tree and to manipulate the tree during compilation for pre- and mid-compilation optimizations.

This change introduces a DSLList type that stores a pre-order traversal of the tree in an array, and an alternate bytecode generation path that consumes the DSLList instead of recursing over the DSLTree, with tests that the generated bytecode is identical between the two structures.

Still to do (note that compilation time will worsen until these are complete):

  • modify the nodes to store only a child count instead of the children themselves
  • generate the DSLList directly from parsing/instantiation
  • eliminate use of the DSLTree representation

This implements bytecode generation from a DSLList instead of a
DSLTree. The change includes tests that all regex patterns in the
`MatchTests` file produce the exact same bytecode from a list as from
a tree.
This likely involves an increase in compilation time, since the list
needs to be generated from the tree before compiling.
@natecook1000 natecook1000 merged commit 4cdb58a into swiftlang:feature/perf Oct 7, 2025
19 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.

1 participant