-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Revise docs for thir::PatKind::ExpandedConstant
#136612
base: master
Are you sure you want to change the base?
Conversation
I have mixed feelings about whether to mention On one hand, it's useful to know that if an ExpandedConstant exists, then it typically wraps the result of On the other hand, there are plenty of cases where the result of |
I was not aware of that, do you have an example? Could we add the wrapper consistently? |
Literals are lowered via (There is an existing diagnostic for numeric literals in irrefutable patterns that could theoretically want such a wrapper, but in practice it can get away with just detecting I think that when I said “plenty of cases”, I was also thinking of paths like |
Hmm, it's fine by me if we don't count a literal as an "expanded constant" since there was no expansion done: it becomes a PatKind::Constant directly. I don't know if that would be clear to everyone though |
Constant { | ||
value: mir::Const<'tcx>, | ||
}, | ||
|
||
/// Pattern obtained by converting a constant (inline or named) to its pattern | ||
/// representation using `const_to_pat`. | ||
/// Marker node that wraps the result of converting some kind of "constant" |
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.
How about something like:
/// A constant in a pattern gets expanded into a `thir::Pat` that exactly matches its value. For
/// non-trivial constants (i.e. those that aren't literals handled by PatKind::Constant), we wrap
/// it in an `ExpandedConstant` node. Unsafeck and some diagnostics rely on the presence of this
/// node.
and then the note about range patterns.
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.
Since apparently we're not adding this node for all constants, we could add "byte string literals are another exception: we don't add an ExpandedConstant
node today".
Also there is at least one kind of literal that gets lowered/expanded to a non-trivial non- (I don't think we have any diagnostics or static checks that specifically care about that at the moment, but it's not hard to imagine someone wanting that in the future.) |
Good point! feels ok to add an |
Side note: Something we can't do right now, but could do in the future if we had If that were the case, we wouldn't even need to worry about peeling off these wrapper nodes in code that wants to pattern-match on node type. Code that cares about the side data would check it, and code that doesn't care would just ignore it. |
Interesting point yes. I'm not sure why we chose to box thir::Pat when the rest of Thir uses ids. |
I think it's just an implementation detail that has historically been hard to change. When I have tried to switch over in the past, I always got stuck on some messy detail. Some of my THIR cleanups have been motivated by trying to resolve those details, so that switching over to |
@Zalathar I'm happy to merge this as-is, or with some of my suggestions. What would you prefer? |
One of the reasons I pursued #136529 was that I found the existing docs for
ExpandedConstant
to be not very helpful when I was trying to understand why that pattern node kind exists, and what it does.These new docs try to explain things in more detail, with a particular focus on the points that I personally found confusing.
r? Nadrieril