fake RefCounted for CTFE?
tsbockman
thomas.bockman at gmail.com
Tue Jun 16 00:03:53 UTC 2020
On Monday, 15 June 2020 at 21:18:23 UTC, Steven Schveighoffer
wrote:
> Would it make sense for RefCounted to turn into GC for CTFE
> mode? That is, if RefCounted is used during CTFE, it just
> allocates on the GC heap and doesn't actually do ref counting.
> ...
> What do you think?
Ref counting isn't only for memory management - sometimes it's
used to ensure that a value's destructor will run at a logical
point in time. Using the garbage collector during CTFE instead of
malloc/free or whatever should be fine, but some thought would
need to be put into whether there are any other valid uses of
destructors during CTFE.
The requirement that CTFE functions be pure at least forbids
*most* other uses of destructors - for example, there is no need
to close a file in CTFE, since you can't open one to begin with.
But, does D's weak purity provably forbid *all* other valid uses
of destructors? Making a bad assumption here could break code in
really ugly and confusing ways, since CTFE is often triggered
implicitly without any deliberate intent on the part of the
programmer.
More information about the Digitalmars-d
mailing list