This is an archive of the discontinued LLVM Phabricator instance.

[clang] adds prototype for being able to alternate diagnostic formats
AbandonedPublic

Authored by cjdb on Jul 11 2022, 10:00 PM.

Details

Reviewers
aaron.ballman
Summary

In an effort to move from unstructured text diagnostics to structured
diagnostics, while keeping support for the existing model, we need to
introduce a way to hotswap between the desired modes. The visitor
pattern is a natural ally here because it allows us to defer logic to
handlers that know the specifics of the diagnostic without cluttering
the compiler's logic.

There are two parts to the design: BasicDiagnostic, which is used as
an abstract base for errors, warnings, and remarks; and
DiagnosticContext, which is used as an abstract base for notes. We've
split diagnostics into these two categories so that it's possible for to
enrich diagnostics with multiple unrelated contexts (notes seem to trail
diagnostics in a detatched and unherded fashion). FixIts are a form of
diagnostic context.

Although parts of BasicDiagnostic and DiagnosticContext should be
generated via TableGen, we're initially implementing everything manually
so that we can prototype what is necessary: it will be far easier to do
this with a handful of diagnostics than to also figure out how to
integrate this into TableGen at the same time.

Reviewers should note that testing is currently lacking. Tests for the
diagnostic framework seem to be nonexistent; this should probably
change.

Depends on: D109701

Diff Detail

Event Timeline

cjdb created this revision.Jul 11 2022, 10:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 10:00 PM
cjdb requested review of this revision.Jul 11 2022, 10:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 10:00 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cjdb updated this revision to Diff 443833.Jul 11 2022, 10:02 PM

arc diff no longer seems to autoformat

aaron.ballman added inline comments.Jul 13 2022, 6:00 AM
clang/include/clang/Basic/Diagnostic.h
212–214

To make sure I understand, notes are one context, but are error/warning/remarks another context, and same for fixits?

I'm having a hard time understanding how you expect to use this; in the diagnostics engine, notes are like any other diagnostic, so are you going to look at the diagnostic ID and dispatch to either the BasicDiagnostic or the DiagnosticContext interface? I'd appreciate a bit more information on how this separation works.

1024

Question: should we have the overload set so that you get a const writer on a const engine and a non-const writer on a non-const engine?

cjdb abandoned this revision.Sep 12 2023, 1:49 PM

Abandoning since this design is obsolete.