On Wed, Jun 10, 2020 at 11:28 AM 'simon place' via golang-nuts
<golang-nuts@googlegroups.com> wrote:
>
> when you have functions that return multiple values, because its more 
> efficient to generate in one go when you are using ALL returned values;
>
> like in math, where you have Sin(), Cos() and Sincos()
>
> and when you also don't use all the returned values (using '_') does the 
> compiler optimise? does it compile multiple times so dead code is removed 
> from the version used with some return values unneeded?
>
> i would guess it doesn't, but i wanted to check, because i seem to keep 
> coming over this, probably the way i think, seems to me to reduce the 
> solution space.
>
> also this seems to, in some ways, overlap with generics, particularly if 
> there were new language features that let you specify some high level/simple 
> code path changes, things specific to the problem that the compiler could 
> never determine.
>
> i guess with code generation its possible, but that doesn't feel like the 
> best way to go.
>
> i could have tested for this but am also interested in all 
> architectures/future developments/other ways to achieve this.

Currently the compiler does not do the kind of optimization you
describe.  A function is compiled once, and computes all of its
results.  The caller receives all the results, and ignores ones that
it does not need.

Of course, if the function is inlined, then any code leading to
results that are not needed will be discarded.  But most functions are
not inlined.

We could implement the general optimization by compiling a function
multiple times, for each permutation of the possible results.  But I
think it's clear that that effort would generally be wasted.  So we
would need some way to decide when this optimization would be useful.
And note that any effort in this area would tend to go against the
overall goal of fast compilation time.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUq34gWU1RryhxLsixwmsN2fOXg%3Dg%3DqvN%2BgGTtHc0azEg%40mail.gmail.com.

Reply via email to