Jump to page: 1 2
Thread overview
[Issue 14363] DMD should compile SDC test0165.d
Mar 28, 2015
ag0aep6g@gmail.com
Mar 29, 2015
Kenji Hara
Mar 29, 2015
Shammah Chancellor
Mar 29, 2015
Kenji Hara
Mar 29, 2015
Kenji Hara
Mar 29, 2015
Shammah Chancellor
Mar 29, 2015
deadalnix
[Issue 14363] [SDC] Error with inheriting nested classes in nested functions
Apr 11, 2015
yebblies
Apr 12, 2015
Kenji Hara
Apr 12, 2015
deadalnix
Dec 17, 2022
Iain Buclaw
March 28, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |ag0aep6g@gmail.com

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> ---
I'm not sure why SDC accepts the code.

The following reduced case is correctly rejected by dmd, because ba.foo() won't work expectedly. Maybe SDC generates wrong code?

void main()
{
    uint x = 7;

    class A
    {
        auto foo()
        {
            return x;
        }
    }

    auto makeB(uint y)
    {
        class B : A
        {
            auto bar()
            {
                return foo() + y;
            }
        }

        return new B(5);
    }

    A a = new A();
    assert(a.foo() == 7);

    auto b = makeB(3);
    assert(b.bar() == 10);

    A ba = b;
    assert(ba.foo() == 7);
}

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #2 from Shammah Chancellor <shammah.chancellor@gmail.com> ---
Your code has a bug?

return new B(5);

Should be:

return new B();


With that, your example compiles and works just fine on SDC.


(In reply to Kenji Hara from comment #1)
> I'm not sure why SDC accepts the code.
> 
> The following reduced case is correctly rejected by dmd, because ba.foo() won't work expectedly. Maybe SDC generates wrong code?
> 
> void main()
> {
>     uint x = 7;
> 
>     class A
>     {
>         auto foo()
>         {
>             return x;
>         }
>     }
> 
>     auto makeB(uint y)
>     {
>         class B : A
>         {
>             auto bar()
>             {
>                 return foo() + y;
>             }
>         }
> 
>         return new B(5);
>     }
> 
>     A a = new A();
>     assert(a.foo() == 7);
> 
>     auto b = makeB(3);
>     assert(b.bar() == 10);
> 
>     A ba = b;
>     assert(ba.foo() == 7);
> }

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Shammah Chancellor from comment #2)
> Your code has a bug?
> 
> return new B(5);
> 
> Should be:
> 
> return new B();

Yes. Sorry.

> With that, your example compiles and works just fine on SDC.

Hmm, interesting. SDC might use a thunk to get valid context pointer for base
classes from the instantiated context.
But it would need some runtime cost and additional vtbl entry. I don't have any
knowledge about the SDC backend, but the ABI around nested classes would be
different from dmd's.

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> ---
Maybe SDC inserts a hidden field to access enclosing scope in each derived classes?

void main() {
    uint x = 7;

    class A {
        int fieldA;
        auto foo() { return x; }
    }

    auto makeB(uint y) {
        class B : A {
            int fieldB;
            auto bar() { return foo() + y; }
        }

        return new B(5);
    }

    A a = new A();
    assert(a.foo() == 7);

    auto b = makeB(3);
    alias B = typeof(b);
    assert(b.bar() == 10);

    pragma(msg, A.fieldA.offsetof);
    pragma(msg, __traits(classInstanceSize, A));
    pragma(msg, B.fieldB.offsetof);
    pragma(msg, __traits(classInstanceSize, B));
}

If B.fieldB.offsetof + int.sizeof + (void*).sizeof <=
__traits(classInstanceSize, B), both B and A have their own hidden fields.

Note that it's intentionally disallowed by dmd. With dmd, implicitly insertion of hidden field is limited at most once. At best, it's an incompatibility between dmd and SDC.

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #5 from Shammah Chancellor <shammah.chancellor@gmail.com> ---
I'm not sure about that part of SDC.  I will investigate and see if deadalnix has some input here.

--
March 29, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

deadalnix <deadalnix@gmail.com> changed:

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

--- Comment #6 from deadalnix <deadalnix@gmail.com> ---
(In reply to Shammah Chancellor from comment #5)
> I'm not sure about that part of SDC.  I will investigate and see if deadalnix has some input here.

SDC does it by sticking one context in the base and one context in the child.

--
April 11, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com
           Hardware|x86                         |All
            Version|unspecified                 |D2
            Summary|DMD should compile SDC      |[SDC] Error with inheriting
                   |test0165.d                  |nested classes in nested
                   |                            |functions
                 OS|Mac OS X                    |All

--
April 12, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to deadalnix from comment #6)
> (In reply to Shammah Chancellor from comment #5)
> > I'm not sure about that part of SDC.  I will investigate and see if deadalnix has some input here.
> 
> SDC does it by sticking one context in the base and one context in the child.

It's definitely different. dmd inserts at most only one context over the all derived classes. The second context pointer in the child class need to be error in SDC.

--
April 12, 2015
https://issues.dlang.org/show_bug.cgi?id=14363

--- Comment #8 from deadalnix <deadalnix@gmail.com> ---
(In reply to Kenji Hara from comment #7)
> (In reply to deadalnix from comment #6)
> > (In reply to Shammah Chancellor from comment #5)
> > > I'm not sure about that part of SDC.  I will investigate and see if deadalnix has some input here.
> > 
> > SDC does it by sticking one context in the base and one context in the child.
> 
> It's definitely different. dmd inserts at most only one context over the all derived classes. The second context pointer in the child class need to be error in SDC.

I see no reason for this limitation.

--
« First   ‹ Prev
1 2