digitalmars.D - Issue with algorithm.fold - dmd hangs
- Borax Man (73/73) Apr 04 Sorry if this is an actual bug with DMD. I suspect it might be, but I'm
- monkyyy (2/79) Apr 04 works for me
- Richard (Rikki) Andrew Cattermole (3/3) Apr 04 Works with dmd 2.109.1 for me.
- Borax Man (3/6) Apr 04 Only using the bundled LLD. For what its worth, I used the .7z archive
- Borax Man (5/13) Apr 06 I tried with DMD 2.110.0 for Linux, and it compiled and ran fine. I now
- Paul Backus (2/8) Apr 04 I can reproduce this on 64-bit Linux with DMD 2.111.0.
Sorry if this is an actual bug with DMD. I suspect it might be, but I'm not sure whether the fault is DMD or my code. Short story, I wrote a program for work to do calculations for my team in D, and use Windows 64bit DMD to compile. I upgraded to the latest DMD, and its hangs on compile. I tried under Linux, and same issue. Verison is DMD64 D Compiler v2.111.0 Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved written by Walter Bright When I compile using dmd with the "-v" switch, these are the last messages. import core.internal.string (/usr/include/dmd/druntime/import/core/internal/string.d) semantic3 foldtest import std.utf (/usr/include/dmd/phobos/std/utf.d) import std.algorithm.internal (/usr/include/dmd/phobos/std/algorithm/internal.d) It hangs at the last line, just stays there consuming CPU cycles. I've extracted a minimal failing copy. The line which calls "fold" to sum the values causes it to hang. This compiles fine with GDC and LDC2, and worked with DMD version before 2.100 (I didn't try anything between 2.100 and 2.111.0) Is my code wrong, or have I stumbled on a bug? Code below ================================================== import std.algorithm; import std.range; import std.stdio; final class DataClass { private: int x; this() {} this(in int _x) { x=_x; } auto ref opOpAssign(string op : "+")(in DataClass other) { x += other.x; return this; } void printx() { writeln(x); } auto opBinary(string op : "+")(in DataClass other) { DataClass newr = new DataClass(); newr.x = x + other.x; return newr; } } int main() { DataClass[] dataclassarray; DataClass result = new DataClass(); DataClass d1 = new DataClass(3); DataClass d2 = new DataClass(4); DataClass d3= new DataClass(10); DataClass d4 = new DataClass(12); DataClass res2 = new DataClass(10); dataclassarray~=d1; dataclassarray~=d2; dataclassarray~=d3; dataclassarray~=d4; res2 += d1; // This works res2.printx(); res2 = d1 + d2; // This works res2.printx(); result = dataclassarray.fold!((a,b) => a + b); // This causes dmd to hang. result.printx(); return 0; }
Apr 04
On Friday, 4 April 2025 at 23:35:14 UTC, Borax Man wrote:Sorry if this is an actual bug with DMD. I suspect it might be, but I'm not sure whether the fault is DMD or my code. Short story, I wrote a program for work to do calculations for my team in D, and use Windows 64bit DMD to compile. I upgraded to the latest DMD, and its hangs on compile. I tried under Linux, and same issue. Verison is DMD64 D Compiler v2.111.0 Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved written by Walter Bright When I compile using dmd with the "-v" switch, these are the last messages. import core.internal.string (/usr/include/dmd/druntime/import/core/internal/string.d) semantic3 foldtest import std.utf (/usr/include/dmd/phobos/std/utf.d) import std.algorithm.internal (/usr/include/dmd/phobos/std/algorithm/internal.d) It hangs at the last line, just stays there consuming CPU cycles. I've extracted a minimal failing copy. The line which calls "fold" to sum the values causes it to hang. This compiles fine with GDC and LDC2, and worked with DMD version before 2.100 (I didn't try anything between 2.100 and 2.111.0) Is my code wrong, or have I stumbled on a bug? Code below ================================================== import std.algorithm; import std.range; import std.stdio; final class DataClass { private: int x; this() {} this(in int _x) { x=_x; } auto ref opOpAssign(string op : "+")(in DataClass other) { x += other.x; return this; } void printx() { writeln(x); } auto opBinary(string op : "+")(in DataClass other) { DataClass newr = new DataClass(); newr.x = x + other.x; return newr; } } int main() { DataClass[] dataclassarray; DataClass result = new DataClass(); DataClass d1 = new DataClass(3); DataClass d2 = new DataClass(4); DataClass d3= new DataClass(10); DataClass d4 = new DataClass(12); DataClass res2 = new DataClass(10); dataclassarray~=d1; dataclassarray~=d2; dataclassarray~=d3; dataclassarray~=d4; res2 += d1; // This works res2.printx(); res2 = d1 + d2; // This works res2.printx(); result = dataclassarray.fold!((a,b) => a + b); // This causes dmd to hang. result.printx(); return 0; }works for me
Apr 04
Works with dmd 2.109.1 for me. I use MSVC to link. Do you have Visual studio installed, or are you using the bundled LLD?
Apr 04
On 2025-04-05, Richard (Rikki) Andrew Cattermole <richard cattermole.co.nz> wrote:Works with dmd 2.109.1 for me. I use MSVC to link. Do you have Visual studio installed, or are you using the bundled LLD?Only using the bundled LLD. For what its worth, I used the .7z archive and extracted it on the Windows machine.
Apr 04
On 2025-04-05, Borax Man <rotflol2 hotmail.com> wrote:On 2025-04-05, Richard (Rikki) Andrew Cattermole <richard cattermole.co.nz> wrote:I tried with DMD 2.110.0 for Linux, and it compiled and ran fine. I now suspect a bug in dmd 2.111.0. Note that when I replace "fold" with "reduce", the compile still hangs. I don't have a github account to file a bug report.Works with dmd 2.109.1 for me. I use MSVC to link. Do you have Visual studio installed, or are you using the bundled LLD?Only using the bundled LLD. For what its worth, I used the .7z archive and extracted it on the Windows machine.
Apr 06
On Friday, 4 April 2025 at 23:35:14 UTC, Borax Man wrote:Sorry if this is an actual bug with DMD. I suspect it might be, but I'm not sure whether the fault is DMD or my code. Short story, I wrote a program for work to do calculations for my team in D, and use Windows 64bit DMD to compile. I upgraded to the latest DMD, and its hangs on compile. I tried under Linux, and same issue.I can reproduce this on 64-bit Linux with DMD 2.111.0.
Apr 04