-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Canonicalize symbolic ref types in the right generic context #25955
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/IRGen/GenMeta.cpp
Outdated
@@ -470,6 +470,7 @@ namespace { | |||
void addExtendedContext() { | |||
auto string = IGM.getTypeRef( | |||
E->getSelfInterfaceType()->getCanonicalType(), | |||
E->getGenericSignature(), |
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 wasn't sure about this one, but it might matter with @Azoy's plan for extensions to have their own generic parameters.
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 haven't poked around IRGen enough yet, but could you explain why this might affect extensions with there own generic parameters?
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.
Mostly because I'm relatively unfamiliar with it too. :-) The point I was trying to make was that this is probably already in the right form today since the extension can't have introduced any new parameters, but I'm not sure if that'll be true if it can. I think it still is, though.
(The latest change to the runtime, though, #25984, almost certainly is not correct in that world.)
lib/IRGen/GenReflection.cpp
Outdated
@@ -466,7 +470,7 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder { | |||
for (auto AssocTy : AssociatedTypes) { | |||
auto NameGlobal = IGM.getAddrOfFieldName(AssocTy.first); | |||
B.addRelativeAddress(NameGlobal); | |||
addTypeRef(AssocTy.second); | |||
addTypeRef(AssocTy.second, /*generic signature*/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.
Should this be using the conformance DC's signature?
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.
Good question. If the conformance is a normal conformance, I would think so, yes.
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.
Oof, even more to check.
lib/IRGen/GenReflection.cpp
Outdated
@@ -901,7 +908,7 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { | |||
|
|||
// Now add typerefs of all of the captures. | |||
for (auto CaptureType : CaptureTypes) { | |||
addTypeRef(CaptureType); | |||
addTypeRef(CaptureType, /*genericSignature*/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.
Should captures and captured parameters be using a particular signature?
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.
It looks like the capture type was computed with mapTypeOutOfContext(). The result of that is always canonical wrt. the generic signature that the archetype was built from.
@swift-ci Please test source compatibility |
lib/IRGen/GenReflection.cpp
Outdated
@@ -466,7 +470,7 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder { | |||
for (auto AssocTy : AssociatedTypes) { | |||
auto NameGlobal = IGM.getAddrOfFieldName(AssocTy.first); | |||
B.addRelativeAddress(NameGlobal); | |||
addTypeRef(AssocTy.second); | |||
addTypeRef(AssocTy.second, /*generic signature*/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.
Good question. If the conformance is a normal conformance, I would think so, yes.
lib/IRGen/GenReflection.cpp
Outdated
@@ -168,25 +168,29 @@ class PrintMetadataSource | |||
} | |||
}; | |||
|
|||
llvm::Constant *IRGenModule::getTypeRef(CanType type, MangledTypeRefRole role) { | |||
llvm::Constant *IRGenModule::getTypeRef(CanType type, |
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.
May as well relax this to just Type so that callers don't have to call getCanonicalType()
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.
Yeah, I guess so.
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.
The whole point of taking a CanType
here, and throughout IRGen, is that the type should already be correctly canonicalized by this point. Are we messing up earlier in the pipeline?
lib/IRGen/GenReflection.cpp
Outdated
@@ -901,7 +908,7 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder { | |||
|
|||
// Now add typerefs of all of the captures. | |||
for (auto CaptureType : CaptureTypes) { | |||
addTypeRef(CaptureType); | |||
addTypeRef(CaptureType, /*genericSignature*/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.
It looks like the capture type was computed with mapTypeOutOfContext(). The result of that is always canonical wrt. the generic signature that the archetype was built from.
@swift-ci Please test |
Build failed |
Build failed |
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, thanks!
@swift-ci Please smoke test |
When referencing a superclass type from a subclass, for example, the type uses the subclass's generic parameters, not the superclass's. This can be important if a nested type constrains away some of its parent type's generic parameters. This doesn't solve all the problems around mis-referenced generic parameters when some are constrained away, though. That might require a runtime change. See the FIXME comments in the test cases. rdar://problem/51627403
@swift-ci Please smoke test |
@swift-ci Please smoke test macOS |
…wiftlang#25955) When referencing a superclass type from a subclass, for example, the type uses the subclass's generic parameters, not the superclass's. This can be important if a nested type constrains away some of its parent type's generic parameters. This doesn't solve all the problems around mis-referenced generic parameters when some are constrained away, though. That might require a runtime change. See the FIXME comments in the test cases. rdar://problem/51627403 (cherry picked from commit 4abefdb)
When referencing a superclass type from a subclass, for example, the type uses the subclass's generic parameters, not the superclass's. This can be important if a nested type constrains away some of its parent type's generic parameters.
This doesn't solve all the problems around mis-referenced generic parameters when some are constrained away, though. That might require a runtime change. See the FIXME comments in the test cases (and rdar://problem/52364601).
rdar://problem/51627403