Use template classes as user defined storage classes

Hi, I want to use a class template as user defined type storages, e.g:

def MyType: .. {
  ...
  let genStorageClass = false;
  let storageClass = "MyStorage<Bar>";
  ...
}

However currently it doesn’t compile because DefGen::emitDecl always emits forward declarations (https://github.com/llvm/llvm-project/blob/9418c40af7ec6913112b82d6f1d6e8a8c43af6c0/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp#L70-L73) and that’s considered as template specilization.

error: template specialization requires 'template<>'
struct MyStorage<Bar>;
       ^           ~~~~~~~~~~~~~~~~~~~

I’m wondering if it’s OK to introduce an additional bit to ODS (such as genStorageClassForwardDecl) in order to control forward decl, or there is a better way to do that. WDYT?

Can’t you forward define it with a using declaration and use this alias in ODS?

Edit: actually it may not like redefining the alias with a forward decl…

Other idea: should we just not emit a forward decl when genStorageClass = false ?

Can’t you forward define it with a using declaration and use this alias in ODS?
Edit: actually it may not like redefining the alias with a forward decl…

Yes I guess we cannot do that with using decl. In that case we have to declare another struct to inherit the template class, which is OK but nicer if we don’t have to insert unnecessary boilerplates.

Other idea: should we just not emit a forward decl when genStorageClass = false ?

Yeah, I think that’s nice idea! I had to add several forward declarations to builtin attributes/types in MLIR codebase but looks very feasible. Submitted a patch here: ⚙ D155225 [mlir] Don't emit forward declaration for user defined storage classes