-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILGen]Check if baseType is DynamicSelfType #80913
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
lib/SILGen/SILGenExpr.cpp
Outdated
if (baseType->getClassOrBoundGenericClass() != propertyClass) { | ||
auto baseClass = baseType->getClassOrBoundGenericClass(); | ||
if (auto dynamicSelfType = baseType->getAs<DynamicSelfType>()) { | ||
baseClass = dynamicSelfType->getSelfType()->getClassOrBoundGenericClass(); |
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.
Instead of calling getClassOrBoundGenericClass() twice, how about we unwrap the DynamicSelfType first:
if (auto selfType = baseType->getAs<DynamicSelfType>()) {
baseType = selfType->getSelfType();
baseClass = baseType->getClassOrBoundGenericClass();
ASSERT(baseClass != nullptr);
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.
Thank you for checking. I tried the below code, but the assertion failed in subclass_generics
.
if (auto selfType = baseType->getAs<DynamicSelfType>())
baseType = selfType->getSelfType()->getCanonicalType();
auto baseClass = baseType->getClassOrBoundGenericClass();
ASSERT(baseClass != nullptr);
This assertion also fails with the current implementation.
Am I misunderstanding something? Should baseClass
always be non-null 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.
@slavapestov
As far as I confirmed, baseClass
still could be nil when baseType
is ArchetypeType
. So, we can not add ASSERT(baseClass != nullptr);
.
Please correct me if I'm wrong. Thank you.
@swift-ci Please smoke test |
Oops, dropped the ball on this one. Let's merge it if the tests pass. |
Resolves #80669
I think the issue mentioned above has been resolved by this, but it’s unrelated. I will create a separate one for it.
The compiler crashed when compiling the following code:
The crash log was as follows:
The cause appears to be that when using
\Self
in a key path, thebaseType
isDynamicSelfType
. This prevents retrieving thebaseClass
usinggetClassOrBoundGenericClass
, as seen here:https://github.com/swiftlang/swift/blob/main/lib/SILGen/SILGenExpr.cpp#L3402
Therefore, a check was added to determine if
baseType
isDynamicSelfType
.