-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix AST export crash for closures in const-expressions #17120
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
Conversation
Tbh, I would prefer a simple solution, e.g. by printing a placeholder in the ast dumper. Accurate ast dumping is not very important. |
That would also be fine with me. Nevertheless I would suggest to keep the first commit (I can send a separate PR for that), as it it definitely fixes a bug in handling of |
This comment was marked as off-topic.
This comment was marked as off-topic.
05e868f
to
45057db
Compare
@iluuu1994 I actually like the full AST being there. While it's not fundamentally necessary for usability, it's nice to have I think. |
One difference imo is that closures may grow large, in comparison to singular expressions. This ast is almost never used, but will still take up shm space with little benefit. |
@iluuu1994 I doubt the amount of closures within attributes will be significant enough to warrant considerations in that regard. |
@bwoebi You're right, probably not. However, it's also a weird exception. E.g. we don't attempt to preserve the AST in other cases. Without opcache, the AST is discarded after the expression has been evaluated, and a lot of time expressions get folded into some concrete value at compile time. So, I'm just wondering why we need to make an exception here. |
@iluuu1994 But it's also a weird exception to not preserve Closure contents, but everything else in an attribute. |
@bwoebi But again, "preserve" is a stretch, compile-time optimizations still apply. I don't believe we preserve the AST solely for the purposes of printing, rather than evaluating. Even But ok, I don't object strongly to this, so feel free to go with this approach if you prefer. |
@iluuu1994 I don't have a strong opinion either way. Shall I extract the first commit (which I consider to be a bugfix) into a separate PR to allow for an independent review? |
@TimWolla If we decide not to store the AST in this case, it might be better to just add some |
That makes sense to me. With the assertions being there in all the locations, (re)doing the implementation is straight forward. The complicated part was finding all the locations. |
I don't know what would be the most useful between displaying the source code or displaying a placeholder with the closure location (filename / lineno). Currently we don't expose a closure's source code in Otherwise, given that we primarily store the AST for evaluation purposes, and the AST is already evaluated in this case (to an op_array), maybe we can store a string instead? This would take less space, and would be comparable to a doc comment. I believe that this is what we do for |
I'd be good with just producing a placeholder and not adding more bits to the runtime memory for this. But maybe I'm missing some context and don't understand the benefits or potential use cases for this, and I'm overlooking some reason why this is useful.
So without a concrete use case at hand, I'd argue for dropping it, and otherwise I'm happy to change my mind. |
c5ad440
to
29977f0
Compare
Okay, I've opted to show a placeholder there, but left commits that store the AST as a string and the original implementation that stores the full AST in the commit history, should we want to decide differently. Regarding the “store as string” variant, it should be noted that it naturally cannot take the |
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.
Code looks correct 👍 Not necessarily a fan of more ast types, but not objecting.
Previously `zend_ast_decl` AST nodes were handled as if they were regular `zend_ast` nodes. This was not observable, because copying an AST only happened when evaluating const-expressions, which could not include declarations until the “Support Closures in constant expressions” RFC.
This is necessary when stringifying a `ReflectionAttribute` that has a closure as a parameter.
This is unreachable / untestable now.
6ee4bad
to
f029cc1
Compare
As per the discussion in phpGH-17120, we are printing a placeholder value only. The commit history of that PR also includes alternative implementations, should a different decision be desirable. Fixes phpGH-17096 Closes phpGH-17120
Fixes GH-17096.