@@ -87,11 +87,8 @@ struct SharedState : llvm::RefCountedBase<SharedState> {
87
87
// / The collection of categories used.
88
88
llvm::DenseMap<const char *, unsigned > Categories;
89
89
90
- using DiagFlagsTy =
91
- llvm::DenseMap<const void *, std::pair<unsigned , StringRef>>;
92
-
93
- // / Map for uniquing strings.
94
- DiagFlagsTy DiagFlags;
90
+ // / The collection of flags used.
91
+ llvm::StringMap<unsigned > Flags;
95
92
96
93
// / Whether we have already started emission of any DIAG blocks. Once
97
94
// / this becomes \c true, we never close a DIAG block until we know that we're
@@ -198,6 +195,14 @@ class SerializedDiagnosticConsumer : public DiagnosticConsumer {
198
195
// Record identifier for the category.
199
196
unsigned getEmitCategory (StringRef Category);
200
197
198
+ // / Emit a flag record that contains a semi-colon separated
199
+ // / list of all of the educational notes associated with the
200
+ // / diagnostic or `0` if there are no notes.
201
+ // /
202
+ // / \returns a flag record identifier that could be embedded in
203
+ // / other records.
204
+ unsigned emitEducationalNotes (const DiagnosticInfo &info);
205
+
201
206
// / Add a source location to a record.
202
207
void addLocToRecord (SourceLoc Loc,
203
208
SourceManager &SM,
@@ -319,6 +324,34 @@ unsigned SerializedDiagnosticConsumer::getEmitCategory(StringRef Category) {
319
324
return entry;
320
325
}
321
326
327
+ unsigned
328
+ SerializedDiagnosticConsumer::emitEducationalNotes (const DiagnosticInfo &Info) {
329
+ if (Info.EducationalNotePaths .empty ())
330
+ return 0 ;
331
+
332
+ SmallString<32 > scratch;
333
+ interleave (
334
+ Info.EducationalNotePaths ,
335
+ [&scratch](const auto ¬ePath) { scratch += notePath; },
336
+ [&scratch] { scratch += ' ;' ; });
337
+
338
+ StringRef paths = scratch.str ();
339
+
340
+ unsigned &recordID = State->Flags [paths];
341
+ if (recordID)
342
+ return recordID;
343
+
344
+ recordID = State->Flags .size ();
345
+
346
+ RecordData Record;
347
+ Record.push_back (RECORD_DIAG_FLAG);
348
+ Record.push_back (recordID);
349
+ Record.push_back (paths.size ());
350
+ State->Stream .EmitRecordWithBlob (State->Abbrevs .get (RECORD_DIAG_FLAG), Record,
351
+ paths.data ());
352
+ return recordID;
353
+ }
354
+
322
355
void SerializedDiagnosticConsumer::addLocToRecord (SourceLoc Loc,
323
356
SourceManager &SM,
324
357
StringRef Filename,
@@ -572,8 +605,10 @@ emitDiagnosticMessage(SourceManager &SM,
572
605
Record.push_back (0 );
573
606
}
574
607
575
- // FIXME: Swift diagnostics currently have no flags.
576
- Record.push_back (0 );
608
+ // Use "flags" slot to emit a semi-colon separated list of
609
+ // educational notes. If there are no notes associated with
610
+ // this diagnostic `0` placeholder would be emitted instead.
611
+ Record.push_back (emitEducationalNotes (Info));
577
612
578
613
// Emit the message.
579
614
Record.push_back (Text.size ());
0 commit comments