Skip to content

Commit 1994869

Browse files
authored
Merge pull request #65462 from hamishknight/whats-up-doc-5.9
2 parents 7d934ed + 793cddb commit 1994869

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
@@ -1522,12 +1522,6 @@ class ASTContext final {
15221522
Optional<ExternalSourceLocs *> getExternalSourceLocs(const Decl *D);
15231523
void setExternalSourceLocs(const Decl *D, ExternalSourceLocs *Locs);
15241524

1525-
Optional<std::pair<RawComment, bool>> getRawComment(const Decl *D);
1526-
void setRawComment(const Decl *D, RawComment RC, bool FromSerialized);
1527-
1528-
Optional<StringRef> getBriefComment(const Decl *D);
1529-
void setBriefComment(const Decl *D, StringRef Comment);
1530-
15311525
friend TypeBase;
15321526
friend ArchetypeType;
15331527
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
@@ -4188,6 +4188,45 @@ class LocalDiscriminatorsRequest
41884188
bool isCached() const { return true; }
41894189
};
41904190

4191+
/// Retrieve the raw documentation comment of a declaration.
4192+
class RawCommentRequest
4193+
: public SimpleRequest<RawCommentRequest,
4194+
RawComment(const Decl *),
4195+
RequestFlags::Cached> {
4196+
public:
4197+
using SimpleRequest::SimpleRequest;
4198+
4199+
private:
4200+
friend SimpleRequest;
4201+
4202+
// Evaluation.
4203+
RawComment evaluate(Evaluator &evaluator, const Decl *D) const;
4204+
4205+
public:
4206+
// Separate caching.
4207+
bool isCached() const { return true; }
4208+
};
4209+
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,
4214+
StringRef(const Decl *),
4215+
RequestFlags::Cached> {
4216+
public:
4217+
using SimpleRequest::SimpleRequest;
4218+
4219+
private:
4220+
friend SimpleRequest;
4221+
4222+
// Evaluation.
4223+
StringRef evaluate(Evaluator &evaluator, const Decl *D) const;
4224+
4225+
public:
4226+
// Separate caching.
4227+
bool isCached() const { return true; }
4228+
};
4229+
41914230
/// Checks that all of a class's \c \@objcImplementation extensions provide
41924231
/// complete and correct implementations for their corresponding interfaces.
41934232
/// 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
@@ -469,6 +469,12 @@ SWIFT_REQUEST(TypeChecker, GetRuntimeDiscoverableAttributes,
469469
SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest,
470470
unsigned(DeclContext *),
471471
Cached, NoLocationInfo)
472+
SWIFT_REQUEST(TypeChecker, RawCommentRequest,
473+
RawComment(const Decl *),
474+
Cached, NoLocationInfo)
475+
SWIFT_REQUEST(TypeChecker, SemanticBriefCommentRequest,
476+
StringRef(const Decl *),
477+
Cached, NoLocationInfo)
472478
SWIFT_REQUEST(TypeChecker, IsNonUserModuleRequest,
473479
bool(ModuleDecl *),
474480
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
@@ -314,12 +314,6 @@ struct ASTContext::Implementation {
314314
/// actual \c SourceLocs that require opening their external buffer.
315315
llvm::DenseMap<const Decl *, ExternalSourceLocs *> ExternalSourceLocs;
316316

317-
/// Map from Swift declarations to raw comments.
318-
llvm::DenseMap<const Decl *, std::pair<RawComment, bool>> RawComments;
319-
320-
/// Map from Swift declarations to brief comments.
321-
llvm::DenseMap<const Decl *, StringRef> BriefComments;
322-
323317
/// Map from declarations to foreign error conventions.
324318
/// This applies to both actual imported functions and to @objc functions.
325319
llvm::DenseMap<const AbstractFunctionDecl *,
@@ -2596,30 +2590,6 @@ void ASTContext::setExternalSourceLocs(const Decl *D,
25962590
getImpl().ExternalSourceLocs[D] = Locs;
25972591
}
25982592

2599-
Optional<std::pair<RawComment, bool>> ASTContext::getRawComment(const Decl *D) {
2600-
auto Known = getImpl().RawComments.find(D);
2601-
if (Known == getImpl().RawComments.end())
2602-
return None;
2603-
2604-
return Known->second;
2605-
}
2606-
2607-
void ASTContext::setRawComment(const Decl *D, RawComment RC, bool FromSerialized) {
2608-
getImpl().RawComments[D] = std::make_pair(RC, FromSerialized);
2609-
}
2610-
2611-
Optional<StringRef> ASTContext::getBriefComment(const Decl *D) {
2612-
auto Known = getImpl().BriefComments.find(D);
2613-
if (Known == getImpl().BriefComments.end())
2614-
return None;
2615-
2616-
return Known->second;
2617-
}
2618-
2619-
void ASTContext::setBriefComment(const Decl *D, StringRef Comment) {
2620-
getImpl().BriefComments[D] = Comment;
2621-
}
2622-
26232593
NormalProtocolConformance *
26242594
ASTContext::getConformance(Type conformingType,
26252595
ProtocolDecl *protocol,
@@ -2922,8 +2892,6 @@ size_t ASTContext::getTotalMemory() const {
29222892
getImpl().Allocator.getTotalMemory() +
29232893
getImpl().Cleanups.capacity() +
29242894
llvm::capacity_in_bytes(getImpl().ModuleLoaders) +
2925-
llvm::capacity_in_bytes(getImpl().RawComments) +
2926-
llvm::capacity_in_bytes(getImpl().BriefComments) +
29272895
llvm::capacity_in_bytes(getImpl().ModuleTypes) +
29282896
llvm::capacity_in_bytes(getImpl().GenericParamTypes) +
29292897
// getImpl().GenericFunctionTypes ?

0 commit comments

Comments
 (0)