Tue, 11 Aug 2009 22:15:15 -0400, Chad J wrote: >> I've noticed an optimization which reduces number of calls to a getter. >> I think you shouldn't do that: you should call getter as many times as >> the expression suggests, and leave the rest to the optimizer. > > It's not so much an optimization. > > I removed those extra calls because it would create an asymmetry between > how many times the getter is called and how many times the setter is > called. I suppose it could be argued that the extra setter calls should > be left in as well, and maybe that would be alright. To be honest, I'm > not too entirely sure how to deal with that.
I think it's a matter of definition. Try to define the rewriting behavior, in English, as simply and unambiguous as possible: how many times getters and setters are called, and in which order. I'm sure this will filter away many behaviors as unpredictable. Then you say that compiler may optimize some calls if it can guarantee the same result and order of side effects. Then you make a straight-forward implementation of your specification. Then you see what you can do about optimizations. Sorry if it's all obvious. I didn't mean to lecture you, honestly.