Want reasonable reference counting? Disable automatic sharing of immutable
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sat Nov 13 06:20:25 UTC 2021
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.
Depends on how you define pure.
Is it a tool for compiler optimizations? Not a problem. The
compiler knows the invariants for reference counting.
Is it a tool to make it easier for programmers to reason about
programs. Clarfy in the sec what you can assume.
Do you want the compiler to check strong purity? Define it. Make
it possible to express it and let the compiler check it.
If you require pure to mean that no life times are extended, say
so in the spec and let the compiler check it.
>>> I'm skeptical that even normal optimizations outside of pure
>>> won't bite you on this either.
>>
>> If it is builtin then optimizations cannot be a concern?
>
> As I said, I'm skeptical, I'm not sure if some optimization
> somewhere isn't going to make hay with our cleverness. We have
> smart people working on the compilers, so I'll leave the
> judgment up to them.
An compiler optimization cannot create problems, by definition,
as it does not change the language. If it creates problems then
it means that the language specification is in need of fixing. Or
that that the programmers assume things that the language does
not guarantee.
More information about the Digitalmars-d
mailing list