The D standard library is built on GC, is that a negative or positive?

Siarhei Siamashka siarhei.siamashka at gmail.com
Fri Dec 16 17:00:30 UTC 2022


On Friday, 16 December 2022 at 15:23:45 UTC, IGotD- wrote:
> On Friday, 16 December 2022 at 15:02:55 UTC, Siarhei Siamashka 
> wrote:
>>
>> Using `const` instead of `immutable` is just hiding the 
>> problem and I don't like this.
>
> Shouldn't the actual implementation of the exception handling 
> be hidden as much as possible towards the programmer, at least 
> on the receiving end. Exposing it too much might lead to that 
> any change in the implementation might not be possible in the 
> future.

Hiding the actual implementation is good, but hiding a memory 
corruption bug is bad. The code from 
https://forum.dlang.org/post/cmtaeuedmdwxjecpcrjh@forum.dlang.org 
can be successfully compiled by D compilers at least from GDC 9 
and up to the most recent versions. But what actually happens is 
that the "immutable" data gets corrupted (the field 'info' is 
overwritten by the exception handling code from druntime) and 
also the catch block can receive it in a mutable form and modify 
it there or pass it around and later modify somewhere else. All 
of this despite the `@safe` attribute. Not to mention the GC 
allocations despite the `@nogc` attribute too.

It was known at least since 
https://issues.dlang.org/show_bug.cgi?id=12118 (mentioned in Nick 
Treleaven's pull request). Replacing "immutable" with "const" 
doesn't change anything on a fundamental level, the hidden 
corruption still remains there.

But I'm not happy about just disallowing to throw immutable 
exceptions instead of fixing them and without a good replacement 
("const" is not a good replacement).

> When you catch an exception, is it then important for the 
> programmer to know how the exception was thrown or can this be 
> done auto magically under the hood?

It's important to know that there are no hidden bugs.


More information about the Digitalmars-d mailing list