Want reasonable reference counting? Disable automatic sharing of immutable

Steven Schveighoffer schveiguy at gmail.com
Sat Nov 13 03:03:21 UTC 2021


On 11/12/21 7:27 PM, Stanislav Blinov wrote:
> On Friday, 12 November 2021 at 23:50:15 UTC, Steven Schveighoffer wrote:
> 
>> That means every pure function must be passed the global table as a 
>> parameter *just in case* there are some reference-counting things to 
>> do, and that means that no pure function can be strong-pure. Might as 
>> well not have pure functions in that case.
> 
> Might as well. So long as you're using (current spec of) GC, pure 
> functions are a big fat lie. Not even because GC allocates, but because 
> it runs finalizers, which can be impure. If a compiler makes any 
> assumptions wrt. "pure" on a function that interacts with GC in any way, 
> they're gonna be wrong assumptions.

This is an odd way to look at it. The finalizers are not run directly, 
and maybe not even run on the same thread as the pure function being 
run. They also should not be observable (for the most part), because you 
should not have access to that data any more.

It's like saying an OS context switch that happens in the middle of a 
pure function must somehow be valid pure code.

-Steve


More information about the Digitalmars-d mailing list