summaryrefslogtreecommitdiff
path: root/libphobos/src
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2024-01-28 12:23:14 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2024-02-03 12:03:37 +0100
commit51c4eb28c192ecff4463c973a0ff089e04a80b89 (patch)
tree160ac2ef2c9d732681e96577ef0009027092aea6 /libphobos/src
parent854b8555bd49ad97c336b8df7098e725dc196e4f (diff)
d: Merge dmd. druntime e770945277, phobos 6d6e0b9b9
D front-end changes: - Import latest fixes from dmd v2.107.0-beta.1. - Hex strings can now be cast to integer arrays. - Add support for Interpolated Expression Sequences. D runtime changes: - Import latest fixes from druntime v2.107.0-beta.1. - New core.interpolation module to provide run-time support for D interpolated expression sequence literals. Phobos changes: - Import latest fixes from phobos v2.107.0-beta.1. - `std.range.primitives.isBidirectionalRange', and `std.range.primitives.isRandomAccessRange' now take an optional element type. gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd e770945277. * Make-lang.in (D_FRONTEND_OBJS): Add d/basicmangle.o, d/enumsem.o, d/funcsem.o, d/templatesem.o. * d-builtins.cc (build_frontend_type): Update for new front-end interface. * d-codegen.cc (declaration_type): Likewise. (parameter_type): Likewise. * d-incpath.cc (add_globalpaths): Likewise. (add_filepaths): Likewise. (add_import_paths): Likewise. * d-lang.cc (d_init_options): Likewise. (d_handle_option): Likewise. (d_parse_file): Likewise. * decl.cc (DeclVisitor::finish_vtable): Likewise. (DeclVisitor::visit (FuncDeclaration *)): Likewise. (get_symbol_decl): Likewise. * expr.cc (ExprVisitor::visit (StringExp *)): Likewise. Implement support for 8-byte hexadecimal strings. * typeinfo.cc (create_tinfo_types): Update internal TypeInfo representation. (TypeInfoVisitor::visit (TypeInfoConstDeclaration *)): Update for new front-end interface. (TypeInfoVisitor::visit (TypeInfoInvariantDeclaration *)): Likewise. (TypeInfoVisitor::visit (TypeInfoSharedDeclaration *)): Likewise. (TypeInfoVisitor::visit (TypeInfoWildDeclaration *)): Likewise. (TypeInfoVisitor::visit (TypeInfoClassDeclaration *)): Move data for TypeInfo_Class.nameSig to the end of the object. (create_typeinfo): Update for new front-end interface. libphobos/ChangeLog: * libdruntime/MERGE: Merge upstream druntime e770945277. * libdruntime/Makefile.am (DRUNTIME_SOURCES): Add core/interpolation.d. * libdruntime/Makefile.in: Regenerate. * src/MERGE: Merge upstream phobos 6d6e0b9b9.
Diffstat (limited to 'libphobos/src')
-rw-r--r--libphobos/src/MERGE2
-rw-r--r--libphobos/src/std/bitmanip.d6
-rw-r--r--libphobos/src/std/range/primitives.d99
3 files changed, 98 insertions, 9 deletions
diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE
index b04aee2c581..1d41231db9d 100644
--- a/libphobos/src/MERGE
+++ b/libphobos/src/MERGE
@@ -1,4 +1,4 @@
-c6e1f98fab2cac046ed631b5c26c850a323aea53
+6d6e0b9b9fb5e882c7296f719baf829feb4939a3
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/bitmanip.d b/libphobos/src/std/bitmanip.d
index e9f61919b0d..c9813e35476 100644
--- a/libphobos/src/std/bitmanip.d
+++ b/libphobos/src/std/bitmanip.d
@@ -263,9 +263,9 @@ Implementation_details: `Bitfields` are internally stored in an
`ubyte`, `ushort`, `uint` or `ulong` depending on the number of bits
used. The bits are filled in the order given by the parameters,
starting with the lowest significant bit. The name of the (private)
-variable used for saving the `bitfield` is created by a prefix `_bf`
-and concatenating all of the variable names, each preceded by an
-underscore.
+variable used for saving the `bitfield` is created by concatenating
+all of the variable names, each preceded by an underscore, and
+a suffix `_bf`.
Params: T = A list of template parameters divided into chunks of 3
items. Each chunk consists (in this order) of a type, a
diff --git a/libphobos/src/std/range/primitives.d b/libphobos/src/std/range/primitives.d
index fec5c85cbef..dddcae9afd2 100644
--- a/libphobos/src/std/range/primitives.d
+++ b/libphobos/src/std/range/primitives.d
@@ -1011,6 +1011,15 @@ have a `save` function.
See_Also:
The header of $(MREF std,range) for tutorials on ranges.
+
+Params:
+ R = type to be tested
+ E = if present, the elements of the range must be
+ $(DDSUBLINK spec/const3, implicit_qualifier_conversions, qualifier-convertible)
+ to this type
+
+Returns:
+ `true` if R is a forward range (possibly with element type `E`), `false` if not
*/
enum bool isForwardRange(R) = isInputRange!R
&& is(typeof((R r) { return r.save; } (R.init)) == R);
@@ -1068,12 +1077,25 @@ element in the range. Calling `r.back` is allowed only if calling
See_Also:
The header of $(MREF std,range) for tutorials on ranges.
+
+Params:
+ R = type to be tested
+ E = if present, the elements of the range must be
+ $(DDSUBLINK spec/const3, implicit_qualifier_conversions, qualifier-convertible)
+ to this type
+
+Returns:
+ `true` if R is a bidirectional range (possibly with element type `E`), `false` if not
*/
enum bool isBidirectionalRange(R) = isForwardRange!R
&& is(typeof((R r) => r.popBack))
&& (is(typeof((return ref R r) => r.back)) || is(typeof(ref (return ref R r) => r.back)))
&& is(typeof(R.init.back.init) == ElementType!R);
+/// ditto
+enum bool isBidirectionalRange(R, E) =
+ .isBidirectionalRange!R && isQualifierConvertible!(ElementType!R, E);
+
///
@safe unittest
{
@@ -1084,6 +1106,18 @@ enum bool isBidirectionalRange(R) = isForwardRange!R
auto t = r.back; // can get the back of the range
auto w = r.front;
static assert(is(typeof(t) == typeof(w))); // same type for front and back
+
+ // Checking the element type
+ static assert( isBidirectionalRange!(int[], const int));
+ static assert(!isBidirectionalRange!(int[], immutable int));
+
+ static assert(!isBidirectionalRange!(const(int)[], int));
+ static assert( isBidirectionalRange!(const(int)[], const int));
+ static assert(!isBidirectionalRange!(const(int)[], immutable int));
+
+ static assert(!isBidirectionalRange!(immutable(int)[], int));
+ static assert( isBidirectionalRange!(immutable(int)[], const int));
+ static assert( isBidirectionalRange!(immutable(int)[], immutable int));
}
@safe unittest
@@ -1133,6 +1167,15 @@ are bidirectional ranges only.
See_Also:
The header of $(MREF std,range) for tutorials on ranges.
+
+Params:
+ R = type to be tested
+ E = if present, the elements of the range must be
+ $(DDSUBLINK spec/const3, implicit_qualifier_conversions, qualifier-convertible)
+ to this type
+
+Returns:
+ `true` if R is a random-access range (possibly with element type `E`), `false` if not
*/
enum bool isRandomAccessRange(R) =
is(typeof(lvalueOf!R[1]) == ElementType!R)
@@ -1143,6 +1186,10 @@ enum bool isRandomAccessRange(R) =
&& (isInfinite!R || !is(typeof(lvalueOf!R[$ - 1]))
|| is(typeof(lvalueOf!R[$ - 1]) == ElementType!R));
+/// ditto
+enum bool isRandomAccessRange(R, E) =
+ .isRandomAccessRange!R && isQualifierConvertible!(ElementType!R, E);
+
///
@safe unittest
{
@@ -1171,6 +1218,18 @@ enum bool isRandomAccessRange(R) =
static if (!isInfinite!R)
static assert(is(typeof(f) == typeof(r[$ - 1])));
}
+
+ // Checking the element type
+ static assert( isRandomAccessRange!(int[], const int));
+ static assert(!isRandomAccessRange!(int[], immutable int));
+
+ static assert(!isRandomAccessRange!(const(int)[], int));
+ static assert( isRandomAccessRange!(const(int)[], const int));
+ static assert(!isRandomAccessRange!(const(int)[], immutable int));
+
+ static assert(!isRandomAccessRange!(immutable(int)[], int));
+ static assert( isRandomAccessRange!(immutable(int)[], const int));
+ static assert( isRandomAccessRange!(immutable(int)[], immutable int));
}
@safe unittest
@@ -1695,11 +1754,9 @@ For finite ranges, the result of `opSlice` must be of the same type as the
original range type. If the range defines `opDollar`, then it must support
subtraction.
-For infinite ranges, when $(I not) using `opDollar`, the result of
-`opSlice` must be the result of $(LREF take) or $(LREF takeExactly) on the
-original range (they both return the same type for infinite ranges). However,
-when using `opDollar`, the result of `opSlice` must be that of the
-original range type.
+For infinite ranges, when $(I not) using `opDollar`, the result of `opSlice`
+may be a forward range of any type. However, when using `opDollar`, the result
+of `opSlice` must be of the same type as the original range type.
The following expression must be true for `hasSlicing` to be `true`:
@@ -1774,6 +1831,38 @@ enum bool hasSlicing(R) = isForwardRange!R
static assert(hasSlicing!InfOnes);
}
+// https://issues.dlang.org/show_bug.cgi?id=24348
+@safe unittest
+{
+ static struct Slice
+ {
+ size_t length;
+ bool empty() => length == 0;
+ int front() => 0;
+ void popFront() { --length; }
+ Slice save() => this;
+ }
+
+ static struct InfZeros
+ {
+ enum empty = false;
+ int front() => 0;
+ void popFront() {}
+ InfZeros save() => this;
+
+ Slice opIndex(size_t[2] bounds)
+ {
+ size_t i = bounds[0], j = bounds[1];
+ size_t length = i <= j ? j - i : 0;
+ return Slice(length);
+ }
+
+ size_t[2] opSlice(size_t dim : 0)(size_t i, size_t j) => [i, j];
+ }
+
+ static assert(hasSlicing!InfZeros);
+}
+
/**
This is a best-effort implementation of `length` for any kind of
range.