Introduce a new API for emitting diagnostics with Diagnostic and InFlightDiagnostic.
authorRiver Riddle <riverriddle@google.com>
Fri, 3 May 2019 17:01:01 +0000 (10:01 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 6 May 2019 15:26:34 +0000 (08:26 -0700)
commitff6e7cf558135055f65202f73a0c06db7a53e77d
tree1bf545d82cbb014499443e3e3da002195486c771
parent8c9fbb7eb833cd0f51cb2f02f0500aec481e8c30
Introduce a new API for emitting diagnostics with Diagnostic and InFlightDiagnostic.

    The Diagnostic class contains all of the information necessary to report a diagnostic to the DiagnosticEngine. It should generally not be constructed directly, and instead used transitively via InFlightDiagnostic. A diagnostic is currently comprised of several different elements:
    * A severity level.
    * A source Location.
    * A list of DiagnosticArguments that help compose and comprise the output message.
      * A DiagnosticArgument represents any value that may be part of the diagnostic, e.g. string, integer, Type, Attribute, etc.
      * Arguments can be added to the diagnostic via the stream(<<) operator.
    * (In a future cl) A list of attached notes.
      * These are in the form of other diagnostics that provide supplemental information to the main diagnostic, but do not have context on their own.

    The InFlightDiagnostic class represents an RAII wrapper around a Diagnostic that is set to be reported with the diagnostic engine. This allows for the user to modify a diagnostic that is inflight. The internally wrapped diagnostic can be reported directly or automatically upon destruction.

    These classes allow for more natural composition of diagnostics by removing the restriction that the message of a diagnostic is comprised of a single Twine. They should also allow for nice incremental improvements to the diagnostics experience in the future, e.g. formatv style diagnostics.

    Simple Example:

    emitError(loc, "integer bitwidth is limited to " + Twine(IntegerType::kMaxWidth) + " bits");
    emitError(loc) << "integer bitwidth is limited to " << IntegerType::kMaxWidth << " bits";

--

PiperOrigin-RevId: 246526439
16 files changed:
mlir/include/mlir/IR/Diagnostics.h
mlir/include/mlir/IR/Function.h
mlir/include/mlir/IR/MLIRContext.h
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/IR/Operation.h
mlir/lib/FxpMathOps/Transforms/LowerUniformRealMath.cpp
mlir/lib/IR/Diagnostics.cpp
mlir/lib/IR/Dialect.cpp
mlir/lib/IR/Function.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Operation.cpp
mlir/lib/IR/StandardTypes.cpp
mlir/lib/IR/Types.cpp
mlir/lib/Parser/Lexer.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp