Bug 14845 – [REG 2.068] some rangified Char[] functions no longer take a static array

Status
RESOLVED
Resolution
WONTFIX
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-07-28T22:33:00Z
Last change time
2015-08-03T20:49:15Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-07-28T22:33:13Z
cat > bug.d << CODE import std.string; auto test(char[25] buf) { return indexOf(buf, '\n', 10); } CODE dmd -c bug ---- bug.d(5): Error: template std.string.indexOf cannot deduce function from argument types !()(char[25], char, int), candidates are: /usr/include/dmd/phobos/std/string.d(346): std.string.indexOf(Range)(Range s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) /usr/include/dmd/phobos/std/string.d(471): std.string.indexOf(T, ulong n)(ref T[n] s, in dchar c, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!T) /usr/include/dmd/phobos/std/string.d(545): std.string.indexOf(Range)(Range s, in dchar c, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range)) /usr/include/dmd/phobos/std/string.d(641): std.string.indexOf(Range, Char)(Range s, const(Char)[] sub, in CaseSensitive cs = CaseSensitive.yes) if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && isSomeChar!Char) /usr/include/dmd/phobos/std/string.d(794): std.string.indexOf(Char1, Char2)(const(Char1)[] s, const(Char2)[] sub, in size_t startIdx, in CaseSensitive cs = CaseSensitive.yes) if (isSomeChar!Char1 && isSomeChar!Char2) ---- The old (Char)(Char[]) signatures would trigger an implicit conversion of static to dynamic arrays, the new (Range)(Range r) signatures don't. A single overload of indexOf was fixed, but we need to go through all functions that have been rangified since 2.067.0 and check for this bug. https://github.com/D-Programming-Language/phobos/pull/3191 The only fully compatible overload is (T, size_t n)(ref T[n] s), which should forward to the rangified function.
Comment #1 by bugzilla — 2015-07-31T00:12:26Z
(In reply to Martin Nowak from comment #0) > The only fully compatible overload is (T, size_t n)(ref T[n] s), which > should forward to the rangified function. The trouble with such overloads is they produce a new instance for every different array size. This can result in an unnoticed blizzard of bloat. I think this should be marked as "wontfix".
Comment #2 by k.hara.pg — 2015-07-31T12:06:42Z
And as my humble opinion, I feel a "rangified funciton" accepts *only* ranges. By definition, static array is not range. So when I use that, I think the explicit slice for the static array is necessary in order to get its range view.
Comment #3 by code — 2015-08-01T18:46:29Z
(In reply to Walter Bright from comment #1) > The trouble with such overloads is they produce a new instance for every > different array size. This can result in an unnoticed blizzard of bloat. Well than you mark that function as always inline. It only slices that static array and forwards that. > I think this should be marked as "wontfix". Didn't we have a strong commitment to no longer break code? We should add those overloads, but can deprecate them IMO. (In reply to Kenji Hara from comment #2) > And as my humble opinion, I feel a "rangified funciton" accepts *only* > ranges. Exactly rangified, those functions didn't took a ranges before and now they *only* take ranges.
Comment #4 by bugzilla — 2015-08-01T20:09:42Z
(In reply to Martin Nowak from comment #3) > Well than you mark that function as always inline. Code is still generated for it. > Didn't we have a strong commitment to no longer break code? We do have a strong commitment to that. It is not an absolute commitment, nor is it a commitment we should follow without using judgment. It is an undue burden to add all these overloads everywhere, and those overloads encourage and hide a bad practice.
Comment #5 by code — 2015-08-03T18:44:18Z
(In reply to Walter Bright from comment #4) > It is an undue burden to add all these overloads everywhere, and those > overloads encourage and hide a bad practice. That's why I suggested to deprecate them.
Comment #6 by code — 2015-08-03T19:18:34Z
(In reply to Walter Bright from comment #4) > It is an undue burden to add all these overloads everywhere, and those > overloads encourage and hide a bad practice. What burden, it's a bunch of one-liners? Ignoring this in the first place already broke vibe.d b/c of indexOf. Who knows what code gets used by the rest of the function and every tiny breaking change fragments the supported dmd versions of dub packages, making it unnecessarily hard for people. The only way we can improve on compiler/language stability is to take it serious.
Comment #7 by code — 2015-08-03T20:49:15Z
Mmh, even the static array overload doesn't work. For whatever reason/bug the ref to a static array gets matched when being called with a string literal. /// Ditto deprecated("Please slice the static array before calling chomp.") auto chomp(C1, size_t n)(ref C1[n] str) if (isSomeChar!C1) { C1[] slice = str[]; return chomp(slice); }