Self-referential struct mixins

Elie Morisse syniurge at gmail.com
Sun Nov 17 17:35:07 UTC 2019


On Sunday, 17 November 2019 at 07:13:52 UTC, rbscott wrote:
> I got this working in the simple case if none of the fields are 
> self-referential, but it breaks as soon as there is a loop.
>
> Here is a gist which demonstrates the issue: 
> https://gist.github.com/rbscott/ee0f3ba94296f9c8224a8c4c13c2f026.

This is a DMD bug, you should open an issue.

It's part of a bigger family of issues caused by how DMD's 
semantic analysis is architectured. I tried to tackle it some 
time ago but didn't see it through the end :

https://github.com/dlang/dmd/pull/7018
https://forum.dlang.org/post/auvbfyzmqjxtfhkvmkxu@forum.dlang.org

As I see it the proper fix requires rewritting a large part of 
the compiler frontend, but this is definitely something worth 
doing at some point to make DMD less brittle esp. regarding 
advanced usage of mixins/CTFE (I don't have time anymore, and 
IMHO someone should be paid 2 months to work full-time on 
re-architecturing DMD for this)

On Sunday, 17 November 2019 at 09:16:19 UTC, Claude wrote:
> Anyway, upon the mixin template instantiation, you can try to 
> 'declare' all your struct's on top and then properly 'define' 
> them afterwards:
>
> struct A;
> struct B;
>
> struct A {
>   B* b;
> }
>
> struct B {
>   A* a;
> }
>
>
> Have you tried that?

Forward declaring structs isn't allowed in D.


More information about the Digitalmars-d mailing list