www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - SOme fun with D compiler

reply Daniel Kozak <kozzi11 gmail.com> writes:
Try to compile this:

import std.stdio;

auto xxx(T)()
{
      return this;
}

struct S
{
     mixin xxx!(typeof(this));
     alias xxx this;
}

void foo(S pos)
{
     writefln("(%.2f|%.2f)", pos.x, pos.y);
}

void main()
{
}


Or this:

import std.stdio;

auto xxx(T)()
if (is(T == struct))
{
      return this;
}

struct Vector2f
{
     mixin xxx!(typeof(this));
     alias xxx this;
}

void foo(ref const Vector2f pos) {}

void main()
{
     Vector2f v;
     foo(v);
}
Oct 18 2016
parent reply wobbles <grogan.colin gmail.com> writes:
On Tuesday, 18 October 2016 at 08:21:09 UTC, Daniel Kozak wrote:
 Try to compile this:

 import std.stdio;

 auto xxx(T)()
 {
      return this;
 }

 struct S
 {
     mixin xxx!(typeof(this));
     alias xxx this;
 }

 void foo(S pos)
 {
     writefln("(%.2f|%.2f)", pos.x, pos.y);
 }

 void main()
 {
 }


 Or this:

 import std.stdio;

 auto xxx(T)()
 if (is(T == struct))
 {
      return this;
 }

 struct Vector2f
 {
     mixin xxx!(typeof(this));
     alias xxx this;
 }

 void foo(ref const Vector2f pos) {}

 void main()
 {
     Vector2f v;
     foo(v);
 }
Compiler bug? Looks like it's constantly going in circles trying to figure out what the hell 'xxx' is :) I cancelled compilation after a minute of 100% CPU usage so not sure if it will ever finish.
Oct 18 2016
next sibling parent wobbles <grogan.colin gmail.com> writes:
On Tuesday, 18 October 2016 at 11:06:08 UTC, wobbles wrote:
 On Tuesday, 18 October 2016 at 08:21:09 UTC, Daniel Kozak wrote:
 Try to compile this:

 import std.stdio;

 auto xxx(T)()
 {
      return this;
 }

 struct S
 {
     mixin xxx!(typeof(this));
     alias xxx this;
 }

 void foo(S pos)
 {
     writefln("(%.2f|%.2f)", pos.x, pos.y);
 }

 void main()
 {
 }


 Or this:

 import std.stdio;

 auto xxx(T)()
 if (is(T == struct))
 {
      return this;
 }

 struct Vector2f
 {
     mixin xxx!(typeof(this));
     alias xxx this;
 }

 void foo(ref const Vector2f pos) {}

 void main()
 {
     Vector2f v;
     foo(v);
 }
Compiler bug? Looks like it's constantly going in circles trying to figure out what the hell 'xxx' is :) I cancelled compilation after a minute of 100% CPU usage so not sure if it will ever finish.
With -v on, this is what it prints: dmd compileFun.d -v binary dmd version v2.071.0 config /usr/local/bin/dmd.conf parse compileFun importall compileFun import object (/Library/D/dmd/src/druntime/import/object.d) import core.attribute (/Library/D/dmd/src/druntime/import/core/attribute.d) import std.stdio (/Library/D/dmd/src/phobos/std/stdio.d) import core.stdc.stdio (/Library/D/dmd/src/druntime/import/core/stdc/stdio.d) import core.stdc.stdint (/Library/D/dmd/src/druntime/import/core/stdc/stdint.d) import core.stdc.stddef (/Library/D/dmd/src/druntime/import/core/stdc/stddef.d) import core.stdc.signal (/Library/D/dmd/src/druntime/import/core/stdc/signal.d) import core.stdc.wchar_ (/Library/D/dmd/src/druntime/import/core/stdc/wchar_.d) import core.stdc.config (/Library/D/dmd/src/druntime/import/core/stdc/config.d) import core.stdc.stdarg (/Library/D/dmd/src/druntime/import/core/stdc/stdarg.d) import core.stdc.stdlib (/Library/D/dmd/src/druntime/import/core/stdc/stdlib.d) import core.stdc.time (/Library/D/dmd/src/druntime/import/core/stdc/time.d) import core.sys.posix.sys.types (/Library/D/dmd/src/druntime/import/core/sys/posix/sys/types.d) import core.sys.posix.config (/Library/D/dmd/src/druntime/import/core/sys/posix/config.d) import std.typecons (/Library/D/dmd/src/phobos/std/typecons.d) import std.meta (/Library/D/dmd/src/phobos/std/meta.d) import std.traits (/Library/D/dmd/src/phobos/std/traits.d) import std.typetuple (/Library/D/dmd/src/phobos/std/typetuple.d) import std.stdiobase (/Library/D/dmd/src/phobos/std/stdiobase.d) import std.range.primitives (/Library/D/dmd/src/phobos/std/range/primitives.d) semantic compileFun import core.stdc.errno (/Library/D/dmd/src/druntime/import/core/stdc/errno.d) import core.stdc.string (/Library/D/dmd/src/druntime/import/core/stdc/string.d) entry main compileFun.d semantic2 compileFun semantic3 compileFun And sticsk on semantic3 forever.
Oct 18 2016
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/18/16 7:06 AM, wobbles wrote:
 Compiler bug?

 Looks like it's constantly going in circles trying to figure out what
 the hell 'xxx' is :)
 I cancelled compilation after a minute of 100% CPU usage so not sure if
 it will ever finish.
If I add: alias byRef this; to Namespace's example either in Vector2f or ByRef, I get the same behavior. Daniel, could you please submit all three examples in an issue? Thanks, Andrei
Oct 18 2016
parent Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
Dne 18.10.2016 v 13:36 Andrei Alexandrescu via Digitalmars-d napsal(a):

 On 10/18/16 7:06 AM, wobbles wrote:
 Compiler bug?

 Looks like it's constantly going in circles trying to figure out what
 the hell 'xxx' is :)
 I cancelled compilation after a minute of 100% CPU usage so not sure if
 it will ever finish.
If I add: alias byRef this; to Namespace's example either in Vector2f or ByRef, I get the same behavior. Daniel, could you please submit all three examples in an issue? Thanks, Andrei
https://issues.dlang.org/show_bug.cgi?id=16621 It is based on Namespace's example, soi I belive it is same error
Oct 18 2016