doc/go1.17: editing pass over the "Compiler" section

Change-Id: I08c082f548daa7011a8dc42769371329684c90e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/333609
Trust: Austin Clements <austin@google.com>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Austin Clements 2021-07-09 16:22:32 -04:00
parent ab4085ce84
commit cfbd73ba33

View file

@ -401,30 +401,37 @@ func Foo() bool {
<p><!-- golang.org/issue/40724 --> <p><!-- golang.org/issue/40724 -->
Go 1.17 implements a new way of passing function arguments and results using Go 1.17 implements a new way of passing function arguments and results using
registers instead of the stack. This work is enabled for Linux, macOS, and registers instead of the stack.
Windows on the 64-bit x86 architecture (the <code>linux/amd64</code>, Benchmarks for a representative set of Go packages and programs show
<code>darwin/amd64</code>, <code>windows/amd64</code> ports). For a performance improvements of about 5%, and a typical reduction in
representative set of Go packages and programs, benchmarking has shown binary size of about 2%.
performance improvements of about 5%, and a typical reduction in binary size This is currently enabled for Linux, macOS, and Windows on the
of about 2%. 64-bit x86 architecture (the <code>linux/amd64</code>,
<code>darwin/amd64</code>, and <code>windows/amd64</code> ports).
</p> </p>
<p> <p>
This change does not affect the functionality of any safe Go code. It can affect This change does not affect the functionality of any safe Go code
code outside the <a href="/doc/go1compat">compatibility guidelines</a> with and is designed to have no impact on most assembly code.
minimal impact. To maintain compatibility with existing assembly functions, It may affect code that violates
adapter functions converting between the new register-based calling convention the <a href="/pkg/unsafe#Pointer"><code>unsafe.Pointer</code></a>
and the previous stack-based calling convention (also known as ABI wrappers) rules when accessing function arguments, or that depends on
are sometimes used. This is mostly invisible to users, except for assembly undocumented behavior involving comparing function code pointers.
functions that have their addresses taken in Go. Using <code>reflect.ValueOf(fn).Pointer()</code> To maintain compatibility with existing assembly functions, the
(or similar approaches such as via <code>unsafe.Pointer</code>) to get the address compiler generates adapter functions that convert between the new
of an assembly function will now return the address of the ABI wrapper. This is register-based calling convention and the previous stack-based
mostly harmless, except for special-purpose assembly code (such as accessing calling convention.
thread-local storage or requiring a special stack alignment). Assembly functions These adapters are typically invisible to users, except that taking
called indirectly from Go via <code>func</code> values will now be made through the address of a Go function in assembly code or taking the address
ABI wrappers, which may cause a very small performance overhead. Also, calling of an assembly function in Go code
Go functions from assembly may now go through ABI wrappers, with a very small using <code>reflect.ValueOf(fn).Pointer()</code>
performance overhead. or <code>unsafe.Pointer</code> will now return the address of the
adapter.
Code that depends on the value of these code pointers may no longer
behave as expected.
Adapters also may cause a very small performance overhead in two
cases: calling an assembly function indirectly from Go via
a <code>func</code> value, and calling Go functions from assembly.
</p> </p>
<p><!-- CL 304470 --> <p><!-- CL 304470 -->
@ -440,11 +447,14 @@ func Foo() bool {
</p> </p>
<p><!-- CL 283112, golang.org/issue/28727 --> <p><!-- CL 283112, golang.org/issue/28727 -->
Functions containing closures can now be inlined. One effect of this change is Functions containing closures can now be inlined.
that a function with a closure may actually produce a distinct closure function One effect of this change is that a function with a closure may
for each place that the function is inlined. Hence, this change could reveal produce a distinct closure code pointer for each place that the
bugs where Go functions are compared (incorrectly) by pointer value. Go function is inlined.
functions are by definition not comparable. Go function values are not directly comparable, but this change
could reveal bugs in code that uses <code>reflect</code>
or <code>unsafe.Pointer</code> to bypass this language restriction
and compare functions by code pointer.
</p> </p>
<h2 id="library">Core library</h2> <h2 id="library">Core library</h2>