Skip to content

Commit b8ae066

Browse files
committed
Rename getBriefComment -> getSemanticBriefComment
Make it clear that we will walk the comment providing decls if needed.
1 parent 95d0ebd commit b8ae066

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,9 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
10241024

10251025
Optional<unsigned> getSourceOrder() const;
10261026

1027-
/// \returns the brief comment attached to this declaration.
1028-
StringRef getBriefComment() const;
1027+
/// \returns The brief comment attached to this declaration, or the brief
1028+
/// comment attached to the comment providing decl.
1029+
StringRef getSemanticBriefComment() const;
10291030

10301031
/// Returns true if there is a Clang AST node associated
10311032
/// with self.

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
161161
///
162162
/// This function is an implementation detail for comment serialization.
163163
/// If you just want to get a comment attached to a decl, use
164-
/// \c Decl::getRawComment() or \c Decl::getBriefComment().
164+
/// \c Decl::getRawComment() or \c Decl::getSemanticBriefComment().
165165
virtual Optional<CommentInfo>
166166
getCommentForDecl(const Decl *D) const {
167167
return None;

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,9 +4187,10 @@ class RawCommentRequest
41874187
bool isCached() const { return true; }
41884188
};
41894189

4190-
/// Retrieve the brief portion of a declaration's document comment.
4191-
class BriefCommentRequest
4192-
: public SimpleRequest<BriefCommentRequest,
4190+
/// Retrieve the brief portion of a declaration's document comment, potentially
4191+
/// walking to find the comment providing decl if needed.
4192+
class SemanticBriefCommentRequest
4193+
: public SimpleRequest<SemanticBriefCommentRequest,
41934194
StringRef(const Decl *),
41944195
RequestFlags::Cached> {
41954196
public:

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest,
469469
SWIFT_REQUEST(TypeChecker, RawCommentRequest,
470470
RawComment(const Decl *),
471471
Cached, NoLocationInfo)
472-
SWIFT_REQUEST(TypeChecker, BriefCommentRequest,
472+
SWIFT_REQUEST(TypeChecker, SemanticBriefCommentRequest,
473473
StringRef(const Decl *),
474474
Cached, NoLocationInfo)
475475
SWIFT_REQUEST(TypeChecker, IsNonUserModuleRequest,

lib/AST/DocComment.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,19 +573,20 @@ static Optional<StringRef> getDirectBriefComment(const Decl *D) {
573573
return Ctx.AllocateCopy(BriefStr.str());
574574
}
575575

576-
StringRef BriefCommentRequest::evaluate(Evaluator &evaluator,
577-
const Decl *D) const {
576+
StringRef SemanticBriefCommentRequest::evaluate(Evaluator &evaluator,
577+
const Decl *D) const {
578578
// Perform a walk over the potential providers of the brief comment,
579579
// retrieving the first one we come across.
580580
CommentProviderFinder finder(getDirectBriefComment);
581581
auto result = finder.findCommentProvider(D);
582582
return result ? result->first : StringRef();
583583
}
584584

585-
StringRef Decl::getBriefComment() const {
585+
StringRef Decl::getSemanticBriefComment() const {
586586
if (!this->canHaveComment())
587587
return StringRef();
588588

589589
auto &eval = getASTContext().evaluator;
590-
return evaluateOrDefault(eval, BriefCommentRequest{this}, StringRef());
590+
return evaluateOrDefault(eval, SemanticBriefCommentRequest{this},
591+
StringRef());
591592
}

lib/IDE/CodeCompletionResultBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void CodeCompletionResultBuilder::setAssociatedDecl(const Decl *D) {
222222
}
223223
}
224224
} else {
225-
setBriefDocComment(AssociatedDecl->getBriefComment());
225+
setBriefDocComment(AssociatedDecl->getSemanticBriefComment());
226226
}
227227
}
228228

lib/Serialization/SerializeDoc.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ static void writeDeclCommentTable(
357357
if (!D->canHaveComment())
358358
return false;
359359

360-
// Skip the decl if it does not have a comment.
360+
// Skip the decl if it does not have a comment. Note this means
361+
// we'll only serialize "direct" brief comments, but that's okay
362+
// because clients can compute the semantic brief comment themselves.
361363
if (D->getRawComment().Comments.empty())
362364
return false;
363365
return true;
@@ -372,9 +374,8 @@ static void writeDeclCommentTable(
372374
return;
373375
}
374376
generator.insert(copyString(USRBuffer.str()),
375-
{ ED->getBriefComment(), ED->getRawComment(),
376-
GroupContext.getGroupSequence(ED),
377-
SourceOrder++ });
377+
{ED->getSemanticBriefComment(), ED->getRawComment(),
378+
GroupContext.getGroupSequence(ED), SourceOrder++});
378379
}
379380

380381
MacroWalking getMacroWalkingBehavior() const override {
@@ -407,9 +408,8 @@ static void writeDeclCommentTable(
407408
}
408409

409410
generator.insert(copyString(USRBuffer.str()),
410-
{ VD->getBriefComment(), D->getRawComment(),
411-
GroupContext.getGroupSequence(VD),
412-
SourceOrder++ });
411+
{VD->getSemanticBriefComment(), D->getRawComment(),
412+
GroupContext.getGroupSequence(VD), SourceOrder++});
413413
return Action::Continue();
414414
}
415415

tools/SourceKit/lib/SwiftLang/SwiftConformingMethodList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ deliverResults(SourceKit::ConformingMethodListConsumer &SKConsumer,
119119
memberElem.BriefComment = RC->getBriefText(ClangContext);
120120
}
121121
} else {
122-
memberElem.BriefComment = member->getBriefComment();
122+
memberElem.BriefComment = member->getSemanticBriefComment();
123123
}
124124
}
125125

tools/SourceKit/lib/SwiftLang/SwiftTypeContextInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void deliverResults(SourceKit::TypeContextInfoConsumer &SKConsumer,
9191
memberElem.BriefComment = RC->getBriefText(ClangContext);
9292
}
9393
} else {
94-
memberElem.BriefComment = member->getBriefComment();
94+
memberElem.BriefComment = member->getSemanticBriefComment();
9595
}
9696
}
9797

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,10 @@ static int printTypeContextInfo(
11831183
VD->getName().print(llvm::outs());
11841184
llvm::outs() << "\n";
11851185

1186-
StringRef BriefDoc = VD->getBriefComment();
1186+
StringRef BriefDoc = VD->getSemanticBriefComment();
11871187
if (!BriefDoc.empty()) {
11881188
llvm::outs() << " DocBrief: \"";
1189-
llvm::outs() << VD->getBriefComment();
1189+
llvm::outs() << VD->getSemanticBriefComment();
11901190
llvm::outs() << "\"\n";
11911191
}
11921192
}
@@ -1251,10 +1251,10 @@ static int printConformingMethodList(
12511251
resultTy.print(llvm::outs());
12521252
llvm::outs() << "\n";
12531253

1254-
StringRef BriefDoc = VD->getBriefComment();
1254+
StringRef BriefDoc = VD->getSemanticBriefComment();
12551255
if (!BriefDoc.empty()) {
12561256
llvm::outs() << " DocBrief: \"";
1257-
llvm::outs() << VD->getBriefComment();
1257+
llvm::outs() << VD->getSemanticBriefComment();
12581258
llvm::outs() << "\"\n";
12591259
}
12601260
}
@@ -3528,7 +3528,7 @@ class ASTCommentPrinter : public ASTWalker {
35283528
OS << " ";
35293529
printRawComment(D->getRawComment());
35303530
OS << " ";
3531-
printBriefComment(D->getBriefComment());
3531+
printBriefComment(D->getSemanticBriefComment());
35323532
OS << " ";
35333533
printDocComment(D);
35343534
OS << "\n";
@@ -3543,7 +3543,7 @@ class ASTCommentPrinter : public ASTWalker {
35433543
OS << " ";
35443544
printRawComment(D->getRawComment());
35453545
OS << " ";
3546-
printBriefComment(D->getBriefComment());
3546+
printBriefComment(D->getSemanticBriefComment());
35473547
OS << " ";
35483548
printDocComment(D);
35493549
OS << "\n";

0 commit comments

Comments
 (0)