diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-01-02 13:36:51 +0100 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-01-03 12:26:05 +0100 |
commit | c43b5909031c7aa32ac65df3e392a12d32c45194 (patch) | |
tree | b7ef2e344e36132f68816e197e39c58bd39e9ac9 /libphobos/src | |
parent | bd5b0fca54341545ecf83f6775fc471f6f174142 (diff) | |
download | gcc-c43b5909031c7aa32ac65df3e392a12d32c45194.zip gcc-c43b5909031c7aa32ac65df3e392a12d32c45194.tar.gz gcc-c43b5909031c7aa32ac65df3e392a12d32c45194.tar.bz2 |
d: Merge upstream dmd 001bfd97b, druntime 759e6023, phobos 468788323.
D front-end changes:
- Import latest changes to mainline.
- Fix bad format specifiers in front-end errors (PR103840).
- Refactoring of some leaf modules to the dmd/root package.
- Updating copyright notice dates and urls.
Phobos changes:
- Import latest changes to mainline.
gcc/d/ChangeLog:
PR d/103840
* dmd/MERGE: Merge upstream dmd 001bfd97b.
* Make-lang.in (D_FRONTEND_OBJS): Rename d/complex.o to
d/root-complex.o, and d/utf.o to d/root/utf.o.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime 759e6023.
* src/MERGE: Merge upstream phobos 468788323.
Diffstat (limited to 'libphobos/src')
-rw-r--r-- | libphobos/src/MERGE | 2 | ||||
-rw-r--r-- | libphobos/src/std/algorithm/mutation.d | 20 | ||||
-rw-r--r-- | libphobos/src/std/container/array.d | 45 | ||||
-rw-r--r-- | libphobos/src/std/conv.d | 4 | ||||
-rw-r--r-- | libphobos/src/std/format/internal/read.d | 22 | ||||
-rw-r--r-- | libphobos/src/std/format/read.d | 13 | ||||
-rw-r--r-- | libphobos/src/std/sumtype.d | 1 | ||||
-rw-r--r-- | libphobos/src/std/uni/package.d | 8 | ||||
-rw-r--r-- | libphobos/src/std/utf.d | 25 | ||||
-rw-r--r-- | libphobos/src/std/xml.d | 2 |
10 files changed, 88 insertions, 54 deletions
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index b517749..b60fa17 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -495e835c2da47606142ff24c85de707e3b955a9a +4687883231eba3bda7691321f2af107fdb3d0a44 The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/algorithm/mutation.d b/libphobos/src/std/algorithm/mutation.d index 22b7b98..b0e7707 100644 --- a/libphobos/src/std/algorithm/mutation.d +++ b/libphobos/src/std/algorithm/mutation.d @@ -866,6 +866,9 @@ if (isInputRange!InputRange Initializes all elements of `range` with their `.init` value. Assumes that the elements of the range are uninitialized. +This function is unavailable if `T` is a `struct` and `T.this()` is annotated +with `@disable`. + Params: range = An $(REF_ALTTEXT input range, isInputRange, std,range,primitives) @@ -874,10 +877,11 @@ Params: See_Also: $(LREF fill) - $(LREF uninitializeFill) + $(LREF uninitializedFill) */ void initializeAll(Range)(Range range) -if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range) +if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range + && __traits(compiles, { static ElementType!Range _; })) { import core.stdc.string : memset, memcpy; import std.traits : hasElaborateAssign, isDynamicArray; @@ -1037,6 +1041,18 @@ if (is(Range == char[]) || is(Range == wchar[])) assert(xs[1].x == 3); } +// https://issues.dlang.org/show_bug.cgi?id=22105 +@system unittest +{ + struct NoDefaultCtor + { + @disable this(); + } + + NoDefaultCtor[1] array = void; + static assert(!__traits(compiles, array[].initializeAll)); +} + // move /** Moves `source` into `target`, via a destructive copy when necessary. diff --git a/libphobos/src/std/container/array.d b/libphobos/src/std/container/array.d index 63dc864..08f9ead 100644 --- a/libphobos/src/std/container/array.d +++ b/libphobos/src/std/container/array.d @@ -428,8 +428,6 @@ if (!is(immutable T == immutable bool)) @property void length(size_t newLength) { - import std.algorithm.mutation : initializeAll; - if (length >= newLength) { // shorten @@ -440,10 +438,22 @@ if (!is(immutable T == immutable bool)) _payload = _payload.ptr[0 .. newLength]; return; } - immutable startEmplace = length; - reserve(newLength); - initializeAll(_payload.ptr[startEmplace .. newLength]); - _payload = _payload.ptr[0 .. newLength]; + + static if (__traits(compiles, { static T _; })) + { + import std.algorithm.mutation : initializeAll; + + immutable startEmplace = length; + reserve(newLength); + initializeAll(_payload.ptr[startEmplace .. newLength]); + _payload = _payload.ptr[0 .. newLength]; + } + else + { + assert(0, "Cannot add elements to array because `" ~ + fullyQualifiedName!T ~ ".this()` is annotated with " ~ + "`@disable`."); + } } @property size_t capacity() const @@ -901,12 +911,16 @@ if (!is(immutable T == immutable bool)) /** * Sets the number of elements in the array to `newLength`. If `newLength` * is greater than `length`, the new elements are added to the end of the - * array and initialized with `T.init`. + * array and initialized with `T.init`. If `T` is a `struct` whose default + * constructor is annotated with `@disable`, `newLength` must be lower than + * or equal to `length`. * * Complexity: * Guaranteed $(BIGOH abs(length - newLength)) if `capacity >= newLength`. * If `capacity < newLength` the worst case is $(BIGOH newLength). * + * Precondition: `__traits(compiles, { static T _; }) || newLength <= length` + * * Postcondition: `length == newLength` */ @property void length(size_t newLength) @@ -1708,6 +1722,23 @@ if (!is(immutable T == immutable bool)) assert(equal(a[], [1,2,3,4,5,6,7,8])); } +// https://issues.dlang.org/show_bug.cgi?id=22105 +@system unittest +{ + import core.exception : AssertError; + import std.exception : assertThrown, assertNotThrown; + + struct NoDefaultCtor + { + int i; + @disable this(); + this(int j) { i = j; } + } + + auto array = Array!NoDefaultCtor([NoDefaultCtor(1), NoDefaultCtor(2)]); + assertNotThrown!AssertError(array.length = 1); + assertThrown!AssertError(array.length = 5); +} //////////////////////////////////////////////////////////////////////////////// // Array!bool diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d index d9db9b0..98df7fd 100644 --- a/libphobos/src/std/conv.d +++ b/libphobos/src/std/conv.d @@ -2377,7 +2377,7 @@ Throws: A $(LREF ConvException) If an overflow occurred during conversion or if no character of the input was meaningfully converted. */ -auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s) +auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source s) if (isSomeChar!(ElementType!Source) && isIntegral!Target && !is(Target == enum)) { @@ -2482,7 +2482,7 @@ if (isSomeChar!(ElementType!Source) && v = -v; static if (isNarrowString!Source) - s = cast(Source) source; + s = s[$-source.length..$]; static if (doCount) { diff --git a/libphobos/src/std/format/internal/read.d b/libphobos/src/std/format/internal/read.d index 102e59f..9130499 100644 --- a/libphobos/src/std/format/internal/read.d +++ b/libphobos/src/std/format/internal/read.d @@ -228,26 +228,8 @@ if (isInputRange!Range && is(StringTypeOf!T) && !isAggregateType!T && !is(T == e } T unformatValueImpl(T, Range, Char)(ref Range input, scope const ref FormatSpec!Char fmt) -if (isInputRange!Range && isArray!T && !is(StringTypeOf!T) && !isAggregateType!T - && !is(T == enum)) -{ - import std.conv : parse, text; - import std.format : enforceFmt; - - const spec = fmt.spec; - if (spec == '(') - { - return unformatRange!T(input, fmt); - } - - enforceFmt(spec == 's', - text("Wrong unformat specifier '%", spec , "' for ", T.stringof)); - - return parse!T(input); -} - -T unformatValueImpl(T, Range, Char)(ref Range input, scope const ref FormatSpec!Char fmt) -if (isInputRange!Range && isAssociativeArray!T && !is(T == enum)) +if (isInputRange!Range && !is(StringTypeOf!T) && !isAggregateType!T + && (isArray!T || isAssociativeArray!T || is(T == enum))) { import std.conv : parse, text; import std.format : enforceFmt; diff --git a/libphobos/src/std/format/read.d b/libphobos/src/std/format/read.d index 0de8818..b3d8d1f 100644 --- a/libphobos/src/std/format/read.d +++ b/libphobos/src/std/format/read.d @@ -719,3 +719,16 @@ T unformatValue(T, Range, Char)(ref Range input, scope const ref FormatSpec!Char int b; assertThrown(formattedRead(str, "%s %d-%s", &a, &b, &c)); } + +// https://issues.dlang.org/show_bug.cgi?id=18051 +@safe pure unittest +{ + import std.format : format; + + enum Op { lt, gt, eq } + + auto s = format!"%s"(Op.lt); + Op op; + assert(formattedRead!"%s"(s, op) == 1); + assert(op == Op.lt); +} diff --git a/libphobos/src/std/sumtype.d b/libphobos/src/std/sumtype.d index 8242f1e..658fd38 100644 --- a/libphobos/src/std/sumtype.d +++ b/libphobos/src/std/sumtype.d @@ -1700,7 +1700,6 @@ template match(handlers...) * Throws: * [MatchException], if the currently-held type has no matching handler. * - * See_Also: `std.variant.tryVisit` * See_Also: $(REF tryVisit, std,variant) */ version (D_Exceptions) diff --git a/libphobos/src/std/uni/package.d b/libphobos/src/std/uni/package.d index a27cbea..192b6fd 100644 --- a/libphobos/src/std/uni/package.d +++ b/libphobos/src/std/uni/package.d @@ -5798,7 +5798,7 @@ if (is(Char1 : dchar) && is(Char2 : dchar)) // Utilities for compression of Unicode code point sets //============================================================================ -@safe void compressTo(uint val, ref ubyte[] arr) pure nothrow +@safe void compressTo(uint val, ref scope ubyte[] arr) pure nothrow { // not optimized as usually done 1 time (and not public interface) if (val < 128) @@ -5817,7 +5817,7 @@ if (is(Char1 : dchar) && is(Char2 : dchar)) } } -@safe uint decompressFrom(const(ubyte)[] arr, ref size_t idx) pure +@safe uint decompressFrom(scope const(ubyte)[] arr, ref size_t idx) pure { import std.exception : enforce; immutable first = arr[idx++]; @@ -8412,7 +8412,7 @@ int hangulSyllableIndex(dchar ch) pure nothrow @nogc @safe } // internal helper: compose hangul syllables leaving dchar.init in holes -void hangulRecompose(dchar[] seq) pure nothrow @nogc @safe +void hangulRecompose(scope dchar[] seq) pure nothrow @nogc @safe { for (size_t idx = 0; idx + 1 < seq.length; ) { @@ -8695,7 +8695,7 @@ inout(C)[] normalize(NormalizationForm norm=NFC, C)(return scope inout(C)[] inpu } // canonically recompose given slice of code points, works in-place and mutates data -private size_t recompose(size_t start, dchar[] input, ubyte[] ccc) pure nothrow @safe +private size_t recompose(size_t start, scope dchar[] input, scope ubyte[] ccc) pure nothrow @safe { assert(input.length == ccc.length); int accumCC = -1;// so that it's out of 0 .. 255 range diff --git a/libphobos/src/std/utf.d b/libphobos/src/std/utf.d index 866ec48..a29025a 100644 --- a/libphobos/src/std/utf.d +++ b/libphobos/src/std/utf.d @@ -1168,7 +1168,7 @@ do /// ditto dchar decode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar, S)( -auto ref S str, ref size_t index) @trusted pure +auto ref scope S str, ref size_t index) @trusted pure if (isSomeString!S) in { @@ -1274,7 +1274,7 @@ do /// ditto dchar decodeFront(UseReplacementDchar useReplacementDchar = No.useReplacementDchar, S)( -ref S str, out size_t numCodeUnits) @trusted pure +ref scope S str, out size_t numCodeUnits) @trusted pure if (isSomeString!S) in { @@ -2541,14 +2541,12 @@ size_t encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( `UTFException` if `c` is not a valid UTF code point. +/ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( - ref char[] str, dchar c) @safe pure + ref scope char[] str, dchar c) @safe pure { - char[] r = str; - if (c <= 0x7F) { assert(isValidDchar(c)); - r ~= cast(char) c; + str ~= cast(char) c; } else { @@ -2589,9 +2587,8 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( c = _utfException!useReplacementDchar("Encoding an invalid code point in UTF-8", c); goto L3; } - r ~= buf[0 .. L]; + str ~= buf[0 .. L]; } - str = r; } /// @@ -2666,10 +2663,8 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( /// ditto void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( - ref wchar[] str, dchar c) @safe pure + ref scope wchar[] str, dchar c) @safe pure { - wchar[] r = str; - if (c <= 0xFFFF) { if (0xD800 <= c && c <= 0xDFFF) @@ -2677,7 +2672,7 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( assert(isValidDchar(c)); L1: - r ~= cast(wchar) c; + str ~= cast(wchar) c; } else if (c <= 0x10FFFF) { @@ -2686,7 +2681,7 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( assert(isValidDchar(c)); buf[0] = cast(wchar)((((c - 0x10000) >> 10) & 0x3FF) + 0xD800); buf[1] = cast(wchar)(((c - 0x10000) & 0x3FF) + 0xDC00); - r ~= buf; + str ~= buf; } else { @@ -2694,8 +2689,6 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( c = _utfException!useReplacementDchar("Encoding an invalid code point in UTF-16", c); goto L1; } - - str = r; } @safe unittest @@ -2727,7 +2720,7 @@ void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( /// ditto void encode(UseReplacementDchar useReplacementDchar = No.useReplacementDchar)( - ref dchar[] str, dchar c) @safe pure + ref scope dchar[] str, dchar c) @safe pure { if ((0xD800 <= c && c <= 0xDFFF) || 0x10FFFF < c) c = _utfException!useReplacementDchar("Encoding an invalid code point in UTF-32", c); diff --git a/libphobos/src/std/xml.d b/libphobos/src/std/xml.d index 37fab6d..fdfdc3f 100644 --- a/libphobos/src/std/xml.d +++ b/libphobos/src/std/xml.d @@ -433,7 +433,7 @@ enum DecodeMode * writefln(decode("a > b")); // writes "a > b" * -------------- */ -string decode(return scope string s, DecodeMode mode=DecodeMode.LOOSE) @safe pure +string decode(string s, DecodeMode mode=DecodeMode.LOOSE) @safe pure { import std.algorithm.searching : startsWith; |