0 dimensional affine maps?

So it seems like affine maps with 0 results are partially supported. Some places in the code support it, and some places don’t (or even crash). For our use cases, 0 result affine maps seem useful and reduce many edge cases. I started to add a small fix for a specific case of 0-dim maps, but then when I went to add tests I discovered more places where it is broken. I was considering making a more complete diff to try to find and fix all the code to add 0-dim support, but before I embark on such a change I wanted to see if there was any reason not support 0-dim maps.
@bondhugula, @nicolasvasilache, @flaub

I haven’t looked at the code in quite awhile, but I agree this makes things more orthogonal and less special case-y. +1 from me.

Same observation on my end, I’m +1 on fixing the places where the support is still missing.

There is no reason to not support them. 0-d affine maps were initially not supported and so a lot of the code written at that time made an assumption which wasn’t removed/fixed when we later added support. Thanks for taking this up - we should correctly handle them everywhere.

+1 here! We’ve also run into some issues with 0d maps recently. Don’t hesitate to create a bugzilla entry with the list of broken/missing support, we may have some patches around.

The original problem was, IIRC, AffineMap not having its own reference to MLIRContext and recovering it from the AffineExprs it contained. Maybe that helps understand some of the problems.

+1. As @ftynse mentioned, we recently ran into some issues with 0d maps. Our problem was that AffineMap::get expected at leas t one result so that it could obtain the context from the results. We since added a new version of AffineMap::get that explicitly takes the context as argument.

I would be interested to understand what problems you are encountering: is it just a matter of switching to the new constructor everywhere it is used? Or is the code breaking in some over way? In the former case, it might be useful to remove the old version of AffineMap::get to avoid any unexpected problem in the future.

Sounds like there is a strong consensus that 0-dim support is desirable everywhere. As everyone points out, the issue really seems to stem mostly from the form of AffineMap::get that does not take a context. My plan to fix things everywhere was to remove the no context version of get (and the similar for MutableAffineMap), fix all the compilation bugs, add some additional tests, and additional look for code that special cases 0-dim and removing it where possible (via searching for getNumResults()). I hope to have a diff ready in the next day or two if I don’t get pulled onto something else.

I think that part is already implemented. See here : https://github.com/llvm/llvm-project/blob/edccc35e8fa2c546e0ef1c8efde56e6b12e3c175/mlir/include/mlir/IR/AffineMap.h#L49

But overall +1 for proper support for 0-dim maps. Some work was done by @nicolasvasilache (and some other probably as well which I am missing), but there are definitely still holes. Thanks for taking this up!