Thread overview
[Issue 23414] Import order emits "Error: no size because of forward references"
Nov 25, 2022
Richard Cattermole
Dec 17, 2022
Iain Buclaw
Jan 23, 2024
Walter Bright
Jan 23, 2024
Richard Cattermole
Jan 26, 2024
Walter Bright
Jan 26, 2024
Richard Cattermole
Jan 29, 2024
Walter Bright
Jan 29, 2024
Max Samukha
November 25, 2022
https://issues.dlang.org/show_bug.cgi?id=23414

--- Comment #1 from Richard Cattermole <alphaglosined@gmail.com> ---
I have since removed all inter-dependency imports between the modules and forced them to import the package module (which in turn publically imports them all).

That has fixed it.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23414

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
January 23, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
It would be nice if this could be reduced to the two modules, and then removing everything that is not necessary to trigger the error.

--
January 23, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

--- Comment #3 from Richard Cattermole <alphaglosined@gmail.com> ---
It probably isn't limited to two modules.

There is a possibility of it being upwards of nine modules.

Unfortunately, dustmite doesn't like this project, it gets stuck and requires a lot of help, and minimizing isn't a fast thing to do, I had to do it a few times around the time of this bug report.

--
January 26, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
I would like to fix this, once a smallish test case can be devised. But keep in mind some things cannot be fixed. At least the compiler issues an error for those cases. An example:

struct S
{
    static if (S.sizeof == 0)
    {
        int x;
    }
}

It's impossible for the compiler to resolve it. While the example looks trivial and ridiculous, sometimes these cases are hidden behind a thicket of complex templates.

When module A imports module B, and B also imports A, there's always the potential for an ordering issue. I try to solve as many as possible, but they cannot always be fixed. These are commonly the result of two declarations with a mutual dependence. A solution that works is to refactor A and B so that the mutually dependent portions are extracted and placed into module C. Then, A and B import C.

--
January 26, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

--- Comment #5 from Richard Cattermole <alphaglosined@gmail.com> ---
My assumption has been that this isn't fixable, but worth documenting.

Each module has one public declaration a struct. Which in turn uses similar structs in other modules.

ASCII, UTF-8, UTF-16, UTF-32 each having a read only slice and a builder. Then there are the raw slices too.

Not much you can do to break that up, except for using something like implicitly constructed sum types at the declaration level to break up the dependency.

Right now the package module is ensuring the imports are all in the right order and every module goes through that which works. Not ideal, however, I haven't had any further issues so not a bad workaround.

--
January 29, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
January 29, 2024
https://issues.dlang.org/show_bug.cgi?id=23414

Max Samukha <maxsamukha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha@gmail.com

--- Comment #6 from Max Samukha <maxsamukha@gmail.com> ---
(In reply to Walter Bright from comment #4)

> struct S
> {
>     static if (S.sizeof == 0)
>     {
>         int x;
>     }
> }
> 
> It's impossible for the compiler to resolve it. While the example looks trivial and ridiculous, sometimes these cases are hidden behind a thicket of complex templates.
> 

While there is often a real circular dependence, D still fails in many cases when there is not, like:

```
struct S(alias self)
{
    alias Outer = __traits(parent, self);
    ref Outer outer() => *cast(Outer*)(cast(ubyte*)&this - self.offsetof);
}

struct S2
{
    S!s s;
}
```
Error: circular reference to variable `a.S2.s

It would be immensely cool if that worked.

--
December 13
https://issues.dlang.org/show_bug.cgi?id=23414

--- Comment #7 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18129

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--