-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SE] Allow where clauses on non-generic declarations in generic contexts #23489
[SE] Allow where clauses on non-generic declarations in generic contexts #23489
Conversation
cc @slavapestov Mind having a look? P.S. I am aware this most likely needs an evolution proposal |
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 only skimmed this but it looks great.
The next step I think is to write some SILGen, IRGen and execution tests. And yeah, an evolution proposal would be nice. I don't expect much controversy since this is lifting an "obvious" restriction.
Thanks for taking a look! |
For SILGen tests, I think it’s enough to just have some CHECK lines to verify that the lowered generic signature looks correct. |
I will try. It should be identical to one in a constrained extension, correct? |
@AnthonyLatsis Yes, the generic signature should be identical to a constrained extension. The mangling should be slightly different though (and please test declarations that only differ in where clause; we should mangle them uniquely). |
c35ea0f
to
71521d5
Compare
Added SILGen tests. I also noticed that a nil literal in a subscript getter is hitting a null type assert. It only happens if type checking succeeds elsewhere: protocol P { associatedtype Assoc }
class Class<T> {
subscript(arg: Int) -> T.Assoc? where T: P {
return nil
}
}
Almost sure this is specific to subscript accessors and the way they currently inherit the generic signature of the subscript. Once fixed, what is the preferred way to test against this: simply add the subscript to the silgen tests or create a separate "fixed crasher"? |
@AnthonyLatsis a SILGen test is probably your best bet for tests that only fail when no errors are emitted. We should fix the AST verifier one day to be smarter about this... |
@slavapestov, regarding IRGen, can you give a rough idea of what to test for? Thanks. |
@AnthonyLatsis testing in IRGen probably won't get you much coverage because at that stage a generic type member with a where clause is not much different from a top level function with a 'flat' generic signature. However, one interesting thing to test would be the runtime's mangled name to metadata recovery. Take a look at test/Runtime/demangleToMetadata.swift. The idea would be to define a non-generic type with a where clause nested inside a generic type and see if you can demangle it. |
@slavapestov I am having a hard time guessing the mangled names. By picking a specific example and comparing the output from EDIT |
e623829
to
b21244f
Compare
@slavapestov I think this is ready for a smoke test. P.S. What do you think of the error messages? |
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
60e9b6b
to
d4c9e02
Compare
Let's try again? |
@swift-ci Please test source compatibility |
@swift-ci Please smoke test |
@AnthonyLatsis Can you try to prepare a new PR to merge as much of this as possible without the language change/proposal? In particular I'm interested in the TypeCheckGeneric.cpp cleanups to unify the function/subscript code paths. We're about to start reworking that code for the request evaluator and I'd have to either lose the cleanup or make you redo your work. |
Sure. I'll cherry-pick the cleanups onto a new branch and open a PR. Let's hope we can land them without merge conflicts. |
@AnthonyLatsis Thanks! Also of course I hope the overall change is accepted too! But I know it can take a while to go through the process. |
d4c9e02
to
0f29427
Compare
@slavapestov Wrapped this up. Let me know what you think. |
0df2ea0
to
9f42953
Compare
Sure, it should be ready now. All the comments I have addressed so far are marked as resolved (folded). |
9f42953
to
5bfb0a9
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5bfb0a9
to
f762644
Compare
Ouch, the crasher from #27987. That is a separate circularity issue I thought I had fixed here, but forgot to remove. |
@theblixguy Could you trigger the tests for me once more please? |
@swift-ci please test |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Let's merge this. Can you take a look at my other comments that you didn't address yet though?
|
Alright, let's merge this! |
Sure thing, they are on my mind. |
SE-0267
I'm not happy with using pointer unions, but couldn't come up with a better idea that wouldn't require further unrelated changes of uncertain scale; there will be a lot of opportunities to get rid of this later through making where clauses less dependent on parameter lists.
where
on non-generic top-level declarations in Parsewhere
clauseswhere
clauseswhere
clauses are mangled correctlywhere
clauseswhere
clausescheckConstrainedExtensionRequirements
to look out for contextualwhere
clauses as well