This is an archive of the discontinued LLVM Phabricator instance.

[clang][extract-api] Refactor ExtractAPI and improve docs
ClosedPublic

Authored by zixuw on Mar 21 2022, 10:34 AM.

Details

Summary
  • The name SymbolGraph is inappropriate and confusing for the new library for clang-extract-api. Refactor and rename things to make it clear that ExtractAPI is the core functionality and SymbolGraph is one serializer for the API information.
  • Add documentation comments to ExtractAPI classes and methods to improve readability and clearness of the ExtractAPI work.

Diff Detail

Event Timeline

zixuw created this revision.Mar 21 2022, 10:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: mgorny. · View Herald Transcript
zixuw requested review of this revision.Mar 21 2022, 10:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2022, 10:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dang added inline comments.Mar 21 2022, 12:23 PM
clang/include/clang/ExtractAPI/API.h
36

You should use the actual name of the type or "This"

39

If it wouldn't make things simpler we wouldn't have it. IMHO it is better to use definitive terms in documentation. here it would "This simplifies calculating [...]"

105

Nit: instead of "of a" maybe use "associated with"

125

This is new so I don't think it belongs in this patch.

131–136

why is stuff reordered in the patch?

clang/include/clang/ExtractAPI/DeclarationFragments.h
114

Not sure an explanation of the process is needed. Anyway "quicking" is not a word ;) I would suggest "Other is moved from and can not be used after a call to this method".

clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
34

If we are going for a base class, I am not sure that the base should be JSON specific.

clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
35

Not sure why we need this.

clang/lib/ExtractAPI/API.cpp
34

"Create the record if it does not already exist."

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
195

The kind of serializer should be made configurable somehow.

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
26

This is unnecessary imho.

Would you mind putting a high level description of the intent at the top of the main header.

Maybe even a link at https://github.com/apple/swift-docc-symbolkit

zixuw added a comment.Mar 21 2022, 1:02 PM

Would you mind putting a high level description of the intent at the top of the main header.

Maybe even a link at https://github.com/apple/swift-docc-symbolkit

Sure thing!

zixuw updated this revision to Diff 417132.Mar 21 2022, 4:54 PM
zixuw marked 11 inline comments as done.

Address review issues.

clang/include/clang/ExtractAPI/API.h
125

This is to follow the LLVM Coding Standards guideline of providing an out-of-line virtual method anchor for a class defined in a header file and has a vtable. Still coding style/standard fix/improvement.

131–136

I looked into some other class definitions inside Clang, and was trying to list "interesting" APIs upfront and less-interesting stuff like constructors near the end for large class definitions to make them more readable.

clang/include/clang/ExtractAPI/DeclarationFragments.h
114

Whops didn't realize that I typed that. Friday's work huh? :p

clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
35

As above. Refactor to follow LLVM Coding Standards.

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
195

Yes for sure. I didn't include that change here because it would probably involve adding command line options and changing the driver, which should have its own patch later.
I added a FIXME here to point it out for now.

zixuw updated this revision to Diff 417145.Mar 21 2022, 5:54 PM
  • Minor Doxygen auto-link string adjustments
  • Forgot to rename the test directory
dang accepted this revision.Mar 22 2022, 3:22 AM

LGTM once the last few bits of feedback I left are considered.

clang/include/clang/ExtractAPI/API.h
131–136

OK that is a nice change then, I wasn't aware that this is a thing. I was just complaining because it made the diff harder to parse for me ;)

144

Maybe we should document that the caller is meant to keep Name and USR alive. Name is expected to refer to the appropriate Decl member so it shouldn't be an issue, but this usage should be documented. WRT USR these comments would be a good place to mention the existence of recordUSR and the copyString method as a way of getting USR strings that are guaranteed to have the right lifetime.

209

Should this be a private member function? The overload that doesn't take in an allocator makes sense since it uses the APISet's allocator, but this one does not seem like it should be publicly accessible, since it just ties the lifetime of the returned String to that of an arbitrary allocator?

clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
195

Yeah that makes sense, we can do this as a follow up patch, definitely not urgent as SymbolGraph is the only use case at the moment. However, we should do this relatively soon so that the structure of the existing command line arguments is stable before we are fully done with this.

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
30

You don't need both static an anonymous namespace afaik.

This revision is now accepted and ready to land.Mar 22 2022, 3:22 AM
zixuw updated this revision to Diff 417361.Mar 22 2022, 12:08 PM
zixuw marked 3 inline comments as done.

Address review issues:

  • Documenting the responsibility of keeping StringRefs alive for APISet
  • Remove unnecessary static for helper functions in an anonymous namespace
zixuw updated this revision to Diff 417365.Mar 22 2022, 12:16 PM

Address review issue: remove unnecessary copyString overload

dang accepted this revision.Mar 22 2022, 1:18 PM

LGTM

This revision was automatically updated to reflect the committed changes.
zixuan-wu added inline comments.
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
160

It's same name as Language variable above, and it cause compile error. @zixuw
Maybe the error depends on host compiler version so that it does not report immediately.

zixuw added inline comments.Mar 24 2022, 11:26 AM
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
160

Hi! Thanks for the report! Do you have a link to the failed build or detailed error output and compile configuration?

zixuw marked an inline comment as done.Mar 24 2022, 3:13 PM
zixuw added inline comments.
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
160
clang/lib/SymbolGraph/Serialization.cpp