vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

web.render argument garbage #863

Open vuaru opened 9 years ago

vuaru commented 9 years ago
dmd 2.066
vibe.d 0.7.21-rc.3

I ran into a situation where the compiler would crash&burn with

Assertion failure: 'type->ty != Tstruct || ((TypeStruct *)type)->sym == this' on line 915 in file 'struct.c'

I seemingly reduced my code to the following. However, the reduced case does not crash as the original did, but it does print garbage. /1 and /3 work fine, /2 has the problem (with the <---------- :).

app.d

shared static this()
{
    auto router = new URLRouter;
    router.registerWebInterface(new Web);

    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = ["::1", "127.0.0.1"];
    settings.sessionStore = new MemorySessionStore;
    listenHTTP(settings, router);
}

class Web
{
    @path(`/1`)
    void get1()
    {
        import std.random: uniform;
        auto rnd = uniform(0, 2);

        if(rnd == 0)
        {
            C c = new C;
            render!(`test.dt`, rnd, c);
            // rnd 0 C 0
        }
        else
        {
            C c = new C;
            render!(`test.dt`, rnd, c);
            // rnd 1 C 0
        }
    }

    @path(`/2`)
    void get2(HTTPServerRequest req, HTTPServerResponse res)
    {
        import std.random: uniform;
        auto rnd = uniform(0, 2);

        if(rnd == 0)
        {
            C c = new C;
            render!(`test.dt`, rnd, c);
            // rnd 0 C 0
        }
        else
        {
            C c = new C;
            render!(`test.dt`, rnd, c);
            // rnd 1 C 13314720 <----------------
        }
    }

    @path(`/3`)
    void get3(HTTPServerRequest req, HTTPServerResponse res)
    {
        import std.random: uniform;
        auto rnd = uniform(0, 2);

        C c = new C;

        if(rnd == 0)
        {
            render!(`test.dt`, rnd, c);
            // rnd 0 C 0
        }
        else
        {
            render!(`test.dt`, rnd, c);
            // rnd 1 C 0
        }
    }
}

class C
{
    int i;
}

views/test.dt

html

body
    p rnd #{rnd} C #{c.i}
s-ludwig commented 9 years ago

Looks like it may be related to D issue 11260. Maybe it's possible to reproduce the issue with a dummy render!() function, too? Something like:

void render(ALIASES...)()
{
    import std.stdio;
    writefln("%s C %s", ALIASES[0], ALIASES[1]);
}
vuaru commented 9 years ago
dmd v2.066.1
vibe.d v0.7.22

This reduced code now indeed crashes the compiler same as my original code did.

That dummy render makes it compile. It also compiles when I move the C c = new C(); outside the if/then to below the auto rnd = ...

s-ludwig commented 9 years ago

In the D issue it's mentioned that this is supposed to be fixed on recent DMD versions. Can we close this?

vuaru commented 9 years ago
dmd 2.067.1
vibe.d 0.7.24-beta.3

Still the same for me.

s-ludwig commented 9 years ago

There is a new bugzilla issue for this. I've added a reduced case of the example here: https://issues.dlang.org/show_bug.cgi?id=10619

Geod24 commented 9 years ago

You'll be happy to know that Kenji's upcoming fix (the one which covers 9748) will fix that as well then.