Add emitOptional(Error|Warning|Remark) functions to simplify emission with an optiona...
authorRiver Riddle <riverriddle@google.com>
Wed, 4 Dec 2019 23:49:09 +0000 (15:49 -0800)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 4 Dec 2019 23:49:42 +0000 (15:49 -0800)
commit2c930f8d9daa04576ac49e14c19dc540ebf823fe
tree6dcb8515f827477ef49752a5d19818404988e53c
parentb3f7cf80a7dc7e9edd5b53827a942bada4a6aeb2
Add emitOptional(Error|Warning|Remark) functions to simplify emission with an optional location.

In some situations a diagnostic may optionally be emitted by the presence of a location, e.g. attribute and type verification. These situations currently require extra 'if(loc) emitError(...); return failure()' wrappers that make verification clunky. These new overloads take an optional location and a list of arguments to the diagnostic, and return a LogicalResult. We take the arguments directly and return LogicalResult instead of returning InFlightDiagnostic because we cannot create a valid diagnostic with a null location. This creates an awkward situation where a user may try to treat the, potentially null, diagnostic as a valid one and encounter crashes when attaching notes/etc. Below is an example of how these methods simplify some existing usages:

Before:

  if (loc)
    emitError(*loc, "this is my diagnostic with argument: ") << 5;
  return failure();

After:

  return emitOptionalError(loc, "this is my diagnostic with argument: ", 5);

PiperOrigin-RevId: 283853599
mlir/include/mlir/Dialect/QuantOps/QuantTypes.h
mlir/include/mlir/IR/Attributes.h
mlir/include/mlir/IR/Diagnostics.h
mlir/include/mlir/IR/StandardTypes.h
mlir/include/mlir/IR/Types.h
mlir/lib/Dialect/QuantOps/IR/QuantTypes.cpp
mlir/lib/IR/Attributes.cpp
mlir/lib/IR/StandardTypes.cpp
mlir/lib/IR/Types.cpp