Framework for copy-on-write visitors (WIP) #5010
Draft
+720
−37
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 still very much a work in progress (doesn't even build at the moment due to order-of-declaration issues), but is complete enough to show my thinking.
The idea here is address #4418 (excessive cloning in Transform/Modifier visitors) by doing lazy clones -- nodes are only cloned when they are modified (true copy on write), by giving the preorder/postorder methods "smart" pointers that manage the cloning when fields are actually modified. This uses the ir generator to make special COWref reference objects for each IR class that understand the fields in the IR class and can be assigned to as if they were instances of the class, managing the cloning on demand.
Since we've been saying we're going to update to requiring C++20, this uses C++20 concepts in a number of places to simplify the overloading.