1
0
mirror of https://github.com/golang/go synced 2024-11-12 08:50:22 -07:00
go/doc/go1.3.html

461 lines
17 KiB
HTML
Raw Normal View History

<!--{
"Title": "Go 1.3 Release Notes",
"Path": "/doc/go1.3",
"Template": true
}-->
<h2 id="introduction">Introduction to Go 1.3</h2>
<p>
The latest Go release, version 1.3, arrives six months after 1.2,
and contains no language changes.
It focuses primarily on implementation work, providing
precise garbage collection,
a major refactoring of the compiler tool chain that results in
faster builds, especially for large projects,
significant performance improvements across the board,
and support for Solaris, Plan 9 and Google's Native Client architecture (NaCl).
It also has an important refinement to the memory model regarding synchronization.
As always, Go 1.3 keeps the <a href="/doc/go1compat.html">promise
of compatibility</a>,
and almost everything
will continue to compile and run without change when moved to 1.3.
</p>
<h2 id="os">Changes to the supported operating systems and architectures</h2>
<h3 id="nacl">Support for Native Client</h3>
<p>
Support for the Native Client virtual machine architecture has returned to Go with the 1.3 release.
It runs on the 32-bit Intel architectures (<code>GOARCH=386</code>) and also on 64-bit Intel, but using
32-bit pointers (<code>GOARCH=amd64p32</code>).
There is not yet support for Native Client on ARM.
Note that this is Native Client (NaCl), not Portable Native Client (PNaCl).
Details about Native Client are <a href="https://developers.google.com/native-client/dev/">here</a>;
how to set up the Go version is described <a href="http://golang.org/wiki/NativeClient">here</a>.
</p>
<h3 id="solaris">Support for Solaris</h3>
<p>
Go 1.3 now includes experimental support for Solaris on the <code>amd64</code> (64-bit x86) architecture.
</p>
<h3 id="plan9">Support for Plan 9</h3>
<p>
Go 1.3 now includes experimental support for Plan 9 on the <code>386</code> (32-bit x86) architecture.
</p>
<h3 id="win2000">Removal of support for Windows 2000</h3>
<p>
Microsoft stopped supporting Windows 2000 in 2010.
Since it has <a href="https://codereview.appspot.com/74790043">implementation difficulties</a>
regarding exception handling (signals in Unix terminology),
as of Go 1.3 it is not supported by Go either.
</p>
<h3 id="freebsd">Support for FreeBSD</h3>
<p>
It was not announced at the time, but since the release of Go 1.2, support for Go on FreeBSD
requires FreeBSD 8 or above.
</p>
<p>
As of Go 1.3, support for Go on FreeBSD requires that the kernel be compiled with the
<code>COMPAT_FREEBSD32</code> flag configured.
</p>
<p>
In concert with the switch to EABI syscalls for ARM platforms, Go 1.3 will run only on
FreeBSD 10. The x86 platforms, 386 and amd64, are unaffected.
</p>
<h2 id="memory">Changes to the memory model</h2>
<p>
The Go 1.3 memory model <a href="https://codereview.appspot.com/75130045">adds a new rule</a>
concerning sending and receiving on buffered channels,
to make explicit that a buffered channel can be used as a simple
semaphore, using a send into the
channel to acquire and a receive from the channel to release.
This is not a language change, just a clarification about an expected property of communication.
</p>
<h2 id="impl">Changes to the implementations and tools</h2>
<h3 id="stacks">Stack</h3>
<p>
Go 1.3 has changed the implementation of goroutine stacks away from the old,
"segmented" model to a contiguous model.
When a goroutine needs more stack
than is available, its stack is transferred to a larger single block of memory.
The overhead of this transfer operation amortizes well and eliminates the old "hot spot"
problem when a calculation repeatedly steps across a segment boundary.
Details including performance numbers are in this
<a href="http://golang.org/s/contigstacks">design document</a>.
</p>
<h3 id="stack_size">Stack size</h3>
<p>
Go 1.2 increased the minimum stack size to 8 kilobytes; with the new stack model, it has been
put back to 4 kilobytes.
</p>
<h3 id="garbage_collector">Changes to the garbage collector</h3>
<p>
For a while now, the garbage collector has been <em>precise</em> when examining
values in the heap; the Go 1.3 release adds equivalent precision to values on the stack.
This means that a non-pointer Go value such as an integer will never be mistaken for a
pointer and prevent unused memory from being reclaimed.
</p>
<h3 id="liblink">The linker</h3>
<p>
As part of the general <a href="http://golang.org/s/go13linker">overhaul</a> to
the Go linker, the compilers and linkers have been refactored.
The linker is still a C program, but now the instruction selection phase that
was part of the linker has been moved to the compiler through the creation of a new
library called <code>liblink</code>.
By doing instruction selection only once, when the package is first compiled,
this can speed up compilation of large projects significantly.
</p>
<p>
<em>Updating</em>: Although this is a major internal change, it should have no
effect on programs.
</p>
<h3 id="gccgo">Status of gccgo</h3>
<p>
GCC release 4.9 will contain the Go 1.2 (not 1.3) version of gccgo.
The release schedules for the GCC and Go projects do not coincide,
which means that 1.3 will be available in the development branch but
that the next GCC release, 4.10, will likely have the Go 1.4 version of gccgo.
</p>
<h3 id="gocmd">Changes to the go command</h3>
<p>
The <a href="/cmd/go/"><code>cmd/go</code></a> command has several new
features.
The <a href="/cmd/go/"><code>go run</code></a> and
<a href="/cmd/go/"><code>go test</code></a> subcommands
support a new <code>-exec</code> option to specify an alternate
way to run the resulting binary.
Its immediate purpose is to support NaCl.
</p>
<p>
The test coverage support of the <a href="/cmd/go/"><code>go test</code></a>
subcommand now automatically sets the coverage mode to <code>-atomic</code>
when the race detector is enabled, to eliminate false reports about unsafe
access to coverage counters.
</p>
<p>
The <a href="/cmd/go/"><code>go test</code></a> subcommand
now always builds the package, even if it has no test files.
Previously, it would do nothing if no test files were present.
</p>
<p>
The <a href="/cmd/go/"><code>go build</code></a> subcommand
supports a new <code>-i</code> option to install dependencies
of the specified target, but not the target itself.
</p>
<p>
Finally, the go command now supports packages that import Objective-C
files (suffixed <code>.m</code>) through cgo.
</p>
<h3 id="swig">SWIG 3.0 required for programs that use SWIG</h3>
<p>
For Go programs that use SWIG, SWIG version 3.0 is now required. The
<a href="/cmd/go"><code>cmd/go</code></a> command will now link the
SWIG generated object files directly into the binary, rather than
building and linking with a shared library.
</p>
build: remove tmp dir names from objects, support GOROOT_FINAL again If we compile a generated file stored in a temporary directory - let's say /tmp/12345/work/x.c - then by default 6c stores the full path and then the pcln table in the final binary includes the full path. This makes repeated builds (using different temporary directories) produce different binaries, even if the inputs are the same. In the old 'go tool pack', the P flag specified a prefix to remove from all stored paths (if present), and cmd/go invoked 'go tool pack grcP $WORK' to remove references to the temporary work directory. We've changed the build to avoid pack as much as possible, under the theory that instead of making pack convert from .6 to .a, the tools should just write the .a directly and save a round of I/O. Instead of going back to invoking pack always, define a common flag -trimpath in the assemblers, C compilers, and Go compilers, implemented in liblink, and arrange for cmd/go to use the flag. Then the object files being written out have the shortened paths from the start. While we are here, reimplement pcln support for GOROOT_FINAL. A build in /tmp/go uses GOROOT=/tmp/go, but if GOROOT_FINAL=/usr/local/go is set, then a source file named /tmp/go/x.go is recorded instead as /usr/local/go/x.go. We use this so that we can prepare distributions to be installed in /usr/local/go without actually working in that directory. The conversion to liblink deleted all the old file name handling code, including the GOROOT_FINAL translation. Bring the GOROOT_FINAL translation back. Before this CL, using GOROOT_FINAL=/goroot make.bash: g% strings $(which go) | grep -c $TMPDIR 6 g% strings $(which go) | grep -c $GOROOT 793 g% After this CL: g% strings $(which go) | grep -c $TMPDIR 0 g% strings $(which go) | grep -c $GOROOT 0 g% (The references to $TMPDIR tend to be cgo-generated source files.) Adding the -trimpath flag to the assemblers required converting them to the new Go-semantics flag parser. The text in go1.3.html is copied and adjusted from go1.1.html, which is when we applied that conversion to the compilers and linkers. Fixes #6989. LGTM=iant R=r, iant CC=golang-codereviews https://golang.org/cl/88300045
2014-04-15 18:46:46 -06:00
<h3 id="gc_flag">Command-line flag parsing</h3>
<p>
In the gc tool chain, the assemblers now use the
same command-line flag parsing rules as the Go flag package, a departure
from the traditional Unix flag parsing. This may affect scripts that invoke
the tool directly.
For example,
<code>go tool 6a -SDfoo</code> must now be written
<code>go tool 6a -S -D foo</code>.
(The same change was made to the compilers and linkers in <a href="/doc/go1.1#gc_flag">Go 1.1</a>.)
</p>
<h3 id="misc">Miscellany</h3>
<p>
The program <code>misc/benchcmp</code> that compares
performance across benchmarking runs has been rewritten.
Once a shell and awk script in the main repository, it is now a Go program in the <code>go.tools</code> repo.
Documentation is <a href="http://godoc.org/code.google.com/p/go.tools/cmd/benchcmp">here</a>.
</p>
<p>
For the few of us that build Go distributions, the tool <code>misc/dist</code> has been
moved and renamed; it now lives in <code>misc/makerelease</code>, still in the main repository.
</p>
<h2 id="performance">Performance</h2>
<p>
The performance of Go binaries for this release has improved in many cases due to changes
in the runtime and garbage collection, plus some changes to libraries.
Significant instances include:
</p>
<ul>
<li>
As mentioned above, the default stack size has been reduced from 8 kilobytes to 4 kilobytes.
</li>
<li>
The runtime handles defers more efficiently, reducing the memory footprint by about two kilobytes
per goroutine that calls defer.
</li>
<li>
The garbage collector has been sped up, using a concurrent sweep algorithm,
better parallelization, and larger pages.
The cumulative effect can be a 50-70% reduction in collector pause time.
</li>
<li>
The race detector (see <a href="/doc/articles/race_detector.html">this guide</a>)
is now about 40% faster.
</li>
<li>
The regular expression package <a href="/pkg/regexp/"><code>regexp</code></a>
is now significantly faster for certain simple expressions due to the implementation of
a second, one-pass execution engine. The choice of which engine to use is automatic;
the details are hidden from the user.
</li>
</ul>
<p>
Also, the runtime now includes in stack dumps how long a goroutine has been blocked,
which can be useful information when debugging deadlocks or performance issues.
</p>
<h2 id="library">Changes to the standard library</h2>
<h3 id="new_packages">New packages</h3>
<p>
A new package <a href="/pkg/debug/plan9obj/"><code>debug/plan9obj</code></a> was added to the standard library.
It implements access to Plan 9 <a href="http://plan9.bell-labs.com/magic/man2html/6/a.out">a.out</a> object files.
</p>
<h3 id="major_library_changes">Major changes to the library</h3>
<p>
A previous bug in <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a>
made it possible to skip verification in TLS inadvertently.
In Go 1.3, the bug is fixed: one must specify either ServerName or
InsecureSkipVerify, and if ServerName is specified it is enforced.
This may break existing code that incorrectly depended on insecure
behavior.
</p>
<p>
There is an important new type added to the standard library: <a href="/pkg/sync/#Pool"><code>sync.Pool</code></a>.
It provides an efficient mechanism for implementing certain types of caches whose memory
can be reclaimed automatically by the system.
</p>
<p>
The <a href="/pkg/testing/"><code>testing</code></a> package's benchmarking helper,
<a href="/pkg/testing/#B"><code>B</code></a>, now has a
<a href="/pkg/testing/#B.RunParallel"><code>RunParallel</code></a> method
to make it easier to run benchmarks that exercise multiple CPUs.
</p>
<p>
<em>Updating</em>: The crypto/tls fix may break existing code, but such
code was erroneous and should be updated.
</p>
<h3 id="minor_library_changes">Minor changes to the library</h3>
<p>
The following list summarizes a number of minor changes to the library, mostly additions.
See the relevant package documentation for more information about each change.
</p>
<ul>
<li>
The complex power function, <a href="/pkg/math/cmplx/#Pow"><code>Pow</code></a>,
now specifies the behavior when the first argument is zero. It was undefined before.
The details are in the <a href="/pkg/math/cmplx/#Pow">documentation for the function</a>.
</li>
<li> In the <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package,
a new <a href="/pkg/crypto/tls/#DialWithDialer"><code>DialWithDialer</code></a>
function lets one establish a TLS connection using an existing dialer, making it easier
to control dial options such as timeouts.
The package also now reports the TLS version used by the connection in the
<a href="/pkg/crypto/tls/#ConnectionState"><code>ConnectionState</code></a>
struct.
</li>
<li> The <a href="/pkg/crypto/x509/#CreateCertificate"><code>CreateCertificate</code></a>
function of the <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
now supports parsing (and elsewhere, serialization) of PKCS #10 certificate
signature requests.
</li>
<li>
The formatted print functions of the <code>fmt</code> package now define <code>%F</code>
as a synonym for <code>%f</code> when printing floating-point values.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package now exposes the
properties of a TLS connection used to make a client request in the new
<a href="/pkg/net/http/#Response"><code>Response.TLS</code></a> field.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package now
allows setting an optional server error logger
with <a href="/pkg/net/http/#Server"><code>Server.ErrorLog</code></a>.
The default is still that all errors go to stderr.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package now
supports disabling HTTP keep-alive connections on the server
with <a href="/pkg/net/http/#Server.SetKeepAlivesEnabled"><code>Server.SetKeepAlivesEnabled</code></a>.
The default continues to be that the server does keep-alive (reuses
connections for multiple requests) by default. Only
resource-constrained servers or those in the process of graceful
shutdown will want to disable them.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package adds an optional
<a href="/pkg/net/http/#Transport"><code>Transport.TLSHandshakeTimeout</code></a>
setting to cap the amount of time HTTP client requests will wait for
TLS handshakes to complete. It's now also set by default
on <a href="/pkg/net/http#DefaultTransport"><code>DefaultTransport</code></a>.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package's
<a href="/pkg/net/http/#DefaultTransport"><code>DefaultTransport</code></a>,
used by the HTTP client code, now
enables <a href="http://en.wikipedia.org/wiki/Keepalive#TCP_keepalive">TCP
keep-alives</a> by
default. Other <a href="/pkg/net/http/#Transport"><code>Transport</code></a>
values with a nil <code>Dial</code> field continue to function the same
as before: no TCP keep-alives are used.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package
now enables <a href="http://en.wikipedia.org/wiki/Keepalive#TCP_keepalive">TCP
keep-alives</a> for incoming server requests when
<a href="/pkg/net/http/#ListenAndServe"><code>ListenAndServe</code></a>
or
<a href="/pkg/net/http/#ListenAndServeTLS"><code>ListenAndServeTLS</code></a>
are used. When a server is started otherwise, TCP keep-alives are not enabled.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package now
provides an
optional <a href="/pkg/net/http/#Server"><code>Server.ConnState</code></a>
callback to hook various phases of a server connection's lifecycle
(see <a href="/pkg/net/http/#ConnState"><code>ConnState</code></a>). This
can be used to implement rate limiting or graceful shutdown.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package's HTTP
client now has an
optional <a href="/pkg/net/http/#Client"><code>Client.Timeout</code></a>
field to specify an end-to-end timeout on requests made using the
client.
</li>
<li> In the <a href="/pkg/net/"><code>net</code></a> package,
the <a href="/pkg/net/#Dialer"><code>Dialer</code></a> struct now
has a <code>KeepAlive</code> option to specify a keep-alive period for the connection.
</li>
<li>
The <a href="/pkg/net/http/"><code>net/http</code></a> package's
<a href="/pkg/net/http/#Transport"><code>Transport</code></a>
now closes <a href="/pkg/net/http/#Request"><code>Request.Body</code></a>
consistently, even on error.
</li>
<li>
The <a href="/pkg/os/exec/"><code>os/exec</code></a> package now implements
what the documentation has always said with regard to relative paths for the binary.
In particular, it only calls <a href="/pkg/os/exec/#LookPath"><code>LookPath</code></a>
when the binary's file name contains no path separators.
</li>
<li>
If the main goroutine calls
<a href="/pkg/runtime/#Goexit"><code>runtime.Goexit</code></a>
and all other goroutines finish execution, the program now always crashes,
reporting a detected deadlock.
Earlier versions of Go handled this situation inconsistently: most instances
were reported as deadlocks, but some trivial cases exited cleanly instead.
</li>
<li>
The <a href="/pkg/strconv/#CanBackquote"><code>CanBackquote</code></a>
function in the <a href="/pkg/strconv/"><code>strconv</code></a> package
now considers the <code>DEL</code> character, <code>U+007F</code>, to be
non-printing.
</li>
<li>
On Windows, the <a href="/pkg/syscall/"><code>syscall</code></a> package now
supports the cdecl calling convention through the addition of a new function
<a href="/pkg/syscall/#NewCallbackCDecl"><code>NewCallbackCDecl</code></a>
alongside the existing function
<a href="/pkg/syscall/#NewCallback"><code>NewCallback</code></a>.
</li>
<li>
The <a href="/pkg/testing/"><code>testing</code></a> package now
diagnoses tests that call <code>panic(nil)</code>, which are almost always erroneous.
Also, tests now write profiles (if invoked with profiling flags) even on failure.
</li>
<li>
The <a href="/pkg/unicode/"><code>unicode</code></a> package and associated
support throughout the system has been upgraded from
Unicode 6.2.0 to <a href="http://www.unicode.org/versions/Unicode6.3.0/">Unicode 6.3.0</a>.
</li>
</ul>