<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61701>61701</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][ODS] Default of printing types unqualified can generate invalid parser and printers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:core,
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zero9178
</td>
</tr>
</table>
<pre>
If a type has optional parameters it may choose to have an assembly format that looks something like: `(`<` $parameters^ `>` )?`.
This essentially means that the type may be printed as just `!dialect.typeName` if the optional parameter is not present.
This sadly causes issues for the printer and parser of operations using that type however. Consider an operation that looks roughly like the following:
```
def Op : Op<...> {
let results = (outs DialectType:$out);
let assemblyFormat = "... `:` type($out)";
}
```
since `$out` is known to be `DialectType` the generated printer will print it unqualified, meaning "!dialect.typeName" is NOT emitted. If the type does not have any parameters either nothing is printed afterwards either. Therefore, it ends up not printing anything for the type except the `:`. This makes it impossible for the parser to read in the type as well, since there is nothing to parser.
An in-tree example can also be seen here: https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td#L399-L402
`!llvm.ptr` is a valid type, and printing it unqualified when it is the default address space of 0, leads to nothing being printed.
I think it should be possible to create a safe parser and printer combo without needing to explicitly specify `qualified` in the general case.
I can see multiple solutions to the problem:
* Allowing types to specify that they may not be printed unqualified (or detecting it)
* Detecting in the printer if nothing was printed in the unqualified form and then attempting again in qualified form.
* Changing the default from `unqualified` to `qualified`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVsFu47gS_Br60hhBpuzYOviQicdAgLwJ8DbYOyW1LE4oUsum4vF-_aJJyXJ25rJAIMcW2V2sqi5JEemzRTyI7VexPa7UGDrnD3-jd-V6t19VrrkenltQEK4DQqcI3BC0s8rAoLzqMaAn0AF6dYW6c44QgoNOfSAoC4oI-8pcoXW-VwFCpwIY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