go1.4.html 33 KB

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