Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

asl
Copy link
Contributor

@asl asl commented Nov 7, 2024

Fixes #75711

protocol conditional conformance.

Fixes #75711
@asl
Copy link
Contributor Author

asl commented Nov 7, 2024

@swift-ci please test

@asl
Copy link
Contributor Author

asl commented Nov 7, 2024

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(),
Copy link
Contributor

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

Copy link
Contributor Author

@asl asl Nov 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid type parameter in getReducedType()
2 participants