May 21, 2021

On Friday, 21 May 2021 at 00:31:52 UTC, TheGag96 wrote:

>

Dunno if that's a pipe dream, though.

Once it is all inlined, the backend ought to be able to see what is going on here and elide the allocations.

@nogc might not pass that though since it is before all those optimizations are performed......

But like i just checked ldc -O and it indeed optimizes it out today.

May 28, 2021

On Friday, 21 May 2021 at 00:54:27 UTC, Max Haughton wrote:

>

On Friday, 21 May 2021 at 00:31:52 UTC, TheGag96 wrote:

>

The delegate-related thing I really want improved is being able to capture local variables in places like:

int i = 3;
someRange.map!(x => x.thing == i).each!writeln;

...without needing the GC, since we "know" that i doesn't escape. Dunno if that's a pipe dream, though.

This has to be an aim. It's simply stupid that using map in the way it's intended to be used results in a GC allocation (there are workarounds, but this is missing the point entirely). I know it won't be easy, but quite frankly if it's not possible that's a knock on us and our infrastructure - if we can't do big and important things properly we need to change that too.

I was a little surprised that it needs the GC in the first place. It's a template parameter after all. Here, it even seems a runtime delegate parameter would shine since it could be marked scope. If nothing else goes on, an allocation is not necessary. It's even @nogc. (Maybe the lambda bound to the alias could have scope implied?)

May 28, 2021

On Friday, 28 May 2021 at 02:41:27 UTC, Q. Schroll wrote:

>

I was a little surprised that it needs the GC in the first place. It's a template parameter after all.

It isn't the lambda that allocates per se, it is the MapResult struct that cannot necessarily be scope since it doesn't know if the range will be stored or returned or whatever.

Though perhaps if the returned map result inherited the lifetime of the captured variables it could work, just that gets complicated.

May 28, 2021

On Friday, 28 May 2021 at 02:47:41 UTC, Adam D. Ruppe wrote:

>

On Friday, 28 May 2021 at 02:41:27 UTC, Q. Schroll wrote:

>

I was a little surprised that it needs the GC in the first place. It's a template parameter after all.

It isn't the lambda that allocates per se, it is the MapResult struct that cannot necessarily be scope since it doesn't know if the range will be stored or returned or whatever.

Though perhaps if the returned map result inherited the lifetime of the captured variables it could work, just that gets complicated.

I suspect the compiler should be able to see through it after a few rounds of inlining.

If there are so many layers that it doesn't, I suspect one allocation isn't going to be your bottleneck.

May 28, 2021

On Friday, 28 May 2021 at 13:47:32 UTC, deadalnix wrote:

>

On Friday, 28 May 2021 at 02:47:41 UTC, Adam D. Ruppe wrote:

>

On Friday, 28 May 2021 at 02:41:27 UTC, Q. Schroll wrote:

>

I was a little surprised that it needs the GC in the first place. It's a template parameter after all.

It isn't the lambda that allocates per se, it is the MapResult struct that cannot necessarily be scope since it doesn't know if the range will be stored or returned or whatever.

Though perhaps if the returned map result inherited the lifetime of the captured variables it could work, just that gets complicated.

I suspect the compiler should be able to see through it after a few rounds of inlining.

If there are so many layers that it doesn't, I suspect one allocation isn't going to be your bottleneck.

ldc -O is able to elide the allocation: https://d.godbolt.org/z/9aoMo9hbe

However, the code still does not qualify as @nogc, because @nogc analysis is done prior to optimization.

May 28, 2021

On Friday, 28 May 2021 at 14:29:50 UTC, Paul Backus wrote:

>

On Friday, 28 May 2021 at 13:47:32 UTC, deadalnix wrote:

>

On Friday, 28 May 2021 at 02:47:41 UTC, Adam D. Ruppe wrote:

>

On Friday, 28 May 2021 at 02:41:27 UTC, Q. Schroll wrote:

>

I was a little surprised that it needs the GC in the first place. It's a template parameter after all.

It isn't the lambda that allocates per se, it is the MapResult struct that cannot necessarily be scope since it doesn't know if the range will be stored or returned or whatever.

Though perhaps if the returned map result inherited the lifetime of the captured variables it could work, just that gets complicated.

I suspect the compiler should be able to see through it after a few rounds of inlining.

If there are so many layers that it doesn't, I suspect one allocation isn't going to be your bottleneck.

ldc -O is able to elide the allocation: https://d.godbolt.org/z/9aoMo9hbe

However, the code still does not qualify as @nogc, because @nogc analysis is done prior to optimization.

Some more context (i.e. how LDC goes about doing this)

https://d.godbolt.org/z/jsPdoTxY1

https://github.com/ldc-developers/ldc/blob/master/gen/passes/GarbageCollect2Stack.cpp

GCC does not do this optimization (yet?), but it does for malloc and new in C++.

May 30, 2021

On Friday, 28 May 2021 at 14:29:50 UTC, Paul Backus wrote:

>

ldc -O is able to elide the allocation: https://d.godbolt.org/z/9aoMo9hbe

However, the code still does not qualify as @nogc, because @nogc analysis is done prior to optimization.

I've long argued that nogc needs to trigger n leaks, not allocations, and this is one more example as to why.

And tracking leak isn't as crazy as it sound whn you track ownership, a leak is a transfers of ownership to the GC.

May 31, 2021

On Sunday, 30 May 2021 at 21:09:36 UTC, deadalnix wrote:

>

I've long argued that nogc needs to trigger n leaks, not allocations, and this is one more example as to why.

And tracking leak isn't as crazy as it sound whn you track ownership, a leak is a transfers of ownership to the GC.

I don't disagree that tracking ownership through the type system is desirable, but it isn't possible without explicit ownership. Shape analysis get tricky very fast.

May 31, 2021

On Monday, 31 May 2021 at 15:08:34 UTC, Ola Fosheim Grøstad wrote:

>

On Sunday, 30 May 2021 at 21:09:36 UTC, deadalnix wrote:

>

I've long argued that nogc needs to trigger n leaks, not allocations, and this is one more example as to why.

And tracking leak isn't as crazy as it sound whn you track ownership, a leak is a transfers of ownership to the GC.

I don't disagree that tracking ownership through the type system is desirable, but it isn't possible without explicit ownership. Shape analysis get tricky very fast.

I think it is unavoidable. DIP1000 and alike are just doing exactly that while pretending they aren't, and it is causing a parsing XML with regex kind of running problem - it looks like it'll actually work, but it doesn't.

June 01, 2021

On Monday, 31 May 2021 at 23:37:21 UTC, deadalnix wrote:

>

I think it is unavoidable. DIP1000 and alike are just doing exactly that while pretending they aren't, and it is causing a parsing XML with regex kind of running problem - it looks like it'll actually work, but it doesn't.

True, no point in avoiding the machinery if that is what one is aiming for. Better to take the full machinery with explicit annotations, and then provide syntactical sugar for the common case if that is desirable. Going the other way will most likely be messy.

1 2 3 4 5 6 7 8
Next ›   Last »