-
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
Changes from 14 commits
cf44889
f368b77
02f5e47
efeb709
6cee193
a7fa469
f6f53f6
86730ca
1d56338
f7a82ac
5e4fbc4
733648b
d971d48
b7c6348
5dced8e
f018328
6e6ca13
3021071
ee331a8
6060de6
c48b593
992a871
6608bf8
626bea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ struct TypeJoin : CanTypeVisitor<TypeJoin, CanType> { | |
CanType visitBoundGenericStructType(CanType second); | ||
CanType visitMetatypeType(CanType second); | ||
CanType visitExistentialMetatypeType(CanType second); | ||
CanType visitExistentialType(CanType second); | ||
CanType visitModuleType(CanType second); | ||
CanType visitDynamicSelfType(CanType second); | ||
CanType visitArchetypeType(CanType second); | ||
|
@@ -271,6 +272,29 @@ CanType TypeJoin::visitExistentialMetatypeType(CanType second) { | |
return ExistentialMetatypeType::get(joinInstance)->getCanonicalType(); | ||
} | ||
|
||
CanType TypeJoin::visitExistentialType(CanType second) { | ||
assert(First != second); | ||
|
||
if (First->getKind() != second->getKind()) | ||
return TheAnyType; | ||
|
||
auto firstConstraint = First->castTo<ExistentialType>() | ||
->getConstraintType()->getCanonicalType(); | ||
auto secondConstraint = second->castTo<ExistentialType>() | ||
->getConstraintType()->getCanonicalType(); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Note: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 |
||
return joinInstance; | ||
|
||
return ExistentialType::get(joinInstance)->getCanonicalType(); | ||
} | ||
|
||
CanType TypeJoin::visitModuleType(CanType second) { | ||
assert(First != second); | ||
|
||
|
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 makeAnyMetatypeType::getInstanceType()
returnExistentialType
for existential metatypes. Alternatively, I could addgetRawInstanceType()
or something like that for the few places that actually need the storedInstanceType
. Really, I'd like to just replaceExistentialMetatypeType
withExistentialType(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.