-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix issue with 'Self' metadata when class conforms to protocol with default implementations #12174
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
Fix issue with 'Self' metadata when class conforms to protocol with default implementations #12174
Conversation
ac56212
to
0ca945d
Compare
123a72a
to
cb4e1d9
Compare
@swift-ci Please test source compatibility |
@swift-ci Please test compiler performance |
!!! Couldn't read commit file !!! |
@swift-ci Please benchmark |
Build comment file:Optimized (O)No Changes (333)
Unoptimized (Onone)Improvement (1)
No Changes (332)
Hardware Overview
|
@graydon "Test compiler performance" failure you might want to look at |
…onstrained 'Self'
At this point, we already have a witness, so the requirement environment can depend on the witness as well as the requirement. Then, store the RequirementEnvironment inside the RequirementMatch.
…rotocol extension
…s conformances have an abstract 'Self' Consider the following code: protocol P { func foo<A>(_: A) } extension P { func foo<A>(_: A) {} } class C<T> : P {} Before, the witness thunk for [C : P].foo() had the generic signature <T, A>, and the witness P.foo() was called with a substitution Self := C<T>. This is incorrect because the caller might be using a subclass of C as the 'Self' type, but this was being erased. Now, the witness thunk for [C : P].foo() has the generic signature <X : C<T>, T, A>, and the witness P.foo() is called with the substitution Self := X. Fixes <rdar://problem/33690383>, <https://bugs.swift.org/browse/SR-617>.
… resolveWitnessViaLookup()
974889b
to
0f5f272
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
1 similar comment
@swift-ci Please test source compatibility |
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
Build failed |
…t implementations returning 'Self' Now that we pass in the correct type metadata for 'Self', it is sound for a class to conform to a protocol with a default implementation for a method returning 'Self'. Fixes <rdar://problem/23671426>.
…ment-operator.swift, it was never being run
Build failed |
0f5f272
to
f8b06dc
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
This broke the simulator, reverting. |
This builds upon #12118. Witness thunks for conformances of classes now have a generic parameter for
Self
, constrained to the class. If the witness is defined in a protocol extension, we pass through theSelf
parameter instead of using the static conforming type.This means we now allow the following:
Previously, we rejected this, to paper over the problem with passing
Self
metadata. However this was an unsatisfactory fix, because not only does it ban a useful pattern, it also means adding a new protocol requirement is source breaking, even when there is a default implementation.Furthermore, even if your default implementation does not return
Self
, it was possible to observe the incorrectSelf
metadata, as was shown in https://bugs.swift.org/browse/SR-617.Fixes rdar://problem/23671426, rdar://problem/33690383, https://bugs.swift.org/browse/SR-617.