January 12
On 12/01/2024 2:36 PM, Siarhei Siamashka wrote:
>     So, anyone actually relying on @nogc preventing collections is
>     arguably asking for trouble even with the current GC - though it
>     seems like the kind of folks who like to use @nogc are often the
>     kind of folks who are likely to avoid the GC entirely, so if @nogc
>     is used everywhere in their code, then they won't end up with either
>     GC allocations or collections.
> 
> You are probably talking about the OS kernel developers. Something like PowerNex, d-virtio and maybe a few other seemingly inactive/dead D projects.
> 
> But a common scenario for games is to load resources taking advantage of the GC. And then try to avoid GC allocations in the main loop for performance reasons. Do D language maintainers refuse to acknowledge the existence of game developers? I think that there are a few of them in this forum.

No, nobody is refusing such a clear use case. Especially when a few have been very vocal over the years and have had language features implemented for them.

What you are suggesting is that ``@nogc`` should for each function, call into the GC to disable/enable it automatically.

This is slow. You need to be responsible for doing this.
It should not be automated.

We can only guarantee in the compiler that this set of branches in the call stack will not trigger the GC. It is not possible to do other (potentially unknown) branches across all threads.

>     However, anyone using it selectively really can't rely on it to
>     avoid collections unless their program is single-threaded and will
>     always remain so.
> 
> What if the other threads are also |@nogc|?

"then they won't end up with either GC allocations or collections."

January 12

On Friday, 12 January 2024 at 01:49:34 UTC, zjh wrote:

>

On Friday, 12 January 2024 at 01:42:42 UTC, zjh wrote:

>

void opApply[aset b](scope int delegate()a dg)a{
....
}

Here, 'aset' should be a 'predict' and there should be a 'attribute' function.

January 12
On Thursday, 11 January 2024 at 20:03:36 UTC, Paolo Invernizzi wrote:
>
> I've no ideas how you can have a list or external created pthreads without horrible hack like hooking pthread_create.
>


Ocaml is exactly like D with that: https://v2.ocaml.org/manual/intfc.html#ss:c-thread-register
January 12

On Friday, 12 January 2024 at 01:50:25 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

What you are suggesting is that @nogc should for each function, call into the GC to disable/enable it automatically.

I haven't suggested anything like this.

I'm in favor of something simple like a @localnogc attribute, though the details still need to be clarified to see how it applies to the actual @nogc-compatible libraries and benefits them. But Walter opposes this idea in principle: https://forum.dlang.org/post/unpn1j$1617$1@digitalmars.com ("I don't see much utility in a "logical @nogc" that allows using the gc anyway"). So no progress can be made without a fork. But the OpenD fork doesn't care about the @nogc use case.

January 12

On Friday, 12 January 2024 at 01:21:32 UTC, H. S. Teoh wrote:

>

On Fri, Jan 12, 2024 at

void registerCallbackSystem(void delegate() @system cb) @system;
void registerCallbackSafe(void delegate() @safe cb) @safe;
...

I think 'abstract attributes' is also a good idea. Can we turn the above function into:

bool @attribute f(set b){
    return b.hasone(@system);
}

void registerCallback(void delegate() cb) @safe{
    static if(f(attrs(cb))){
        ...
    }
    static if(attrs(cb)==@nogc){
        ...
    }
    ...
}

Combining attribute functions to avoid function splitting.

January 12

On Friday, 12 January 2024 at 02:31:21 UTC, zjh wrote:

>

Combining attribute functions to avoid function splitting.

It's best to be able to deduct function etc. Then, you can use the information deducted from the deduction for metaprogramming.

Deductthe common attribute, Is it @nogc? Is it @pure?Or@system,@safety?.

January 12
On 1/12/24 03:27, Siarhei Siamashka wrote:
> But the OpenD fork doesn't care about the `@nogc` use case.

I don't think it's exactly like that, they mostly just dislike the pattern of rejecting new features for introducing implicit GC allocations. Anyway, personally I think something like @localnogc can be part of embracing the GC.
January 12

On Friday, 12 January 2024 at 02:43:56 UTC, zjh wrote:

>

Deductthe common attribute, Is it @nogc? Is it @pure?Or@system,@safety?.

A function (variable, construction block) has an 'attribute dictionary'. This attribute dict can contain four common attributes: '@nogc, @pure,@system,@safe', and user attributes. Each 'attribute dict' can be calculated

This kind of attribute dictionary should be very useful!

January 12
On Friday, 12 January 2024 at 01:21:32 UTC, H. S. Teoh wrote:
>
> The only way a library author can deal with this mess is (1) write in the most restricted language subset, i.e., betterC + @nogc, so that it's usable by everybody. But the GC crowd will be unlikely to use it, because it will lack the conveniences they're accustomed to, the API will have manual memory management paraphrenalia that doesn't fit well with the rest of user code. Plus this is also a much higher bar for the library author, so you're further limiting the already small number of people who are writing D libraries.  Or (2) be opinionated and write a GC-using library, in which case the betterC / @nogc people won't use it. Either alternative leads to ecosystem fragmentation. Or write a @nogc library but the betterC people won't use it.  Etc..
>

Interesting post thanks. Describes the situation very well.
I think more escape hatches (@localnogc?) may help with the delegate situation you related.
January 12

On Thursday, 11 January 2024 at 22:49:51 UTC, Guillaume Piolat wrote:

>

@nogc could get an escape hatch maybe?
pure is especially annoying because no escape hatch.

Perhaps we can live with their UB in a per-attribute basis.
UB of @nogc is allocating with GC, it only annoys in cases without GC, else well, type system was broken.

There is an escape hatch for them already.

void fakeNoGc(ref Appender!string) @nogc;

pragma(mangle, fakeNoGc.mangleof)
void fakeNoGcImpl(ref Appender!string app) {
    app ~= "text";
}

void test() {
    auto app = appender!string();
    app.reserve(8);
    () @nogc {
        fakeNoGc(app); // If it actually reallocates, it's UB.
    }();
}

The compiler blindly trusts us that fakeNoGc won’t touch the GC. It does not check anything.

It’s a very dangerous pattern. Are you certain it needs a more convenient syntax?