no-autodecode -- game plan

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Wed Aug 19 13:35:34 UTC 2020


On 8/19/20 8:23 AM, Steven Schveighoffer wrote:
> On 8/18/20 6:21 PM, Andrei Alexandrescu wrote:
>> On 8/16/20 1:00 PM, Steven Schveighoffer wrote:
>>> Hi all,
>>>
>>> TL;DR: I'm working on removing autodecoding from phobos. I have the 
>>> first real PR: https://github.com/dlang/phobos/pull/7595
>>
>> Why not do it in std.v2021.*?
>>
> 
> What do you mean? Have a complete alternative phobos library?

We discussed this here a couple of times before - just add a new package 
v2021 in std. Inside it, alias all declarations that you don't plan to 
change to the corresponding symbols in std, then add declarations for 
the things you do want to change.

It's like patching - you only add the deltas. It's simple and easy to 
set up.

> autodecoding infects so many other modules, so it would be really hard 
> to single out only some modules, we'd likely have to make a copy of 
> nearly everything.

I wouldn't be so sure. I think there are large swaths of the stdlib that 
don't do anything with autodecoding. Like, threading stuff, parallel 
stuff, file stuff, numeric stuff, conversion stuff (sans strings), most 
of datetime stuff, and probably a ton more. I know there's likely to 
find some autodecoding parts in the above but the point is they are not 
about strings or autodecoding.

Even those that do can be arranged so you only write deltas. Let me pick 
one at random:

// Current code
auto cmp(R1, R2)(R1 r1, R2 r2)
if (isInputRange!R1 && isInputRange!R2)
{
     ... somewhere inside ...
     static if (isDynamicArray!R1 && isDynamicArray!R2
         && __traits(isUnsigned, E1) && __traits(isUnsigned, E2)
         && E1.sizeof == 1 && E2.sizeof == 1
         // Both or neither must auto-decode.
         && (is(immutable E1 == immutable char) == is(immutable E2 == 
immutable char)))
     {
         ... special case arrays of ubyte/char ...
     }
     else static if (!(isSomeString!R1 && isSomeString!R2))
     {
         ... not influenced by autodecoding ...
     }
     else
     {
         ... autodecode stuff ...
     }
}


// New code in std.v2021
auto cmp(R1, R2)(R1 r1, R2 r2)
if (isInputRange!R1 && isInputRange!R2)
{
     enum bool influencedByAutodecode = ...;
     static if (!influencedByAutodecode)
         return std.cmp(r1, r2);
     else
     {
         ... patch ...
     }
}

Even the patch can reuse std.cmp if you pass std.cmp a range of code 
units so you undo its penchant to autodecode.

* * *

Lastly, I should add the following. You wrote, and I quote it again 
because it is so important:

> autodecoding infects so many other modules, so it would be really hard 
> to single out only some modules, we'd likely have to make a copy of 
> nearly everything.

This is a very powerful argument AGAINST your current approach to CHANGE 
things. You are basically saying the semantics of the standard library 
will be deeply affected by your work. Put another way, the rework of the 
standard library will be very incompatible with its current version. So 
you are killing all compatibility.

We don't want another Python 3 vs. Python 2. It almost killed Python, 
and they could afford to lose a lot more than we do. And let's face it - 
nobody is singing an ode to Python 3 now that they have Unicode built 
in. They solved no real problem and in the best of cases they made it 
marginally easy to do work that was very well done by a couple of 
specialized libraries.

Changing the stdlib to remove autodecoding would kill the D programming 
language.

You don't want to kill the D programming language, do you?

Stop changing.

Start adding.


More information about the Digitalmars-d mailing list