On Sunday 14 November 2010 04:26:56 bearophile wrote: > Jonathan M Davis: > >The one problem I see is that if the compiler has to determine whether a > >given function can be pure and/or nothrow, it's going to potentially have > >to go arbitrarily deep into the call hierarchy to figure it out< > > This is already done for pure functions, const, immutable, nothrow, etc, > all of them are transitive.
Except that right now, all it has to do is look one level. If a function isn't marked as pure, then any pure function which tries to call it gets an error. The signature is all that's needed. If the function being called is marked as pure but isn't really pure, then you'll get an error when that function is compiled. The compiler just has to worry about the signatures and doesn't have to dig arbitrarily deep. The same goes for the other attributes. If you wanted to base the purity of a function on whether the functions it used being pure, you could just go off of the signatures, but then you couldn't get purity this way for more than one level, which doesn't solve the problem. For instance, all it would take would be a function in std.algorithm having to call empty on a range and have that empty being pure or not based on what _it_ was doing internally, and that std.algorithm function couldn't be pure. Effectively (ignoring the issue of mutual recursion), if you started at one function, you'd have to recursively check all of the functions that it calls for whether they can be pure, meaning that it cannot be compiled until all of them have been compiled. Right now, the signatures are enough. They wouldn't be if their purity could changed. Now, since you'd be dealing with templates which have to be instantiated anyway, maybe it would work. But it could be seriously problematic. - Jonathan M Davis