-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] NFC - Make #15419 work with weak vars #15542
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
[Sema] NFC - Make #15419 work with weak vars #15542
Conversation
@swift-ci please smoke test |
I don't think this makes sense. |
Can you elaborate? The validation test suite passes on my Linux box. |
I think I get it now, the #15419 optimization doesn't optimize anything if the expression is not a tuple/dictionary/array literal, and weak variables will never be tuple/array/dictionary literals. I guess this pull request is superficial. Do you find the resulting code to be prettier? Or would you rather have two switch statements? And what about |
Oh sorry, I just meant that it wouldn't be legal code. Compiling:
Results in:
I had originally tried to make this work, as well as things with Now having said that, it would produce a diagnostic faster (or at all the the case of expressions where we would otherwise bail out with "expression was too complex"). When I had a similar change I wasn't really able to convince myself that it was actually correct, though, since the RHS might be inferred to be an optional as well, so whether you're wrapping it in another optional or not really shouldn't depend on whether we knew we had an optional on the RHS before the type checker runs. |
That's a tuple pattern, which already recursively decomposes the elements (see |
Oh, duh, yes you're right about tuple patterns. As for weak variables, they're kind of gross. They intentionally let this work, which is why this pull request does what it does:
Are faster weak diagnostics worth it? |
Probably not worth the effort. We've only had the exponential tuple type checking issue reported a few times. I happened to be looking into exponential cases involving arrays and dictionaries and noticed that the tuple case was pretty easy to fix for the simple pattern kinds, so I did that, and then spent way too much time trying to generalize it :). |
What about bypassing the optimization in the |
I think it's fine to leave it as is, since we should report the error faster with the optimization in place. |
I get the impression that you want me to abandon this pull request then. For the record, it seems lame to me unnecessarily different logic for weak versus unowned/unmanaged, especially when the work to unify the code has already been done in this PR. Please confirm that you want me to abandon this PR. Thanks. |
I think this PR is reasonable as a cleanup. |
@davezarzycki I'm not suggesting you abandon the PR. I'm just not sure it's worth trying to fix this case, and as I mentioned I abandoned a similar change because I couldn't convince myself it would work. I just spent a few minutes putting together a test case, and this is the sort of thing that I think will be broken if you were to use the same type variable that appears on the RHS and then attempt to wrap that type variable in an optional: #15557 There may be some way to generalize this to this case as well as other nested pattern kinds, I'm just not sure it's worth the effort. |
1d1707a
to
3d276f3
Compare
BTW – Whether this PR is "worth the effort" or not, good things have happened because of it. Like your test in #15557, and my understanding of this code improved too (which improved the QoI of my branch). Thanks. :-) |
Sure, I don’t mean to tell you how to spend your time for sure, and appreciate any efforts towards generalizing things to remove special cases. I’ll take another look at your updated code when I am in front of a keyboard again rather than on my phone. |
3d276f3
to
660d1d2
Compare
@swift-ci please smoke test |
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
1 similar comment
@swift-ci Please test source compatibility |
Unless I'm reading the source compatibility results incorrectly, that failure looks unrelated:
Also, I'm going to need to rebase this to fix a merge conflict due to #15545 |
660d1d2
to
f4d4a3d
Compare
@swift-ci please smoke test |
Hi @rudkx – Out of respect to the tentative "make reviewing mandatory" policy discussion, can you please approve, decline, or actionably comment on this change? Thanks! |
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 request: Please add a test case showing that we are now fast when weak
is used.
@rudkx – I'm not familiar with performance sensitive tests. How does one show that a particular semantic scenario is "fast"? |
Actually I just realized that I didn't do that with my original change. Let's merge your change and then I will set up a validation test with my original test update and a new test for We have two mechanisms for this, neither of which is perfect. Timer-based testing, and |
Merge at will, thanks! |
This extends the tuple liternal type checking optimization to handle weak variables.