toHash => pure, nothrow, const, @safe

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 13 09:59:04 PDT 2012


On Tue, Mar 13, 2012 at 11:06:00AM -0500, Andrei Alexandrescu wrote:
> On 3/13/12 10:47 AM, deadalnix wrote:
> >This problem is pretty close to garbage collection. Let's use pure as
> >example, but it work with other qualifier too.
> >
> >function are marked pure, impure, or pure given all function called
> >are pure (possibly pure). Then you go throw all possibly pure
> >function and if it call an impure function, they mark it impure. When
> >you don't mark any function as impure on a loop, you can mark all
> >remaining possibly pure functions as pure.
> 
> Certain analyses can be done using the so-called worklist approach.
> The analysis can be pessimistic (initially marking all functions as
> not carrying the property analyzed and gradually proving some do carry
> it) or optimistic (the other way around). The algorithm ends when the
> worklist is empty. This approach is well-studied and probably ought
> more coverage in compiler books. I learned about it in a graduate
> compiler class.
[...]

I have an idea.

Instead of making potentially risky changes to the compiler, or changes
with unknown long-term consequences, what about an external tool (or a
new compiler option) that performs this analysis and saves it into a
file, say in json format or something?

So we run the analysis on druntime, and it tells us exactly which
functions can be marked pure, const, whatever, then we can (1) look
through the list to see if functions that *should* be pure aren't, then
investigate why and (possibly) fix the problem; (2) annotate all
functions in druntime just by going through the list, without needing to
manually fix one function, find out it breaks 5 other functions, fix
those functions, find another 25 broken, etc..

We can also run this on phobos, cleanup whatever functions aren't marked
pure, and then go through the list and annotate everything in one shot.

Now that I think of it, it seems quite silly that we should be agonizing
over the amount of manual work needed to annotate druntime and phobos,
when the compiler already has all the necessary information to automate
most of the tedious work.


T

-- 
It is not the employer who pays the wages. Employers only handle the
money. It is the customer who pays the wages. -- Henry Ford


More information about the Digitalmars-d mailing list