digitalmars.D.learn - std.traits functions causing the compiler to crash
- Eric (76/76) Jun 07 2013 mport std.traits;
- bearophile (18/19) Jun 07 2013 This is your code reduced a little:
- Eric (18/32) Jun 07 2013 Yes, the template constraint is much better. However, the
- bearophile (5/7) Jun 07 2013 Because there's a type definition loop, regardless. Using a
- Eric (5/12) Jun 07 2013 How is there a type definition loop? I'm just trying to constrain
- Regan Heath (22/36) Jun 11 2013 There is a type loop but I agree the compiler should really be able to
mport std.traits; interface Xidentity(V, K) { static if (hasMember!(V, "k")) static assert(0); public int getInstanceCount(); } class X(K) : Xidentity!(X!(K), K) { private K k; X newInstance(K k) { return(new X(k)); } private this(K k) { this.k = k; } public int getInstanceCount() { return(5); } } void main() { auto x = new X!(double)(6.0); } If I compile the above code, the static if statement in the interface declaration causes the compiler to segfault without any other information. gdb give the following stacktrace: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xf75106c0 (LWP 30889)] 0x08170d26 in TraitsExp::semantic () Current language: auto; currently asm (gdb) backtrace I'm using compiler version v2.063-devel-53aa503. Is this a known problem, or is there a work-around? Thanks, Eric
Jun 07 2013
Eric:Is this a known problem, or is there a work-around?This is your code reduced a little: import std.traits: hasMember; interface Xidentity(V, K) if (!hasMember!(V, "x")) { } class Foo(K): Xidentity!(Foo!K, K) { K x; } void main() { new Foo!double; } I think it contains a loop at the level of types. In theory the compiler should catch them and give a nice error message. You probably want to use the template constraint syntax, as I have used. In D return is not a function, so don't use the ( ). Bye, bearophile
Jun 07 2013
Oimport std.traits: hasMember; interface Xidentity(V, K) if (!hasMember!(V, "x")) { } class Foo(K): Xidentity!(Foo!K, K) { K x; } void main() { new Foo!double; } I think it contains a loop at the level of types. In theory the compiler should catch them and give a nice error message. You probably want to use the template constraint syntax, as I have used.Yes, the template constraint is much better. However, the compiler still crashes, even with the new code: import std.traits: hasMember; interface Identity(V, K) if (!hasMember!(V, "k")) { } class Foo(K): Identity!(Foo!K, K) { K k; } void main() { new Foo!double; } (dmd7) mrbig:~/tp/d_test2/dlib>dmd Test.d Segmentation fault (core dumped)In D return is not a function, so don't use the ( ).Yeah, I know. return returns an expression, and parenthesis are legal expression syntax:) -Eric
Jun 07 2013
Eric:Yes, the template constraint is much better. However, the compiler still crashes, even with the new code:Because there's a type definition loop, regardless. Using a constraint doesn't change that situation. Bye, bearophile
Jun 07 2013
On Saturday, 8 June 2013 at 02:32:57 UTC, bearophile wrote:Eric:How is there a type definition loop? I'm just trying to constrain the interface. At a minimum this should be a compiler bug, but I would hope that dimple constraints would work. -EricYes, the template constraint is much better. However, the compiler still crashes, even with the new code:Because there's a type definition loop, regardless. Using a constraint doesn't change that situation. Bye, bearophile
Jun 07 2013
On Sat, 08 Jun 2013 05:52:49 +0100, Eric <eric makechip.com> wrote:On Saturday, 8 June 2013 at 02:32:57 UTC, bearophile wrote:There is a type loop but I agree the compiler should really be able to catch it. Using bearophile's short example.. import std.traits: hasMember; interface Xidentity(V, K) if (!hasMember!(V, "x")) { } class Foo(K): Xidentity!(Foo!K, K) { K x; } void main() { new Foo!double; } The compiler starts by generating the template for Foo(double), requiring Xidentity(Foo!double,.. requiring Foo(double), requiring Xidentity(Foo!double,.., and so on.. It should really be able to detect that it is re-generating the original Foo(double) and simply re-use/terminate the loop there, I think. (I am no compiler expert however) R -- Using Opera's revolutionary email client: http://www.opera.com/mail/Eric:How is there a type definition loop? I'm just trying to constrain the interface. At a minimum this should be a compiler bug, but I would hope that dimple constraints would work.Yes, the template constraint is much better. However, the compiler still crashes, even with the new code:Because there's a type definition loop, regardless. Using a constraint doesn't change that situation. Bye, bearophile
Jun 11 2013