Skip to content

[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

Merged
merged 1 commit into from
Jul 8, 2019

Conversation

jrose-apple
Copy link
Contributor

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

@@ -470,6 +470,7 @@ namespace {
void addExtendedContext() {
auto string = IGM.getTypeRef(
E->getSelfInterfaceType()->getCanonicalType(),
E->getGenericSignature(),
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.)

@@ -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);
Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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);
Copy link
Contributor Author

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?

Copy link
Contributor

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.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@@ -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);
Copy link
Contributor

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.

@@ -168,25 +168,29 @@ class PrintMetadataSource
}
};

llvm::Constant *IRGenModule::getTypeRef(CanType type, MangledTypeRefRole role) {
llvm::Constant *IRGenModule::getTypeRef(CanType type,
Copy link
Contributor

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess so.

Copy link
Contributor

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?

@@ -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);
Copy link
Contributor

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.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@jckarter How's this version look?

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Jul 5, 2019

Build failed
Swift Test Linux Platform
Git Sha - 834dc483b7bd53e733aa6517aa0cdfe8987da1d2

@swift-ci
Copy link
Contributor

swift-ci commented Jul 5, 2019

Build failed
Swift Test OS X Platform
Git Sha - 834dc483b7bd53e733aa6517aa0cdfe8987da1d2

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@jrose-apple
Copy link
Contributor Author

@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
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@jrose-apple jrose-apple merged commit 4abefdb into swiftlang:master Jul 8, 2019
@jrose-apple jrose-apple deleted the headcanon branch July 8, 2019 21:40
jrose-apple added a commit to jrose-apple/swift that referenced this pull request Jul 8, 2019
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants