Skip to content

Commit 62f8d03

Browse files
committed
Merge remote-tracking branch 'upstream/master' into stable
2 parents dfcbee7 + 330d6a4 commit 62f8d03

29 files changed

+553
-233
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Better static assert messages for `std.algorithm.iteration.permutations`
2+
3+
Until now, `permutations` used a template constraint to check if the passed types
4+
could be used. If they were not, it was very tedious to figure out why.
5+
6+
As the template constraint is not used for overload resolution
7+
the constrains are moved into static asserts with expressive error
8+
messages.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Added `std.system.instructionSetArchitecture` and `std.system.ISA`
2+
3+
A new enum representing the instruction set architecture for the targeted
4+
system was added. It is intended for cases where a targeted CPU's ISA is only
5+
needed at runtime, such as providing human-readable messages as demonstrated
6+
below.
7+
-------
8+
import std.stdio;
9+
import std.system;
10+
11+
void main()
12+
{
13+
writeln("Hello ", instructionSetArchitecture, " world!");
14+
}
15+
-------

posix.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ROOT_OF_THEM_ALL = generated
7474
ROOT = $(ROOT_OF_THEM_ALL)/$(OS)/$(BUILD)/$(MODEL)
7575
DUB=dub
7676
TOOLS_DIR=../tools
77-
DSCANNER_HASH=d5d6920502bf1bfdb29474007a59fd606df0aadc
77+
DSCANNER_HASH=5a53c538d0aa832f03840840271b6631fbbfc53d
7878
DSCANNER_DIR=$(ROOT_OF_THEM_ALL)/dscanner-$(DSCANNER_HASH)
7979

8080
# Set DRUNTIME name and full path

std/algorithm/iteration.d

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ private struct ChunkByGroup(alias eq, Range, bool eqEquivalenceAssured)
20262026
}
20272027
}
20282028

2029-
// Cannot be a copy constructor due to issue 22239
2029+
// Cannot be a copy constructor due to https://issues.dlang.org/show_bug.cgi?id=22239
20302030
this(this) @trusted
20312031
{
20322032
import core.lifetime : emplace;
@@ -2128,7 +2128,7 @@ if (isForwardRange!Range)
21282128
}();
21292129
}
21302130

2131-
// Cannot be a copy constructor due to issue 22239
2131+
// Cannot be a copy constructor due to https://issues.dlang.org/show_bug.cgi?id=22239
21322132
this(this) @trusted
21332133
{
21342134
import core.lifetime : emplace;
@@ -7939,15 +7939,23 @@ See_Also:
79397939
$(REF nextPermutation, std,algorithm,sorting).
79407940
*/
79417941
Permutations!Range permutations(Range)(Range r)
7942-
if (isRandomAccessRange!Range && hasLength!Range)
79437942
{
7943+
static assert(isRandomAccessRange!Range, Range.stringof,
7944+
" must be a RandomAccessRange");
7945+
static assert(hasLength!Range, Range.stringof
7946+
, " must have a length");
7947+
79447948
return typeof(return)(r);
79457949
}
79467950

79477951
/// ditto
79487952
struct Permutations(Range)
7949-
if (isRandomAccessRange!Range && hasLength!Range)
79507953
{
7954+
static assert(isRandomAccessRange!Range, Range.stringof,
7955+
" must be a RandomAccessRange");
7956+
static assert(hasLength!Range, Range.stringof
7957+
, " must have a length");
7958+
79517959
private size_t[] _indices, _state;
79527960
private Range _r;
79537961
private bool _empty;

std/algorithm/mutation.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ if (isBlitAssignable!T && !is(typeof(lhs.proxySwap(rhs))))
30493049
swap(b1, b2);
30503050
}
30513051

3052-
// issue 20732
3052+
// https://issues.dlang.org/show_bug.cgi?id=20732
30533053
@safe unittest
30543054
{
30553055
static struct A

std/algorithm/searching.d

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ if (isInputRange!R &&
12821282

12831283
@safe pure unittest
12841284
{
1285-
//example from issue 19727
1285+
//example from https://issues.dlang.org/show_bug.cgi?id=19727
12861286
import std.path : asRelativePath;
12871287
string[] ext = ["abc", "def", "ghi"];
12881288
string path = "/foo/file.def";
@@ -1315,19 +1315,12 @@ in
13151315
}
13161316
do
13171317
{
1318-
import std.typecons : Rebindable;
1318+
import std.typecons : Rebindable2;
13191319

13201320
alias Element = ElementType!Range;
1321-
Rebindable!Element seed = r.front;
1321+
auto seed = Rebindable2!Element(r.front);
13221322
r.popFront();
1323-
static if (is(typeof(seed) == Unqual!Element))
1324-
{
1325-
return extremum!(map, selector)(r, seed);
1326-
}
1327-
else
1328-
{
1329-
return extremum!(map, selector)(r, seed.get);
1330-
}
1323+
return extremum!(map, selector)(r, seed.get);
13311324
}
13321325

13331326
private auto extremum(alias map, alias selector = "a < b", Range,
@@ -1337,35 +1330,24 @@ if (isInputRange!Range && !isInfinite!Range &&
13371330
!is(CommonType!(ElementType!Range, RangeElementType) == void) &&
13381331
is(typeof(unaryFun!map(ElementType!(Range).init))))
13391332
{
1340-
import std.typecons : Rebindable;
1333+
import std.typecons : Rebindable2;
13411334

13421335
alias mapFun = unaryFun!map;
13431336
alias selectorFun = binaryFun!selector;
13441337

13451338
alias Element = ElementType!Range;
13461339
alias CommonElement = CommonType!(Element, RangeElementType);
1347-
Rebindable!CommonElement extremeElement = seedElement;
1340+
auto extremeElement = Rebindable2!CommonElement(seedElement);
13481341

13491342
// if we only have one statement in the loop, it can be optimized a lot better
13501343
static if (__traits(isSame, map, a => a))
13511344
{
1352-
CommonElement getExtremeElement()
1353-
{
1354-
static if (is(typeof(extremeElement) == Unqual!CommonElement))
1355-
{
1356-
return extremeElement;
1357-
}
1358-
else
1359-
{
1360-
return extremeElement.get;
1361-
}
1362-
}
13631345
// direct access via a random access range is faster
13641346
static if (isRandomAccessRange!Range)
13651347
{
13661348
foreach (const i; 0 .. r.length)
13671349
{
1368-
if (selectorFun(r[i], getExtremeElement))
1350+
if (selectorFun(r[i], extremeElement.get))
13691351
{
13701352
extremeElement = r[i];
13711353
}
@@ -1375,7 +1357,7 @@ if (isInputRange!Range && !isInfinite!Range &&
13751357
{
13761358
while (!r.empty)
13771359
{
1378-
if (selectorFun(r.front, getExtremeElement))
1360+
if (selectorFun(r.front, extremeElement.get))
13791361
{
13801362
extremeElement = r.front;
13811363
}
@@ -1386,7 +1368,7 @@ if (isInputRange!Range && !isInfinite!Range &&
13861368
else
13871369
{
13881370
alias MapType = Unqual!(typeof(mapFun(CommonElement.init)));
1389-
MapType extremeElementMapped = mapFun(extremeElement);
1371+
MapType extremeElementMapped = mapFun(extremeElement.get);
13901372

13911373
// direct access via a random access range is faster
13921374
static if (isRandomAccessRange!Range)
@@ -1415,15 +1397,7 @@ if (isInputRange!Range && !isInfinite!Range &&
14151397
}
14161398
}
14171399
}
1418-
// For several cases, such as classes or arrays, Rebindable!T aliases itself to T or Unqual!T.
1419-
static if (is(typeof(extremeElement) == Unqual!CommonElement))
1420-
{
1421-
return extremeElement;
1422-
}
1423-
else
1424-
{
1425-
return extremeElement.get;
1426-
}
1400+
return extremeElement.get;
14271401
}
14281402

14291403
private auto extremum(alias selector = "a < b", Range)(Range r)
@@ -1555,7 +1529,7 @@ if (isInputRange!Range && !isInfinite!Range &&
15551529
}
15561530

15571531
// https://issues.dlang.org/show_bug.cgi?id=24027
1558-
@safe nothrow pure unittest
1532+
@safe nothrow unittest
15591533
{
15601534
class A
15611535
{
@@ -2336,7 +2310,7 @@ private R1 simpleMindedFind(alias pred, R1, R2)(R1 haystack, scope R2 needle)
23362310
@safe:
23372311
string _impl;
23382312

2339-
// This is what triggers issue 7992.
2313+
// This is what triggers https://issues.dlang.org/show_bug.cgi?id=7992.
23402314
@property size_t length() const { return _impl.length; }
23412315
@property void length(size_t len) { _impl.length = len; }
23422316

@@ -2349,7 +2323,7 @@ private R1 simpleMindedFind(alias pred, R1, R2)(R1 haystack, scope R2 needle)
23492323
@property CustomString save() { return this; }
23502324
}
23512325

2352-
// If issue 7992 occurs, this will throw an exception from calling
2326+
// If https://issues.dlang.org/show_bug.cgi?id=7992 occurs, this will throw an exception from calling
23532327
// popFront() on an empty range.
23542328
auto r = find(CustomString("a"), CustomString("b"));
23552329
assert(r.empty);

std/bigint.d

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ public:
254254

255255
static if (op=="+")
256256
{
257-
data = BigUint.addOrSubInt(data, u, sign != (y<0), sign);
257+
data = BigUint.addOrSubInt!ulong(data, u, wantSub: sign != (y<0), sign);
258258
}
259259
else static if (op=="-")
260260
{
261-
data = BigUint.addOrSubInt(data, u, sign == (y<0), sign);
261+
data = BigUint.addOrSubInt!ulong(data, u, wantSub: sign == (y<0), sign);
262262
}
263263
else static if (op=="*")
264264
{
@@ -323,7 +323,15 @@ public:
323323
else static if (op=="^^")
324324
{
325325
sign = (y & 1) ? sign : false;
326-
data = BigUint.pow(data, u);
326+
if (y < 0)
327+
{
328+
checkDivByZero();
329+
data = cast(ulong) (data == 1);
330+
}
331+
else
332+
{
333+
data = BigUint.pow(data, u);
334+
}
327335
}
328336
else static if (op=="&")
329337
{
@@ -411,6 +419,19 @@ public:
411419
));
412420
}
413421

422+
// https://issues.dlang.org/show_bug.cgi?id=24028
423+
@system unittest
424+
{
425+
import std.exception : assertThrown;
426+
import core.exception : AssertError;
427+
428+
assert(BigInt(100) ^^ -1 == BigInt(0));
429+
assert(BigInt(1) ^^ -1 == BigInt(1));
430+
assert(BigInt(-1) ^^ -1 == BigInt(-1));
431+
assert(BigInt(-1) ^^ -2 == BigInt(1));
432+
assertThrown!AssertError(BigInt(0) ^^ -1);
433+
}
434+
414435
/**
415436
* Implements assignment operators of the form `BigInt op= BigInt`.
416437
*/
@@ -613,7 +634,7 @@ public:
613634
static if (op == "-")
614635
{
615636
r.sign = sign;
616-
r.data = BigUint.addOrSubInt(data, u, sign == (y<0), r.sign);
637+
r.data = BigUint.addOrSubInt!ulong(data, u, wantSub: sign == (y<0), r.sign);
617638
r.negate();
618639
}
619640
return r;
@@ -670,12 +691,12 @@ public:
670691
{
671692
static if (op=="++")
672693
{
673-
data = BigUint.addOrSubInt(data, 1UL, sign, sign);
694+
data = BigUint.addOrSubInt!ulong(data, 1UL, wantSub: sign, sign);
674695
return this;
675696
}
676697
else static if (op=="--")
677698
{
678-
data = BigUint.addOrSubInt(data, 1UL, !sign, sign);
699+
data = BigUint.addOrSubInt!ulong(data, 1UL, wantSub: !sign, sign);
679700
return this;
680701
}
681702
}

std/checkedint.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,16 +2129,16 @@ static:
21292129
{
21302130
// Not value convertible, only viable option is rhs fits within the
21312131
// bounds of Lhs
2132-
static if (ProperCompare.hookOpCmp(Rhs.min, Lhs.min) < 0)
2132+
static if (ProperCompare.hookOpCmp!(Rhs, Lhs)(lhs: Rhs.min, rhs: Lhs.min) < 0)
21332133
{
21342134
// Example: hookOpCast!short(int(42)), hookOpCast!uint(int(42))
2135-
if (ProperCompare.hookOpCmp(rhs, Lhs.min) < 0)
2135+
if (ProperCompare.hookOpCmp!(Rhs, Lhs)(lhs: rhs, rhs: Lhs.min) < 0)
21362136
return defaultValue!Lhs;
21372137
}
2138-
static if (ProperCompare.hookOpCmp(Rhs.max, Lhs.max) > 0)
2138+
static if (ProperCompare.hookOpCmp!(Rhs, Lhs)(lhs: Rhs.max, rhs: Lhs.max) > 0)
21392139
{
21402140
// Example: hookOpCast!int(uint(42))
2141-
if (ProperCompare.hookOpCmp(rhs, Lhs.max) > 0)
2141+
if (ProperCompare.hookOpCmp!(Rhs, Lhs)(lhs: rhs, rhs: Lhs.max) > 0)
21422142
return defaultValue!Lhs;
21432143
}
21442144
return cast(Lhs) rhs;

std/complex.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ Complex!T asin(T)(Complex!T z) @safe pure nothrow @nogc
10661066
{
10671067
import std.math.operations : isClose;
10681068
import std.math.constants : PI;
1069-
version (DigitalMars) {} else // Disabled because of issue 21376
1069+
version (DigitalMars) {} else // Disabled because of https://issues.dlang.org/show_bug.cgi?id=21376
10701070
assert(isClose(asin(complex(0.5f)), float(PI) / 6));
10711071
}
10721072

@@ -1092,7 +1092,7 @@ Complex!T acos(T)(Complex!T z) @safe pure nothrow @nogc
10921092
{
10931093
import std.math.operations : isClose;
10941094
import std.math.constants : PI;
1095-
version (DigitalMars) {} else // Disabled because of issue 21376
1095+
version (DigitalMars) {} else // Disabled because of https://issues.dlang.org/show_bug.cgi?id=21376
10961096
assert(isClose(acos(complex(0.5f)), float(PI) / 3));
10971097
}
10981098

std/container/array.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ if (!is(immutable T == immutable bool))
15661566
r2[0 .. 0] += 0;
15671567
}
15681568

1569-
// Test issue 11194
1569+
// Test https://issues.dlang.org/show_bug.cgi?id=11194
15701570
@system unittest
15711571
{
15721572
static struct S {

0 commit comments

Comments
 (0)