Conversation
6fb2481 to
aa34160
Compare
|
Shouldn't the restriction be that it be |
|
the doc unittest could use some more failing asserts |
|
Ping @andralex |
|
ping @andralex |
|
I plan to be more aggressive about this: if an artifact defines |
|
Ping @MartinNowak |
std/range/primitives.d
Outdated
| This is because a narrow string's length does not reflect the number of | ||
| characters, but instead the number of encoding units, and as such is not useful | ||
| with range-oriented algorithms. To use strings as random-access ranges with | ||
| length, use $(XREF string, representation) or $(XREF utf, byCodeUnit). */ |
There was a problem hiding this comment.
The XREF macro was deprecated, please use the universal REF, e.g. `$(REF, byCodeUnit, std, utf)
How about hacking template constraints together for a pseudo-deprecation message as we private enum bool oldHasLengthImpl(R) = !isNarrowString!R && is(typeof(
(inout int = 0)
{
R r = R.init;
ulong l = r.length;
}));
private enum bool newHasLengthImpl(R) = !isNarrowString!R && is(typeof(
(inout int = 0)
{
R r = R.init;
auto x = r.length;
static assert(is(typeof(x) == size_t) || is(typeof(x) == ulong));
}));
template hasLength(R)
if (oldHasLengthImpl!R && newHasLengthImpl!R)
{
enum bool hasLength = true;
}
template hasLength(R)
if (oldHasLengthImpl!R && !newHasLengthImpl!R)
{
pragma(msg, "Deprecation: length of " ~ R.stringof ~ " needs to return size_t or ulong");
enum bool hasLength = true;
}
template hasLength(R)
if (!oldHasLengthImpl!R)
{
enum bool hasLength = false;
}In Phobos there is only this one violation in |
|
ping @andralex |
cf8223e to
7d411b0
Compare
da69804 to
0e86125
Compare
|
OK, this is reviewable now. The new solution is nicer than the |
| { | ||
| // Uncomment the deprecated(...) message and take the pragma(msg) | ||
| // out once https://issues.dlang.org/show_bug.cgi?id=10181 is fixed. | ||
| pragma(msg, __FILE__ ~ "(" ~ __LINE__.stringof ~ |
There was a problem hiding this comment.
You should probably include an @@@deprecated... comment and deprecation end date here, so that one can easily grep for it and remove this bit eventually.
std/range/primitives.d
Outdated
| // Uncomment the deprecated(...) message and take the pragma(msg) | ||
| // out once https://issues.dlang.org/show_bug.cgi?id=10181 is fixed. | ||
| pragma(msg, __FILE__ ~ "(" ~ __LINE__.stringof ~ | ||
| "): Deprecation: length must have type size_t on all systems"); |
There was a problem hiding this comment.
I'd rather not imitate the compiler's message format, as it might be confusing for people compiling with deprecation warnings as errors, or who have them disabled entirely. LGTM otherwise.
|
Updated |
| { | ||
| enum bool hasLength = !isNarrowString!R; | ||
| } | ||
| else static if (is(Length : ulong)) |
There was a problem hiding this comment.
Any reason why you mix the Length == size_t and Length : ulong styles?
There was a problem hiding this comment.
These aren't styles. == checks for exact match, : is convertibility.
std/range/primitives.d
Outdated
| range-oriented algorithms. | ||
| */ | ||
| Yields `true` if `R` has a `length` member that returns a value of either | ||
| `size_t` or `ulong` type. `R` does not have to be a range. If `R` is a range, |
There was a problem hiding this comment.
Shouldn't this be updated as well if you deprecate ulong?
|
|
@andralex I changed your commit message, s.t. the bug can detect the issue and added a small changelog entry (basically just copied your last paragraph). |
wilzbach
left a comment
There was a problem hiding this comment.
Let's get this shipped ;-)
| // @@@DEPRECATED_2017-12@@@ | ||
| // Uncomment the deprecated(...) message and take the pragma(msg) | ||
| // out once https://issues.dlang.org/show_bug.cgi?id=10181 is fixed. | ||
| pragma(msg, __FILE__ ~ "(" ~ __LINE__.stringof ~ |
There was a problem hiding this comment.
How is the FILE and LINE of std.range.primitives interesting here? You'd need to pass them as defaults for template arguments to get the instantiating side.
There was a problem hiding this comment.
They emulate what the deprecated facility does.
Fixes https://issues.dlang.org/show_bug.cgi?id=16566.
hasLengthwas in fact intended to allow only integrals, but its code predatesalias thisand we didn't update it.Throughout Phobos we use interchangeably
auto s = r.length;,size_t s = r.length;, cache the length of a range in a variable, or just use it as asize_t. Supporting other types thansize_tmeaningfully would put too much burden on the definition and the implementation.