Skip to content

RequirementMachine: Fix minimization when protocol is constrained to a class that conforms to the protocol #41615

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Mar 2, 2022

Consider this example:

protocol P : C {}
class C : P {}

<T where T : P>

The GenericSignatureBuilder thinks the minimized signature is <T where T : P>. The RequirementMachine would minimize it down to <T where T : C>. The latter is more correct, since the conformance here is concrete and no witness table needs to be passed in at runtime, however for strict binary compatibility we need to produce the same signature as the GenericSignatureBuilder.

Accomplish this by changing the minimal conformances algorithm to detect "circular concrete conformance rules", which take the form

[P].[concrete: C : Q]

Where Q : P. These rules are given special handling. Ordinarily a protocol conformance rule is eliminated before a concrete conformance rule; however concrete conformances derived from circular conformances are considered to be redundant from the get-go, preventing protocol conformances that can be written in terms of such concrete conformances from themselves becoming redundant.

Fixes rdar://problem/89633532.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

…a class that conforms to the protocol

Consider this example:

    protocol P : C {}
    class C : P {}

    <T where T : P>

The GenericSignatureBuilder thinks the minimized signature is
<T where T : P>. The RequirementMachine would minimize it down to
<T where T : C>. The latter is more correct, since the conformance
here is concrete and no witness table needs to be passed in at
runtime, however for strict binary compatibility we need to produce
the same signature as the GenericSignatureBuilder.

Accomplish this by changing the minimal conformances algorithm to
detect "circular concrete conformance rules", which take the form

    [P].[concrete: C : Q]

Where Q : P. These rules are given special handling. Ordinarily a
protocol conformance rule is eliminated before a concrete conformance
rule; however concrete conformances derived from circular
conformances are considered to be redundant from the get-go,
preventing protocol conformances that can be written in terms of
such concrete conformances from themselves becoming redundant.

Fixes rdar://problem/89633532.
@slavapestov slavapestov force-pushed the rqm-protocol-superclass-circular-conformance branch from 337024b to 5281426 Compare March 2, 2022 08:13
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit bd5a437 into swiftlang:main Mar 2, 2022
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.

1 participant