On 23-05-2012 05:22, Steven Schveighoffer wrote:
I have come across a dilemma.

Alex Rønne Petersen has a pull request changing some things in the GC to
pure. I think gc_collect() should be weak-pure, because it could
technically run on any memory allocation (which is already allowed in
pure functions), and it runs in a context that doesn't really affect
execution of the pure function.

So I think it should be able to be run inside a strong pure function.
But because it has no parameters and no return, marking it as pure makes
it strong pure, and an optimizing compiler can effectively remove the
call completely!

So how do we force something to be weak-pure? What I want is:

1. it can be called from a pure function
2. it will not be optimized out in any way.

This solution looks crappy to me:

void gc_collect(void *unused = null);

any other ideas?

-Steve

I'm in favor of what you suggested on GitHub: A @weak attribute to enforce weak purity for functions marked pure.

BTW, any compiler with alias analysis and LTO might even decide to remove the call even with the unused parameter, since it, well, isn't used. I think we need a language-level solution here.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to