Skip to content

[5.7] IR generation for constrained existentials #42328

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

rjmccall
Copy link
Contributor

5.7 version of #42317

rjmccall added 12 commits April 12, 2022 19:57
…ocols

This is preparation for supporting parameterized protocols in
protocol compositions.  The `sameTypeRequirements` field will
probably have to go; it's just not general enough to capture
what we want.  That's assuming that we keep ExistentialLayout
in the long term at all, of course.
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
Smaller values of FormalLinkage are actually wider scopes,
so std::min'ing with PublicUnique actually just gives you
a result that's always PublicUnique.  And we need to start
with PublicNonUnique because even things derived solely
from uniquely-emitted types are not themselves generally
unique.

I don't want to immediately open the can of worms that fixing
this for everyone would entail, so I'm just adding the new
version in parallel and moving new clients to it gradually.
Parameterized composition components are preserved over
non-parameterized components on the same protocol.  They are
also preserved even if they are redundant with parameterized
derived protocols.  Otherwise, they're just put in usual protocol
order.

This assumes that argument lists on the same protocol are always
redundant with each other, which may not be correct when we add
abstract constraints.  We are also, of course, still not making
an effort to diagnose conflicts.
The basic concept here was previously laid out in the metadata
system commits adding ExtendedExistentialTypeShape, but to recap,
we want to produce (for any existential type, but we're really
only going to use it for constrained or otherwise generalized
existentials) a "shape" signature and type that will be agreed
upon by all possible abstractions of the type.  In this
signature+type pair, any substitutable position in the original
type is abstracted as a parameter in the signature, which the
original type is a concrete application of.  This permits
agreement on the type in the face of runtime generic execution.

I have made every effort to support protocol compositions in
the code I've written, but of course until you're allowed to
actually write them, that's all untested.

I have not yet implemented signature minimization of the
generalization signature. I think this will be necessary in order
to ensure that there are no non-redundant parameters, especially
for compositions, which is something the runtime currently assumes
and is better for code size anyway.  But it can wait a few days,
I think.
@rjmccall rjmccall requested a review from a team as a code owner April 12, 2022 23:59
@rjmccall
Copy link
Contributor Author

Please test with following pull request:
swiftlang/llvm-project#4213

@swift-ci Please test

@rjmccall rjmccall merged commit a7f0fff into swiftlang:release/5.7 Apr 13, 2022
@rjmccall rjmccall deleted the build-constrained-existential-metadata-5.7 branch April 13, 2022 04:23
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.

2 participants