-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0335] Enable explicit existential types. #40666
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
c1a9a0f
to
54783da
Compare
2e4e40b
to
1c1ea77
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
Build failed |
dfb922f
to
8d2e059
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
Build failed |
@@ -2731,6 +2734,8 @@ class ExistentialMetatypeType : public AnyMetatypeType { | |||
static bool classof(const TypeBase *T) { | |||
return T->getKind() == TypeKind::ExistentialMetatype; | |||
} | |||
|
|||
Type getExistentialInstanceType(); |
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.
I don't like the existence of this method, but it messes up TypeWalker
if I make AnyMetatypeType::getInstanceType()
return ExistentialType
for existential metatypes. Alternatively, I could add getRawInstanceType()
or something like that for the few places that actually need the stored InstanceType
. Really, I'd like to just replace ExistentialMetatypeType
with ExistentialType(MetatypeType(...))
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.
I think your longer-term goal of removing ExistentialMetatypeType is good and in the meantime, this workaround is reasonable.
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
Build failed |
7d9661e
to
a7b50a0
Compare
@swift-ci please test source compatibility |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
in ExistentialType for the type of error values.
existential types.
…able initializer requirements with explicit existential Encodable and Decodable parameters.
the ClangImporter.
finding the protocol decl for an existential type.
explicit ExistentialType. The ASTDemangler needs to produce ExistentialType based on context, not unconditionally when producing a protocol composition. This is tricky because existential types are mangled the same way as other protocol references, e.g. in conformance requirements. For now, drop the explicit existentials when reconstructing types.
must be marked with 'any' as a warning.
resolve to ProtocolType or ProtocolCompositionType are always existential types. This can happen because type aliases to protocol constraints can also be used as type witnesses. The type alias itself is still a constraint, because it can be used in generic signatures in addition to being used as an existential type, e.g. in parameter position. So, we need to wrap the type alias in an ExistentialType during type witness resolution.
metatypes always wrap the constraint type directly, and the instance type of an existential metatype is an existential type.
…icit existential types.
existential types. Use the correct type resolver context when resolving SIL metatypes and function types, and diagnose an error if an explicit existential type appears in a protocol composition.
various places that expect ProtocolType or ProtocoolCompositionType.
are printed with the `any` keyword. For now, printing `any` is off by default in order to turn on explicit existential types with minimal changes to the test suite. The option will also allow control over how existential types are printed in Swift interfaces.
explicit existential types are enabled.
…Type by propagating whether the decoded type is for a requirement through TypeDecoder.
existential arguments to not return before checking the second argument type.
a7b50a0
to
6608bf8
Compare
…ence when the member is a typealias to a protocol or composition.
@swift-ci please test source compatibility |
@swift-ci please smoke test |
@swift-ci please smoke test macOS platform |
This PR caused is causing a few crashes in the stress tester: SR-15742. |
@@ -1183,6 +1183,10 @@ namespace { | |||
} | |||
} | |||
|
|||
if (bridgedType->isConstraintType() && |
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.
Can bridgedType
really happen to be an protocol/composition here, or was this a forethought?
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.
Yes, it can be Error
auto joinInstance = join(firstConstraint, secondConstraint); | ||
if (!joinInstance) | ||
return CanType(); | ||
|
||
if (joinInstance->is<ExistentialMetatypeType>() || | ||
joinInstance->isAny() || | ||
joinInstance->isAnyObject()) |
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.
Note: is<ExistentialMetatypeType>()
seems unnecessary here.
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.
I believe I removed this code in my follow-up PR but I'm not certain
EDIT: oops, this is my follow up PR, I got it confused with the original 😅
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.
Ah, I did remove this bit of code in a follow-up commit in this PR. You're right that it's unnecessary.
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.
Whoops, sorry, I ought to have checked if it's still there on main
.
This change enables explicit existential types by default, which changes the representation of existential types to use
ExistentialType
, and allows theany
keyword in the source language.Note that many of the conditional
getAs<ExistentialType>()
variable bindings are temporary. After explicit existential types are enabled, existential types will always resolve toExistentialType
(regardless of whether or not they're spelled withany
), and theisExistentialType()
checks can be changed tois<ExistentialType>()
. I'm holding off on making that change for now to allow explicit existential types to be turned off if needed.Resolves: rdar://86347236