Repository navigation
Clear stale node connections when reconnecting an edited AST - #1180
Open
sergioperezcheco wants to merge 1 commit into
Open
sergioperezcheco wants to merge 1 commit into
sergioperezcheco wants to merge 1 commit into
Conversation
Preserve non-connection attributes and the inactive reference namespace while rebuilding links after AST edits. Assisted-by: Hermes Agent (Nous Research) Signed-off-by: sergioperezcheco <checo520@outlook.com>
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.
Reconnecting an edited AST
NodeConnectingVisitoradds the links needed by the current traversal, but does not remove links that no longer have a replacement. Running it again after editing an AST can therefore leave a parent on a node promoted to the root, apreviouslink on the new first sibling, or anextlink on the new last sibling.For example, this prints
falsebefore the change andtrueafterwards:Clear the current reference mode's three connection attributes on entry, then let the existing traversal rebuild them. Other attributes, including source positions and the inactive reference namespace, are preserved. This only updates visited nodes; it does not clean up detached nodes or change the separate-traversal usage described in #697.
The regressions cover reordered siblings, a promoted child, and removed siblings in both strong and weak reference modes.
Verification and cost
With the final tests and original production code, the full suite has six failures. With this change:
There is a performance trade-off:
getAttributes()followed by modification andsetAttributes()copies the PHP attribute array. In a local PHP 8.3 benchmark of 72,000 parsed nodes, three independent processes per configuration and 13 repeated traversals per process, median visitor time changed from 45.9 to 55.6 ms for strong references and 48.1 to 60.3 ms for weak references. With 32 extra attributes per node, it changed from 58.5 to 78.0 ms and 64.7 to 84.4 ms respectively. These are visitor-only measurements, not whole-application results. The patch keeps the existing node API rather than adding an attribute-removal method.Native PHP 7.4, coverage, the php-src integration jobs, and the remaining platform/version matrix were not run locally and remain for CI.
This contribution was produced and reviewed by autonomous AI agents; no human review is claimed.