[MLIR] Add note for file-line numbers in tablegen errors for assembly formats
authorStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Sun, 5 Apr 2020 05:54:35 +0000 (22:54 -0700)
committerStephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Tue, 7 Apr 2020 22:06:51 +0000 (15:06 -0700)
commit19fec004e23adbc43b839ddf1be8bc2e22e58aca
tree5164dba87dd72e1db4726d62fe60b69c7fbf00bd
parent75f60c698fdfc0ea46f84b7f92d667d6e7f53f7f
[MLIR] Add note for file-line numbers in tablegen errors for assembly formats

Error messages for the custom assembly format are difficult to understand
because there are no line numbers.  This happens because the assembly format
is parsed as a standalone line, separate from it's parent file, with no useful
location information.  Fixing this properly probably requires quite a bit
of invasive plumbing through the SourceMgr, similar to how included files
are handled

This proposal is a less invasive short term solution.  When generating an
error message we generate an additional note which at least properly describes
the operation definition the error occured in, if not the actual line number
of the assemblyFormat definition.

A typical message is like:

error: type of operand #0, named 'operand', is not buildable and a buildable type cannot be inferred
  $operand type($result) attr-dict
  ^
/src/llvm-project/mlir/test/mlir-tblgen/op-format-spec.td:296:1: note: in custom assembly format for this operation
def ZCoverageInvalidC : TestFormat_Op<"variable_invalid_c", [{
^
note: suggest adding a type constraint to the operation or adding a 'type($operand)' directive to the custom assembly format
  $operand type($result) attr-dict
  ^

Differential Revision: https://reviews.llvm.org/D77488
mlir/test/mlir-tblgen/op-format-spec.td
mlir/tools/mlir-tblgen/OpFormatGen.cpp