This is an archive of the discontinued LLVM Phabricator instance.

[mlir][AsmPrinter] Fallback to using qualified printer if unqualified output is empty
ClosedPublic

Authored by zero9178 on Mar 27 2023, 4:13 AM.

Details

Summary

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

Diff Detail

Event Timeline

zero9178 created this revision.Mar 27 2023, 4:13 AM
zero9178 requested review of this revision.Mar 27 2023, 4:13 AM
mehdi_amini accepted this revision.Mar 27 2023, 4:52 AM
This revision is now accepted and ready to land.Mar 27 2023, 4:52 AM
This revision was landed with ongoing or failed builds.Mar 27 2023, 6:49 AM
This revision was automatically updated to reflect the committed changes.