Skip to content

Fix generics invariant violations in protocol requirement override checking #41622

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

Merged
merged 4 commits into from
Mar 3, 2022

Conversation

slavapestov
Copy link
Contributor

We have to be careful not to feed an invalid type parameter into the Requirement Machine since that triggers asserts instead of returning bogus results like the GenericSignatureBuilder.

Fixes https://bugs.swift.org/browse/SR-15826 / rdar://problem/89641535.

…h protocols

We want to avoid feeding invalid type parameters into the Requirement Machine
when checking if a protocol requirement overrides another protocol requirement
in an inherited protocol.

In order to do that we need to make sure the potential override has a
compatible generic signature before we attempt substitution, just like we
already do for classes.

To do that, we need a way to 'rewrite' a generic signature for the base
requirement into a generic signature that can be compared with the derived
requirement, just as we do with class methods.

For protocols this is a little easier than with class methods, since protocols
only ever have a single 'Self' generic parameter. So just add the
'Self : DerivedProto' requirement to the base requirement's signature and
rebuild.
…ocol requirements

We need a substitution map written in terms of the base requirement's signature;
getProtocolSubstitutions() alone was not enough because it does not include
the extra generic parameters that the base requirement might have if it is
itself generic.
@slavapestov slavapestov force-pushed the fix-protocol-overrides branch from 6378977 to b48ce17 Compare March 2, 2022 19:17
This avoids feeding invalid type parameters to the Requirement Machine
when a protocol requirement looks similar to a protocol requirement in
the inherited protocol but has an incompatible type.

Fixes https://bugs.swift.org/browse/SR-15826 / rdar://problem/89641535.
@slavapestov slavapestov force-pushed the fix-protocol-overrides branch from b48ce17 to 345185f Compare March 2, 2022 19:18
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

To avoid breaking the ABI of the standard library and possibly other
modules, we can't actually enable the new accurate logic for checking
protocol requirement overrides after all.

Just skip the check if the protocol requirement is generic to get
back the old behavior.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test Linux

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