Skip to content

Commit fcd1783

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

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
@@ -4207,9 +4207,10 @@ class RawCommentRequest
42074207
bool isCached() const { return true; }
42084208
};
42094209

4210-
/// Retrieve the brief portion of a declaration's document comment.
4211-
class BriefCommentRequest
4212-
: public SimpleRequest<BriefCommentRequest,
4210+
/// Retrieve the brief portion of a declaration's document comment, potentially
4211+
/// walking to find the comment providing decl if needed.
4212+
class SemanticBriefCommentRequest
4213+
: public SimpleRequest<SemanticBriefCommentRequest,
42134214
StringRef(const Decl *),
42144215
RequestFlags::Cached> {
42154216
public:

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest,
472472
SWIFT_REQUEST(TypeChecker, RawCommentRequest,
473473
RawComment(const Decl *),
474474
Cached, NoLocationInfo)
475-
SWIFT_REQUEST(TypeChecker, BriefCommentRequest,
475+
SWIFT_REQUEST(TypeChecker, SemanticBriefCommentRequest,
476476
StringRef(const Decl *),
477477
Cached, NoLocationInfo)
478478
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
@@ -227,7 +227,7 @@ void CodeCompletionResultBuilder::setAssociatedDecl(const Decl *D) {
227227
}
228228
}
229229
} else {
230-
setBriefDocComment(AssociatedDecl->getBriefComment());
230+
setBriefDocComment(AssociatedDecl->getSemanticBriefComment());
231231
}
232232
}
233233

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
@@ -1178,10 +1178,10 @@ static int printTypeContextInfo(
11781178
VD->getName().print(llvm::outs());
11791179
llvm::outs() << "\n";
11801180

1181-
StringRef BriefDoc = VD->getBriefComment();
1181+
StringRef BriefDoc = VD->getSemanticBriefComment();
11821182
if (!BriefDoc.empty()) {
11831183
llvm::outs() << " DocBrief: \"";
1184-
llvm::outs() << VD->getBriefComment();
1184+
llvm::outs() << VD->getSemanticBriefComment();
11851185
llvm::outs() << "\"\n";
11861186
}
11871187
}
@@ -1246,10 +1246,10 @@ static int printConformingMethodList(
12461246
resultTy.print(llvm::outs());
12471247
llvm::outs() << "\n";
12481248

1249-
StringRef BriefDoc = VD->getBriefComment();
1249+
StringRef BriefDoc = VD->getSemanticBriefComment();
12501250
if (!BriefDoc.empty()) {
12511251
llvm::outs() << " DocBrief: \"";
1252-
llvm::outs() << VD->getBriefComment();
1252+
llvm::outs() << VD->getSemanticBriefComment();
12531253
llvm::outs() << "\"\n";
12541254
}
12551255
}
@@ -3523,7 +3523,7 @@ class ASTCommentPrinter : public ASTWalker {
35233523
OS << " ";
35243524
printRawComment(D->getRawComment());
35253525
OS << " ";
3526-
printBriefComment(D->getBriefComment());
3526+
printBriefComment(D->getSemanticBriefComment());
35273527
OS << " ";
35283528
printDocComment(D);
35293529
OS << "\n";
@@ -3538,7 +3538,7 @@ class ASTCommentPrinter : public ASTWalker {
35383538
OS << " ";
35393539
printRawComment(D->getRawComment());
35403540
OS << " ";
3541-
printBriefComment(D->getBriefComment());
3541+
printBriefComment(D->getSemanticBriefComment());
35423542
OS << " ";
35433543
printDocComment(D);
35443544
OS << "\n";

0 commit comments

Comments
 (0)