Skip to content

[SymbolGraph] add a USR for RHS types in generic conformances #36242

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 2 commits into from
Mar 5, 2021

Conversation

QuietMisdreavus
Copy link
Contributor

Fixes rdar://70442228

When reading a generic conformance in a symbol graph, it can be useful to know what precise type or protocol a conformance is linking to. This PR adds an extra rhsPrecise field to the constraints object in the swiftGenerics mixin to give a USR that corresponds to rhs. This can be used to look up the item being referenced in the constraint.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@@ -105,6 +106,16 @@ void swift::symbolgraphgen::serialize(const Requirement &Req,
OS.attribute("kind", Kind);
OS.attribute("lhs", Req.getFirstType()->getString());
OS.attribute("rhs", Req.getSecondType()->getString());

// If the RHS type has a USR we can link to, add it to the output
if (!Req.getSecondType()->isTypeParameter() && !Req.getSecondType()->hasArchetype()) {
Copy link
Contributor

@slavapestov slavapestov Mar 3, 2021

Choose a reason for hiding this comment

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

Maybe you want Req->getSecondType()->getAnyNominal() here? The predicate as written above will also return true for function types that don't contain generic parameters, metatypes, etc. Also the RHS might be a nominal type and contain a generic parameter, eg Array<T>, in which case you can still emit a USR to link to the definition of Array, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Array<T> will return false from isTypeParameter because that function is meant to check for the T itself - there's a separate hasTypeParameter for checking whether a type has parameters, as afar as i can tell. The separate hasArchetype call is meant to guard against an assertion in printTypeUSR.

getAnyNominal does seem like a better choice for what this needs, though - i'll take a look at that instead.

@QuietMisdreavus
Copy link
Contributor Author

It looks like getAnyNominal also generated USRs that looked more like the ones we'll have on hand anyway, so that's also a win. I've pushed up a commit with the new implementation; i can squash if necessary/desired.

@swift-ci Please smoke test

@franklinsch franklinsch self-requested a review March 5, 2021 12:01
@QuietMisdreavus QuietMisdreavus merged commit 1451960 into main Mar 5, 2021
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/generic-usr branch March 5, 2021 15:24
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.

3 participants