From: Rob Pike Date: Tue, 10 Sep 2013 05:13:45 +0000 (+1000) Subject: doc/go1.2.html: introduction, language changes X-Git-Tag: go1.2rc2~291 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6cbc5387c30b7358d930c10f465c70c16357fd36;p=gostls13.git doc/go1.2.html: introduction, language changes R=golang-dev, remyoudompheng, dominik.honnef, adg CC=golang-dev https://golang.org/cl/13341049 --- diff --git a/doc/go1.2.html b/doc/go1.2.html index 2e86eb0f74..c3d5466cbc 100644 --- a/doc/go1.2.html +++ b/doc/go1.2.html @@ -7,67 +7,128 @@

Introduction to Go 1.2

+ RED TEXT IS FROM THE 1.1 DOC AND NEEDS TO BE UPDATED. (It is here for formatting and style reference.) -

- -The release of Go version 1 (Go 1 or Go 1.0 for short) -in March of 2012 introduced a new period -of stability in the Go language and libraries. -That stability has helped nourish a growing community of Go users -and systems around the world. -Several "point" releases since -then—1.0.1, 1.0.2, and 1.0.3—have been issued. -These point releases fixed known bugs but made -no non-critical changes to the implementation.

- -This new release, Go 1.1, keeps the promise -of compatibility but adds a couple of significant -(backwards-compatible, of course) language changes, has a long list -of (again, compatible) library changes, and -includes major work on the implementation of the compilers, -libraries, and run-time. -The focus is on performance. -Benchmarking is an inexact science at best, but we see significant, -sometimes dramatic speedups for many of our test programs. -We trust that many of our users' programs will also see improvements -just by updating their Go installation and recompiling. - +Since the release of Go version 1.1 in April, 2013, +the release schedule has been shortened to make the release process more efficient. +This release, Go version 1.2 or Go 1.2 for short, arrives roughly six months after 1.1, +while 1.1 took over a year to appear after 1.0. +Because of the shorter time scale, 1.2 is a smaller delta than the step from 1.0 to 1.1, +but it still has some significant developments, including +a better scheduler and one new language feature. +Of course, Go 1.2 keeps the promise +of compatibility. +The overwhelming majority of programs built with Go 1.1 (or 1.0 for that matter) +will run without any changes whatsoever when moved to 1.2, +although the introduction of one restriction +to a corner of the language may expose already-incorrect code +(see the discussion of the use of nil).

+

Changes to the language

+

- -This document summarizes the changes between Go 1 and Go 1.2. -Very little if any code will need modification to run with Go 1.1, -although a couple of rare error cases surface with this release -and need to be addressed if they arise. -Details appear below; see the discussion of XXX. - +In the interest of firming up the specification, one corner case has been clarified, +with consequences for programs. +There is also one new language feature.

-

Changes to the language

+

Use of nil

- -The Go compatibility document promises -that programs written to the Go 1 language specification will continue to operate, -and those promises are maintained. -In the interest of firming up the specification, though, there are -details about some error cases that have been clarified. -There are also some new language features. - +The language now specifies that, for safety reasons, +certain uses of nil pointers are guaranteed to trigger a run-time panic. +For instance, in Go 1.0, given code like +

+ +
+type T struct {
+    X [1<<24]byte
+    Field int32
+}
+
+func main() {
+    var x *T
+    ...
+}
+
+ +

+the nil pointer x could be used to access memory incorrectly: +the expression x.Field could access memory at address 1<<24. +To prevent such unsafe behavior, in Go 1.2 the compilers now guarantee that any indirection through +a nil pointer, such as illustrated here but also in nil pointers to arrays, nil interface values, +nil slices, and so on, will either panic or return a correct, safe non-nil value. +In short, any expression that explicitly or implicitly requires evaluation of a nil address is an error. +The implementation may inject extra tests into the compiled program to enforce this behavior. +

+ +

+Further details are in the +design document. +

+ +

+Updating: +Most code that depended on the old behavior is erroneous and will fail when run. +Such programs will need to be updated by hand. +

+ +

Three-index slices

+ +

+Go 1.2 adds the ability to specify the capacity as well as the length when using a slicing operation +on an existing array or slice. +A slicing operation creates a new slice by describing a contiguous section of an already-created array or slice: +

+ +
+var array [10]int
+slice := array[2:4]
+
+ +

+The capacity of the slice is the maximum number of elements that the slice may hold, even after reslicing; +it reflects the size of the underlying array. +In this example, the capacity of the slice variable is 8. +

+ +

+Go 1.2 adds new syntax to allow a slicing operation to specify the capacity as well as the length. +A second +colon introduces the capacity value, which must be less than or equal to the capacity of the +source slice or array, adjusted for the origin. For instance,

-

Three-index slices

+
+slice = array[2:4:6]
+
+ +

+sets the slice to have the same length as in the earlier example but its capacity is now only 4 elements (6-2). +It is impossible to use this new slice value to access the last two elements of the original array. +

-cmd/gc: three-index slicing to set cap as well as length (CL 10743046). +In this three-index notation, a missing first index ([:i:j]) defaults to zero but the other +two indices must always be specified explicitly. +It is possible that future releases of Go may introduce default values for these indices.

+

+Further details are in the +design document. +

+ +

+Updating: +This is a backwards-compatible change that affects no existing programs. +

Changes to the implementations and tools

@@ -81,6 +142,45 @@ go/build: support including C++ code with cgo (CL 8248043). +

Godoc moved to the go.tools subrepository

+ +

+A binary is still included with the distribution, but the source code for the +godoc command has moved to the +go.tools subrepository. +The core of the program has been split into a +library, +while the command itself is in a separate +directory. +The move allows the code to be updated easily and the separation into a library and command +makes it easier to construct custom binaries for local sites and different deployment methods. +

+ +

+Updating: +Since godoc was not part of the library, +no client code depends on the godoc sources and no updating is required. +

+ +

+The binary distributions available from + +

+$ go get code.google.com/p/go.tools/cmd/godoc
+
+ +

The vet tool moved to the go.tools subrepository

+ +

+TODO +

+

Status of gccgo

@@ -90,7 +190,7 @@ The GCC release schedule does not coincide with the Go release schedule, so some The 4.8.0 version of GCC shipped in March, 2013 and includes a nearly-Go 1.1 version of gccgo. Its library is a little behind the release, but the biggest difference is that method values are not implemented. Sometime around July 2013, we expect 4.8.2 of GCC to ship with a gccgo -providing a complete Go 1.1 implementaiton. +providing a complete Go 1.1 implementation.

@@ -228,11 +328,11 @@ archive/tar,archive/zip: fix os.FileInfo implementation to provide base name onl
  • -fmt: indexed access to arguments in Printf etc. (CL 9680043). +encoding: new package defining generic encoding interfaces (CL 12541051).
  • -encoding: new package defining generic encoding interfaces (CL 12541051). +fmt: indexed access to arguments in Printf etc. (CL 9680043).
  • @@ -247,43 +347,6 @@ text/template: allow {{"{{"}}else if ... {{"}}"}} to simplify if chains (CL 1332
  • -

    Exp and old subtrees moved to go.exp and go.text subrepositories

    - -

    - -To make it easier for binary distributions to access them if desired, the exp -and old source subtrees, which are not included in binary distributions, -have been moved to the new go.exp subrepository at -code.google.com/p/go.exp. To access the ssa package, -for example, run - -

    - -

    New packages

    - -

    - -There are three new packages. - -

    - -
    -

    Minor changes to the library

    @@ -404,7 +467,7 @@ described above.

  • The encoding/json package -now will alway escape ampersands as "\u0026" when printing strings. +now will always escape ampersands as "\u0026" when printing strings. It will now accept but correct invalid UTF-8 in Marshal (such input was previously rejected). @@ -420,7 +483,7 @@ It also supports the generic encoding interfaces of the encoding package described above through the new Marshaler, -UnMarshaler, +Unmarshaler, and related MarshalerAttr and UnmarshalerAttr