@@ -87,11 +87,8 @@ struct SharedState : llvm::RefCountedBase<SharedState> {
8787 // / The collection of categories used.
8888 llvm::DenseMap<const char *, unsigned > Categories;
8989
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;
9592
9693 // / Whether we have already started emission of any DIAG blocks. Once
9794 // / this becomes \c true, we never close a DIAG block until we know that we're
@@ -198,6 +195,14 @@ class SerializedDiagnosticConsumer : public DiagnosticConsumer {
198195 // Record identifier for the category.
199196 unsigned getEmitCategory (StringRef Category);
200197
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+
201206 // / Add a source location to a record.
202207 void addLocToRecord (SourceLoc Loc,
203208 SourceManager &SM,
@@ -319,6 +324,34 @@ unsigned SerializedDiagnosticConsumer::getEmitCategory(StringRef Category) {
319324 return entry;
320325}
321326
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+
322355void SerializedDiagnosticConsumer::addLocToRecord (SourceLoc Loc,
323356 SourceManager &SM,
324357 StringRef Filename,
@@ -572,8 +605,10 @@ emitDiagnosticMessage(SourceManager &SM,
572605 Record.push_back (0 );
573606 }
574607
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));
577612
578613 // Emit the message.
579614 Record.push_back (Text.size ());
0 commit comments