Divide & Conquer divides, but doesn't conquer

Stefan Koch uplink.coder at googlemail.com
Mon May 25 18:43:33 UTC 2020


On Monday, 25 May 2020 at 18:33:13 UTC, Andrei Alexandrescu wrote:
> On 5/25/20 12:07 PM, Stefan Koch wrote:
>> On Monday, 25 May 2020 at 16:04:24 UTC, Andrei Alexandrescu 
>> wrote:
>>> On 5/25/20 3:15 AM, Max Samukha wrote:
>>>> On Monday, 25 May 2020 at 06:18:13 UTC, FeepingCreature 
>>>> wrote:
>>>>
>>>>> static foreach and stringof were used so I didn't have to 
>>>>> pull in `format` or `to!string`, which had issues in 
>>>>> std.meta.
>>>>>
>>>>> I'm seeing some improvement over 2.086 at least; it should 
>>>>> be about equivalent to the hand-unrolled version in master.
>>>>
>>>> How could you miss the state-of-the-art?) Preallocate the 
>>>> result string and use the string counter hack!
>>>> http://dpldocs.info/this-week-in-d/Blog.Posted_2020_05_11.html#dmd-and-static-foreach
>>>>
>>>
>>> static foreach is quadratic? Is this a matter of principle, 
>>> or QoI?
>> 
>> Yes it is.
>> I did present this fact at the pre-event to Dconf 2018.
>> 
>> As for your other question it's both. The QoI is not stellar.
>> But it is fundamentally limited by having to create 
>> independent scopes.
>
> How do you mean that? static foreach does not create a scope.

The scope I am talking about is what dmd calls Scope.
This has to do with compiler internals.
static foreach has a manifest variable as IV.
That means it introduces a static name.
That name for example I has to resolve to a different value on 
every iteration.
This violates the rules of the language outside of static foreach.
Therefore the a construct has to be introduces which allows 
special behavior
inside a foreach body.



More information about the Digitalmars-d mailing list