Skip to content

Commit

Permalink
De-optimize opAssign of std.typecons.Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
0xEAB committed Jan 16, 2025
1 parent 153ec5f commit 777beeb
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -980,24 +980,35 @@ if (distinctFieldNames!(Specs))
{
import std.algorithm.mutation : swap;

static if (is(R == Tuple!Types) && !__traits(isRef, rhs) && isTuple!R)
/*
This optimization caused compilation failures with no error message available:
> Error: unknown, please file report on issues.dlang.org
> std/sumtype.d(1262): Error: template instance `std.sumtype.SumType!(Flag, Tuple!(This*))` error instantiating
*/
version (none)
{
if (__ctfe)
static if (is(R == Tuple!Types) && !__traits(isRef, rhs) && isTuple!R)
{
// Cannot use swap at compile time
field[] = rhs.field[];
if (__ctfe)
{
// Cannot use swap at compile time
field[] = rhs.field[];
}
else
{
// Use swap-and-destroy to optimize rvalue assignment
swap!(Tuple!Types)(this, rhs);
}
}
else
{
// Use swap-and-destroy to optimize rvalue assignment
swap!(Tuple!Types)(this, rhs);
// Do not swap; opAssign should be called on the fields.
field[] = rhs.field[];
}
}
else
{
// Do not swap; opAssign should be called on the fields.
field[] = rhs.field[];
}

field[] = rhs.field[];
return this;
}

Expand Down

0 comments on commit 777beeb

Please sign in to comment.