Skip to content

Commit 9a91075

Browse files
committed
Serialization: Add an error when group information for a specific source file is not found.
1 parent d81edcb commit 9a91075

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ ERROR(not_implemented,none,
4545
ERROR(error_opening_output,none,
4646
"error opening '%0' for output: %1", (StringRef, StringRef))
4747

48+
ERROR(error_no_group_info,none,
49+
"no group info found for file: '%0'", (StringRef))
4850

4951
NOTE(previous_decldef,none,
5052
"previous %select{declaration|definition}0 of %1 is here",

lib/Serialization/Serialization.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,10 +3612,12 @@ class DeclGroupNameContext {
36123612
class GroupNameCollectorFromJson : public GroupNameCollector {
36133613
StringRef RecordPath;
36143614
FileNameToGroupNameMap* pMap = nullptr;
3615+
ASTContext &Ctx;
36153616

36163617
public:
3617-
GroupNameCollectorFromJson(StringRef RecordPath) :
3618-
GroupNameCollector(!RecordPath.empty()), RecordPath(RecordPath) {}
3618+
GroupNameCollectorFromJson(StringRef RecordPath, ASTContext &Ctx) :
3619+
GroupNameCollector(!RecordPath.empty()), RecordPath(RecordPath),
3620+
Ctx(Ctx) {}
36193621
StringRef getGroupNameInternal(const ValueDecl *VD) override {
36203622
// We need the file path, so there has to be a location.
36213623
if (VD->getLoc().isInvalid())
@@ -3637,7 +3639,11 @@ class DeclGroupNameContext {
36373639
return NullGroupName;
36383640
StringRef FileName = llvm::sys::path::filename(FullPath);
36393641
auto Found = pMap->find(FileName);
3640-
return Found == pMap->end() ? NullGroupName : Found->second;
3642+
if (Found == pMap->end()) {
3643+
Ctx.Diags.diagnose(SourceLoc(), diag::error_no_group_info, FileName);
3644+
return NullGroupName;
3645+
}
3646+
return Found->second;
36413647
}
36423648
};
36433649

@@ -3646,8 +3652,8 @@ class DeclGroupNameContext {
36463652
std::unique_ptr<GroupNameCollector> pNameCollector;
36473653

36483654
public:
3649-
DeclGroupNameContext(StringRef RecordPath) :
3650-
pNameCollector(new GroupNameCollectorFromJson(RecordPath)) {}
3655+
DeclGroupNameContext(StringRef RecordPath, ASTContext &Ctx) :
3656+
pNameCollector(new GroupNameCollectorFromJson(RecordPath, Ctx)) {}
36513657
uint32_t getGroupSequence(const ValueDecl *VD) {
36523658
return Map.insert(std::make_pair(pNameCollector->getGroupName(VD),
36533659
Map.size())).first->second;
@@ -4040,7 +4046,7 @@ void Serializer::writeToStream(raw_ostream &os, ModuleOrSourceFile DC,
40404046
}
40414047

40424048
void Serializer::writeDocToStream(raw_ostream &os, ModuleOrSourceFile DC,
4043-
StringRef GroupInfoPath) {
4049+
StringRef GroupInfoPath, ASTContext &Ctx) {
40444050
Serializer S{MODULE_DOC_SIGNATURE, DC};
40454051
// FIXME: This is only really needed for debugging. We don't actually use it.
40464052
S.writeDocBlockInfoBlock();
@@ -4050,7 +4056,7 @@ void Serializer::writeDocToStream(raw_ostream &os, ModuleOrSourceFile DC,
40504056
S.writeDocHeader();
40514057
{
40524058
BCBlockRAII restoreBlock(S.Out, COMMENT_BLOCK_ID, 4);
4053-
DeclGroupNameContext GroupContext(GroupInfoPath);
4059+
DeclGroupNameContext GroupContext(GroupInfoPath, Ctx);
40544060
comment_block::DeclCommentListLayout DeclCommentList(S.Out);
40554061
writeDeclCommentTable(DeclCommentList, S.SF, S.M, GroupContext);
40564062
comment_block::GroupNamesLayout GroupNames(S.Out);
@@ -4130,7 +4136,8 @@ void swift::serialize(ModuleOrSourceFile DC,
41304136
(void)withOutputFile(getContext(DC), options.DocOutputPath,
41314137
[&](raw_ostream &out) {
41324138
SharedTimer timer("Serialization (swiftdoc)");
4133-
Serializer::writeDocToStream(out, DC, options.GroupInfoPath);
4139+
Serializer::writeDocToStream(out, DC, options.GroupInfoPath,
4140+
getContext(DC));
41344141
});
41354142
}
41364143
}

lib/Serialization/Serialization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class Serializer {
339339

340340
/// Serialize module documentation to the given stream.
341341
static void writeDocToStream(raw_ostream &os, ModuleOrSourceFile DC,
342-
StringRef GroupInfoPath);
342+
StringRef GroupInfoPath, ASTContext &Ctx);
343343

344344
/// Records the use of the given Type.
345345
///

0 commit comments

Comments
 (0)