Skip to content

[AST] Only use serialized locs for 'getRawComment()' in symbol graph #36270

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 3 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ class alignas(1 << DeclAlignInBits) Decl {
}

/// \returns the unparsed comment attached to this declaration.
RawComment getRawComment(bool SerializedOK = true) const;
RawComment getRawComment(bool SerializedOK = false) const;

Optional<StringRef> getGroupName() const;

Expand Down
3 changes: 3 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ const Decl::CachedExternalSourceLocs *Decl::getSerializedLocs() const {
return CachedSerializedLocs;
}
auto *File = cast<FileUnit>(getDeclContext()->getModuleScopeContext());
assert(File->getKind() == FileUnitKind::SerializedAST &&
"getSerializedLocs() should only be called on decls in "
"a 'SerializedASTFile'");
auto Locs = File->getBasicLocsForDecl(this);
if (!Locs.hasValue()) {
static const Decl::CachedExternalSourceLocs NullLocs{};
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DocComment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ const ValueDecl *findRequirementDeclWithDocComment(const ValueDecl *VD,
std::queue<const ValueDecl *> requirements;
while (true) {
for (auto *req : VD->getSatisfiedProtocolRequirements()) {
if (!req->getRawComment().isEmpty())
if (!req->getRawComment(AllowSerialized).isEmpty())
return req;
else
requirements.push(req);
Expand Down
28 changes: 20 additions & 8 deletions lib/AST/RawComment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
return Result;
}

// Ask the parent module.
if (auto *Unit =
dyn_cast<FileUnit>(this->getDeclContext()->getModuleScopeContext())) {
if (!getDeclContext())
return RawComment();
auto *Unit = dyn_cast<FileUnit>(getDeclContext()->getModuleScopeContext());
if (!Unit)
return RawComment();

switch (Unit->getKind()) {
case FileUnitKind::SerializedAST: {
if (SerializedOK) {
if (const auto *CachedLocs = getSerializedLocs()) {
if (!CachedLocs->DocRanges.empty()) {
Expand All @@ -158,8 +163,8 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
if (Range.isValid()) {
SRCs.push_back({ Range, Context.SourceMgr });
} else {
// if we've run into an invalid range, don't bother trying to load any of
// the other comments
// if we've run into an invalid range, don't bother trying to load
// any of the other comments
SRCs.clear();
break;
}
Expand All @@ -178,10 +183,17 @@ RawComment Decl::getRawComment(bool SerializedOK) const {
Context.setRawComment(this, C->Raw);
return C->Raw;
}
}

// Give up.
return RawComment();
return RawComment();
}
case FileUnitKind::Source:
case FileUnitKind::Builtin:
case FileUnitKind::Synthesized:
case FileUnitKind::ClangModule:
case FileUnitKind::DWARFModule:
return RawComment();
}
llvm_unreachable("invalid file kind");
}

static const Decl* getGroupDecl(const Decl *D) {
Expand Down