April 30, 2015
On 4/29/15 8:35 PM, Martin Nowak wrote:
> Occasionally I'm using if (auto ary = func()), despite the fact that the
> semantics are wrong, but it's nice and short and works as long a func
> always returns null instead of empty slices.

I wonder if it's possible to fix this, as it is, IMO, the only legitimate drawback of this change. Could we make the following work?

if((auto ary = func()).length)

-Steve
April 30, 2015
On Wednesday, 29 April 2015 at 19:15:46 UTC, Jonathan M Davis
wrote:
> but std.allocator is definitely not your average code

OK, I'm tired of hearing this argument.

Here's the results against my ae library:

C:\Projects\ae\net\http\caching.d(97,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.uncompressedDataCache !is null,
this.uncompressedDataCache.length, or
this.uncompressedDataCache.ptr instead
C:\Projects\ae\net\http\caching.d(104,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.deflateDataCache !is null,
this.deflateDataCache.length, or this.deflateDataCache.ptr instead
C:\Projects\ae\net\http\caching.d(112,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.gzipDataCache !is null,
this.gzipDataCache.length, or this.gzipDataCache.ptr instead
C:\Projects\ae\net\http\caching.d(169,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.contentType !is null,
this.contentType.length, or this.contentType.ptr instead
C:\Projects\ae\sys\file.d(383,8): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: tmp !is null, tmp.length, or tmp.ptr instead
C:\Projects\ae\sys\file.d(971,17): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.oldPath !is null,
this.oldPath.length, or this.oldPath.ptr instead
C:\Projects\ae\sys\file.d(977,11): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.oldPath !is null,
this.oldPath.length, or this.oldPath.ptr instead
C:\Projects\ae\sys\file.d(988,6): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: dir !is null, dir.length, or dir.ptr instead
C:\Projects\ae\sys\persistence.d(142,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.fileName !is null,
this.fileName.length, or this.fileName.ptr instead
C:\Projects\ae\sys\persistence.d(157,11): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.fileName !is null,
this.fileName.length, or this.fileName.ptr instead
C:\Projects\ae\utils\xmlsel.d(84,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: tag !is null, tag.length, or tag.ptr
instead
C:\Projects\ae\utils\xmlsel.d(86,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: id !is null, id.length, or id.ptr instead
C:\Projects\ae\utils\xmlsel.d(88,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: cls !is null, cls.length, or cls.ptr
instead
C:\Projects\ae\net\http\server.d(357,4): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: vhost !is null, vhost.length, or
vhost.ptr instead
C:\Projects\ae\net\ietf\message.d(166,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: rawContent !is null, rawContent.length,
or rawContent.ptr instead
C:\Projects\ae\net\ietf\message.d(168,9): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.mimeType !is null,
this.mimeType.length, or this.mimeType.ptr instead
C:\Projects\ae\net\ietf\message.d(188,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: part.content !is null,
part.content.length, or part.content.ptr instead
C:\Projects\ae\net\ietf\message.d(188,27): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.content !is null,
this.content.length, or this.content.ptr instead
C:\Projects\ae\net\ietf\message.d(193,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.content !is null,
this.content.length, or this.content.ptr instead
C:\Projects\ae\net\ietf\message.d(354,35): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.id !is null, this.id.length, or
this.id.ptr instead
C:\Projects\ae\net\ietf\message.d(451,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.id !is null, this.id.length, or
this.id.ptr instead
C:\Projects\ae\net\http\client.d(65,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.currentRequest.data !is null,
this.currentRequest.data.length, or this.currentRequest.data.ptr
instead
C:\Projects\ae\sys\install\dmc.d(32,65): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.ver !is null, this.ver.length, or
this.ver.ptr instead
C:\Projects\ae\sys\net\curl.d(61,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: result !is null, result.length, or
result.ptr instead
C:\Projects\ae\utils\xmlbuild.d(75,29): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: (*__withSym).text !is null,
(*__withSym).text.length, or (*__withSym).text.ptr instead
C:\Projects\ae\net\irc\client.d(610,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: reason !is null, reason.length, or
reason.ptr instead
C:\Projects\ae\sys\vfs\package.d(103,17): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: getVFSName(path) !is null,
getVFSName(path).length, or getVFSName(path).ptr instead
C:\Projects\ae\utils\bench.d(46,6): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: action !is null, action.length, or
action.ptr instead
C:\Projects\ae\utils\bench.d(46,16): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: currentAction !is null,
currentAction.length, or currentAction.ptr instead
C:\Projects\ae\utils\bench.d(46,16): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: currentAction !is null,
currentAction.length, or currentAction.ptr instead
C:\Projects\ae\sys\file.d(176,7): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: dir !is null, dir.length, or dir.ptr instead
C:\Projects\ae\sys\file.d(40,13): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: pattern !is null, pattern.length, or pattern.ptr
instead
C:\Projects\ae\sys\file.d(46,27): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: pattern !is null, pattern.length, or pattern.ptr
instead
C:\Projects\ae\sys\file.d(46,27): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: pattern !is null, pattern.length, or pattern.ptr
instead
C:\Projects\ae\sys\file.d(213,7): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: dir !is null, dir.length, or dir.ptr instead
C:\Projects\ae\sys\paths.d(59,45): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: appName !is null, appName.length, or
appName.ptr instead
C:\Projects\ae\net\nntp\listener.d(60,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.lastDate !is null,
this.lastDate.length, or this.lastDate.ptr instead
C:\Projects\ae\net\dns\dnsbl.d(81,6): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: result !is null, result.length, or
result.ptr instead
C:\Projects\ae\net\dns\dnsbl.d(84,6): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: result !is null, result.length, or
result.ptr instead
C:\Projects\ae\net\irc\server.d(78,36): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.server.addressMask !is null,
this.server.addressMask.length, or this.server.addressMask.ptr
instead
C:\Projects\ae\net\irc\server.d(191,33): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: channel.modes.strings[107] !is null,
channel.modes.strings[107].length, or
channel.modes.strings[107].ptr instead
C:\Projects\ae\net\irc\server.d(254,78): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: channel.topic !is null,
channel.topic.length, or channel.topic.ptr instead
C:\Projects\ae\net\irc\server.d(292,15): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: mask !is null, mask.length, or mask.ptr
instead
C:\Projects\ae\net\irc\server.d(304,14): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: mask !is null, mask.length, or mask.ptr
instead
C:\Projects\ae\net\irc\server.d(321,37): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: mask !is null, mask.length, or mask.ptr
instead
C:\Projects\ae\net\irc\server.d(363,9): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: client.away !is null, client.away.length,
or client.away.ptr instead
C:\Projects\ae\net\irc\server.d(413,12): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.server.operPassword !is null,
this.server.operPassword.length, or this.server.operPassword.ptr
instead
C:\Projects\ae\net\irc\server.d(460,9): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.server.password !is null,
this.server.password.length, or this.server.password.ptr instead
C:\Projects\ae\net\irc\server.d(611,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: channel.topic !is null,
channel.topic.length, or channel.topic.ptr instead
C:\Projects\ae\net\irc\server.d(642,32): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: channel.modes.strings[cast(ulong)c] !is
null, channel.modes.strings[cast(ulong)c].length, or
channel.modes.strings[cast(ulong)c].ptr instead
C:\Projects\ae\net\irc\server.d(790,35): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: channel.modes.strings[cast(ulong)c] !is
null, channel.modes.strings[cast(ulong)c].length, or
channel.modes.strings[cast(ulong)c].ptr instead
C:\Projects\ae\net\irc\server.d(1041,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.network !is null,
this.network.length, or this.network.ptr instead
C:\Projects\ae\sys\log.d(34,7): Warning: implicit conversion of
dynamic arrays to bool can be ambiguous and will be deprecated.
Use one of: logDir !is null, logDir.length, or logDir.ptr instead
C:\Projects\ae\net\http\responseex.d(145,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: mimeType !is null, mimeType.length, or
mimeType.ptr instead
C:\Projects\ae\net\http\responseex.d(230,27): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: details !is null, details.length, or
details.ptr instead
C:\Projects\ae\net\http\responseex.d(241,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: location !is null, location.length, or
location.ptr instead
C:\Projects\ae\sys\windows\exception.d(55,6): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: cond !is null, cond.length, or cond.ptr
instead
C:\Projects\ae\sys\net\wininet.d(230,10): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: location !is null, location.length, or
location.ptr instead
C:\Projects\ae\sys\net\ae.d(95,10): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: result !is null, result.length, or
result.ptr instead
C:\Projects\ae\sys\d\manager.d(152,9): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.git.path !is null,
this.git.path.length, or this.git.path.ptr instead
C:\Projects\ae\sys\d\manager.d(235,9): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.git.path !is null,
this.git.path.length, or this.git.path.ptr instead
C:\Soft\dmd2d\windows\bin\..\..\src\phobos\std\exception.d(351,10):
Warning: implicit conversion of dynamic arrays to bool can be
ambiguous and will be deprecated. Use one of: value !is null,
value.length, or value.ptr instead
C:\Projects\ae\sys\d\manager.d(1090,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.config.deps.hostDC !is null,
this.config.deps.hostDC.length, or this.config.deps.hostDC.ptr
instead
C:\Projects\ae\sys\d\manager.d(1104,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.config.deps.dmcDir !is null,
this.config.deps.dmcDir.length, or this.config.deps.dmcDir.ptr
instead
C:\Projects\ae\sys\d\manager.d(1109,15): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: ver !is null, ver.length, or ver.ptr
instead
C:\Projects\ae\sys\d\manager.d(1123,8): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.config.deps.vsDir !is null,
this.config.deps.vsDir.length, or this.config.deps.vsDir.ptr
instead
C:\Projects\ae\sys\windows\exception.d(46,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: str !is null, str.length, or str.ptr
instead
C:\Projects\ae\sys\config.d(34,9): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: appName !is null, appName.length, or
appName.ptr instead
C:\Projects\ae\sys\config.d(36,8): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: companyName !is null, companyName.length,
or companyName.ptr instead
C:\Projects\ae\net\http\common.d(92,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: protocol !is null, protocol.length, or
protocol.ptr instead
C:\Soft\dmd2d\windows\bin\..\..\src\phobos\std\functional.d-mixin-119(119,1):
Warning: implicit conversion of dynamic arrays to bool can be
ambiguous and will be deprecated. Use one of: __a !is null,
__a.length, or __a.ptr instead
C:\Projects\ae\net\http\common.d(470,7): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: acceptEncoding !is null,
acceptEncoding.length, or acceptEncoding.ptr instead
C:\Projects\ae\utils\feed.d(72,7): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: link !is null, link.length, or link.ptr
instead
C:\Projects\ae\sys\d\repo.d(41,10): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.git.path !is null,
this.git.path.length, or this.git.path.ptr instead
C:\Projects\ae\sys\d\repo.d(81,8): Warning: implicit conversion
of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.currentHead !is null,
this.currentHead.length, or this.currentHead.ptr instead
C:\Projects\ae\sys\persistence.d(157,11): Warning: implicit
conversion of dynamic arrays to bool can be ambiguous and will be
deprecated. Use one of: this.fileName !is null,
this.fileName.length, or this.fileName.ptr instead

I didn't examine every single one, but the first dozen are all
false positives.

Oh, and note the few that occur in Phobos templates (with no
instantiation trace). I'll have fun tracking those down!
April 30, 2015
On 4/29/15 10:41 PM, Steven Schveighoffer wrote:
> On 4/29/15 4:29 AM, Iain Buclaw via Digitalmars-d wrote:

>> if (dg)  // Implicitly converted to (dg.ptr | dg.funcptr) != 0
>
> I don't know if I've ever expected that, you sure that's true? I would
> actually expect if(dg) to be equivalent to if(dg.funcptr). I have no
> idea how a dg would have a null pointer but valid funcptr.

reverse that, I don't know how a dg would have a null funcptr but valid ptr.

>
>> if (aa)  // Implicitly converted to (aa.ptr != null)
>
> This is easily fixed when we fix aa to be a library type. We don't need
> compiler help to fix this issue (we do need compiler help to remove AA
> specialty code from the compiler, but once it's out, we can fix this
> without effort).

Hah! without *compiler* effort :)

-Steve
April 30, 2015
On Thursday, 30 April 2015 at 02:44:22 UTC, Steven Schveighoffer wrote:
> On 4/29/15 8:35 PM, Martin Nowak wrote:
>> Occasionally I'm using if (auto ary = func()), despite the fact that the
>> semantics are wrong, but it's nice and short and works as long a func
>> always returns null instead of empty slices.
>
> I wonder if it's possible to fix this, as it is, IMO, the only legitimate drawback of this change. Could we make the following work?
>
> if((auto ary = func()).length)

Another thing to consider is how this is a general problem. It's not that atypical to want to declare a variable in the if condition and then use a function call on it for the actual condition, which it looks like your suggestion would work with, but if we consider a solution like that, I think that we need to consider the general case and not just checking for length on arrays.

Another syntax might be something like

if(auto ary = func(); ary.length)

and make it similar to how for loops work. That would also allow you to check stuff other than what the variable gets initialized with or to use it in a more complicated expression. e.g.

if(auto ary = func(); foo(ary))

It's also arguably more consistent with other language features. But regardless, the general idea of what you're proposing could provide some good syntactic sugar.

- Jonathan M Davis
April 30, 2015
On 30 April 2015 at 04:41, Steven Schveighoffer via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On 4/29/15 4:29 AM, Iain Buclaw via Digitalmars-d wrote:
>>
>> On 29 April 2015 at 06:38, Steven Schveighoffer via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>>>
>>> FYI, Andrei and Walter are reversing this change barring any new evidence it's helpful to people. Please speak up if you disagree.
>>>
>>>
>>> https://github.com/D-Programming-Language/dmd/pull/2885#issuecomment-97299912
>>>
>>
>> I disagree, and I would extend my thoughts to say that I don't think that the change is enough.  We should also be warning on delegates and associative arrays too!
>>
>> if (arr)  // Implicitly converted to (arr.ptr | arr.length) != 0
>
> if(arr) simply means if(arr.ptr) != 0. Length does not come into play.
>

https://github.com/D-Programming-Language/dlang.org/pull/981#commitcomment-10918439

The two mov's followed by an 'or' suspiciously look like (.ptr | .length) to me.

>> if (dg)  // Implicitly converted to (dg.ptr | dg.funcptr) != 0
>
>
> I don't know if I've ever expected that, you sure that's true? I would
> actually expect if(dg) to be equivalent to if(dg.funcptr). I have no idea
> how a dg would have a null pointer but valid funcptr.
>

Yes, it does (it emits the same assembly as arrays).

>> if (aa)  // Implicitly converted to (aa.ptr != null)
>
>
> This is easily fixed when we fix aa to be a library type. We don't need compiler help to fix this issue (we do need compiler help to remove AA specialty code from the compiler, but once it's out, we can fix this without effort).
>

It's still annoying to have to special-case non-scalar types in boolean contexts.  The front-end should do this lowering. :-)

https://github.com/D-Programming-GDC/GDC/blob/e9bfc0332e42d01402aeb2063d38fc5ea4e12fea/gcc/d/d-codegen.cc#L605

Iain.
April 30, 2015
On Wednesday, 29 April 2015 at 17:35:58 UTC, Andrei Alexandrescu wrote:
> I have no doubt the change can find certain errors. Problem is false positives. FWIW these are the changes I had to operate on std.allocator to make it work with the new compiler.

That code is contrived, confusing and consequently bug-prone, I'd say compiler complaints are legit in those cases, they are not as false positive as you want to make it look like. All in all your argument is quite biased and impractical.
April 30, 2015
Andrei Alexandrescu:

> I have no doubt the change can find certain errors. Problem is false positives. FWIW these are the changes I had to operate on std.allocator to make it work with the new compiler. One per 194 lines on average, all false positives:

Just fix your code Andrei Alexandrescu :-)

Bye,
bearophile
April 30, 2015
On Thursday, 30 April 2015 at 02:51:33 UTC, Vladimir Panteleev wrote:
> OK, I'm tired of hearing this argument.

Distinction between null and empty can be done, the problem is it doesn't fly in mainstream.
April 30, 2015
"Vladimir Panteleev"  wrote in message news:ajrysqkjmlqjlmkipboz@forum.dlang.org...

> On Wednesday, 29 April 2015 at 19:15:46 UTC, Jonathan M Davis
> wrote:
> > but std.allocator is definitely not your average code
>
> OK, I'm tired of hearing this argument.

It's valid though.  Most array code cares more about the contents than the address, while std.allocator only cares about the address.

> Here's the results against my ae library:
...
> I didn't examine every single one, but the first dozen are all
> false positives.

Yeah, looks like you're intentionally checking for null rather than empty. It sucks that so many places need updating.

> Oh, and note the few that occur in Phobos templates (with no
> instantiation trace). I'll have fun tracking those down!

Is that from string lambdas?  Does it give an instantiation trace when you use it with warning as errors? 

April 30, 2015
On Thursday, 30 April 2015 at 11:46:05 UTC, Daniel Murphy wrote:
> Is that from string lambdas?

I don't know. The one in std.exception is probably due to an array being used as a condition for enforce.

> Does it give an instantiation trace when you use it with warning as errors?

It doesn't.