-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TypeJoin] Implement Type::join for protocols and protocol compositions. #19677
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
This is mostly complete, but we still need to add support for joins between these two types and other types.
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
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.
LGTM! Very nice!
lib/AST/TypeJoinMeet.cpp
Outdated
assert(First != second); | ||
|
||
// FIXME: Handle other types here. | ||
if (First->getKind() != TypeKind::Protocol && |
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.
You should be using isa<>
instead of getKind()
, I think
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 yes, I'll fix that up.
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.
Is that because isa<> strips sugar? I still can’t say when it would make sense to use getKind vs. isa<> with confidence... is getKind supposed to be used only by switch statements?
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.
In general that's a good reason to use is<>
and getAs<>
, but in this case we're working with CanType
s so that shouldn't make a difference (*
). It's generally shorter and more idiomatic to use these templated functions.
Add a comment explaining that the distributive law isn't generally true for lattices but should be for ours, and fix up the test case to not use the real stdlib Strideable protocol in a couple places.
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
lib/AST/TypeJoinMeet.cpp
Outdated
assert(First != second); | ||
|
||
// FIXME: Handle other types here. | ||
if (!First->is<ProtocolType>() && |
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.
This is First->isExistentialType()
lib/AST/TypeJoinMeet.cpp
Outdated
} | ||
|
||
// Return true if the first ProtocolDecl is a supertype of the second. | ||
static bool isSupertypeOf(ProtocolDecl *super, ProtocolDecl *sub) { |
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.
Is this not the same as ProtocolDecl::inheritsFrom()?
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.
Close enough for my purposes, but the function I defined returns true if they are the same type. It shouldn't be calling them with the same type though, so I'll change it.
@swift-ci Please smoke test |
@swift-ci Please test source compatibility |
This is mostly complete, but we still need to add support for joins
between these two types and other types.