diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-05-16 18:30:46 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-05-16 19:07:45 +0200 |
commit | 5eb9927aae076200bb7ba3f22c33b0a7c97c5643 (patch) | |
tree | f80210439a5d8995ebf189bce7f2e141fcb1caec /libphobos/src | |
parent | 682e587f1021241758f7dfe0b22651008622a312 (diff) | |
download | gcc-5eb9927aae076200bb7ba3f22c33b0a7c97c5643.tar.gz |
d: Merge upstream dmd 60bfa0ee7, druntime 94bd5bcb, phobos 3a1cd9a01.
D front-end changes:
- Import dmd v2.100.0.
- Add bit fields to D, enabled via the -fpreview=bitfields switch.
- Removed the -ftransition=markdown and -frevert=markdown switches.
- Added new trait `__traits(classInstanceAlignment)' to provide the
required data alignment for classes.
- The check for `pragma(crt_constructor)' and `pragma(crt_destructor)'
linkage has been relaxed to allow all `void()' signatures.
- ImportC parser now recognizes the `typeof(...)' operator.
D runtime changes:
- Import druntime v2.100.0.
Phobos changes:
- Import phobos v2.100.0.
- To comply with dip1000, `std.socket.Socket` methods now accept only
`scope' arrays.
- The `fill', `alignSize', `align2', and `align4' methods of
`std.outbuffer.OutBuffer' have been extended to allow specifying a custom
value when pre-filling or padding the buffer.
gcc/d/ChangeLog:
* dmd/MERGE: Merge upstream dmd 60bfa0ee7.
* dmd/VERSION: Update version to v2.100.0.
* d-builtins.cc (d_init_versions): Update for new front-end interface.
* d-codegen.cc (d_decl_context): Use resolvedLinkage to get
declaration linkage.
(build_struct_literal): Track offset in bits.
* d-gimplify.cc (d_gimplify_modify_expr): Check both operands for a
bit-field reference.
* d-lang.cc (d_handle_option): Handle -fpreview=bitfields, remove
-frevert=markdown and -ftransition=vmarkdown.
(d_post_options): Set flag_rtti and flag_exceptions if -fno-druntime
was seen on command-line.
(d_parse_file): Update for new front-end interface.
(d_type_promotes_to): Use resolvedLinkage to get declaration linkage.
* decl.cc (make_thunk): Likewise.
* expr.cc (ExprVisitor::visit (CatAssignExp *)): Remove lowering for
appending of an element or array to another array.
* lang.opt (fpreview=bitfields): New option.
(frevert=markdown): Remove.
(ftransition=vmarkdown): Remove.
* types.cc (layout_aggregate_members): Ignore anonymous fields in
total count.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime 94bd5bcb.
* libdruntime/Makefile.am (ALL_DRUNTIME_INSTALL_DSOURCES): Add
$(DRUNTIME_DSOURCES_ELF).
(ALL_DRUNTIME_SOURCES): Likewise.
(DRUNTIME_DSOURCES_ELF): New variable.
* libdruntime/Makefile.in: Regenerate.
* src/MERGE: Merge upstream phobos 3a1cd9a01.
* testsuite/libphobos.init_fini/custom_gc.d: Update test.
Diffstat (limited to 'libphobos/src')
-rw-r--r-- | libphobos/src/MERGE | 2 | ||||
-rw-r--r-- | libphobos/src/std/exception.d | 2 | ||||
-rw-r--r-- | libphobos/src/std/experimental/logger/core.d | 8 | ||||
-rw-r--r-- | libphobos/src/std/math/exponential.d | 4 | ||||
-rw-r--r-- | libphobos/src/std/math/hardware.d | 4 | ||||
-rw-r--r-- | libphobos/src/std/outbuffer.d | 71 | ||||
-rw-r--r-- | libphobos/src/std/socket.d | 70 | ||||
-rw-r--r-- | libphobos/src/std/sumtype.d | 23 | ||||
-rw-r--r-- | libphobos/src/std/traits.d | 5 | ||||
-rw-r--r-- | libphobos/src/std/typecons.d | 4 |
10 files changed, 137 insertions, 56 deletions
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index 3218ace50a0..3de142fe009 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -ac296f80cda437483b743f953dc69cb1271c82df +3a1cd9a01479155958c7799e573e55a93dd189a0 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/exception.d b/libphobos/src/std/exception.d index 4f7f3c39153..94a2e7a0012 100644 --- a/libphobos/src/std/exception.d +++ b/libphobos/src/std/exception.d @@ -1641,7 +1641,7 @@ package string errnoString(int errno) nothrow @trusted class ErrnoException : Exception { /// Operating system error code. - final @property uint errno() nothrow pure @nogc @safe { return _errno; } + final @property uint errno() nothrow pure scope @nogc @safe { return _errno; } private uint _errno; /// Constructor which takes an error message. The current global $(REF errno, core,stdc,errno) value is used as error code. this(string msg, string file = null, size_t line = 0) @safe diff --git a/libphobos/src/std/experimental/logger/core.d b/libphobos/src/std/experimental/logger/core.d index 6a28de52ed0..efc4ef7f74a 100644 --- a/libphobos/src/std/experimental/logger/core.d +++ b/libphobos/src/std/experimental/logger/core.d @@ -1628,7 +1628,8 @@ private @property Logger defaultSharedLoggerImpl() @trusted import core.lifetime : emplace; import std.stdio : stderr; - __gshared align(FileLogger.alignof) void[__traits(classInstanceSize, FileLogger)] _buffer; + __gshared align(__traits(classInstanceAlignment, FileLogger)) + void[__traits(classInstanceSize, FileLogger)] _buffer; import std.concurrency : initOnce; initOnce!stdSharedDefaultLogger({ @@ -1762,9 +1763,8 @@ private @property Logger stdThreadLocalLogImpl() @trusted { import core.lifetime : emplace; - static void*[(__traits(classInstanceSize, StdForwardLogger) - 1) / (void*).sizeof + 1] _buffer; - - auto buffer = cast(ubyte[]) _buffer; + static align(__traits(classInstanceAlignment, StdForwardLogger)) + void[__traits(classInstanceSize, StdForwardLogger)] buffer; if (stdLoggerDefaultThreadLogger is null) { diff --git a/libphobos/src/std/math/exponential.d b/libphobos/src/std/math/exponential.d index a9ec930d90c..daf2cecbebe 100644 --- a/libphobos/src/std/math/exponential.d +++ b/libphobos/src/std/math/exponential.d @@ -968,10 +968,10 @@ if (isUnsigned!F && isUnsigned!G && isUnsigned!H) pragma(inline, true) real exp(real x) @trusted pure nothrow @nogc // TODO: @safe { - import std.math.constants : LOG2E; - version (InlineAsm_X87) { + import std.math.constants : LOG2E; + // e^^x = 2^^(LOG2E*x) // (This is valid because the overflow & underflow limits for exp // and exp2 are so similar). diff --git a/libphobos/src/std/math/hardware.d b/libphobos/src/std/math/hardware.d index b768969d4cf..7bff07e86d4 100644 --- a/libphobos/src/std/math/hardware.d +++ b/libphobos/src/std/math/hardware.d @@ -214,12 +214,12 @@ private: } else version (SPARC) { - /* + /* int retval; asm pure nothrow @nogc { st %fsr, retval; } return retval; */ - assert(0, "Not yet supported"); + assert(0, "Not yet supported"); } else version (ARM) { diff --git a/libphobos/src/std/outbuffer.d b/libphobos/src/std/outbuffer.d index c434481dda3..92af9a9a16a 100644 --- a/libphobos/src/std/outbuffer.d +++ b/libphobos/src/std/outbuffer.d @@ -173,21 +173,40 @@ class OutBuffer } /**************************************** - * Append nbytes of 0 to the internal buffer. + * Append nbytes of val to the internal buffer. + * Params: + * nbytes = Number of bytes to fill. + * val = Value to fill, defaults to 0. */ - void fill0(size_t nbytes) + void fill(size_t nbytes, ubyte val = 0) { reserve(nbytes); - data[offset .. offset + nbytes] = 0; + data[offset .. offset + nbytes] = val; offset += nbytes; } + /**************************************** + * Append nbytes of 0 to the internal buffer. + * Param: + * nbytes - number of bytes to fill. + */ + void fill0(size_t nbytes) + { + fill(nbytes); + } + /********************************** - * 0-fill to align on power of 2 boundary. + * Append bytes until the buffer aligns on a power of 2 boundary. + * + * By default fills with 0 bytes. + * + * Params: + * alignsize = Alignment value. Must be power of 2. + * val = Value to fill, defaults to 0. */ - void alignSize(size_t alignsize) + void alignSize(size_t alignsize, ubyte val = 0) in { assert(alignsize && (alignsize & (alignsize - 1)) == 0); @@ -200,7 +219,35 @@ class OutBuffer { auto nbytes = offset & (alignsize - 1); if (nbytes) - fill0(alignsize - nbytes); + fill(alignsize - nbytes, val); + } + /// + @safe unittest + { + OutBuffer buf = new OutBuffer(); + buf.write(cast(ubyte) 1); + buf.align2(); + assert(buf.toBytes() == "\x01\x00"); + buf.write(cast(ubyte) 2); + buf.align4(); + assert(buf.toBytes() == "\x01\x00\x02\x00"); + buf.write(cast(ubyte) 3); + buf.alignSize(8); + assert(buf.toBytes() == "\x01\x00\x02\x00\x03\x00\x00\x00"); + } + /// ditto + @safe unittest + { + OutBuffer buf = new OutBuffer(); + buf.write(cast(ubyte) 1); + buf.align2(0x55); + assert(buf.toBytes() == "\x01\x55"); + buf.write(cast(ubyte) 2); + buf.align4(0x55); + assert(buf.toBytes() == "\x01\x55\x02\x55"); + buf.write(cast(ubyte) 3); + buf.alignSize(8, 0x55); + assert(buf.toBytes() == "\x01\x55\x02\x55\x03\x55\x55\x55"); } /// Clear the data in the buffer @@ -211,23 +258,27 @@ class OutBuffer /**************************************** * Optimize common special case alignSize(2) + * Params: + * val = Value to fill, defaults to 0. */ - void align2() + void align2(ubyte val = 0) { if (offset & 1) - write(cast(byte) 0); + write(cast(byte) val); } /**************************************** * Optimize common special case alignSize(4) + * Params: + * val = Value to fill, defaults to 0. */ - void align4() + void align4(ubyte val = 0) { if (offset & 3) { auto nbytes = (4 - offset) & 3; - fill0(nbytes); + fill(nbytes, val); } } diff --git a/libphobos/src/std/socket.d b/libphobos/src/std/socket.d index 915159f180f..6ec79858194 100644 --- a/libphobos/src/std/socket.d +++ b/libphobos/src/std/socket.d @@ -122,6 +122,12 @@ version (StdUnittest) writefln("Ignoring std.socket(%d) test failure (likely caused by flaky environment): %s", line, e.msg); } } + + // Without debug=std_socket, still compile the slow tests, just don't run them. + debug (std_socket) + private enum runSlowTests = true; + else + private enum runSlowTests = false; } /// Base exception thrown by `std.socket`. @@ -1698,7 +1704,7 @@ public: } }); - debug (std_socket) + if (runSlowTests) softUnittest({ // test failing reverse lookup const InternetAddress ia = new InternetAddress("255.255.255.255", 80); @@ -2633,7 +2639,7 @@ private: @safe unittest { - debug (std_socket) + if (runSlowTests) softUnittest({ import std.datetime.stopwatch; import std.typecons; @@ -3000,7 +3006,7 @@ public: * Returns: The number of bytes actually sent, or `Socket.ERROR` on * failure. */ - ptrdiff_t send(const(void)[] buf, SocketFlags flags) @trusted + ptrdiff_t send(scope const(void)[] buf, SocketFlags flags) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -3014,7 +3020,7 @@ public: } /// ditto - ptrdiff_t send(const(void)[] buf) + ptrdiff_t send(scope const(void)[] buf) { return send(buf, SocketFlags.NONE); } @@ -3026,7 +3032,7 @@ public: * Returns: The number of bytes actually sent, or `Socket.ERROR` on * failure. */ - ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to) @trusted + ptrdiff_t sendTo(scope const(void)[] buf, SocketFlags flags, Address to) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -3042,7 +3048,7 @@ public: } /// ditto - ptrdiff_t sendTo(const(void)[] buf, Address to) + ptrdiff_t sendTo(scope const(void)[] buf, Address to) { return sendTo(buf, SocketFlags.NONE, to); } @@ -3050,7 +3056,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags) @trusted + ptrdiff_t sendTo(scope const(void)[] buf, SocketFlags flags) @trusted { static if (is(typeof(MSG_NOSIGNAL))) { @@ -3065,7 +3071,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t sendTo(const(void)[] buf) + ptrdiff_t sendTo(scope const(void)[] buf) { return sendTo(buf, SocketFlags.NONE); } @@ -3077,7 +3083,7 @@ public: * Returns: The number of bytes actually received, `0` if the remote side * has closed the connection, or `Socket.ERROR` on failure. */ - ptrdiff_t receive(void[] buf, SocketFlags flags) @trusted + ptrdiff_t receive(scope void[] buf, SocketFlags flags) @trusted { version (Windows) // Does not use size_t { @@ -3094,7 +3100,7 @@ public: } /// ditto - ptrdiff_t receive(void[] buf) + ptrdiff_t receive(scope void[] buf) { return receive(buf, SocketFlags.NONE); } @@ -3106,7 +3112,7 @@ public: * Returns: The number of bytes actually received, `0` if the remote side * has closed the connection, or `Socket.ERROR` on failure. */ - ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, ref Address from) @trusted + ptrdiff_t receiveFrom(scope void[] buf, SocketFlags flags, ref Address from) @trusted { if (!buf.length) //return 0 and don't think the connection closed return 0; @@ -3129,7 +3135,7 @@ public: /// ditto - ptrdiff_t receiveFrom(void[] buf, ref Address from) + ptrdiff_t receiveFrom(scope void[] buf, ref Address from) { return receiveFrom(buf, SocketFlags.NONE, from); } @@ -3137,7 +3143,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t receiveFrom(void[] buf, SocketFlags flags) @trusted + ptrdiff_t receiveFrom(scope void[] buf, SocketFlags flags) @trusted { if (!buf.length) //return 0 and don't think the connection closed return 0; @@ -3158,7 +3164,7 @@ public: //assumes you connect()ed /// ditto - ptrdiff_t receiveFrom(void[] buf) + ptrdiff_t receiveFrom(scope void[] buf) { return receiveFrom(buf, SocketFlags.NONE); } @@ -3169,7 +3175,7 @@ public: * Returns: The number of bytes written to `result`. * The length, in bytes, of the actual result - very different from getsockopt() */ - int getOption(SocketOptionLevel level, SocketOption option, void[] result) @trusted + int getOption(SocketOptionLevel level, SocketOption option, scope void[] result) @trusted { socklen_t len = cast(socklen_t) result.length; if (_SOCKET_ERROR == .getsockopt(sock, cast(int) level, cast(int) option, result.ptr, &len)) @@ -3217,7 +3223,7 @@ public: } /// Set a socket option. - void setOption(SocketOptionLevel level, SocketOption option, void[] value) @trusted + void setOption(SocketOptionLevel level, SocketOption option, scope void[] value) @trusted { if (_SOCKET_ERROR == .setsockopt(sock, cast(int) level, cast(int) option, value.ptr, cast(uint) value.length)) @@ -3647,55 +3653,55 @@ class UdpSocket: Socket { checkAttributes!q{@trusted}; assert(0); } - @trusted ptrdiff_t send(const(void)[] buf, SocketFlags flags) + @trusted ptrdiff_t send(scope const(void)[] buf, SocketFlags flags) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t send(const(void)[] buf) + @safe ptrdiff_t send(scope const(void)[] buf) { checkAttributes!q{@safe}; assert(0); } - @trusted ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags, Address to) + @trusted ptrdiff_t sendTo(scope const(void)[] buf, SocketFlags flags, Address to) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t sendTo(const(void)[] buf, Address to) + @safe ptrdiff_t sendTo(scope const(void)[] buf, Address to) { checkAttributes!q{@safe}; assert(0); } - @trusted ptrdiff_t sendTo(const(void)[] buf, SocketFlags flags) + @trusted ptrdiff_t sendTo(scope const(void)[] buf, SocketFlags flags) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t sendTo(const(void)[] buf) + @safe ptrdiff_t sendTo(scope const(void)[] buf) { checkAttributes!q{@safe}; assert(0); } - @trusted ptrdiff_t receive(void[] buf, SocketFlags flags) + @trusted ptrdiff_t receive(scope void[] buf, SocketFlags flags) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t receive(void[] buf) + @safe ptrdiff_t receive(scope void[] buf) { checkAttributes!q{@safe}; assert(0); } - @trusted ptrdiff_t receiveFrom(void[] buf, SocketFlags flags, ref Address from) + @trusted ptrdiff_t receiveFrom(scope void[] buf, SocketFlags flags, ref Address from) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t receiveFrom(void[] buf, ref Address from) + @safe ptrdiff_t receiveFrom(scope void[] buf, ref Address from) { checkAttributes!q{@safe}; assert(0); } - @trusted ptrdiff_t receiveFrom(void[] buf, SocketFlags flags) + @trusted ptrdiff_t receiveFrom(scope void[] buf, SocketFlags flags) { checkAttributes!q{@trusted}; assert(0); } - @safe ptrdiff_t receiveFrom(void[] buf) + @safe ptrdiff_t receiveFrom(scope void[] buf) { checkAttributes!q{@safe}; assert(0); } - @trusted int getOption(SocketOptionLevel level, SocketOption option, void[] result) + @trusted int getOption(SocketOptionLevel level, SocketOption option, scope void[] result) { checkAttributes!q{@trusted}; assert(0); } @@ -3711,7 +3717,7 @@ class UdpSocket: Socket { checkAttributes!q{@trusted}; } - @trusted void setOption(SocketOptionLevel level, SocketOption option, void[] value) + @trusted void setOption(SocketOptionLevel level, SocketOption option, scope void[] value) { checkAttributes!q{@trusted}; } @@ -3793,11 +3799,11 @@ Socket[2] socketPair() @trusted /// @safe unittest { - immutable ubyte[] data = [1, 2, 3, 4]; + immutable ubyte[4] data = [1, 2, 3, 4]; auto pair = socketPair(); scope(exit) foreach (s; pair) s.close(); - pair[0].send(data); + pair[0].send(data[]); auto buf = new ubyte[data.length]; pair[1].receive(buf); diff --git a/libphobos/src/std/sumtype.d b/libphobos/src/std/sumtype.d index dac531ff1ae..869c36fdfe8 100644 --- a/libphobos/src/std/sumtype.d +++ b/libphobos/src/std/sumtype.d @@ -1830,7 +1830,7 @@ class MatchException : Exception template canMatch(alias handler, Ts...) if (Ts.length > 0) { - enum canMatch = is(typeof((Ts args) => handler(args))); + enum canMatch = is(typeof((ref Ts args) => handler(args))); } /// @@ -2575,6 +2575,27 @@ version (D_Exceptions) } } +// return ref +// issue: https://issues.dlang.org/show_bug.cgi?id=23101 +@safe unittest +{ + static assert(!__traits(compiles, () { + SumType!(int, string) st; + return st.match!( + function int* (string x) => assert(0), + function int* (return ref int i) => &i, + ); + })); + + SumType!(int, string) st; + static assert(__traits(compiles, () { + return st.match!( + function int* (string x) => null, + function int* (return ref int i) => &i, + ); + })); +} + private void destroyIfOwner(T)(ref T value) { static if (hasElaborateDestructor!T) diff --git a/libphobos/src/std/traits.d b/libphobos/src/std/traits.d index 18400e3e859..cc08ea638be 100644 --- a/libphobos/src/std/traits.d +++ b/libphobos/src/std/traits.d @@ -788,7 +788,8 @@ private template fqnType(T, ~ (attrs & FA.trusted ? " @trusted" : "") ~ (attrs & FA.safe ? " @safe" : "") ~ (attrs & FA.nogc ? " @nogc" : "") - ~ (attrs & FA.return_ ? " return" : ""); + ~ (attrs & FA.return_ ? " return" : "") + ~ (attrs & FA.live ? " @live" : ""); } string addQualifiers(string typeString, @@ -4838,7 +4839,7 @@ Returns class instance alignment. template classInstanceAlignment(T) if (is(T == class)) { - alias classInstanceAlignment = maxAlignment!(void*, typeof(T.tupleof)); + enum classInstanceAlignment = __traits(classInstanceAlignment, T); } /// diff --git a/libphobos/src/std/typecons.d b/libphobos/src/std/typecons.d index 1ee7faaee7b..8a3e22f74a9 100644 --- a/libphobos/src/std/typecons.d +++ b/libphobos/src/std/typecons.d @@ -8267,7 +8267,7 @@ if (is(T == class)) { // _d_newclass now use default GC alignment (looks like (void*).sizeof * 2 for // small objects). We will just use the maximum of filed alignments. - alias alignment = classInstanceAlignment!T; + enum alignment = __traits(classInstanceAlignment, T); alias aligned = _alignUp!alignment; static struct Scoped @@ -9418,6 +9418,8 @@ private template replaceTypeInFunctionTypeUnless(alias pred, From, To, fun) result ~= " shared"; static if (attributes & FunctionAttribute.return_) result ~= " return"; + static if (attributes & FunctionAttribute.live) + result ~= " @live"; return result; } |