FirstAttrDerivedResultType + Attributes + types in ODS

Hi all,

I’m trying to implement an std.constant like operation that just takes integer operations, I’d like to use it as: %x = xyz.constant 42 : i32. I’ve tried defining it like this, but I get a grammatical ambiguity between the colon in the attribute and the colon in the type descriptor:

def ConstantOp : XYZOp<"constant", [NoSideEffect, ConstantLike,
                                    FirstAttrDerivedResultType]> {

  let arguments = (ins APIntAttr:$value);
  let results = (outs AnySignlessInteger:$result);
  let assemblyFormat = [{
     $value attr-dict `:` type($result)

I can solve this by introducing extra punctuation, but I’d really like to tie the type of the attribute and the type of $result together. I would think the FirstAttrDerivedResultType would be enough to do this, but it doesn’t seem to have any effect here.

Is there a way to achieve this, or is a custom parser/printer required?

We did a cleanup in IREE where we used the ODS assemblyFormat for most things, but when I went to copy/paste you the example, I found that that one still uses a custom printer/parser. I assume that the same issue you hit was the culprit.

I ran into this issue recently as well, but I was using AllTypesMatch. River said type inference with attributes isn’t implemented yet. Also from the docs only a subset of type inference traits are supported at the moment

The currently supported traits are: AllTypesMatch , SameTypeOperands , and SameOperandsAndResultType .

So the short answer is, yeah I think you have to do a custom parser :-/