Fix Phobos dependencies on autodecoding

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Tue Aug 13 07:51:23 UTC 2019


On Tuesday, 13 August 2019 at 07:31:28 UTC, a11e99z wrote:
> On Tuesday, 13 August 2019 at 07:08:03 UTC, Walter Bright wrote:
>> We don't yet have a good plan on how to remove autodecoding 
>> and yet provide backward compatibility with 
>> autodecoding-reliant projects, but one thing we can do is make 
>> Phobos work properly with and without autodecoding.
>>
>> To that end, I created a build of Phobos that disables 
>> autodecoding:
>>
>> https://github.com/dlang/phobos/pull/7130
>>
>> Of course, it fails. If people want impactful things to work 
>> on, fixing each failure is worthwhile (each in separate PRs).
>>
>> Note that this is neither trivial nor mindless code editing. 
>> Each case has to be examined as to why it is doing 
>> autodecoding, is autodecoding necessary, and deciding to 
>> replace it with byChar, byDchar, or simply hardcoding the 
>> decoding logic.
>
> imo autodecoding is one of right thing.
> maybe will be better to leave it as is and just to add
>> immutable(ubyte)[] bytes( string str ) @nogc nothrow {
>>     return *cast( immutable(ubyte)[]* )&str;
>> }
> and use it as
>> foreach( b; "Привет, Мир!".bytes) // Hello world in RU
>>     writefln( "%x", b );          // 21 bytes, 12 runes
> ?
>
> why u decide to fight with autodecoding?

One of the reasons is that it adds unnecessary complexity for 
templated code that is working with ranges. Check function 
prototypes for some algorithms found in std.algorithm package, 
you're bound to find special treatment for autodecoding strings. 
It also messes up user expectation when suddenly applying a range 
function on a string instead of front char you're getting dchar.

Best regards,
Alexandru


More information about the Digitalmars-d mailing list