On Saturday, 19 April 2014 at 18:41:39 UTC, Walter Bright wrote:
On 4/19/2014 11:05 AM, Dicebot wrote:
I feel like the origin of the discussion has been completely
lost here and we
don't speak the same language right now. The very point I have
made initially is
that @nogc in a way it is defined in your DIP is too
restrictive to be
effectively used in Phobos.
In lot of standard library functions you may actually need to
allocate as part
of algorithm, strict @nogc is not applicable there. However,
it is still
extremely useful that no _hidden_ allocations happen outside
of weel-defined
user API and this is something that less restrictive version
of @nogc could help
with.
The fact that you propose me to use unit tests to verify same
guarantees hints
that I have completely failed to explain my proposal but I
can't really rephrase
it any better without some help from your side to identify the
point of confusion.
The way I understood your idea, was that a template could be
marked @nogc, and yet still allow template arguments that
themselves may gc.
This can be accomplished by creating a unit test that passes
non-allocating template parameters, and then verifying the
instantiation is @nogc.
The only way that works is if the unittest has coverage of all
possible currently non-GC-using instantiations of all templates
all the way down the call-tree.*
Imagine the case where some function deep down the call-tree has
a `static if(T == NastyType) doGCStuff();`.
In order to protect against this, you have to check the internals
of the entire call-tree in order to write the required unittest,
and verify manually that you haven't missed a case every time
anything changes.
*alright, technically only those that can be instantiated by the
function your testing, but this still blows up pretty fast.