February 07, 2018
On 2/7/2018 11:29 AM, Ralph Doncaster wrote:
> I just did a quick check, and with DMD v2.078.1, the hexString template increases code size by ~300 bytes vs the hex literal. So yet one more reason to prefer the hex literals.

Indeed it does, and that is the result of a poor implementation of hexString. I've figured out how to fix that, and hope to make a PR for it shortly.

  https://issues.dlang.org/show_bug.cgi?id=18397
February 07, 2018
On 2/7/2018 4:25 PM, H. S. Teoh wrote:
> Should templates like octal and hexString be in druntime instead?

No, because their usage by druntime is nearly nonexistent.
February 07, 2018
On 2/7/2018 5:03 PM, Seb wrote:
> On Thursday, 8 February 2018 at 00:24:22 UTC, Walter Bright wrote:
>> On 2/7/2018 8:03 AM, Ralph Doncaster wrote:
>>> As expected,
>>> auto data = cast(ubyte[]) x"deadbeef";
>>> works with -betterC, but
>>> auto data = cast(ubyte[]) hexString!"deadbeef";
>>> does not.
>>>
>>
>> When I tried it:
>>
>>   import std.conv;
>>   void test() {
>>     auto data = cast(ubyte[]) hexString!"deadbeef";
>>   }
>>
>> with:
>>
>>   dmd -c -betterC test2.d
>>
>> it compiled without complaint. Are you doing something different? (This is why posting complete examples, not snippets, is better. That way I don't have to fill in the blanks with guesswork.)
> 
> https://run.dlang.io/is/TEJDZO and hit "Run".

I wish people would say "does not link" or "links with undefined symbols" or something more helpful than "does not work" leaving me to guess.


> I also opened a Bugzilla issue, s.t. it doesn't get lost https://issues.dlang.org/show_bug.cgi?id=18395

February 07, 2018
On Thu, Feb 08, 2018 at 02:39:50AM +0000, Adam D. Ruppe via Digitalmars-d wrote:
> On Thursday, 8 February 2018 at 01:55:19 UTC, Walter Bright wrote:
> > No, because their usage by druntime is nearly nonexistent.
> 
> Only because they're not supported!
> 
> Code like `0xsomething // octal something else` is found a whopping 200 times in druntime (granted btw all in the core.sys bindings).

I'm guessing most of those occurrences are in interfacing with Posix (or
other OS) calls involving bitmasks, like umask().


> By contrast, the word "octal" only occurs 100 times through all of Phobos, and the octal template is used only 15 times, excluding its own unit tests.

Ironically, octal literals are probably most used in OS API calls like umask(), so .octal really should be in druntime rather than Phobos!


T

-- 
What are you when you run out of Monet? Baroque.
February 07, 2018
On Wed, Feb 07, 2018 at 05:53:43PM -0800, Walter Bright via Digitalmars-d wrote:
> On 2/7/2018 11:29 AM, Ralph Doncaster wrote:
> > I just did a quick check, and with DMD v2.078.1, the hexString template increases code size by ~300 bytes vs the hex literal. So yet one more reason to prefer the hex literals.
> 
> Indeed it does, and that is the result of a poor implementation of hexString. I've figured out how to fix that, and hope to make a PR for it shortly.
> 
>   https://issues.dlang.org/show_bug.cgi?id=18397

The bug report didn't explain what exactly in the implementation wasn't done right. :-/

Another data point: instantiating 10000 hex literals causes compilation time to bloat to 10 seconds.  While I'm not saying we should expect user code to have so many hex literals, the point is that that's unacceptably slow for D, given our motto of fast-this and fast-that.


T

-- 
Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.
February 08, 2018
On Thursday, 8 February 2018 at 01:55:19 UTC, Walter Bright wrote:
> No, because their usage by druntime is nearly nonexistent.

Only because they're not supported!

Code like `0xsomething // octal something else` is found a whopping 200 times in druntime (granted btw all in the core.sys bindings).

By contrast, the word "octal" only occurs 100 times through all of Phobos, and the octal template is used only 15 times, excluding its own unit tests.
February 07, 2018
On 2/7/2018 6:39 PM, H. S. Teoh wrote:
>> and hope to make a PR forit shortly.
>>
>>    https://issues.dlang.org/show_bug.cgi?id=18397
> 
> The bug report didn't explain what exactly in the implementation wasn't
> done right. :-/

The PR does.

https://github.com/dlang/phobos/pull/6138


> Another data point: instantiating 10000 hex literals causes compilation
> time to bloat to 10 seconds.  While I'm not saying we should expect user
> code to have so many hex literals, the point is that that's unacceptably
> slow for D, given our motto of fast-this and fast-that.

Try it with the new PR.
February 07, 2018
On 2/7/2018 6:39 PM, Adam D. Ruppe wrote:
> On Thursday, 8 February 2018 at 01:55:19 UTC, Walter Bright wrote:
>> No, because their usage by druntime is nearly nonexistent.
> 
> Only because they're not supported!
> 
> Code like `0xsomething // octal something else` is found a whopping 200 times in druntime (granted btw all in the core.sys bindings).

Nearly all of that is in 3 files, and most are copy/pasta of the same groups lines for different systems.

I didn't find any uses of x"string" at all, or my grep-fu is wanting.
February 08, 2018
On Thursday, 8 February 2018 at 00:24:22 UTC, Walter Bright wrote:
> On 2/7/2018 8:03 AM, Ralph Doncaster wrote:
>> As expected,
>> auto data = cast(ubyte[]) x"deadbeef";
>> works with -betterC, but
>> auto data = cast(ubyte[]) hexString!"deadbeef";
>> does not.
>> 
>
> When I tried it:
>
>   import std.conv;
>   void test() {
>     auto data = cast(ubyte[]) hexString!"deadbeef";
>   }
>
> with:
>
>   dmd -c -betterC test2.d
>
> it compiled without complaint. Are you doing something different? (This is why posting complete examples, not snippets, is better. That way I don't have to fill in the blanks with guesswork.)

I didn't think it would be that hard to guess I'm trying to make an executable.

ralphdoncaster@gl1u:~/code/d$ dmd -betterC hex.d
hex.o: In function `_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa':
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x2e): undefined reference to `_D11TypeInfo_Aa6__initZ'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x33): undefined reference to `_d_arraysetlengthiT'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x7c): undefined reference to `_D3std5ascii10isHexDigitFNaNbNiNfwZb'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x160): undefined reference to `_D11TypeInfo_Aa6__initZ'
hex.d:(.text._D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa[_D3std4conv__T10hexStrImplTAyaZQrFNaNbNfMQoZAa]+0x165): undefined reference to `_d_arraysetlengthiT'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
ralphdoncaster@gl1u:~/code/d$ cat hex.d
import std.conv;

extern (C) int main() {
    //auto data = cast(ubyte[]) x"deadbeef";
    auto data = cast(ubyte[]) hexString!"deadbeef";
    return cast(int) data[0];
}

While the string hex literal version works fine:
ralphdoncaster@gl1u:~/code/d$ dmd -betterC hex.d
ralphdoncaster@gl1u:~/code/d$ ./hex
ralphdoncaster@gl1u:~/code/d$ echo $?
222
ralphdoncaster@gl1u:~/code/d$ cat hex.d
//import std.conv;

extern (C) int main() {
    auto data = cast(ubyte[]) x"deadbeef";
    //auto data = cast(ubyte[]) hexString!"deadbeef";
    return cast(int) data[0];
}

February 08, 2018
On Thursday, 8 February 2018 at 01:27:46 UTC, Seb wrote:
> On Thursday, 8 February 2018 at 00:55:28 UTC, Seb wrote:
>> On Wednesday, 7 February 2018 at 15:41:37 UTC, Seb wrote:
>>> On Wednesday, 7 February 2018 at 15:25:05 UTC, Steven Schveighoffer wrote:
>>>> [...]
>>>
>>> They are deprecated:
>>>
>>> https://dlang.org/changelog/pending.html#hexstrings
>>> https://dlang.org/deprecate.html#Hexstring%20literals
>>>
>>> Hence, the grammar has been incompletely updated. As it's not an error to use them now, it should have stated that they are deprecated.
>>>
>>> Anyhow, you can always go back in time:
>>>
>>> https://docarchives.dlang.io/v2.078.0/spec/lex.html#HexString
>>
>> PR: https://github.com/dlang/dlang.org/pull/2190
>
> ... and back online: http://dlang.org/spec/lex.html#hex_strings

I'm impressed.  I think I'll keep using D for at least a little while longer.  While it has it warts, I'm attracted to a language that has an intelligent group of people working to cauterize those warts.