How to produce type alias inside nested types?

I am looking at type aliases in the context of FIR (Fortran IR) mlir dialect. The FIR types we are producing for Fortran derived types are quickly getting very long in the IR assembly, and I would like to take advantage of MLIR type alias infrastructure. I managed to get type alias working in certain cases, but when the FIR types I wish to alias are always nested into some other types, no alias is ever generated for it.

Here is an example of MLIR we are currently generating where I would like to alias !fir.type<a{i:i32,x:f32}> by !a:

module  {
  func @foo(%arg0: !fir.ref<!fir.type<a{i:i32,x:f32}>>) {
    fir.call @bar(%arg0) : (!fir.ref<!fir.type<a{i:i32,x:f32}>>) -> ()
    return
  }
  func private @bar(!fir.ref<!fir.type<a{i:i32,x:f32}>>)
}

The MLIR I wish to produce instead for this is:

    !a = type !fir.type<a{i:i32,x:f32}>
    module  {
      func @foo(%arg0: !fir.ref<!a>) {
        fir.call @bar(%arg0) : (!fir.ref<!a>) -> ()
        return
      }
      func private @bar(!fir.ref<!a>)
    }

I added an mlir::OpAsmDialectInterface to FIR dialect interfaces with a getAlias(Type type, raw_ostream &os) method that creates aliases for !fir.type<> types. It is working as I expect when the !fir.type<a{i:i32,x:f32}> appears in an operation without being nested in another type, but when !fir.type<a{i:i32,x:f32}> always appears inside another type (!fir.ref<> in my example). It is not getting aliased by the assembly printer.

I believe the issue lies in the fact that mlir::AliasInitializer::visit(Type type) defined here is not visiting the types that may be nested in the types of the operation (except for a few built-in types where this is done manually).

Is what I want already possible and I am just doing something wrong, or should something be done in mlir::AliasInitializer::visit to make this possible ?

Note: the FIR example I gave can be parsed/unparsed by the fir-opt tool of the flang project in LLVM main branch, but the mlir::OpAsmDialectInterface interface for the FIR dialect I am referring to is not added there yet.

Yeah, this has been a known issue. I vaguely recall someone else mentioning this recently, so I went ahead and sent something out to support this: ⚙ D102945 [mlir] Add new SubElementAttr/SubElementType Interfaces

– River

Thanks for working on adding support for this so fast ! The idea of having dialects defining something like the walkSubElementsImpl makes sense to me.