February 05

On Monday, 5 February 2024 at 16:46:20 UTC, Paul Backus wrote:

>

On Monday, 5 February 2024 at 16:36:02 UTC, monkyyy wrote:

>

On Monday, 5 February 2024 at 15:40:11 UTC, Paul Backus wrote:

> >

I think our goal is to make -betterC obsolete. As in: if you don't use the feature, you don't pay for it, and it's implicit.

Even in the 100% pay-as-you-go world, I think we'll still want Phobos APIs to avoid depending on (and paying for) more druntime features than they really need to.

This feels delusional to me; like I don't know how the formal style with its contracts and extra asserts and 5 layered datetime will ever avoid rogue imports that aren't part of a blessed compile environment.

The way you avoid this stuff is by testing. Run your unit tests with -betterC and any accidental druntime dependencies you add will be revealed to you very quickly.

That just adds a singluar blessed environment, it will be very very unlikely that it will compile on wasm, a new embedded chip that releases in 2025, bsd, or a new rust os in 2040.

Which is a potential option but it's not a mythical "pay-as-you-go" and then you'll see nogc avocates being like "oi I needed to import toStringz but your (algorthim thats 100x simplier with allocation) allocates and broke my code, because of a 9 long import chain of unused code"

https://www.youtube.com/watch?v=a-767WnbaCQ

"just do ___"; no we are not even close to the phase change point, I suggest someone needs an answer for how you reduce the fundamental "order"/R0 of imports, which I think is 2 imports per file, or being extremely strict about local imports being in templates so they dont compile if unused

February 05
On Monday, 5 February 2024 at 15:45:36 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 06/02/2024 3:41 AM, Atila Neves wrote:
>>     The EH problem has two potential answers.
>> 
>> Three: copy Herb Sutter's idea.
>> 
>
> Oh look, someone has already done it!
>
> https://github.com/rikkimax/DIPs/blob/value_type_exceptions/DIPs/DIP1xxx-RC.md

Nice! How did I miss this??
February 06
On 06/02/2024 6:38 AM, Atila Neves wrote:
> On Monday, 5 February 2024 at 15:45:36 UTC, Richard (Rikki) Andrew Cattermole wrote:
>> On 06/02/2024 3:41 AM, Atila Neves wrote:
>>>     The EH problem has two potential answers.
>>>
>>> Three: copy Herb Sutter's idea.
>>>
>>
>> Oh look, someone has already done it!
>>
>> https://github.com/rikkimax/DIPs/blob/value_type_exceptions/DIPs/DIP1xxx-RC.md
> 
> Nice! How did I miss this??

Probably because you weren't on Discord or reading any of my comments on the N.G. ;)
February 06

On Friday, 2 February 2024 at 09:09:37 UTC, Adam Wilson wrote:

>

Walter and I had a productive conversation yesterday about Phobos 3 and we felt it would be appropriate to share some notes on our discussion.

Snip...

Finally, we touched briefly on the major changes we would like to see in Phobos 3 and these are the major changes we are committing to for Phobos 3 so far:

  • Removal of Autodecoding.
  • Promoting allocators out of experimental.
  • Range interface redesign (see JMD's thread here).
  • Fix std.traits.

The above list is not exhaustive and we are open to further suggestions. For myself, I would love to see Cryptography and Stream API's make it into Phobos, but I am sure that the list of what the community wants to add is legion so those could end up being lower priority.

Snip...

If you would like to participate in the design discussion on Phobos 3, I am currently hosting a repo on my GitHub with GH Discussions for unresolved/undesigned topics, and PR's for editing the actual design document. Link is here: https://github.com/LightBender/PhobosV3-Design

Very interesting!

I really like the Allocator idea. Something I think will benefit D and is overdue if being honest.

Curious to know how this will work for D. Will Allocators be available for BetterC as well? I certainly hope so!

If so, I guess the default Allocator will be the GC one, and can still be disabled. Being able to change the default (or change locally like in a function or pass it as parameter) would provide a lot of flexibility.

It's just I see possiblities of BetterC being able to use certain features that are not available, like dynamic or associative arrays. To be designed for allowing us to specify the Allocator to use (or default if not specified at all) and it doesn't need to be a GC one gives the programmer a lot of control for low level as well as high.

February 07

On Tuesday, 6 February 2024 at 14:41:27 UTC, Martyn wrote:

>

Curious to know how this will work for D. Will Allocators be available for BetterC as well? I certainly hope so!

Nothing's set in stone yet, but in the proposal I'm working on, there is nothing stopping allocators from being available in BetterC.

>

If so, I guess the default Allocator will be the GC one, and can still be disabled. Being able to change the default (or change locally like in a function or pass it as parameter) would provide a lot of flexibility.

In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, Array!(int, GC)). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.

I'm not planning to include a global default allocator. Built-in language features like new, dynamic arrays, associative arrays, and delegate contexts will always use the GC, and there will not be an option to change this.

February 07

On Wednesday, 7 February 2024 at 05:55:04 UTC, Paul Backus wrote:

>

On Tuesday, 6 February 2024 at 14:41:27 UTC, Martyn wrote:

>

... Snip

Nothing's set in stone yet, but in the proposal I'm working on, there is nothing stopping allocators from being available in BetterC.

>

... Snip

In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, Array!(int, GC)). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.

I'm not planning to include a global default allocator. Built-in language features like new, dynamic arrays, associative arrays, and delegate contexts will always use the GC, and there will not be an option to change this.

Thank you for taking the time to respond. I understand a proposal is working on, but your answers above sound very promising. Thanks again.

February 07

On Wednesday, 7 February 2024 at 05:55:04 UTC, Paul Backus wrote:

>

On Tuesday, 6 February 2024 at 14:41:27 UTC, Martyn wrote:

>

Curious to know how this will work for D. Will Allocators be available for BetterC as well? I certainly hope so!

Nothing's set in stone yet, but in the proposal I'm working on, there is nothing stopping allocators from being available in BetterC.

>

If so, I guess the default Allocator will be the GC one, and can still be disabled. Being able to change the default (or change locally like in a function or pass it as parameter) would provide a lot of flexibility.

In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, Array!(int, GC)). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.

I'm not planning to include a global default allocator. Built-in language features like new, dynamic arrays, associative arrays, and delegate contexts will always use the GC, and there will not be an option to change this.

The problem with this approach, as C++ found out, is that Vector!(int, MyAlloc) is a different type from Vector!(int, YourAlloc). The way I got around that is by defaulting to a global allocator. This has its drawbacks as well of course, because now everything is a virtual call.

February 07

On Wednesday, 7 February 2024 at 10:10:27 UTC, Atila Neves wrote:

>

On Wednesday, 7 February 2024 at 05:55:04 UTC, Paul Backus wrote:

>

On Tuesday, 6 February 2024 at 14:41:27 UTC, Martyn wrote:

>

Curious to know how this will work for D. Will Allocators be available for BetterC as well? I certainly hope so!

Nothing's set in stone yet, but in the proposal I'm working on, there is nothing stopping allocators from being available in BetterC.

>

If so, I guess the default Allocator will be the GC one, and can still be disabled. Being able to change the default (or change locally like in a function or pass it as parameter) would provide a lot of flexibility.

In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, Array!(int, GC)). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.

I'm not planning to include a global default allocator. Built-in language features like new, dynamic arrays, associative arrays, and delegate contexts will always use the GC, and there will not be an option to change this.

The problem with this approach, as C++ found out, is that Vector!(int, MyAlloc) is a different type from Vector!(int, YourAlloc). The way I got around that is by defaulting to a global allocator. This has its drawbacks as well of course, because now everything is a virtual call.

I do that as well

struct Array(T)
{
    T[] items;
    Allocator allocator;
    size_t count = 0;

Just store the allocator in the struct, it's no big deal, granted your allocator type is a simple and compact struct

struct Allocator
{
    void* ptr;
    AllocatorFN* fn;
}
struct AllocatorFN
{
    alloc_d alloc;
    resize_d resize;
    free_d free;
}

// libc
enum c_allocator = Allocator(null, &CAllocator.fn);
struct CAllocator
{
    __gshared AllocatorFN fn = {
        alloc: &alloc_impl,
        resize: &resize_impl,
        free: &free_impl
    };
}

That's it


Allocator heap = c_allocator;

auto entities = Array!(Entity).create(heap);

February 08
On 07/02/2024 11:10 PM, Atila Neves wrote:
> On Wednesday, 7 February 2024 at 05:55:04 UTC, Paul Backus wrote:
>> On Tuesday, 6 February 2024 at 14:41:27 UTC, Martyn wrote:
>>> Curious to know how this will work for D. Will Allocators be available for BetterC as well? I certainly hope so!
>>
>> Nothing's set in stone yet, but in the proposal I'm working on, there is nothing stopping allocators from being available in BetterC.
>>
>>> If so, I guess the **default** Allocator will be the GC one, and can still be disabled. Being able to change the default (or change locally like in a function or pass it as parameter) would provide a lot of flexibility.
>>
>> In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, `Array!(int, GC)`). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.
>>
>> I'm not planning to include a global default allocator. Built-in language features like `new`, dynamic arrays, associative arrays, and delegate contexts will always use the GC, and there will not be an option to change this.
> 
> The problem with this approach, as C++ found out, is that `Vector!(int, MyAlloc)` is a different type from `Vector!(int, YourAlloc)`. The way I got around that is by defaulting to a global allocator. This has its drawbacks as well of course, because now everything is a virtual call.

I came to a similar conclusion from my usage of std.experimental.allocator.

My stuff doesn't use template parameters for things like memory allocators.

My conclusion was that you really only have two use cases for composable allocators:

1. You know about memory patterns, locking, type sizes ext. Use composable directly.
2. Otherwise, use virtual.

There doesn't seem to be anything in between.
February 07

On Wednesday, 7 February 2024 at 10:10:27 UTC, Atila Neves wrote:

>

On Wednesday, 7 February 2024 at 05:55:04 UTC, Paul Backus wrote:

>

In my proposal, when you use a library container (like an array, a hash table, a binary tree, etc.), you can specify what type of allocator you want to use as a template parameter (as in, Array!(int, GC)). It will probably default to the GC, but you can just as easily use malloc, or even a custom allocator that you write yourself.

The problem with this approach, as C++ found out, is that Vector!(int, MyAlloc) is a different type from Vector!(int, YourAlloc). The way I got around that is by defaulting to a global allocator. This has its drawbacks as well of course, because now everything is a virtual call.

Yes, I'm aware of this problem, but I don't see a way around it.

The thing is, the compiler has to know what allocator you're using at compile time in order to infer the correct function attributes for the container. If you want Array!int to default to using the GC, but also work in @nogc code when you're using malloc...how would that even work?

I have two potential mitigations for this problem in mind.

The first is to realize that D already has a solution for writing data-structure-agnostic code: ranges! If Array implements all of the relevant range interfaces, the rest of your code doesn't have to depend on any single concrete Array type--it can just depend on the range interface.

If you really need a concrete type, there's always std.range.interfaces, although that does come with some sacrifices (virtual calls, not @safe or @nogc, etc.).

The second is to have the allocator library provide a runtime-polymorphic allocator, which users can depend on if they absolutely need a single concrete container type for whatever reason. We'd have to make some serious tradeoffs between runtime overhead and attribute compatibility, and it's possible that no one-size-fits-all solution exists, but in principle, it can be done.

Finally, on the subject of global allocators: I don't think having a global allocator is a good idea, period, whether it's used as a default or not. Containers generally cannot tolerate having their allocators mutated "behind their backs," and a user-accessible global variable would make it very easy and tempting to write code that does this.