On Thu, Feb 11, 2016 at 4:19 PM, <
thebroke...@gmail.com> wrote:
>
> I was thinking about this, but wouldn't the compiler be able to do a global
> analysis of all concrete types that implement io.Writer.
The compiler can only see the package being compiled and whatever
information it can glean from the packages that it imports. In this
case Bar might be called by some other package that hasn't even been
written at the time that Bar is being compiled. There is no way for
the compiler to know whether that unwritten package implements a Write
method that lets the argument escape.
This kind of optimization can be done at link time (assuming no shared
libraries are involved). At link time you really do see all the
relevant code. But of course at that point code has already been
generated, so you are really talking about a different kind of
compiler architecture. Compilers like GCC and LLVM are in fact
capable of doing this kind of optimization. The gc compiler is not,
and there are no current plans to make it work that way.
Ian