Helping the compiler with assumptions while using exceptions

2011-05-30 Thread simendsjo
I'm having some problems trying to get the best of both worlds here. void f(Class c) { assert(c != null); // use c } In this example, we tell the compiler that c is never able to be null. The compiler can use assertions like this for optimizations (not sure if dmd does this though). But

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Timon Gehr
Jonathan M Davis wrote: On 2011-05-30 12:49, simendsjo wrote: I'm having some problems trying to get the best of both worlds here. void f(Class c) { assert(c != null); // use c } In this example, we tell the compiler that c is never able to be null. The compiler can use assertions

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Jonathan M Davis
On 2011-05-30 14:39, Timon Gehr wrote: Jonathan M Davis wrote: On 2011-05-30 12:49, simendsjo wrote: I'm having some problems trying to get the best of both worlds here. void f(Class c) { assert(c != null); // use c } In this example, we tell the compiler that c is

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread bearophile
Timon Gehr: The answer is yes, theoretically it could. (It would either have to have some very advanced code analysis caps, or would just have to treat enforce specially.) Id's not so advanced stuff. Bye, bearophile

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Brad Roberts
On 5/30/2011 2:55 PM, Jonathan M Davis wrote: I'd be very surprised to see the compiler ever optimize code based on assert or enforce statement. It's unlikely to do so based on assert simply because the assertion is going to be compiled out. I think that there's a high chance that

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Jonathan M Davis
On 2011-05-30 15:03, Brad Roberts wrote: On 5/30/2011 2:55 PM, Jonathan M Davis wrote: I'd be very surprised to see the compiler ever optimize code based on assert or enforce statement. It's unlikely to do so based on assert simply because the assertion is going to be compiled out. I think

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Timon Gehr
Timon Gehr: The answer is yes, theoretically it could. (It would either have to have some very advanced code analysis caps, or would just have to treat enforce specially.) Id's not so advanced stuff. Bye, bearophile You are saying that analyzing a function for thrown exceptions and