Thread overview
Issue with algorithm.fold - dmd hangs
Apr 04
Borax Man
Apr 04
monkyyy
Apr 05
Borax Man
Apr 06
Borax Man
April 04
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;
}
April 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
April 05
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?
April 05
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.
April 05
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.
April 06
On 2025-04-05, Borax Man <rotflol2@hotmail.com> wrote:
> 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.

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.