Skip to content

[SymbolGraphGen] Add filename and module name to symbols' doc comments #58857

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 4 commits into from
May 24, 2022

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://81190369

Currently, doc comments in the symbol graph only include information about line/column numbers when referring to its location. However, if docs are inherited (and source information is available), these locations may point to a different file than the one for the symbol's declaration. In addition, the inherited doc comment might have been written with its original module in mind, for example by using Swift-DocC symbol links that point to other symbols in the module. These symbols may not be able to resolve in the inheriting module, which causes spurious errors when building documentation.

This PR adds two new sub-fields to the docComment field: uri and module. The uri field points to the file from which the doc comment was declared, and the module field indicates which module it's in. This can be used for more accurate diagnostics (even in docs are inherited within the same module) and to determine when a doc comment is inherited from a different module than the one being documented.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

auto Loc = DocCommentProvidingDecl->getLoc(/*SerializedOK=*/true);
if (Loc.isValid()) {
auto FileName = DocCommentProvidingDecl->getASTContext().SourceMgr.getDisplayNameForLoc(Loc);
if (!FileName.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this pattern could be refactored to avoid code duplication?

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've pushed up an attempt to split out the file name collection and serialization so that serializeLocation can use the same code paths as serializeDocComment here. It was a bit awkward to work it around serializeLocation, but maybe i could re-duplicate the file-name collection but keep the serialization refactored like this. 🤷‍♀️

Copy link
Contributor

Choose a reason for hiding this comment

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

The second option is what I had in mind (just deduplicating the code that is now in serializeFileURI). However the new version is kinda nice, I don't think it is awkward to read. Maybe the functions shouldn't be called getFileURI since they don't actually return URIs but rather pathnames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! I've amended the commit to rename the functions.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/comment-loc branch from 75d9acf to ef15476 Compare May 16, 2022 15:32
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@daniel-grumberg daniel-grumberg self-requested a review May 16, 2022 18:06
Copy link
Contributor

@daniel-grumberg daniel-grumberg left a comment

Choose a reason for hiding this comment

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

LGTM

@QuietMisdreavus
Copy link
Contributor Author

I added a test to double-check that docs inherited from an external module (in this case, the standard library) correctly identifies the source module of the comment.

@swift-ci Please smoke test

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.

2 participants