Skip to content

Commit

Permalink
Merge pull request #7830 from MartinNowak/merge_stable
Browse files Browse the repository at this point in the history
merge stable
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Mar 6, 2021
2 parents 51a70ee + 9032d86 commit 1bd4faf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
9 changes: 8 additions & 1 deletion std/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -796,14 +796,15 @@ in
do
{
import std.format : format;
import std.meta : allSatisfy;
import std.typecons : Tuple;

Tuple!(T) ret;

thisInfo.ident.mbox.get((T val) {
static if (T.length)
{
static if (isAssignable!T)
static if (allSatisfy!(isAssignable, T))
{
ret.field = val;
}
Expand Down Expand Up @@ -888,6 +889,12 @@ do
assert(result == "Unexpected message type: expected 'string', got 'int'");
}

// https://issues.dlang.org/show_bug.cgi?id=21663
@safe unittest
{
alias test = receiveOnly!(string, bool, bool);
}

/**
* Receives a message from another thread and gives up if no match
* arrives within a specified duration.
Expand Down
52 changes: 52 additions & 0 deletions std/format/internal/write.d
Original file line number Diff line number Diff line change
Expand Up @@ -1918,13 +1918,18 @@ enum HasToStringResult
{
none,
hasSomeToString,
inCharSink,
inCharSinkFormatString,
inCharSinkFormatSpec,
constCharSink,
constCharSinkFormatString,
constCharSinkFormatSpec,
customPutWriter,
customPutWriterFormatSpec,
}

private enum hasPreviewIn = !is(typeof(mixin(q{(in ref int a) => a})));

template hasToString(T, Char)
{
static if (isPointer!T)
Expand Down Expand Up @@ -1971,6 +1976,23 @@ template hasToString(T, Char)
{
enum hasToString = HasToStringResult.constCharSink;
}

else static if (hasPreviewIn &&
is(typeof({ T val = void; FormatSpec!Char f; val.toString((in char[] s){}, f); })))
{
enum hasToString = HasToStringResult.inCharSinkFormatSpec;
}
else static if (hasPreviewIn &&
is(typeof({ T val = void; val.toString((in char[] s){}, "%s"); })))
{
enum hasToString = HasToStringResult.inCharSinkFormatString;
}
else static if (hasPreviewIn &&
is(typeof({ T val = void; val.toString((in char[] s){}); })))
{
enum hasToString = HasToStringResult.inCharSink;
}

else static if (is(typeof({ T val = void; return val.toString(); }()) S) && isSomeString!S)
{
enum hasToString = HasToStringResult.hasSomeToString;
Expand Down Expand Up @@ -2051,6 +2073,18 @@ template hasToString(T, Char)
if (isOutputRange!(Writer, string))
{}
}
static struct M
{
void toString(scope void delegate(in char[]) sink, in FormatSpec!char fmt) {}
}
static struct N
{
void toString(scope void delegate(in char[]) sink, string fmt) {}
}
static struct O
{
void toString(scope void delegate(in char[]) sink) {}
}

with(HasToStringResult)
{
Expand All @@ -2066,6 +2100,12 @@ template hasToString(T, Char)
static assert(hasToString!(J, char) == hasSomeToString);
static assert(hasToString!(K, char) == constCharSinkFormatSpec);
static assert(hasToString!(L, char) == none);
static if (hasPreviewIn)
{
static assert(hasToString!(M, char) == inCharSinkFormatSpec);
static assert(hasToString!(N, char) == inCharSinkFormatString);
static assert(hasToString!(O, char) == inCharSink);
}
}
}

Expand Down Expand Up @@ -2100,6 +2140,18 @@ if (hasToString!(T, Char))
{
static if (!noop) val.toString((scope const(char)[] s) { put(w, s); });
}
else static if (overload == HasToStringResult.inCharSinkFormatSpec)
{
static if (!noop) val.toString((in char[] s) { put(w, s); }, f);
}
else static if (overload == HasToStringResult.inCharSinkFormatString)
{
static if (!noop) val.toString((in char[] s) { put(w, s); }, f.getCurFmtStr());
}
else static if (overload == HasToStringResult.inCharSink)
{
static if (!noop) val.toString((in char[] s) { put(w, s); });
}
else static if (overload == HasToStringResult.hasSomeToString)
{
static if (!noop) put(w, val.toString());
Expand Down
9 changes: 5 additions & 4 deletions std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -5152,7 +5152,7 @@ private:

static uint getIeeeFlags() @trusted pure
{
version (InlineAsm_X87)
version (InlineAsm_X86_Any)
{
ushort sw;
asm pure nothrow @nogc { fstsw sw; }
Expand Down Expand Up @@ -5196,7 +5196,7 @@ private:

static void resetIeeeFlags() @trusted
{
version (InlineAsm_X87)
version (InlineAsm_X86_Any)
{
asm nothrow @nogc
{
Expand Down Expand Up @@ -7985,8 +7985,9 @@ if (isFloatingPoint!(F) && isFloatingPoint!(G))
auto c1 = complex(-2.5, 0.0);
auto c2 = complex(-1.5, 0.0);
auto result = c1 ^^ c2;
assert(isClose(result.re, -4.64705438e-17));
assert(isClose(result.im, 2.52982213e-1));
// exact result apparently depends on `real` precision => increased tolerance
assert(isClose(result.re, -4.64705438e-17, 2e-4));
assert(isClose(result.im, 2.52982e-1, 2e-4));
}

@safe pure nothrow @nogc unittest
Expand Down

0 comments on commit 1bd4faf

Please sign in to comment.