Skip to content

Commit a55ae62

Browse files
authored
Merge pull request #65265 from hamishknight/whats-up-doc
2 parents 2ad1589 + be31c22 commit a55ae62

31 files changed

+574
-350
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,12 +1545,6 @@ class ASTContext final {
15451545
Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
15461546
void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs);
15471547

1548-
Optional<std::pair<RawComment, bool>> getRawComment(const Decl *D);
1549-
void setRawComment(const Decl *D, RawComment RC, bool FromSerialized);
1550-
1551-
Optional<StringRef> getBriefComment(const Decl *D);
1552-
void setBriefComment(const Decl *D, StringRef Comment);
1553-
15541548
friend TypeBase;
15551549
friend ArchetypeType;
15561550
friend OpaqueTypeDecl;

include/swift/AST/Comment.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,16 @@ class DocComment {
9393
};
9494

9595
/// Get a parsed documentation comment for the declaration, if there is one.
96-
///
97-
/// \param AllowSerialized Allow loading serialized doc comment data, including
98-
/// comment ranges.
9996
DocComment *getSingleDocComment(swift::markup::MarkupContext &Context,
100-
const Decl *D, bool AllowSerialized = false);
97+
const Decl *D);
10198

10299
/// Get the declaration that actually provides a doc comment for another.
103-
///
104-
/// \param AllowSerialized Allow loading serialized doc comment data, including
105-
/// comment ranges.
106-
const Decl *getDocCommentProvidingDecl(const Decl *D,
107-
bool AllowSerialized = false);
100+
const Decl *getDocCommentProvidingDecl(const Decl *D);
108101

109102
/// Attempt to get a doc comment from the declaration, or other inherited
110103
/// sources, like from base classes or protocols.
111-
///
112-
/// \param AllowSerialized Allow loading serialized doc comment data, including
113-
/// comment ranges.
114104
DocComment *getCascadingDocComment(swift::markup::MarkupContext &MC,
115-
const Decl *D,
116-
bool AllowSerialized = false);
105+
const Decl *D);
117106

118107
/// Extract comments parts from the given Markup node.
119108
swift::markup::CommentParts
@@ -122,6 +111,25 @@ extractCommentParts(swift::markup::MarkupContext &MC,
122111

123112
/// Extract brief comment from \p RC, and print it to \p OS .
124113
void printBriefComment(RawComment RC, llvm::raw_ostream &OS);
114+
115+
/// Describes the intended serialization target for a doc comment.
116+
enum class DocCommentSerializationTarget : uint8_t {
117+
/// The doc comment should not be serialized.
118+
None = 0,
119+
120+
/// The doc comment should only be serialized in the 'swiftsourceinfo'.
121+
SourceInfoOnly,
122+
123+
/// The doc comment should be serialized in both the 'swiftdoc' and
124+
/// 'swiftsourceinfo'.
125+
SwiftDocAndSourceInfo,
126+
};
127+
128+
/// Retrieve the expected serialization target for a documentation comment
129+
/// attached to the given decl.
130+
DocCommentSerializationTarget
131+
getDocCommentSerializationTargetFor(const Decl *D);
132+
125133
} // namespace swift
126134

127135
#endif // LLVM_SWIFT_AST_COMMENT_H

include/swift/AST/Decl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
747747
friend class IterableDeclContext;
748748
friend class MemberLookupTable;
749749
friend class DeclDeserializer;
750+
friend class RawCommentRequest;
750751

751752
private:
752753
llvm::PointerUnion<DeclContext *, ASTContext *> Context;
@@ -1015,16 +1016,17 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
10151016
}
10161017

10171018
/// \returns the unparsed comment attached to this declaration.
1018-
RawComment getRawComment(bool SerializedOK = false) const;
1019+
RawComment getRawComment() const;
10191020

10201021
Optional<StringRef> getGroupName() const;
10211022

10221023
Optional<StringRef> getSourceFileName() const;
10231024

10241025
Optional<unsigned> getSourceOrder() const;
10251026

1026-
/// \returns the brief comment attached to this declaration.
1027-
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;
10281030

10291031
/// Returns true if there is a Clang AST node associated
10301032
/// with self.

include/swift/AST/FileUnit.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,16 @@ 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;
168168
}
169169

170+
/// For a serialized AST file, returns \c true if an adjacent swiftdoc has been
171+
/// loaded. Otherwise, returns \c false.
172+
virtual bool hasLoadedSwiftDoc() const { return false; }
173+
170174
virtual Optional<StringRef>
171175
getGroupNameForDecl(const Decl *D) const {
172176
return None;

include/swift/AST/TypeCheckRequests.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,45 @@ class LocalDiscriminatorsRequest
41684168
bool isCached() const { return true; }
41694169
};
41704170

4171+
/// Retrieve the raw documentation comment of a declaration.
4172+
class RawCommentRequest
4173+
: public SimpleRequest<RawCommentRequest,
4174+
RawComment(const Decl *),
4175+
RequestFlags::Cached> {
4176+
public:
4177+
using SimpleRequest::SimpleRequest;
4178+
4179+
private:
4180+
friend SimpleRequest;
4181+
4182+
// Evaluation.
4183+
RawComment evaluate(Evaluator &evaluator, const Decl *D) const;
4184+
4185+
public:
4186+
// Separate caching.
4187+
bool isCached() const { return true; }
4188+
};
4189+
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,
4194+
StringRef(const Decl *),
4195+
RequestFlags::Cached> {
4196+
public:
4197+
using SimpleRequest::SimpleRequest;
4198+
4199+
private:
4200+
friend SimpleRequest;
4201+
4202+
// Evaluation.
4203+
StringRef evaluate(Evaluator &evaluator, const Decl *D) const;
4204+
4205+
public:
4206+
// Separate caching.
4207+
bool isCached() const { return true; }
4208+
};
4209+
41714210
/// Checks that all of a class's \c \@objcImplementation extensions provide
41724211
/// complete and correct implementations for their corresponding interfaces.
41734212
/// This is done on all of a class's implementations at once to improve diagnostics.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ SWIFT_REQUEST(TypeChecker, GetRuntimeDiscoverableAttributes,
466466
SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest,
467467
unsigned(DeclContext *),
468468
Cached, NoLocationInfo)
469+
SWIFT_REQUEST(TypeChecker, RawCommentRequest,
470+
RawComment(const Decl *),
471+
Cached, NoLocationInfo)
472+
SWIFT_REQUEST(TypeChecker, SemanticBriefCommentRequest,
473+
StringRef(const Decl *),
474+
Cached, NoLocationInfo)
469475
SWIFT_REQUEST(TypeChecker, IsNonUserModuleRequest,
470476
bool(ModuleDecl *),
471477
Cached, NoLocationInfo)

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ class SerializedASTFile final : public LoadedFile {
430430

431431
Optional<CommentInfo> getCommentForDecl(const Decl *D) const override;
432432

433+
bool hasLoadedSwiftDoc() const override;
434+
433435
Optional<StringRef> getGroupNameForDecl(const Decl *D) const override;
434436

435437

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,6 @@ struct ASTContext::Implementation {
316316
/// actual \c SourceLocs that require opening their external buffer.
317317
llvm::DenseMap<const Decl *, ExternalSourceLocs *> ExternalSourceLocs;
318318

319-
/// Map from Swift declarations to raw comments.
320-
llvm::DenseMap<const Decl *, std::pair<RawComment, bool>> RawComments;
321-
322-
/// Map from Swift declarations to brief comments.
323-
llvm::DenseMap<const Decl *, StringRef> BriefComments;
324-
325319
/// Map from declarations to foreign error conventions.
326320
/// This applies to both actual imported functions and to @objc functions.
327321
llvm::DenseMap<const AbstractFunctionDecl *,
@@ -2610,30 +2604,6 @@ void ASTContext::setExternalSourceLocs(const Decl *D,
26102604
getImpl().ExternalSourceLocs[D] = Locs;
26112605
}
26122606

2613-
Optional<std::pair<RawComment, bool>> ASTContext::getRawComment(const Decl *D) {
2614-
auto Known = getImpl().RawComments.find(D);
2615-
if (Known == getImpl().RawComments.end())
2616-
return None;
2617-
2618-
return Known->second;
2619-
}
2620-
2621-
void ASTContext::setRawComment(const Decl *D, RawComment RC, bool FromSerialized) {
2622-
getImpl().RawComments[D] = std::make_pair(RC, FromSerialized);
2623-
}
2624-
2625-
Optional<StringRef> ASTContext::getBriefComment(const Decl *D) {
2626-
auto Known = getImpl().BriefComments.find(D);
2627-
if (Known == getImpl().BriefComments.end())
2628-
return None;
2629-
2630-
return Known->second;
2631-
}
2632-
2633-
void ASTContext::setBriefComment(const Decl *D, StringRef Comment) {
2634-
getImpl().BriefComments[D] = Comment;
2635-
}
2636-
26372607
NormalProtocolConformance *
26382608
ASTContext::getConformance(Type conformingType,
26392609
ProtocolDecl *protocol,
@@ -2936,8 +2906,6 @@ size_t ASTContext::getTotalMemory() const {
29362906
getImpl().Allocator.getTotalMemory() +
29372907
getImpl().Cleanups.capacity() +
29382908
llvm::capacity_in_bytes(getImpl().ModuleLoaders) +
2939-
llvm::capacity_in_bytes(getImpl().RawComments) +
2940-
llvm::capacity_in_bytes(getImpl().BriefComments) +
29412909
llvm::capacity_in_bytes(getImpl().ModuleTypes) +
29422910
llvm::capacity_in_bytes(getImpl().GenericParamTypes) +
29432911
// getImpl().GenericFunctionTypes ?

0 commit comments

Comments
 (0)