-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support WeakReferences in NodeConnectingVisitor #1057
Conversation
I think in CloningVisitor we don't need a weak-ref because we clone the elements, right? |
if ($this->weakReferences) { | ||
$parent = \WeakReference::create($parent); | ||
} | ||
$node->setAttribute('parent', $parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I'm wondering about here is whether we should reuse the same attribute names, or use a different one like 'weak_parent'
, to avoid having two possible types for these attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use separate attribute names, but then I would go with a separate WeakNodeConnectingVisitor class and leave NodeConnectingVisitor untouched ..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the implementation themselves are pretty trivial, I'd be fine with adding separate classes as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with the PR as is, in case you are also ok with it
Friendly ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also update https://github.com/nikic/PHP-Parser/blob/master/doc/component/FAQ.markdown to mention the new option (and why it is recommended to use it)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update the class comment for the new option?
if ($this->previous !== null) { | ||
if ( | ||
$this->weakReferences | ||
&& $this->previous->getAttribute('weak_parent') === $node->getAttribute('weak_parent') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd split these conditions. If weakReferences we don't want to fall through to the condition below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, update class comment.
addressed your feedback, thank you. |
closes #1055
we observed perf improvements on a similar visitor in staabm/phpstan-dba#667 (comment)