On Tue, 17 Nov 2009 18:34:32 -0500, retard <[email protected]> wrote:
Tue, 17 Nov 2009 15:04:01 -0800, Bill Baxter wrote:
On Tue, Nov 17, 2009 at 2:53 PM, Robert Jacques <[email protected]>
*sigh* The reason the compiler would have to create a temporary struct,
is because that's what a tuple is at runtime. Tuples need to be compact
(like structs) so that they can be passed to functions, etc.
Sigh back at ya. I think all of us are just assuming that the compiler
will be smart enough to realize that the tuple value is not being used
and optimize it away.
It should be fairly trivial to detect and handle appropriately. At
least in the case of that for loop there. I think unused value
elimination is probably one of the first things you study in compiler
classes on optimization. It must be because even *I* know about it and
I've only taken one compiler class that barely touched on optimization
at all. :-)
Elimination of unused values has been one of the basic optimizations in C
compilers for decades. E.g. gcc 4.4 does tremendous amounts of
optimizations and the constant folding logic might even optimize away the
whole 'for' loop, the function containing the for loop or even the whole
object file containing the function.
If this kind of argumentation is used against new features, almost every
high level feature in D should be shaved off - classes, scope statements,
all literals etc. There is a serious amount of extra code those produce
compared to a hand crafted asm version of the program.
Yes, I know all this. But, before Bill, no-one seemed be cognizant of it
(either the optimization or the representation). Also, all those well
known optimizations don't magically work for structs: I've seen modern
compilers do some pretty stupid things when structs and temporary values
are involved.