On Tuesday, 8 October 2013 at 16:24:05 UTC, Dicebot wrote:
Runtime check is almost useless for this.

They're how I do most the allocation checks now and could also be put in unit tests.

But I agree the ideal would be a compile time check. The way I want it to work is to define a new thing in the language, maybe via __traits, that can recursively check the call graph of a function for the presence of any UDA.

Then we attach @gc to the druntime functions that use them, starting at gc_malloc and right up into aaDup, d_newclass, whatever concat is called.

Ensure that the compiler considers these implicit function calls the same as any others and propagates the druntime UDA through the recursive trait.

Then we define @nogc to just be static assert(!hasAttribute!(gc, __traits(getAttributesRecursively, FUNCTION)). Maybe do a compiler or druntime change to @something can be expanded to a template instantation too so this doesn't even have to be a specific builtin. (Though I've actually been able to do this by hacking druntime before.) But whatever that specific impl doesn't matter.



Bottom line: @nogc works after just marking the core functions in druntime that may allocate, and the very same functionality can be used for other things too, like @noheap. Mark malloc with a uda, then define noheap as static assert(!gc && !malloc)

Then we have compile time checking, at least on the function level.

Reply via email to