blob: ca44d56ceb2b61cfc53d91e3a0f3a13ef0b25e65 [file] [log] [blame]
Rob Pike456df7c2014-10-27 14:23:24 -07001<!--{
2 "Title": "Go 1.4 Release Notes",
3 "Path": "/doc/go1.4",
4 "Template": true
5}-->
6
7<h2 id="introduction">Introduction to Go 1.4</h2>
8
9<p>
Rob Pikef03f0cb2014-11-18 13:32:00 +110010The latest Go release, version 1.4, arrives as scheduled six months after 1.3.
Andrew Gerrand33da2432014-12-11 11:22:54 +110011</p>
12
13<p>
Rob Pikef03f0cb2014-11-18 13:32:00 +110014It contains only one tiny language change,
15in the form of a backwards-compatible simple variant of <code>for</code>-<code>range</code> loop,
16and a possibly breaking change to the compiler involving methods on pointers-to-pointers.
Andrew Gerrand33da2432014-12-11 11:22:54 +110017</p>
18
19<p>
Rob Pike456df7c2014-10-27 14:23:24 -070020The release focuses primarily on implementation work, improving the garbage collector
21and preparing the ground for a fully concurrent collector to be rolled out in the
22next few releases.
23Stacks are now contiguous, reallocated when necessary rather than linking on new
24"segments";
25this release therefore eliminates the notorious "hot stack split" problem.
26There are some new tools available including support in the <code>go</code> command
Rob Pike97b24a02014-10-29 13:07:34 -070027for build-time source code generation.
Rob Piked7660142014-10-28 12:11:34 -070028The release also adds support for ARM processors on Android and Native Client (NaCl)
Rob Pikef03f0cb2014-11-18 13:32:00 +110029and for AMD64 on Plan 9.
Andrew Gerrand33da2432014-12-11 11:22:54 +110030</p>
31
32<p>
Rob Pike456df7c2014-10-27 14:23:24 -070033As always, Go 1.4 keeps the <a href="/doc/go1compat.html">promise
34of compatibility</a>,
35and almost everything
36will continue to compile and run without change when moved to 1.4.
37</p>
38
39<h2 id="language">Changes to the language</h2>
40
41<h3 id="forrange">For-range loops</h3>
42<p>
43Up until Go 1.3, <code>for</code>-<code>range</code> loop had two forms
44</p>
45
46<pre>
Andrew Gerrand33da2432014-12-11 11:22:54 +110047for i, v := range x {
Rob Pike456df7c2014-10-27 14:23:24 -070048 ...
49}
50</pre>
51
52<p>
53and
54</p>
55
56<pre>
Andrew Gerrand33da2432014-12-11 11:22:54 +110057for i := range x {
Rob Pike456df7c2014-10-27 14:23:24 -070058 ...
59}
60</pre>
61
62<p>
63If one was not interested in the loop values, only the iteration itself, it was still
64necessary to mention a variable (probably the <a href="/ref/spec#Blank_identifier">blank identifier</a>, as in
65<code>for</code> <code>_</code> <code>=</code> <code>range</code> <code>x</code>), because
66the form
67</p>
68
69<pre>
70for range x {
71 ...
72}
73</pre>
74
75<p>
76was not syntactically permitted.
77</p>
78
79<p>
80This situation seemed awkward, so as of Go 1.4 the variable-free form is now legal.
Rob Piked7660142014-10-28 12:11:34 -070081The pattern arises rarely but the code can be cleaner when it does.
Rob Pike456df7c2014-10-27 14:23:24 -070082</p>
83
84<p>
85<em>Updating</em>: The change is strictly backwards compatible to existing Go
86programs, but tools that analyze Go parse trees may need to be modified to accept
87this new form as the
88<code>Key</code> field of <a href="/pkg/go/ast/#RangeStmt"><code>RangeStmt</code></a>
89may now be <code>nil</code>.
90</p>
91
Rob Pike982dcb22014-10-28 13:49:41 -070092<h3 id="methodonpointertopointer">Method calls on **T</h3>
93
94<p>
95Given these declarations,
96</p>
97
98<pre>
99type T int
100func (T) M() {}
101var x **T
102</pre>
103
104<p>
105both <code>gc</code> and <code>gccgo</code> accepted the method call
106</p>
107
108<pre>
109x.M()
110</pre>
111
112<p>
113which is a double dereference of the pointer-to-pointer <code>x</code>.
114The Go specification allows a single dereference to be inserted automatically,
115but not two, so this call is erroneous according to the language definition.
116It has therefore been disallowed in Go 1.4, which is a breaking change,
117although very few programs will be affected.
118</p>
119
120<p>
121<em>Updating</em>: Code that depends on the old, erroneous behavior will no longer
122compile but is easy to fix by adding an explicit dereference.
123</p>
124
Rob Pike456df7c2014-10-27 14:23:24 -0700125<h2 id="os">Changes to the supported operating systems and architectures</h2>
126
Rob Piked7660142014-10-28 12:11:34 -0700127<h3 id="android">Android</h3>
Rob Pike456df7c2014-10-27 14:23:24 -0700128
129<p>
Rob Piked7660142014-10-28 12:11:34 -0700130Go 1.4 can build binaries for ARM processors running the Android operating system.
131It can also build a <code>.so</code> library that can be loaded by an Android application
Russ Cox6bc812e2014-11-06 15:18:47 -0500132using the supporting packages in the <a href="https://golang.org/x/mobile">mobile</a> subrepository.
Rob Piked7660142014-10-28 12:11:34 -0700133A brief description of the plans for this experimental port are available
Russ Cox6bc812e2014-11-06 15:18:47 -0500134<a href="https://golang.org/s/go14android">here</a>.
Rob Piked7660142014-10-28 12:11:34 -0700135</p>
136
137<h3 id="naclarm">NaCl on ARM</h3>
138
139<p>
140The previous release introduced Native Client (NaCl) support for the 32-bit x86
141(<code>GOARCH=386</code>)
142and 64-bit x86 using 32-bit pointers (GOARCH=amd64p32).
143The 1.4 release adds NaCl support for ARM (GOARCH=arm).
144</p>
145
146<h3 id="plan9amd64">Plan9 on AMD64</h3>
147
148<p>
149This release adds support for the Plan 9 operating system on AMD64 processors,
150provided the kernel supports the <code>nsec</code> system call and uses 4K pages.
Rob Pike456df7c2014-10-27 14:23:24 -0700151</p>
152
Rob Pikecd692182014-10-27 22:47:50 -0700153<h2 id="compatibility">Changes to the compatibility guidelines</h2>
154
155<p>
156The <a href="/pkg/unsafe/"><code>unsafe</code></a> package allows one
157to defeat Go's type system by exploiting internal details of the implementation
158or machine representation of data.
159It was never explicitly specified what use of <code>unsafe</code> meant
160with respect to compatibility as specified in the
Rob Pikebd1169d2014-10-28 10:51:28 -0700161<a href="go1compat.html">Go compatibility guidelines</a>.
Rob Pikecd692182014-10-27 22:47:50 -0700162The answer, of course, is that we can make no promise of compatibility
163for code that does unsafe things.
164</p>
165
166<p>
167We have clarified this situation in the documentation included in the release.
Rob Pikece7c8fe2014-10-28 20:12:17 -0700168The <a href="go1compat.html">Go compatibility guidelines</a> and the
Rob Pikecd692182014-10-27 22:47:50 -0700169docs for the <a href="/pkg/unsafe/"><code>unsafe</code></a> package
170are now explicit that unsafe code is not guaranteed to remain compatible.
171</p>
172
173<p>
174<em>Updating</em>: Nothing technical has changed; this is just a clarification
175of the documentation.
176</p>
177
178
179<h2 id="impl">Changes to the implementations and tools</h2>
180
181<h3 id="runtime">Changes to the runtime</h3>
Rob Piked39907e2014-10-27 20:35:34 -0700182
183<p>
Andrew Gerrand33da2432014-12-11 11:22:54 +1100184Prior to Go 1.4, the runtime (garbage collector, concurrency support, interface management,
Rob Piked39907e2014-10-27 20:35:34 -0700185maps, slices, strings, ...) was mostly written in C, with some assembler support.
186In 1.4, much of the code has been translated to Go so that the garbage collector can scan
187the stacks of programs in the runtime and get accurate information about what variables
188are active.
189This change was large but should have no semantic effect on programs.
190</p>
191
192<p>
193This rewrite allows the garbage collector in 1.4 to be fully precise,
194meaning that it is aware of the location of all active pointers in the program.
195This means the heap will be smaller as there will be no false positives keeping non-pointers alive.
196Other related changes also reduce the heap size, which is smaller by 10%-30% overall
197relative to the previous release.
198</p>
199
200<p>
201A consequence is that stacks are no longer segmented, eliminating the "hot split" problem.
202When a stack limit is reached, a new, larger stack is allocated, all active frames for
203the goroutine are copied there, and any pointers into the stack are updated.
204Performance can be noticeably better in some cases and is always more predictable.
Russ Cox6bc812e2014-11-06 15:18:47 -0500205Details are available in <a href="https://golang.org/s/contigstacks">the design document</a>.
Rob Piked39907e2014-10-27 20:35:34 -0700206</p>
207
208<p>
209The use of contiguous stacks means that stacks can start smaller without triggering performance issues,
Andrew Gerrand33da2432014-12-11 11:22:54 +1100210so the default starting size for a goroutine's stack in 1.4 has been reduced from 8192 bytes to 2048 bytes.
Rob Piked39907e2014-10-27 20:35:34 -0700211</p>
212
213<p>
214As preparation for the concurrent garbage collector scheduled for the 1.5 release,
215writes to pointer values in the heap are now done by a function call,
216called a write barrier, rather than directly from the function updating the value.
217In this next release, this will permit the garbage collector to mediate writes to the heap while it is running.
218This change has no semantic effect on programs in 1.4, but was
219included in the release to test the compiler and the resulting performance.
220</p>
221
222<p>
223The implementation of interface values has been modified.
224In earlier releases, the interface contained a word that was either a pointer or a one-word
225scalar value, depending on the type of the concrete object stored.
226This implementation was problematical for the garbage collector,
227so as of 1.4 interface values always hold a pointer.
228In running programs, most interface values were pointers anyway,
229so the effect is minimal, but programs that store integers (for example) in
230interfaces will see more allocations.
231</p>
232
Rob Pikece7c8fe2014-10-28 20:12:17 -0700233<p>
234As of Go 1.3, the runtime crashes if it finds a memory word that should contain
235a valid pointer but instead contains an obviously invalid pointer (for example, the value 3).
236Programs that store integers in pointer values may run afoul of this check and crash.
237In Go 1.4, setting the <a href="/pkg/runtime/"><code>GODEBUG</code></a> variable
238<code>invalidptr=0</code> disables
239the crash as a workaround, but we cannot guarantee that future releases will be
240able to avoid the crash; the correct fix is to rewrite code not to alias integers and pointers.
241</p>
242
243<h3 id="asm">Assembly</h3>
244
245<p>
246The language accepted by the assemblers <code>cmd/5a</code>, <code>cmd/6a</code>
247and <code>cmd/8a</code> has had several changes,
248mostly to make it easier to deliver type information to the runtime.
249</p>
250
251<p>
252First, the <code>textflag.h</code> file that defines flags for <code>TEXT</code> directives
253has been copied from the linker source directory to a standard location so it can be
254included with the simple directive
255</p>
256
257<pre>
258#include "textflag.h"
259</pre>
260
261<p>
262The more important changes are in how assembler source can define the necessary
263type information.
264For most programs it will suffice to move data
265definitions (<code>DATA</code> and <code>GLOBL</code> directives)
266out of assembly into Go files
267and to write a Go declaration for each assembly function.
268The <a href="/doc/asm#runtime">assembly document</a> describes what to do.
269</p>
270
271<p>
272<em>Updating</em>:
273Assembly files that include <code>textflag.h</code> from its old
274location will still work, but should be updated.
275For the type information, most assembly routines will need no change,
276but all should be examined.
277Assembly source files that define data,
278functions with non-empty stack frames, or functions that return pointers
279need particular attention.
280A description of the necessary (but simple) changes
281is in the <a href="/doc/asm#runtime">assembly document</a>.
282</p>
283
284<p>
285More information about these changes is in the <a href="/doc/asm">assembly document</a>.
286</p>
287
Rob Pike456df7c2014-10-27 14:23:24 -0700288<h3 id="gccgo">Status of gccgo</h3>
289
290<p>
Rob Pike97b24a02014-10-29 13:07:34 -0700291The release schedules for the GCC and Go projects do not coincide.
292GCC release 4.9 contains the Go 1.2 version of gccgo.
293The next release, GCC 5, will likely have the Go 1.4 version of gccgo.
Rob Pike456df7c2014-10-27 14:23:24 -0700294</p>
295
Rob Pikecd692182014-10-27 22:47:50 -0700296<h3 id="internalpackages">Internal packages</h3>
Rob Pikecd692182014-10-27 22:47:50 -0700297
Rob Pikebd1169d2014-10-28 10:51:28 -0700298<p>
299Go's package system makes it easy to structure programs into components with clean boundaries,
300but there are only two forms of access: local (unexported) and global (exported).
301Sometimes one wishes to have components that are not exported,
302for instance to avoid acquiring clients of interfaces to code that is part of a public repository
303but not intended for use outside the program to which it belongs.
304</p>
305
306<p>
307The Go language does not have the power to enforce this distinction, but as of Go 1.4 the
308<a href="/cmd/go/"><code>go</code></a> command introduces
309a mechanism to define "internal" packages that may not be imported by packages outside
310the source subtree in which they reside.
311</p>
312
313<p>
314To create such a package, place it in a directory named <code>internal</code> or in a subdirectory of a directory
315named internal.
316When the <code>go</code> command sees an import of a package with <code>internal</code> in its path,
317it verifies that the package doing the import
318is within the tree rooted at the parent of the <code>internal</code> directory.
319For example, a package <code>.../a/b/c/internal/d/e/f</code>
320can be imported only by code in the directory tree rooted at <code>.../a/b/c</code>.
321It cannot be imported by code in <code>.../a/b/g</code> or in any other repository.
322</p>
323
324<p>
325For Go 1.4, the internal package mechanism is enforced for the main Go repository;
326from 1.5 and onward it will be enforced for any repository.
327</p>
328
329<p>
330Full details of the mechanism are in
Russ Cox6bc812e2014-11-06 15:18:47 -0500331<a href="https://golang.org/s/go14internal">the design document</a>.
Rob Pikebd1169d2014-10-28 10:51:28 -0700332</p>
333
334<h3 id="canonicalimports">Canonical import paths</h3>
335
336<p>
337Code often lives in repositories hosted by public services such as <code>github.com</code>,
338meaning that the import paths for packages begin with the name of the hosting service,
339<code>github.com/rsc/pdf</code> for example.
340One can use
341<a href="/cmd/go/#hdr-Remote_import_paths">an existing mechanism</a>
342to provide a "custom" or "vanity" import path such as
343<code>rsc.io/pdf</code>, but
344that creates two valid import paths for the package.
345That is a problem: one may inadvertently import the package through the two
346distinct paths in a single program, which is wasteful;
347miss an update to a package because the path being used is not recognized to be
348out of date;
349or break clients using the old path by moving the package to a different hosting service.
350</p>
351
352<p>
353Go 1.4 introduces an annotation for package clauses in Go source that identify a canonical
354import path for the package.
355If an import is attempted using a path that is not canonical,
356the <a href="/cmd/go/"><code>go</code></a> command
357will refuse to compile the importing package.
358</p>
359
360<p>
361The syntax is simple: put an identifying comment on the package line.
362For our example, the package clause would read:
363</p>
Rob Pikecd692182014-10-27 22:47:50 -0700364
365<pre>
Rob Pikebd1169d2014-10-28 10:51:28 -0700366package pdf // import "rsc.io/pdf"
Rob Pikecd692182014-10-27 22:47:50 -0700367</pre>
368
Rob Pikebd1169d2014-10-28 10:51:28 -0700369<p>
370With this in place,
371the <code>go</code> command will
372refuse to compile a package that imports <code>github.com/rsc/pdf</code>,
373ensuring that the code can be moved without breaking users.
374</p>
375
376<p>
377The check is at build time, not download time, so if <code>go</code> <code>get</code>
378fails because of this check, the mis-imported package has been copied to the local machine
379and should be removed manually.
380</p>
381
382<p>
Andrew Gerrandb8022402014-11-03 17:01:17 +1100383To complement this new feature, a check has been added at update time to verify
384that the local package's remote repository matches that of its custom import.
385The <code>go</code> <code>get</code> <code>-u</code> command will fail to
386update a package if its remote repository has changed since it was first
387downloaded.
388The new <code>-f</code> flag overrides this check.
389</p>
390
391<p>
Rob Pikebd1169d2014-10-28 10:51:28 -0700392Further information is in
Russ Cox6bc812e2014-11-06 15:18:47 -0500393<a href="https://golang.org/s/go14customimport">the design document</a>.
Rob Pikebd1169d2014-10-28 10:51:28 -0700394</p>
395
Russ Cox67742ef2014-11-05 20:15:48 -0500396<h3 id="subrepo">Import paths for the subrepositories</h3>
397
398<p>
399The Go project subrepositories (<code>code.google.com/p/go.tools</code> and so on)
400are now available under custom import paths replacing <code>code.google.com/p/go.</code> with <code>golang.org/x/</code>,
401as in <code>golang.org/x/tools</code>.
402We will add canonical import comments to the code around June 1, 2015,
403at which point Go 1.4 and later will stop accepting the old <code>code.google.com</code> paths.
404</p>
405
406<p>
407<em>Updating</em>: All code that imports from subrepositories should change
408to use the new <code>golang.org</code> paths.
409Go 1.0 and later can resolve and import the new paths, so updating will not break
410compatibility with older releases.
411Code that has not updated will stop compiling with Go 1.4 around June 1, 2015.
412</p>
413
Rob Pikecd692182014-10-27 22:47:50 -0700414<h3 id="gogenerate">The go generate subcommand</h3>
Rob Pike456df7c2014-10-27 14:23:24 -0700415
416<p>
Rob Pikecd692182014-10-27 22:47:50 -0700417The <a href="/cmd/go/"><code>go</code></a> command has a new subcommand,
418<a href="/cmd/go/#hdr-Generate_Go_files_by_processing_source"><code>go generate</code></a>,
419to automate the running of tools to generate source code before compilation.
Rob Pikebd1169d2014-10-28 10:51:28 -0700420For example, it can be used to run the <a href="/cmd/yacc"><code>yacc</code></a>
Rob Pikecd692182014-10-27 22:47:50 -0700421compiler-compiler on a <code>.y</code> file to produce the Go source file implementing the grammar,
422or to automate the generation of <code>String</code> methods for typed constants using the new
Russ Cox67742ef2014-11-05 20:15:48 -0500423<a href="http://godoc.org/golang.org/x/tools/cmd/stringer">stringer</a>
424tool in the <code>golang.org/x/tools</code> subrepository.
Rob Pike456df7c2014-10-27 14:23:24 -0700425</p>
426
Rob Pikecd692182014-10-27 22:47:50 -0700427<p>
428For more information, see the
Russ Cox6bc812e2014-11-06 15:18:47 -0500429<a href="https://golang.org/s/go1.4-generate">design document</a>.
Rob Pikecd692182014-10-27 22:47:50 -0700430</p>
431
432<h3 id="filenames">Change to file name handling</h3>
433
434<p>
435Build constraints, also known as build tags, control compilation by including or excluding files
436(see the documentation <a href="/pkg/go/build/"><code>/go/build</code></a>).
437Compilation can also be controlled by the name of the file itself by "tagging" the file with
438a suffix (before the <code>.go</code> or <code>.s</code> extension) with an underscore
439and the name of the architecture or operating system.
440For instance, the file <code>gopher_arm.go</code> will only be compiled if the target
441processor is an ARM.
442</p>
443
444<p>
445Before Go 1.4, a file called just <code>arm.go</code> was similarly tagged, but this behavior
446can break sources when new architectures are added, causing files to suddenly become tagged.
447In 1.4, therefore, a file will be tagged in this manner only if the tag (architecture or operating
448system name) is preceded by an underscore.
449</p>
450
451<p>
452<em>Updating</em>: Packages that depend on the old behavior will no longer compile correctly.
Rob Pikebd1169d2014-10-28 10:51:28 -0700453Files with names like <code>windows.go</code> or <code>amd64.go</code> should either
Rob Pikecd692182014-10-27 22:47:50 -0700454have explicit build tags added to the source or be renamed to something like
Rob Pikebd1169d2014-10-28 10:51:28 -0700455<code>os_windows.go</code> or <code>support_amd64.go</code>.
Rob Pikecd692182014-10-27 22:47:50 -0700456</p>
457
458<h3 id="gocmd">Other changes to the go command</h3>
459
460<p>
461There were a number of minor changes to the
462<a href="/cmd/go/"><code>cmd/go</code></a>
463command worth noting.
464</p>
465
466<ul>
467
468<li>
469Unless <a href="/cmd/cgo/"><code>cgo</code></a> is being used to build the package,
470the <code>go</code> command now refuses to compile C source files,
471since the relevant C compilers
472(<a href="/cmd/6c/"><code>6c</code></a> etc.)
473are intended to be removed from the installation in some future release.
474(They are used today only to build part of the runtime.)
475It is difficult to use them correctly in any case, so any extant uses are likely incorrect,
476so we have disabled them.
477</li>
478
479<li>
480The <a href="/cmd/go/#hdr-Test_packages"><code>go</code> <code>test</code></a>
481subcommand has a new flag, <code>-o</code>, to set the name of the resulting binary,
482corresponding to the same flag in other subcommands.
483The non-functional <code>-file</code> flag has been removed.
484</li>
485
486<li>
487The <a href="/cmd/go/#hdr-Test_packages"><code>go</code> <code>test</code></a>
Rob Pikebd1169d2014-10-28 10:51:28 -0700488subcommand will compile and link all <code>*_test.go</code> files in the package,
Rob Pikecd692182014-10-27 22:47:50 -0700489even when there are no <code>Test</code> functions in them.
490It previously ignored such files.
491</li>
492
493<li>
494The behavior of the
Rob Pikebd1169d2014-10-28 10:51:28 -0700495<a href="/cmd/go/#hdr-Test_packages"><code>go</code> <code>build</code></a>
496subcommand's
Rob Pikecd692182014-10-27 22:47:50 -0700497<code>-a</code> flag has been changed for non-development installations.
498For installations running a released distribution, the <code>-a</code> flag will no longer
499rebuild the standard library and commands, to avoid overwriting the installation's files.
500</li>
501
502</ul>
503
Rob Pike456df7c2014-10-27 14:23:24 -0700504<h3 id="pkg">Changes to package source layout</h3>
505
506<p>
507In the main Go source repository, the source code for the packages was kept in
508the directory <code>src/pkg</code>, which made sense but differed from
Russ Cox67742ef2014-11-05 20:15:48 -0500509other repositories, including the Go subrepositories.
Rob Pike456df7c2014-10-27 14:23:24 -0700510In Go 1.4, the<code> pkg</code> level of the source tree is now gone, so for example
511the <a href="/pkg/fmt/"><code>fmt</code></a> package's source, once kept in
512directory <code>src/pkg/fmt</code>, now lives one level higher in <code>src/fmt</code>.
513</p>
514
515<p>
516<em>Updating</em>: Tools like <code>godoc</code> that discover source code
517need to know about the new location. All tools and services maintained by the Go team
518have been updated.
519</p>
520
Rob Pike799da9c2014-10-29 08:15:58 -0700521
522<h3 id="swig">SWIG</h3>
523
524<p>
Andrew Gerrand8ea28022014-12-11 09:11:08 +1100525Due to runtime changes in this release, Go 1.4 requires SWIG 3.0.3.
Rob Pike799da9c2014-10-29 08:15:58 -0700526</p>
527
Rob Pike456df7c2014-10-27 14:23:24 -0700528<h3 id="misc">Miscellany</h3>
529
530<p>
Rob Pike982dcb22014-10-28 13:49:41 -0700531The standard repository's top-level <code>misc</code> directory used to contain
532Go support for editors and IDEs: plugins, initialization scripts and so on.
533Maintaining these was becoming time-consuming
534and needed external help because many of the editors listed were not used by
535members of the core team.
536It also required us to make decisions about which plugin was best for a given
537editor, even for editors we do not use.
538</p>
539
540<p>
541The Go community at large is much better suited to managing this information.
542In Go 1.4, therefore, this support has been removed from the repository.
543Instead, there is a curated, informative list of what's available on
Andrew Gerrand33da2432014-12-11 11:22:54 +1100544a <a href="//golang.org/wiki/IDEsAndTextEditorPlugins">wiki page</a>.
Rob Pike456df7c2014-10-27 14:23:24 -0700545</p>
546
547<h2 id="performance">Performance</h2>
548
549<p>
Rob Piked39907e2014-10-27 20:35:34 -0700550Most programs will run about the same speed or slightly faster in 1.4 than in 1.3;
551some will be slightly slower.
552There are many changes, making it hard to be precise about what to expect.
553</p>
554
555<p>
556As mentioned above, much of the runtime was translated to Go from C,
557which led to some reduction in heap sizes.
558It also improved performance slightly because the Go compiler is better
559at optimization, due to things like inlining, than the C compiler used to build
560the runtime.
561</p>
562
563<p>
564The garbage collector was sped up, leading to measurable improvements for
565garbage-heavy programs.
566On the other hand, the new write barriers slow things down again, typically
567by about the same amount but, depending on their behavior, some programs
568may be somewhat slower or faster.
569</p>
570
571<p>
572Library changes that affect performance are documented below.
Rob Pike456df7c2014-10-27 14:23:24 -0700573</p>
574
575<h2 id="library">Changes to the standard library</h2>
576
577<h3 id="new_packages">New packages</h3>
578
579<p>
Rob Pike982dcb22014-10-28 13:49:41 -0700580There are no new packages in this release.
Rob Pike456df7c2014-10-27 14:23:24 -0700581</p>
582
583<h3 id="major_library_changes">Major changes to the library</h3>
584
Rob Pikebfe459a2014-10-29 15:35:48 -0700585<h4 id="scanner">bufio.Scanner</h4>
586
Rob Pike456df7c2014-10-27 14:23:24 -0700587<p>
Rob Pikebfe459a2014-10-29 15:35:48 -0700588The <a href="/pkg/bufio/#Scanner"><code>Scanner</code></a> type in the
589<a href="/pkg/bufio/"><code>bufio</code></a> package
590has had a bug fixed that may require changes to custom
591<a href="/pkg/bufio/#SplitFunc"><code>split functions</code></a>.
592The bug made it impossible to generate an empty token at EOF; the fix
593changes the end conditions seen by the split function.
594Previously, scanning stopped at EOF if there was no more data.
595As of 1.4, the split function will be called once at EOF after input is exhausted,
596so the split function can generate a final empty token
597as the documentation already promised.
Rob Pike456df7c2014-10-27 14:23:24 -0700598</p>
599
Rob Pikebfe459a2014-10-29 15:35:48 -0700600<p>
601<em>Updating</em>: Custom split functions may need to be modified to
602handle empty tokens at EOF as desired.
603</p>
604
605<h4 id="syscall">syscall</h4>
606
607<p>
608The <a href="/pkg/syscall/"><code>syscall</code></a> package is now frozen except
609for changes needed to maintain the core repository.
610In particular, it will no longer be extended to support new or different system calls
611that are not used by the core.
Russ Cox6bc812e2014-11-06 15:18:47 -0500612The reasons are described at length in <a href="https://golang.org/s/go1.4-syscall">a
Rob Pikebfe459a2014-10-29 15:35:48 -0700613separate document</a>.
614</p>
615
616<p>
Russ Cox6bc812e2014-11-06 15:18:47 -0500617A new subrepository, <a href="https://golang.org/x/sys">golang.org/x/sys</a>,
Rob Pikebfe459a2014-10-29 15:35:48 -0700618has been created to serve as the location for new developments to support system
619calls on all kernels.
620It has a nicer structure, with three packages that each hold the implementation of
621system calls for one of
Russ Cox67742ef2014-11-05 20:15:48 -0500622<a href="http://godoc.org/golang.org/x/sys/unix">Unix</a>,
623<a href="http://godoc.org/golang.org/x/sys/windows">Windows</a> and
624<a href="http://godoc.org/golang.org/x/sys/plan9">Plan 9</a>.
Rob Pikebfe459a2014-10-29 15:35:48 -0700625These packages will be curated more generously, accepting all reasonable changes
626that reflect kernel interfaces in those operating systems.
627See the documentation and the article mentioned above for more information.
628</p>
629
630<p>
631<em>Updating</em>: Existing programs are not affected as the <code>syscall</code>
632package is largely unchanged from the 1.3 release.
633Future development that requires system calls not in the <code>syscall</code> package
Russ Cox67742ef2014-11-05 20:15:48 -0500634should build on <code>golang.org/x/sys</code> instead.
Rob Pikebfe459a2014-10-29 15:35:48 -0700635</p>
Rob Piked7660142014-10-28 12:11:34 -0700636
Rob Pike456df7c2014-10-27 14:23:24 -0700637<h3 id="minor_library_changes">Minor changes to the library</h3>
638
639<p>
640The following list summarizes a number of minor changes to the library, mostly additions.
641See the relevant package documentation for more information about each change.
642</p>
643
644<ul>
645
Rob Pike799da9c2014-10-29 08:15:58 -0700646<li>
Nigel Taoe522a472014-11-11 16:06:47 +1100647The <a href="/pkg/archive/zip/"><code>archive/zip</code></a> package's
648<a href="/pkg/archive/zip/#Writer"><code>Writer</code></a> now supports a
649<a href="/pkg/archive/zip/#Writer.Flush"><code>Flush</code></a> method.
650</li>
651
652<li>
Rob Pike799da9c2014-10-29 08:15:58 -0700653The <a href="/pkg/compress/flate/"><code>compress/flate</code></a>,
654<a href="/pkg/compress/gzip/"><code>compress/gzip</code></a>,
655and <a href="/pkg/compress/zlib/"><code>compress/zlib</code></a>
656packages now support a <code>Reset</code> method
657for the decompressors, allowing them to reuse buffers and improve performance.
Nigel Taoe522a472014-11-11 16:06:47 +1100658The <a href="/pkg/compress/gzip/"><code>compress/gzip</code></a> package also has a
659<a href="/pkg/compress/gzip/#Reader.Multistream"><code>Multistream</code></a> method to control support
660for multistream files.
661</li>
662
663<li>
664The <a href="/pkg/crypto/"><code>crypto</code></a> package now has a
665<a href="/pkg/crypto/#Signer"><code>Signer</code></a> interface, implemented by the
666<code>PrivateKey</code> types in
667<a href="/pkg/crypto/ecdsa"><code>crypto/ecdsa</code></a> and
668<a href="/pkg/crypto/rsa"><code>crypto/rsa</code></a>.
Rob Pike456df7c2014-10-27 14:23:24 -0700669</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700670
671<li>
672The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
Mikio Hara70dc39e2014-10-30 14:15:00 +0900673now supports ALPN as defined in <a href="http://tools.ietf.org/html/rfc7301">RFC 7301</a>.
Rob Pike799da9c2014-10-29 08:15:58 -0700674</li>
675
676<li>
677The <a href="/pkg/crypto/tls/"><code>crypto/tls</code></a> package
678now supports programmatic selection of server certificates
679through the new <a href="/pkg/crypto/tls/#Config.CertificateForName"><code>CertificateForName</code></a> function
Shenghou Ma63f59b62015-03-24 12:58:51 -0400680of the <a href="/pkg/crypto/tls/#Config"><code>Config</code></a> struct.
Rob Pike799da9c2014-10-29 08:15:58 -0700681</li>
682
683<li>
Rob Pike97b24a02014-10-29 13:07:34 -0700684Also in the crypto/tls package, the server now supports
Rob Pike799da9c2014-10-29 08:15:58 -0700685<a href="https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv-00">TLS_FALLBACK_SCSV</a>
Rob Pike97b24a02014-10-29 13:07:34 -0700686to help clients detect fallback attacks.
687(The Go client does not support fallback at all, so it is not vulnerable to
688those attacks.)
Rob Pike799da9c2014-10-29 08:15:58 -0700689</li>
690
691<li>
Nigel Taoe522a472014-11-11 16:06:47 +1100692The <a href="/pkg/database/sql/"><code>database/sql</code></a> package can now list all registered
693<a href="/pkg/database/sql/#Drivers"><code>Drivers</code></a>.
694</li>
695
696<li>
697The <a href="/pkg/debug/dwarf/"><code>debug/dwarf</code></a> package now supports
698<a href="/pkg/debug/dwarf/#UnspecifiedType"><code>UnspecifiedType</code></a>s.
699</li>
700
701<li>
Rob Pike799da9c2014-10-29 08:15:58 -0700702In the <a href="/pkg/encoding/asn1/"><code>encoding/asn1</code></a> package,
703optional elements with a default value will now only be omitted if they have that value.
704</li>
705
706<li>
707The <a href="/pkg/encoding/csv/"><code>encoding/csv</code></a> package no longer
708quotes empty strings but does quote the end-of-data marker <code>\.</code> (backslash dot).
709This is permitted by the definition of CSV and allows it to work better with Postgres.
710</li>
711
712<li>
713The <a href="/pkg/encoding/gob/"><code>encoding/gob</code></a> package has been rewritten to eliminate
714the use of unsafe operations, allowing it to be used in environments that do not permit use of the
715<a href="/pkg/unsafe/"><code>unsafe</code></a> package.
716For typical uses it will be 10-30% slower, but the delta is dependent on the type of the data and
717in some cases, especially involving arrays, it can be faster.
718There is no functional change.
719</li>
720
721<li>
Nigel Taoe522a472014-11-11 16:06:47 +1100722The <a href="/pkg/encoding/xml/"><code>encoding/xml</code></a> package's
723<a href="/pkg/encoding/xml/#Decoder"><code>Decoder</code></a> can now report its input offset.
724</li>
725
726<li>
Rob Pike799da9c2014-10-29 08:15:58 -0700727In the <a href="/pkg/fmt/"><code>fmt</code></a> package,
728formatting of pointers to maps has changed to be consistent with that of pointers
729to structs, arrays, and so on.
730For instance, <code>&amp;map[string]int{"one":</code> <code>1}</code> now prints by default as
731<code>&amp;map[one:</code> <code>1]</code> rather than as a hexadecimal pointer value.
732</li>
733
Rob Pikebfe459a2014-10-29 15:35:48 -0700734<li>
Nigel Taoe522a472014-11-11 16:06:47 +1100735The <a href="/pkg/image/"><code>image</code></a> package's
736<a href="/pkg/image/#Image"><code>Image</code></a>
737implementations like
738<a href="/pkg/image/#RGBA"><code>RGBA</code></a> and
739<a href="/pkg/image/#Gray"><code>Gray</code></a> have specialized
740<a href="/pkg/image/#RGBA.RGBAAt"><code>RGBAAt</code></a> and
741<a href="/pkg/image/#Gray.GrayAt"><code>GrayAt</code></a> methods alongside the general
742<a href="/pkg/image/#Image.At"><code>At</code></a> method.
743</li>
744
745<li>
746The <a href="/pkg/image/png/"><code>image/png</code></a> package now has an
747<a href="/pkg/image/png/#Encoder"><code>Encoder</code></a>
748type to control the compression level used for encoding.
749</li>
750
751<li>
752The <a href="/pkg/math/"><code>math</code></a> package now has a
753<a href="/pkg/math/#Nextafter32"><code>Nextafter32</code><a/> function.
754</li>
755
756<li>
Rob Pikebfe459a2014-10-29 15:35:48 -0700757The <a href="/pkg/net/http/"><code>net/http</code></a> package's
758<a href="/pkg/net/http/#Request"><code>Request</code></a> type
759has a new <a href="/pkg/net/http/#Request.BasicAuth"><code>BasicAuth</code></a> method
760that returns the username and password from authenticated requests using the
761HTTP Basic Authentication
762Scheme.
763</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700764
Rob Pikebfe459a2014-10-29 15:35:48 -0700765<li>The <a href="/pkg/net/http/"><code>net/http</code></a> package's
766<a href="/pkg/net/http/#Request"><code>Transport</code></a> type
Brad Fitzpatrickf21a02a2014-10-30 10:58:31 -0300767has a new <a href="/pkg/net/http/#Transport.DialTLS"><code>DialTLS</code></a> hook
768that allows customizing the behavior of outbound TLS connections.
Rob Pikebfe459a2014-10-29 15:35:48 -0700769</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700770
Rob Pikebfe459a2014-10-29 15:35:48 -0700771<li>
772The <a href="/pkg/net/http/httputil/"><code>net/http/httputil</code></a> package's
773<a href="/pkg/net/http/httputil/#ReverseProxy"><code>ReverseProxy</code></a> type
774has a new field,
775<a href="/pkg/net/http/#ReverseProxy.ErrorLog"><code>ErrorLog</code></a>, that
776provides user control of logging.
777</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700778
779<li>
780The <a href="/pkg/os/"><code>os</code></a> package
781now implements symbolic links on the Windows operating system
782through the <a href="/pkg/os/#Symlink"><code>Symlink</code></a> function.
783Other operating systems already have this functionality.
Nigel Taoe522a472014-11-11 16:06:47 +1100784There is also a new <a href="/pkg/os/#Unsetenv"><code>Unsetenv</code></a> function.
Rob Pike799da9c2014-10-29 08:15:58 -0700785</li>
786
787<li>
788The <a href="/pkg/reflect/"><code>reflect</code></a> package's
789<a href="/pkg/reflect/#Type"><code>Type</code></a> interface
790has a new method, <a href="/pkg/reflect/#type.Comparable"><code>Comparable</code></a>,
791that reports whether the type implements general comparisons.
792</li>
793
794<li>
795Also in the <a href="/pkg/reflect/"><code>reflect</code></a> package, the
796<a href="/pkg/reflect/#Value"><code>Value</code></a> interface is now three instead of four words
797because of changes to the implementation of interfaces in the runtime.
798This saves memory but has no semantic effect.
799</li>
800
Rob Pikebfe459a2014-10-29 15:35:48 -0700801<li>
802The <a href="/pkg/runtime/"><code>runtime</code></a> package
803now implements monotonic clocks on Windows,
804as it already did for the other systems.
805</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700806
Rob Pikebfe459a2014-10-29 15:35:48 -0700807<li>
808The <a href="/pkg/runtime/"><code>runtime</code></a> package's
809<a href="/pkg/runtime/#MemStats.Mallocs"><code>Mallocs</code></a> counter
810now counts very small allocations that were missed in Go 1.3.
811This may break tests using <a href="/pkg/runtime/#ReadMemStats"><code>ReadMemStats</code></a>
812or <a href="/pkg/testing/#AllocsPerRun"><code>AllocsPerRun</code></a>
813due to the more accurate answer.
814</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700815
Rob Pikebfe459a2014-10-29 15:35:48 -0700816<li>
817In the <a href="/pkg/runtime/"><code>runtime</code></a> package,
818an array <a href="/pkg/runtime/#MemStats.PauseEnd"><code>PauseEnd</code></a>
819has been added to the
820<a href="/pkg/runtime/#MemStats"><code>MemStats</code></a>
821and <a href="/pkg/runtime/#GCStats"><code>GCStats</code></a> structs.
822This array is a circular buffer of times when garbage collection pauses ended.
823The corresponding pause durations are already recorded in
824<a href="/pkg/runtime/#MemStats.PauseNs"><code>PauseNs</code></a>
825</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700826
Rob Pikebfe459a2014-10-29 15:35:48 -0700827<li>
828The <a href="/pkg/runtime/race/"><code>runtime/race</code></a> package
829now supports FreeBSD, which means the
830<a href="/pkg/cmd/go/"><code>go</code></a> command's <code>-race</code>
831flag now works on FreeBSD.
832</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700833
Rob Pikebfe459a2014-10-29 15:35:48 -0700834<li>
835The <a href="/pkg/sync/atomic/"><code>sync/atomic</code></a> package
836has a new type, <a href="/pkg/sync/atomic/#Value"><code>Value</code></a>.
837<code>Value</code> provides an efficient mechanism for atomic loads and
838stores of values of arbitrary type.
839</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700840
Rob Pikebfe459a2014-10-29 15:35:48 -0700841<li>
842In the <a href="/pkg/syscall/"><code>syscall</code></a> package's
843implementation on Linux, the
844<a href="/pkg/syscall/#Setuid"><code>Setuid</code></a>
845and <a href="/pkg/syscall/#Setgid"><code>Setgid</code></a> have been disabled
846because those system calls operate on the calling thread, not the whole process, which is
847different from other platforms and not the expected result.
848</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700849
Rob Pikebfe459a2014-10-29 15:35:48 -0700850<li>
851The <a href="/pkg/testing/"><code>testing</code></a> package
852has a new facility to provide more control over running a set of tests.
853If the test code contains a function
854<pre>
855func TestMain(m *<a href="/pkg/testing/#M"><code>testing.M</code></a>)
856</pre>
Rob Pike799da9c2014-10-29 08:15:58 -0700857
Rob Pikebfe459a2014-10-29 15:35:48 -0700858that function will be called instead of running the tests directly.
859The <code>M</code> struct contains methods to access and run the tests.
860</li>
861
862<li>
863Also in the <a href="/pkg/testing/"><code>testing</code></a> package,
864a new <a href="/pkg/testing/#Coverage"><code>Coverage</code></a>
865function reports the current test coverage fraction,
866enabling individual tests to report how much they are contributing to the
867overall coverage.
868</li>
Rob Pike799da9c2014-10-29 08:15:58 -0700869
870<li>
871The <a href="/pkg/text/scanner/"><code>text/scanner</code></a> package's
872<a href="/pkg/text/scanner/#Scanner"><code>Scanner</code></a> type
873has a new function,
874<a href="/pkg/text/scanner/#Scanner.IsIdentRune"><code>IsIdentRune</code></a>,
875allowing one to control the definition of an identifier when scanning.
876</li>
877
878<li>
879The <a href="/pkg/text/template/"><code>text/template</code></a> package's boolean
880functions <code>eq</code>, <code>lt</code>, and so on have been generalized to allow comparison
881of signed and unsigned integers, simplifying their use in practice.
882(Previously one could only compare values of the same signedness.)
883All negative values compare less than all unsigned values.
884</li>
885
886<li>
887The <code>time</code> package now uses the standard symbol for the micro prefix,
888the micro symbol (U+00B5 'ยต'), to print microsecond durations.
889<a href="/pkg/time/#ParseDuration"><code>ParseDuration</code></a> still accepts <code>us</code>
890but the package no longer prints microseconds as <code>us</code>.
891<br>
892<em>Updating</em>: Code that depends on the output format of durations
893but does not use ParseDuration will need to be updated.
894</li>
895
Rob Pike456df7c2014-10-27 14:23:24 -0700896</ul>