www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - betterC and CTFE

reply Walter Bright <newshound2 digitalmars.com> writes:
BetterC code does not have a GC, and so doesn't allow using the GC. But many 
have correctly pointed out that not having a GC cripples CTFE. CTFE should be 
able to use the GC, it's a major advantage of having a GC (and cripples 
languages with CTFE that don't have GC).

So, making some experiments, I found it usually worked. Searching bugzilla, I 
found one case that didn't:

   https://issues.dlang.org/show_bug.cgi?id=20101

and fixed it:

   https://github.com/dlang/dmd/pull/14789

For those that still suffer the slings and arrows from this problem, please let 
me know the bugzilla issues for them.

P.S. This also applies to  nogc code - CTFE should still be able to use the GC. 
Isn't that cool? Destroy the question "what good a GC is in a systems 
programming language!"
Jan 06 2023
next sibling parent reply Hipreme <msnmancini hotmail.com> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 BetterC code does not have a GC, and so doesn't allow using the 
 GC. But many have correctly pointed out that not having a GC 
 cripples CTFE. CTFE should be able to use the GC, it's a major 
 advantage of having a GC (and cripples languages with CTFE that 
 don't have GC).

 So, making some experiments, I found it usually worked. 
 Searching bugzilla, I found one case that didn't:

   https://issues.dlang.org/show_bug.cgi?id=20101

 and fixed it:

   https://github.com/dlang/dmd/pull/14789

 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.

 P.S. This also applies to  nogc code - CTFE should still be 
 able to use the GC. Isn't that cool? Destroy the question "what 
 good a GC is in a systems programming language!"
Way to go! Although I deeply hate betterC, this is great! This increases a lot of potential usages on nogc code :)
Jan 06 2023
parent reply Siarhei Siamashka <siarhei.siamashka gmail.com> writes:
On Saturday, 7 January 2023 at 02:45:16 UTC, Hipreme wrote:
 Way to go! Although I deeply hate betterC, this is great! This 
 increases a lot of potential usages on nogc code :)
CTFE can already use GC in nogc code since a long time ago. I don't understand what's the news and in what way does this make betterC more relevant.
Jan 06 2023
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/6/2023 6:59 PM, Siarhei Siamashka wrote:
 CTFE can already use GC in  nogc code since a long time ago. I don't
understand 
 what's the news and in what way does this make betterC more relevant.
Fixing it for mixins is a big deal.
Jan 06 2023
prev sibling next sibling parent reply Dave P. <dave287091 gmail.com> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 [...]
 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.

 [...]
These two still don’t work: https://issues.dlang.org/show_bug.cgi?id=21492 https://issues.dlang.org/show_bug.cgi?id=21482
Jan 06 2023
parent Max Samukha <maxsamukha gmail.com> writes:
On Saturday, 7 January 2023 at 06:45:38 UTC, Dave P. wrote:
 On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright 
 wrote:
 [...]
 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.

 [...]
These two still don’t work: https://issues.dlang.org/show_bug.cgi?id=21492 https://issues.dlang.org/show_bug.cgi?id=21482
It seems you still have to work around these with templates. An improvement anyway because now variadics and overloads can be used (the lambda hack didn't allow that).
Jan 06 2023
prev sibling next sibling parent reply Max Samukha <maxsamukha gmail.com> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:

 So, making some experiments, I found it usually worked. 
 Searching bugzilla, I found one case that didn't:

   https://issues.dlang.org/show_bug.cgi?id=20101

 and fixed it:

   https://github.com/dlang/dmd/pull/14789
Simple test cases still don't compile: string foo()() { string a, b; return a ~ b; } enum s = foo(); ./dmd -c -betterC test.d test.d(4): Error: array concatenation of expression `a ~ b` requires the GC which is not available with -betterC
Jan 07 2023
parent Walter Bright <newshound2 digitalmars.com> writes:
Thank you. I added a bugzilla for it:

https://issues.dlang.org/show_bug.cgi?id=23606

In the future, I'd appreciate adding bugs to bugzilla, then linking to the
issue 
in any n.g. discussion of it.
Jan 07 2023
prev sibling next sibling parent reply Paulo Pinto <pjmlp progtools.org> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 BetterC code does not have a GC, and so doesn't allow using the 
 GC. But many have correctly pointed out that not having a GC 
 cripples CTFE. CTFE should be able to use the GC, it's a major 
 advantage of having a GC (and cripples languages with CTFE that 
 don't have GC).

 So, making some experiments, I found it usually worked. 
 Searching bugzilla, I found one case that didn't:

   https://issues.dlang.org/show_bug.cgi?id=20101

 and fixed it:

   https://github.com/dlang/dmd/pull/14789

 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.

 P.S. This also applies to  nogc code - CTFE should still be 
 able to use the GC. Isn't that cool? Destroy the question "what 
 good a GC is in a systems programming language!"
Cedar, Modula-3 and Oberon, show how it goes. Every time I decide to have a look at what is happening in D, most certainly there is a ongoing discussion thread about the GC. So much discussion about systems programming and GC, while others are shipping hardware running Go and .NET workloads on bare metal, like USB Armoury and Meadow boards.
Jan 07 2023
parent Hipreme <msnmancini hotmail.com> writes:
On Saturday, 7 January 2023 at 10:31:28 UTC, Paulo Pinto wrote:
 Every time I decide to have a look at what is happening in D, 
 most certainly there is a ongoing discussion thread about the 
 GC.

 So much discussion about systems programming and GC, while 
 others are shipping hardware running Go and .NET workloads on 
 bare metal, like USB Armoury and Meadow boards.
Although I really hate betterC, having the nogc thing is a good thing. Making everything nogc is useless though. For example, leaking GC data in a loop is not good, so for my engine I can easily check if I'm doing that and where I'm doing that. What I would prefer though would be nogc, pure and safe inference because most people hates putting all attributes to make it callable by any function. That being said, I don't want discussions about GC unless a way to make it run on WASM or how to make it faster, that is tackling the problems right in the root. Anyway, GC makes people productive and I believe that in 2023 it should not even be a question.
Jan 07 2023
prev sibling next sibling parent reply Dennis <dkorpel gmail.com> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.
I was actually working on a write up about BetterC and CTFE, and collected this list of issues: [Issue 18472 - [Reg 2.078] betterC: cannot use format at compile time](https://issues.dlang.org/show_bug.cgi?id=18472) [Issue 19268 - BetterC turns off DRuntime for CTFE](https://issues.dlang.org/show_bug.cgi?id=19268) [Issue 20095 - core.internal.convert.toUbyte doesn't work with -betterC](https://issues.dlang.org/show_bug.cgi?id=20095) [Issue 20479 - octal integer literals don't work with BetterC mode](https://issues.dlang.org/show_bug.cgi?id=20479) [Issue 21492 - betterC: TypeInfo is generated for code guarded by if(__ctfe) ](https://issues.dlang.org/show_bug.cgi?id=21492) [Issue 23468 - [betterC] Cannot use std.array.join and std.algorithm.map at compile-time](https://issues.dlang.org/show_bug.cgi?id=23468)
Jan 07 2023
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/7/2023 3:53 AM, Dennis wrote:
 On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 For those that still suffer the slings and arrows from this problem, please 
 let me know the bugzilla issues for them.
I was actually working on a write up about BetterC and CTFE, and collected this list of issues: [Issue 18472 - [Reg 2.078] betterC: cannot use format at compile time](https://issues.dlang.org/show_bug.cgi?id=18472) [Issue 19268 - BetterC turns off DRuntime for CTFE](https://issues.dlang.org/show_bug.cgi?id=19268) [Issue 20095 - core.internal.convert.toUbyte doesn't work with -betterC](https://issues.dlang.org/show_bug.cgi?id=20095) [Issue 20479 - octal integer literals don't work with BetterC mode](https://issues.dlang.org/show_bug.cgi?id=20479) [Issue 21492 - betterC: TypeInfo is generated for code guarded by if(__ctfe) ](https://issues.dlang.org/show_bug.cgi?id=21492) [Issue 23468 - [betterC] Cannot use std.array.join and std.algorithm.map at compile-time](https://issues.dlang.org/show_bug.cgi?id=23468)
Thanks, Dennis! I realized that there's a keyword for it, and here are the unresolved betterC-tagged issues: https://issues.dlang.org/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&keywords=betterC&keywords_type=allwords&list_id=243519&query_format=advanced 23468 wasn't tagged properly so I fixed it.
Jan 07 2023
prev sibling parent Dylan Graham <dylan.graham2000 gmail.com> writes:
On Saturday, 7 January 2023 at 02:09:00 UTC, Walter Bright wrote:
 BetterC code does not have a GC, and so doesn't allow using the 
 GC. But many have correctly pointed out that not having a GC 
 cripples CTFE. CTFE should be able to use the GC, it's a major 
 advantage of having a GC (and cripples languages with CTFE that 
 don't have GC).

 So, making some experiments, I found it usually worked. 
 Searching bugzilla, I found one case that didn't:

   https://issues.dlang.org/show_bug.cgi?id=20101

 and fixed it:

   https://github.com/dlang/dmd/pull/14789

 For those that still suffer the slings and arrows from this 
 problem, please let me know the bugzilla issues for them.

 P.S. This also applies to  nogc code - CTFE should still be 
 able to use the GC. Isn't that cool? Destroy the question "what 
 good a GC is in a systems programming language!"
This is handy on embedded. Great work, Walter! :)
Jan 08 2023