-
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
Ensure we are adding T : Differentiable conformance from protocol conditional conformance #77446
base: main
Are you sure you want to change the base?
Conversation
protocol conditional conformance. Fixes #75711
@swift-ci please test |
Tagging @rxwei @JaapWijnen |
// generic signature. Update witness substitution map generic signature to | ||
// have them as well. | ||
if (auto *derivativeId = witness.getDerivativeFunctionIdentifier()) | ||
witnessSubs = SubstitutionMap::get(derivativeId->getDerivativeGenericSignature(), |
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.
Should the correct witnessSubs be computed in Sema? See lib/AST/RequirementEnvironment.cpp
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.
It seems to be calculated correctly there:
<τ_0_0 where τ_0_0 : Differentiable>
is a witness generic thunk signature and the corresponding requirement-to-witness substitution map is:
(substitution_map generic_signature=<Self where Self : P>
(substitution Self ->
(bound_generic_struct_type decl="main.(file)[email protected]:3:8"
(generic_type_param_type depth=0 index=0 param_kind=type)))
(conformance type="Self"
(normal_conformance type="Wrapper<T>" protocol="P"
(assoc_type req="T" type="T")
(assoc_conformance type="Self" proto="Copyable"
(builtin_conformance type="Wrapper<T>" protocol="Copyable"))
(assoc_conformance type="Self" proto="Escapable"
(builtin_conformance type="Wrapper<T>" protocol="Escapable"))
(assoc_conformance type="Self.T" proto="Differentiable"
(abstract_conformance protocol="Differentiable"))
(requirement "T" conforms_to "Differentiable"))))
However, witnessSubs
here is:
(substitution_map generic_signature=<T where T : Copyable, T : Escapable>
(substitution T ->
(primary_archetype_type address=0x15c9d8c18 conforms_to="_Differentiation.(file).Differentiable" name="\xCF\x84_0_0"
(interface_type=generic_type_param_type depth=0 index=0 param_kind=type)))
(conformance type="T"
(abstract_conformance protocol="Copyable"))
(conformance type="T"
(abstract_conformance protocol="Escapable")))
So T : Differentiable
comes from conditional conformance via substitution and is not part of generic signature.
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.
@slavapestov So, what do you think about this? Should we change the calculation somehow? For now I just made it conditional for autodiff and only adding T : Differentiable
requirement. W/o this we are unable to calculate derivative function type in protocol conformance as we need to have corresponding associated types etc.
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.
@slavapestov Any further suggestions here?
@asl It looks like that the following case is related to the issue which is supposed to be fixed by the PR. With this patch applied, we still have an issue described below. Consider the following (with forgotten
When compiling, we get the following crash (see under spoiler).
If we uncomment While it looks like that we should emit an error if conditional conformance is missing, we definitely do not want to crash. The error should probably look like the following (
|
@kovdan01 I believe your example is different than the code from the PR: there is no |
@asl Thanks for clarification. I thought it might be related because the crash stack dump looks similar to the one being fixed by this PR. The issue does not seem to be reported before, so created an issue #78370 |
Fixes #75711