From 777beeb7159a51445de7bfef30175e054393d93c Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Wed, 15 Jan 2025 04:39:42 +0100 Subject: [PATCH] De-optimize `opAssign` of `std.typecons.Tuple` --- std/typecons.d | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/std/typecons.d b/std/typecons.d index a841e4720b2..989ccba042c 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -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; }