[all-commits] [llvm/llvm-project] 70074c: [mlir][AsmPrinter] Fallback to using qualified pri...

Markus Böck via All-commits all-commits at lists.llvm.org
Mon Mar 27 06:50:04 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 70074c113432e4065724b5aba79f610d9d7281de
      https://github.com/llvm/llvm-project/commit/70074c113432e4065724b5aba79f610d9d7281de
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2023-03-27 (Mon, 27 Mar 2023)

  Changed paths:
    M mlir/include/mlir/IR/OpImplementation.h
    A mlir/test/IR/print-empty-attr-or-type.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/lib/Dialect/Test/TestTypeDefs.td

  Log Message:
  -----------
  [mlir][AsmPrinter] Fallback to using qualified printer if unqualified output is empty

The current behaviour of always writing the unqualified form of an attribute or type is problematic for any type or attribute that might output an empty string, making it impossible to parse and therefore roundtrip. This is commonly the case for any types or attributes with optional parameters. One would have to currently woarkaround the issue by either changing ones syntax to not be completetly empty or by explicitly using `qualified` in ALL ops using that type or attribute.

This patch fixes that issue by simply checking whether anything was written to the output. In the case there wasn't, it simply falls back to using the normal printer with the dialect prefix. This also makes the default of unqualified printing always correct and safe. The implementation could theoretically still be tricked if the user were to print just a space or similar. I'd argue this'd be user error and not worth handling.

Fixes https://github.com/llvm/llvm-project/issues/61701

Differential Revision: https://reviews.llvm.org/D146944




More information about the All-commits mailing list