Handling Cyclic Dependencies in Debug Info

@gysit are you aware of any ongoing work on cyclic DI types for the LLVM dialect? We ran into a use case for recursive types too so I’m planning on picking this up.

I see that @Dinistro recently added a DistinctAttr to some DI types. One way I see is to do something similar, and add a recursion-ID field to DICompositeType, and then use the same distinct ID in the self-referencing “back edge” (seems more explicit than just the type name). This seems the least intrusive to the rest of the infrastructure.

#struct = di_composite_type<self_id = 0, name = "node", elements: #field>
#field = di_derived_type<baseType: #ptr>
#ptr = di_derived_type<baseType: #struct_self>
#struct_self = di_composite_type<self_id = 0, name = "node">

This of course handles composite type, but if other DI types might be recursive too (as long as it’s legal I think we should support it), we can go one step further with an abstracted DIRecursiveType attr:

#rec = di_recursive_type<self_id = 0, baseType: #struct>
#struct = di_composite_type<elements: #field>
...
#ptr = di_derived_type<baseType: #rec_self>
#rec_self = di_recursive_type<self_id = 0>

This way we don’t have to support recursion individually on DI types. They can just be handled generically. Happy to hear your thoughts.