From 6e7a55a2c0ab461fd1c8e68c3c7366b0afa4d4d4 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 5 Apr 2013 18:22:38 +0200 Subject: Imported Upstream version 1.1~hg20130405 --- AUTHORS | 5 + CONTRIBUTORS | 6 + api/next.txt | 29 +- doc/articles/godoc_documenting_go_code.html | 7 +- doc/articles/race_detector.html | 52 +- doc/code.html | 470 +++++---- doc/codewalk/markov.xml | 2 +- doc/effective_go.html | 2 +- doc/go1.1.html | 312 +++++- doc/go_faq.html | 49 +- doc/go_spec.html | 10 +- doc/godocs.js | 8 + doc/install.html | 54 +- doc/style.css | 5 +- include/libc.h | 1 + include/plan9/libc.h | 1 + lib/codereview/codereview.py | 3 +- lib/godoc/package.html | 46 +- lib/godoc/package.txt | 39 +- lib/time/update.bash | 4 +- lib/time/zoneinfo.zip | Bin 370359 -> 374065 bytes misc/cgo/gmp/gmp.go | 2 +- misc/cgo/test/callback.go | 43 + misc/cgo/test/cgo_test.go | 1 + misc/cgo/testtls/tls.go | 28 + misc/cgo/testtls/tls_test.go | 13 + misc/cgo/testtls/tls_unix.c | 19 + misc/dashboard/codereview/dashboard/people.go | 3 +- misc/dist/bindist.go | 69 +- misc/emacs/go-mode.el | 14 +- misc/kate/go.xml | 2 +- misc/vim/plugin/godoc.vim | 17 +- src/all.bat | 2 +- src/cmd/5l/5.out.h | 1 + src/cmd/5l/l.h | 1 - src/cmd/5l/obj.c | 15 +- src/cmd/6g/peep.c | 5 +- src/cmd/6g/reg.c | 5 +- src/cmd/6l/6.out.h | 1 + src/cmd/6l/asm.c | 7 + src/cmd/6l/l.h | 1 - src/cmd/6l/obj.c | 15 +- src/cmd/6l/span.c | 24 + src/cmd/8a/a.y | 9 + src/cmd/8a/lex.c | 2 + src/cmd/8a/y.tab.c | 1326 ++++++++++--------------- src/cmd/8a/y.tab.h | 46 +- src/cmd/8l/8.out.h | 3 + src/cmd/8l/asm.c | 6 + src/cmd/8l/l.h | 3 - src/cmd/8l/obj.c | 15 +- src/cmd/8l/optab.c | 8 + src/cmd/8l/pass.c | 50 +- src/cmd/8l/span.c | 35 +- src/cmd/cc/cc.h | 1 + src/cmd/cc/funct.c | 2 +- src/cmd/cc/lexbody | 2 +- src/cmd/dist/a.h | 1 + src/cmd/dist/build.c | 10 + src/cmd/dist/buildruntime.c | 11 +- src/cmd/dist/unix.c | 13 + src/cmd/gc/builtin.c | 1 + src/cmd/gc/closure.c | 6 +- src/cmd/gc/const.c | 1 - src/cmd/gc/dcl.c | 8 +- src/cmd/gc/fmt.c | 2 +- src/cmd/gc/go.h | 3 +- src/cmd/gc/go.y | 3 +- src/cmd/gc/lex.c | 10 +- src/cmd/gc/mkbuiltin | 1 + src/cmd/gc/racewalk.c | 100 +- src/cmd/gc/range.c | 4 +- src/cmd/gc/reflect.c | 7 + src/cmd/gc/runtime.go | 6 + src/cmd/gc/subr.c | 28 +- src/cmd/gc/walk.c | 49 +- src/cmd/gc/y.tab.c | 589 +++++------ src/cmd/go/clean.go | 2 + src/cmd/go/doc.go | 19 +- src/cmd/go/env.go | 1 + src/cmd/go/mkdoc.sh | 1 + src/cmd/go/run.go | 17 +- src/cmd/go/test.go | 16 +- src/cmd/godoc/doc.go | 2 + src/cmd/godoc/format.go | 80 +- src/cmd/godoc/godoc.go | 98 +- src/cmd/godoc/index.go | 2 - src/cmd/godoc/linkify.go | 234 +++++ src/cmd/godoc/main.go | 16 +- src/cmd/godoc/utils.go | 2 - src/cmd/gofmt/gofmt_test.go | 3 + src/cmd/gofmt/rewrite.go | 16 +- src/cmd/gofmt/testdata/rewrite6.golden | 15 + src/cmd/gofmt/testdata/rewrite6.input | 15 + src/cmd/gofmt/testdata/rewrite7.golden | 15 + src/cmd/gofmt/testdata/rewrite7.input | 15 + src/cmd/gofmt/testdata/rewrite8.golden | 10 + src/cmd/gofmt/testdata/rewrite8.input | 10 + src/cmd/ld/data.c | 34 +- src/cmd/ld/doc.go | 17 + src/cmd/ld/dwarf.c | 72 +- src/cmd/ld/elf.c | 8 +- src/cmd/ld/go.c | 8 +- src/cmd/ld/lib.c | 50 +- src/cmd/ld/lib.h | 10 + src/cmd/ld/symtab.c | 20 + src/cmd/nm/nm.c | 6 +- src/cmd/vet/asmdecl.go | 1 + src/cmd/vet/test_asm1.s | 4 +- src/cmd/vet/test_asm2.s | 4 +- src/cmd/vet/test_asm3.s | 4 +- src/cmd/vet/test_deadcode.go | 144 +-- src/lib9/goos.c | 6 + src/lib9/utf/utf.h | 2 - src/libmach/sym.c | 7 +- src/make.bash | 5 + src/make.bat | 4 +- src/pkg/bufio/scan.go | 5 +- src/pkg/builtin/builtin.go | 9 + src/pkg/bytes/asm_386.s | 16 - src/pkg/bytes/asm_amd64.s | 17 - src/pkg/bytes/buffer.go | 56 +- src/pkg/bytes/buffer_test.go | 50 + src/pkg/bytes/bytes_decl.go | 2 +- src/pkg/bytes/bytes_test.go | 76 ++ src/pkg/bytes/equal_test.go | 47 + src/pkg/bytes/export_test.go | 4 + src/pkg/compress/gzip/gzip.go | 24 +- src/pkg/compress/gzip/gzip_test.go | 40 + src/pkg/crypto/rsa/rsa.go | 4 +- src/pkg/crypto/rsa/rsa_test.go | 3 + src/pkg/database/sql/convert.go | 22 +- src/pkg/database/sql/convert_test.go | 3 +- src/pkg/database/sql/fakedb_test.go | 21 +- src/pkg/database/sql/sql.go | 157 +-- src/pkg/database/sql/sql_test.go | 129 ++- src/pkg/go/build/build.go | 8 +- src/pkg/go/doc/doc.go | 8 +- src/pkg/go/doc/reader.go | 1 + src/pkg/go/parser/interface.go | 29 +- src/pkg/go/parser/parser_test.go | 13 +- src/pkg/go/printer/printer.go | 31 +- src/pkg/image/gif/reader_test.go | 17 +- src/pkg/math/big/int.go | 12 +- src/pkg/math/big/rat.go | 14 +- src/pkg/math/big/rat_test.go | 10 +- src/pkg/math/hypot.go | 6 +- src/pkg/math/tanh.go | 2 +- src/pkg/net/dial.go | 237 ++--- src/pkg/net/dial_gen.go | 61 ++ src/pkg/net/example_test.go | 1 + src/pkg/net/fd_plan9.go | 4 +- src/pkg/net/fd_unix.go | 5 +- src/pkg/net/fd_windows.go | 15 +- src/pkg/net/file_windows.go | 12 + src/pkg/net/http/example_test.go | 13 +- src/pkg/net/http/request.go | 42 +- src/pkg/net/http/response_test.go | 6 +- src/pkg/net/http/serve_test.go | 389 +++++++- src/pkg/net/http/server.go | 227 ++++- src/pkg/net/http/transfer.go | 47 +- src/pkg/net/http/transport.go | 15 +- src/pkg/net/http/transport_test.go | 129 ++- src/pkg/net/http/z_last_test.go | 14 +- src/pkg/net/interface_unix_test.go | 10 +- src/pkg/net/ipraw_test.go | 33 +- src/pkg/net/iprawsock.go | 2 - src/pkg/net/iprawsock_plan9.go | 4 +- src/pkg/net/iprawsock_posix.go | 30 +- src/pkg/net/multicast_test.go | 2 +- src/pkg/net/server_test.go | 2 +- src/pkg/net/smtp/auth.go | 11 +- src/pkg/net/smtp/smtp_test.go | 35 + src/pkg/net/sock_posix.go | 13 +- src/pkg/net/tcp_test.go | 42 +- src/pkg/net/tcpsock.go | 2 - src/pkg/net/tcpsock_plan9.go | 6 +- src/pkg/net/tcpsock_posix.go | 61 +- src/pkg/net/textproto/reader.go | 1 + src/pkg/net/textproto/reader_test.go | 2 + src/pkg/net/udp_test.go | 80 +- src/pkg/net/udpsock.go | 2 - src/pkg/net/udpsock_plan9.go | 15 +- src/pkg/net/udpsock_posix.go | 43 +- src/pkg/net/unicast_posix_test.go | 65 +- src/pkg/net/unix_test.go | 132 ++- src/pkg/net/unixsock.go | 2 - src/pkg/net/unixsock_plan9.go | 8 +- src/pkg/net/unixsock_posix.go | 33 +- src/pkg/net/url/url.go | 25 +- src/pkg/os/exec/exec_test.go | 2 +- src/pkg/reflect/all_test.go | 183 ++++ src/pkg/reflect/type.go | 173 +++- src/pkg/runtime/alg.c | 23 +- src/pkg/runtime/asm_386.s | 128 ++- src/pkg/runtime/asm_amd64.s | 120 +++ src/pkg/runtime/asm_arm.s | 45 +- src/pkg/runtime/cgo/gcc_freebsd_386.c | 14 +- src/pkg/runtime/cgo/gcc_freebsd_amd64.c | 16 +- src/pkg/runtime/cgo/gcc_linux_386.c | 17 +- src/pkg/runtime/cgo/gcc_linux_amd64.c | 15 +- src/pkg/runtime/cgo/gcc_netbsd_386.c | 14 +- src/pkg/runtime/cgo/gcc_netbsd_amd64.c | 15 +- src/pkg/runtime/cgo/gcc_openbsd_386.c | 14 +- src/pkg/runtime/cgo/gcc_openbsd_amd64.c | 15 +- src/pkg/runtime/cgocall.c | 15 +- src/pkg/runtime/gc_test.go | 2 +- src/pkg/runtime/hashmap.c | 137 ++- src/pkg/runtime/hashmap_fast.c | 104 +- src/pkg/runtime/malloc.goc | 9 +- src/pkg/runtime/map_test.go | 72 ++ src/pkg/runtime/mapspeed_test.go | 58 ++ src/pkg/runtime/mgc0.c | 94 +- src/pkg/runtime/mgc0.h | 3 + src/pkg/runtime/mkasmh.sh | 138 --- src/pkg/runtime/mprof.goc | 2 +- src/pkg/runtime/netpoll_epoll.c | 7 +- src/pkg/runtime/netpoll_kqueue.c | 7 +- src/pkg/runtime/proc.c | 2 +- src/pkg/runtime/race.c | 7 +- src/pkg/runtime/race/testdata/mop_test.go | 148 ++- src/pkg/runtime/race/testdata/slice_test.go | 3 +- src/pkg/runtime/runtime-gdb.py | 49 +- src/pkg/runtime/runtime.h | 12 +- src/pkg/runtime/string.goc | 10 +- src/pkg/runtime/string_test.go | 28 + src/pkg/runtime/traceback_arm.c | 34 +- src/pkg/runtime/traceback_x86.c | 37 +- src/pkg/sort/example_multi_test.go | 132 +++ src/pkg/strconv/strconv_test.go | 6 +- src/pkg/sync/atomic/asm_arm.s | 16 + src/pkg/sync/atomic/asm_linux_arm.s | 8 + src/pkg/sync/atomic/atomic_test.go | 6 +- src/pkg/syscall/passfd_test.go | 2 +- src/pkg/testing/testing.go | 11 +- src/pkg/text/template/exec.go | 2 + src/pkg/text/template/exec_test.go | 27 +- src/run.bash | 27 +- src/run.bat | 6 +- test/fixedbugs/issue5105.dir/a.go | 7 + test/fixedbugs/issue5105.dir/b.go | 15 + test/fixedbugs/issue5105.go | 10 + test/fixedbugs/issue5125.dir/bug.go | 17 + test/fixedbugs/issue5125.dir/main.go | 10 + test/fixedbugs/issue5125.go | 10 + test/fixedbugs/issue5162.go | 88 ++ 246 files changed, 6586 insertions(+), 3049 deletions(-) create mode 100644 misc/cgo/testtls/tls.go create mode 100644 misc/cgo/testtls/tls_test.go create mode 100644 misc/cgo/testtls/tls_unix.c create mode 100644 src/cmd/godoc/linkify.go create mode 100644 src/cmd/gofmt/testdata/rewrite6.golden create mode 100644 src/cmd/gofmt/testdata/rewrite6.input create mode 100644 src/cmd/gofmt/testdata/rewrite7.golden create mode 100644 src/cmd/gofmt/testdata/rewrite7.input create mode 100644 src/cmd/gofmt/testdata/rewrite8.golden create mode 100644 src/cmd/gofmt/testdata/rewrite8.input create mode 100644 src/pkg/bytes/equal_test.go create mode 100644 src/pkg/net/dial_gen.go delete mode 100755 src/pkg/runtime/mkasmh.sh create mode 100644 src/pkg/sort/example_multi_test.go create mode 100644 test/fixedbugs/issue5105.dir/a.go create mode 100644 test/fixedbugs/issue5105.dir/b.go create mode 100644 test/fixedbugs/issue5105.go create mode 100644 test/fixedbugs/issue5125.dir/bug.go create mode 100644 test/fixedbugs/issue5125.dir/main.go create mode 100644 test/fixedbugs/issue5125.go create mode 100644 test/fixedbugs/issue5162.go diff --git a/AUTHORS b/AUTHORS index 78d149f02..b7acdc6cd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,6 +18,7 @@ Alex Brainman Alexander Orlov Alexander Reece Alexander Surma +Alexei Sholik Alexey Borzenkov Amir Mohammad Saied Amrut Joshi @@ -30,6 +31,7 @@ Andrew Radev Andrew Skiba Andrew Wilkins Andrey Mirtchovski +Andriy Lytvynov Andy Davis Anh Hai Trinh Anschel Schaffer-Cohen @@ -87,6 +89,7 @@ Devon H. O'Dell Dmitry Chestnykh Dominik Honnef Donovan Hide +Duncan Holm Dustin Shields-Cloues Eden Li Egon Elbre @@ -240,6 +243,7 @@ Robert Daniel Kortschak Robert Dinu Robert Figueiredo Robert Hencke +Robert Obryk Robin Eklind Rodrigo Moraes de Oliveira Rodrigo Rafael Monti Kochenburger @@ -298,3 +302,4 @@ Yusuke Kagiwada Yuusei Kuwana Yuval Pavel Zholkover Ziad Hatahet +Zorion Arrizabalaga diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6afe1f0d1..7b8779be9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -46,6 +46,7 @@ Alexander Orlov Alexander Reece Alexander Surma Alexandru Moșoi +Alexei Sholik Alexey Borzenkov Amir Mohammad Saied Amrut Joshi @@ -61,6 +62,7 @@ Andrew Radev Andrew Skiba Andrew Wilkins Andrey Mirtchovski +Andriy Lytvynov Andy Davis Anh Hai Trinh Anschel Schaffer-Cohen @@ -143,6 +145,7 @@ Dmitriy Vyukov Dmitry Chestnykh Dominik Honnef Donovan Hide +Duncan Holm Dustin Shields-Cloues Eden Li Egon Elbre @@ -197,6 +200,7 @@ James Gray James Meneghello James P. Cooper James Toy +James Tucker James Whitehead Jamie Gennis Jan H. Hosang @@ -349,6 +353,7 @@ Robert Dinu Robert Figueiredo Robert Griesemer Robert Hencke +Robert Obryk Robin Eklind Rodrigo Moraes de Oliveira Rodrigo Rafael Monti Kochenburger @@ -421,3 +426,4 @@ Yuusei Kuwana Yuval Pavel Zholkover Yves Junqueira Ziad Hatahet +Zorion Arrizabalaga diff --git a/api/next.txt b/api/next.txt index b45c22526..2aaca2f7a 100644 --- a/api/next.txt +++ b/api/next.txt @@ -28,6 +28,7 @@ pkg bytes, func TrimPrefix([]uint8, []uint8) []uint8 pkg bytes, func TrimSuffix([]uint8, []uint8) []uint8 pkg bytes, method (*Buffer) Grow(int) pkg bytes, method (*Reader) WriteTo(io.Writer) (int64, error) +pkg compress/gzip, method (*Writer) Flush() error pkg crypto/hmac, func Equal([]uint8, []uint8) bool pkg crypto/tls, const TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA uint16 pkg crypto/tls, const TLS_RSA_WITH_AES_256_CBC_SHA uint16 @@ -61,6 +62,8 @@ pkg crypto/x509, type PEMCipher int pkg crypto/x509, type SystemRootsError struct pkg crypto/x509, type VerifyOptions struct, KeyUsages []ExtKeyUsage pkg crypto/x509, var IncorrectPasswordError error +pkg database/sql, method (*DB) Ping() error +pkg database/sql, method (*DB) SetMaxIdleConns(int) pkg database/sql/driver, type Queryer interface { Query } pkg database/sql/driver, type Queryer interface, Query(string, []Value) (Rows, error) pkg debug/elf, method (*File) DynString(DynTag) ([]string, error) @@ -89,6 +92,7 @@ pkg encoding/json, method (Number) String() string pkg encoding/json, type Number string pkg encoding/xml, func EscapeText(io.Writer, []uint8) error pkg encoding/xml, method (*Encoder) Indent(string, string) +pkg encoding/xml, type Decoder struct, DefaultSpace string pkg go/ast, func NewCommentMap(*token.FileSet, Node, []*CommentGroup) CommentMap pkg go/ast, method (CommentMap) Comments() []*CommentGroup pkg go/ast, method (CommentMap) Filter(Node) CommentMap @@ -96,14 +100,20 @@ pkg go/ast, method (CommentMap) String() string pkg go/ast, method (CommentMap) Update(Node, Node) Node pkg go/ast, type ChanType struct, Arrow token.Pos pkg go/ast, type CommentMap map[Node][]*CommentGroup -pkg go/build, type Context struct, InstallTag string +pkg go/build, type Context struct, InstallSuffix string +pkg go/build, type Context struct, ReleaseTags []string pkg go/build, type Package struct, IgnoredGoFiles []string pkg go/build, type Package struct, SwigCXXFiles []string pkg go/build, type Package struct, SwigFiles []string pkg go/doc, type Example struct, EmptyOutput bool pkg go/doc, type Example struct, Order int pkg go/doc, type Example struct, Play *ast.File -pkg go/doc, type Package struct, Notes map[string][]string +pkg go/doc, type Note struct +pkg go/doc, type Note struct, Body string +pkg go/doc, type Note struct, End token.Pos +pkg go/doc, type Note struct, Pos token.Pos +pkg go/doc, type Note struct, UID string +pkg go/doc, type Package struct, Notes map[string][]*Note pkg go/doc, var IllegalPrefixes []string pkg go/format, func Node(io.Writer, *token.FileSet, interface{}) error pkg go/format, func Source([]uint8) ([]uint8, error) @@ -339,28 +349,24 @@ pkg math/big, method (*Int) UnmarshalJSON([]uint8) error pkg math/big, method (*Rat) Float64() (float64, bool) pkg math/big, method (*Rat) SetFloat64(float64) *Rat pkg mime/multipart, method (*Writer) SetBoundary(string) error -pkg net, func Deadline(time.Time) DialOption -pkg net, func DialOpt(string, ...DialOption) (Conn, error) pkg net, func ListenUnixgram(string, *UnixAddr) (*UnixConn, error) -pkg net, func LocalAddress(Addr) DialOption pkg net, func LookupNS(string) ([]*NS, error) -pkg net, func Network(string) DialOption -pkg net, func Timeout(time.Duration) DialOption +pkg net, method (*Dialer) Dial(string, string) (Conn, error) pkg net, method (*IPConn) ReadMsgIP([]uint8, []uint8) (int, int, int, *IPAddr, error) pkg net, method (*IPConn) WriteMsgIP([]uint8, []uint8, *IPAddr) (int, int, error) pkg net, method (*UDPConn) ReadMsgUDP([]uint8, []uint8) (int, int, int, *UDPAddr, error) pkg net, method (*UDPConn) WriteMsgUDP([]uint8, []uint8, *UDPAddr) (int, int, error) pkg net, method (*UnixConn) CloseRead() error pkg net, method (*UnixConn) CloseWrite() error -pkg net, type DialOption interface, unexported methods +pkg net, type Dialer struct +pkg net, type Dialer struct, Deadline time.Time +pkg net, type Dialer struct, LocalAddr Addr +pkg net, type Dialer struct, Timeout time.Duration pkg net, type IPAddr struct, Zone string -pkg net, type IPNet struct, Zone string pkg net, type NS struct pkg net, type NS struct, Host string pkg net, type TCPAddr struct, Zone string pkg net, type UDPAddr struct, Zone string -pkg net, var TCP DialOption -pkg net, var UDP DialOption pkg net/http, func ParseTime(string) (time.Time, error) pkg net/http, method (*Request) PostFormValue(string) string pkg net/http, method (*ServeMux) Handler(*Request) (Handler, string) @@ -385,6 +391,7 @@ pkg net/smtp, method (*Client) Hello(string) error pkg net/textproto, func TrimBytes([]uint8) []uint8 pkg net/textproto, func TrimString(string) string pkg os, method (FileMode) IsRegular() bool +pkg os/signal, func Stop(chan<- os.Signal) pkg reflect, const SelectDefault SelectDir pkg reflect, const SelectRecv SelectDir pkg reflect, const SelectSend SelectDir diff --git a/doc/articles/godoc_documenting_go_code.html b/doc/articles/godoc_documenting_go_code.html index 18a3ee953..96ae7451d 100644 --- a/doc/articles/godoc_documenting_go_code.html +++ b/doc/articles/godoc_documenting_go_code.html @@ -91,10 +91,9 @@ known issue from the bytes packa

-Godoc treats executable commands somewhat differently. Instead of inspecting the -command source code, it looks for a Go source file belonging to the special -package "documentation". The comment on the "package documentation" clause is -used as the command's documentation. For example, see the +Godoc treats executable commands in the same way. It looks for a comment on +package main, which is sometimes put in a separate file called doc.go. +For example, see the godoc documentation and its corresponding doc.go file.

diff --git a/doc/articles/race_detector.html b/doc/articles/race_detector.html index 400d96b19..30458ef0d 100644 --- a/doc/articles/race_detector.html +++ b/doc/articles/race_detector.html @@ -6,7 +6,9 @@

Introduction

-Data races are one of the most common and hardest to debug types of bugs in concurrent systems. A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write. See the The Go Memory Model for details. +Data races are among the most common and hardest to debug types of bugs in concurrent systems. +A data race occurs when two goroutines access the same variable concurrently and at least one of the accesses is a write. +See the The Go Memory Model for details.

@@ -32,7 +34,8 @@ func main() {

Usage

-Fortunately, Go includes a built-in data race detector. To use it, add the -race flag to the go command: +To help diangose such bugs, Go includes a built-in data race detector. +To use it, add the -race flag to the go command:

@@ -45,7 +48,9 @@ $ go install -race mypkg // to install the package
 

Report Format

-When the race detector finds a data race in the program, it prints a report. The report contains stack traces for conflicting accesses, as well as stacks where the involved goroutines were created. For example: +When the race detector finds a data race in the program, it prints a report. +The report contains stack traces for conflicting accesses, as well as stacks where the involved goroutines were created. +Here is an example:

@@ -86,7 +91,8 @@ Goroutine 184 (running) created at:
 

Options

-The GORACE environment variable sets race detector options. The format is: +The GORACE environment variable sets race detector options. +The format is:

@@ -100,7 +106,8 @@ The options are:
 
  • log_path (default stderr): The race detector writes -its report to a file named log_path.pid. The special names stdout +its report to a file named log_path.pid. +The special names stdout and stderr cause reports to be written to standard output and standard error, respectively.
  • @@ -117,8 +124,8 @@ from all reported file paths, to make reports more concise.
  • history_size (default 1): The per-goroutine memory -access history is 32K * 2**history_size elements. Increasing this -value can avoid a "failed to restore the stack" error in reports, but at the +access history is 32K * 2**history_size elements. +Increasing this value can avoid a "failed to restore the stack" error in reports, at the cost of increased memory usage.
@@ -134,9 +141,10 @@ $ GORACE="log_path=/tmp/race/report strip_path_prefix=/my/go/sources/" go test -

Excluding Tests

-When you build with -race flag, go command defines additional +When you build with -race flag, the go command defines additional build tag race. -You can use it to exclude some code/tests under the race detector. For example: +You can use the tag to exclude some code and tests when running the race detector. +Some examples:

@@ -165,7 +173,8 @@ func TestBaz(t *testing.T) {
 

To start, run your tests using the race detector (go test -race). The race detector only finds races that happen at runtime, so it can't find -races in code paths that are not executed. If your tests have incomplete coverage, +races in code paths that are not executed. +If your tests have incomplete coverage, you may find more races by running a binary built with -race under a realistic workload.

@@ -194,9 +203,9 @@ func main() {

The variable i in the function literal is the same variable used by the loop, so -the read in the goroutine races with the loop increment. (This program typically -prints 55555, not 01234.) The program can be fixed by making a copy of the -variable: +the read in the goroutine races with the loop increment. +(This program typically prints 55555, not 01234.) +The program can be fixed by making a copy of the variable:

@@ -246,7 +255,7 @@ func ParallelWrite(data []byte) chan error {
 

-The fix is to introduce new variables in the goroutines (note :=): +The fix is to introduce new variables in the goroutines (note the use of :=):

@@ -260,8 +269,8 @@ The fix is to introduce new variables in the goroutines (note :=):
 

Unprotected global variable

-If the following code is called from several goroutines, it leads to bad races on the service map. -Concurrent reads and writes of a map are not safe: +If the following code is called from several goroutines, it leads to races on the service map. +Concurrent reads and writes of the same map are not safe:

@@ -302,7 +311,8 @@ func LookupService(name string) net.Addr {
 

Primitive unprotected variable

-Data races can happen on variables of primitive types as well (bool, int, int64, etc.), like in the following example: +Data races can happen on variables of primitive types as well (bool, int, int64, etc.), +as in this example:

@@ -327,12 +337,16 @@ func (w *Watchdog) Start() {
 

-Even such “innocent” data races can lead to hard to debug problems caused by (1) non-atomicity of the memory accesses, (2) interference with compiler optimizations and (3) processor memory access reordering issues. +Even such "innocent" data races can lead to hard-to-debug problems caused by +non-atomicity of the memory accesses, +interference with compiler optimizations, +or reordering issues accessing processor memory .

A typical fix for this race is to use a channel or a mutex. -To preserve the lock-free behavior, one can also use the sync/atomic package. +To preserve the lock-free behavior, one can also use the +sync/atomic package.

diff --git a/doc/code.html b/doc/code.html
index 82b211870..2d63d4dc9 100644
--- a/doc/code.html
+++ b/doc/code.html
@@ -6,344 +6,381 @@
 
 

This document demonstrates the development of a simple Go package and -introduces the go command, the standard way to fetch, +introduces the go tool, the standard way to fetch, build, and install Go packages and commands.

-This content is also available as a screencast. +The go tool requires you to organize your code in a specific +way. Please read this document carefully. +It explains the simplest way to get up and running with your Go installation. +

+ +

+A similar explanation is available as a +screencast.

-

Code organization

+

Code organization

-

GOPATH and workspaces

+

Workspaces

-One of Go's design goals is to make writing software easier. To that end, the -go command doesn't use Makefiles or other configuration files to -guide program construction. Instead, it uses the source code to find -dependencies and determine build conditions. This means your source code and -build scripts are always in sync; they are one and the same. +The go tool is designed to work with open source code maintained +in public repositories. Although you don't need to publish your code, the model +for how the environment is set up works the same whether you do or not.

-The one thing you must do is set a GOPATH environment variable. -GOPATH tells the go command (and other related tools) -where to find and install the Go packages on your system. +Go code must be kept inside a workspace. +A workspace is a directory hierarchy with three directories at its root:

+
    +
  • src contains Go source files organized into packages (one package per directory), +
  • pkg contains package objects, and +
  • bin contains executable commands. +
+

-GOPATH is a list of paths. It shares the syntax of your system's -PATH environment variable. A typical GOPATH on -a Unix system might look like this: +The go tool builds source packages and installs the resulting +binaries to the pkg and bin directories.

-
-GOPATH=/home/user/ext:/home/user/mygo
-
-

-(On a Windows system use semicolons as the path separator instead of colons.) +The src subdirectory typically contains multiple version control +repositories (such as for Git or Mercurial) that track the development of one +or more source packages.

-Each path in the list (in this case /home/user/ext or -/home/user/mygo) specifies the location of a workspace. -A workspace contains Go source files and their associated package objects, and -command executables. It has a prescribed structure of three subdirectories: +To give you an idea of how a workspace looks in practice, here's an example:

-
    -
  • src contains Go source files, -
  • pkg contains compiled package objects, and -
  • bin contains executable commands. -
+
+bin/
+    streak                         # command executable
+    todo                           # command executable
+pkg/
+    linux_amd64/
+        code.google.com/p/goauth2/
+            oauth.a                # package object
+        github.com/nf/todo/
+            task.a                 # package object
+src/
+    code.google.com/p/goauth2/
+        .hg/                       # mercurial repository metadata
+        oauth/
+            oauth.go               # package source
+            oauth_test.go          # test source
+    github.com/nf/
+        streak/
+	    .git/                  # git repository metadata
+            oauth.go               # command source
+            streak.go              # command source
+        todo/
+	    .git/                  # git repository metadata
+            task/
+                task.go            # package source
+            todo.go                # command source
+

-Subdirectories of the src directory hold independent packages, and -all source files (.go, .c, .h, and -.s) in each subdirectory are elements of that subdirectory's -package. +This workspace contains three repositories (goauth2, +streak, and todo) comprising two commands +(streak and todo) and two libraries +(oauth and task).

-When building a program that imports the package "widget" the -go command looks for src/pkg/widget inside the Go root, -and then—if the package source isn't found there—it searches -for src/widget inside each workspace in order. +Commands and libraries are built from different kinds of source packages. +We will discuss the distinction later.

+ +

The GOPATH environment variable

+

-Multiple workspaces can offer some flexibility and convenience, but for now -we'll concern ourselves with only a single workspace. +The GOPATH environment variable specifies the location of your +workspace. It is likely the only environment variable you'll need to set +when developing Go code.

-Let's work through a simple example. First, create a $HOME/mygo -directory and its src subdirectory: +To get started, create a workspace directory and set GOPATH +accordingly. Your workspace can be located wherever you like, but we'll use +$HOME/go in this document. Note that this must not be the +same path as your Go installation.

-$ mkdir -p $HOME/mygo/src # create a place to put source code
+$ mkdir $HOME/go
+$ export GOPATH=$HOME/go
 

-Next, set it as the GOPATH. You should also add the -bin subdirectory to your PATH environment variable so -that you can run the commands therein without specifying their full path. -To do this, add the following lines to $HOME/.profile (or -equivalent): +For convenience, add the workspace's bin subdirectory +to your PATH:

-export GOPATH=$HOME/mygo
-export PATH=$PATH:$HOME/mygo/bin
+$ export PATH=$PATH:$GOPATH/bin
 
-

Import paths

+

Package paths

-The standard packages are given short import paths such as "fmt" -and "net/http" for convenience. -For your own projects, it is important to choose a base import path that is -unlikely to collide with future additions to the standard library or other -external libraries. +The packages from the standard library are given short paths such as +"fmt" and "net/http". +For your own packages, you must choose a base path that is unlikely to +collide with future additions to the standard library or other external +libraries.

-The best way to choose an import path is to use the location of your version -control repository. -For instance, if your source repository is at example.com -or code.google.com/p/example, you should begin your package -paths with that URL, as in "example.com/foo/bar" or -"code.google.com/p/example/foo/bar". -Using this convention, the go command can automatically check out and -build the source code by its import path alone. +If you keep your code in a source repository somewhere, then you should use the +root of that source repository as your base path. +For instance, if you have a GitHub account at +github.com/user, that should be your base path.

-If you don't intend to install your code in this way, you should at -least use a unique prefix like "widgets/", as in -"widgets/foo/bar". A good rule is to use a prefix such as your -company or project name, since it is unlikely to be used by another group. +Note that you don't need to publish your code to a remote repository before you +can build it. It's just a good habit to organize your code as if you will +publish it someday. In practice you can choose any arbitrary path name, +as long as it is unique to the standard library and greater Go ecosystem.

-We'll use example/ as our base import path: +We'll use github.com/user as our base path. Create a directory +inside your workspace in which to keep source code:

-$ mkdir -p $GOPATH/src/example
+$ mkdir -p $GOPATH/src/github.com/user
 
-

Package names

+

Your first program

-The first statement in a Go source file should be +To compile and run a simple program, first choose a package path (we'll use +github.com/user/hello) and create a corresponding package directory +inside your workspace:

-package name
+$ mkdir $GOPATH/src/github.com/user/hello
 

-where name is the package's default name for imports. -(All files in a package must use the same name.) +Next, create a file named hello.go inside that directory, +containing the following Go code.

-

-Go's convention is that the package name is the last element of the -import path: the package imported as "crypto/rot13" -should be named rot13. -There is no requirement that package names be unique -across all packages linked into a single binary, -only that the import paths (their full file names) be unique. -

+
+package main
 
-

-Create a new package under example called newmath: -

+import "fmt" -
-$ cd $GOPATH/src/example
-$ mkdir newmath
+func main() {
+	fmt.Printf("Hello, world.\n")
+}
 

-Then create a file named $GOPATH/src/example/newmath/sqrt.go -containing the following Go code: +Now you can build and install that program with the go tool:

-// Package newmath is a trivial example package.
-package newmath
-
-// Sqrt returns an approximation to the square root of x.
-func Sqrt(x float64) float64 {
-        // This is a terrible implementation.
-        // Real code should import "math" and use math.Sqrt.
-        z := 0.0
-        for i := 0; i < 1000; i++ {
-                z -= (z*z - x) / (2 * x)
-        }
-        return z
-}
+$ go install github.com/user/hello
 

-This package is imported by the path name of the directory it's in, starting -after the src component: +Note that you can run this command from anywhere on your system. The +go tool finds the source code by looking for the +github.com/user/hello package inside the workspace specified by +GOPATH. +

+ +

+You can also omit the package path if you run go install from the +package directory:

-import "example/newmath"
+$ cd $GOPATH/src/github.com/user/hello
+$ go install
 

-See Effective Go to learn more about -Go's naming conventions. +This command builds the hello command, producing an executable +binary. It then installs that binary to the workspace's bin +directory as hello (or, under Windows, hello.exe). +In our example, that will be $GOPATH/bin/hello, which is +$HOME/go/bin/hello.

- -

Building and installing

+

+The go tool will only print output when an error occurs, so if +these commands produce no output they have executed successfully. +

-The go command comprises several subcommands, the most central being -install. Running go install importpath builds -and installs a package and its dependencies. +You can now run the program by typing its full path at the command line:

+
+$ $GOPATH/bin/hello
+Hello, world.
+
+

-To "install a package" means to write the package object or executable command -to the pkg or bin subdirectory of the workspace in -which the source resides. +Or, as you have added $GOPATH/bin to your PATH, +just type the binary name:

-

Building a package

+
+$ hello
+Hello, world.
+

-To build and install the newmath package, type +If you're using a source control system, now would be a good time to initialize +a repository, add the files, and commit your first change. Again, this step is +optional: you do not need to use source control to write Go code.

-$ go install example/newmath
+$ cd $GOPATH/src/github.com/user/hello
+$ git init
+Initialized empty Git repository in /home/user/go/src/github.com/user/hello/.git/
+$ git add hello.go
+$ git commit -m "initial commit"
+[master (root-commit) 0b4507d] initial commit
+ 1 file changed, 1 insertion(+)
+  create mode 100644 hello.go
 

-This command will produce no output if the package and its dependencies -are built and installed correctly. +Pushing the code to a remote repository is left as an exercise for the reader. +

+ + +

Your first library

+ +

+Let's write a library and use it from the hello program.

-As a convenience, the go command will assume the current directory -if no import path is specified on the command line. This sequence of commands -has the same effect as the one above: +Again, the first step is to choose a package path (we'll use +github.com/user/newmath) and create the package directory:

-$ cd $GOPATH/src/example/newmath
-$ go install
+$ mkdir $GOPATH/src/github.com/user/newmath
 

-The resulting workspace directory tree (assuming we're running Linux on a 64-bit -system) looks like this: +Next, create a file named sqrt.go in that directory with the +following contents.

-pkg/
-    linux_amd64/
-        example/
-            newmath.a  # package object
-src/
-    example/
-        newmath/
-            sqrt.go    # package source
-
- +// Package newmath is a trivial example package. +package newmath -

Building a command

+// Sqrt returns an approximation to the square root of x. +func Sqrt(x float64) float64 { + z := 0.0 + for i := 0; i < 1000; i++ { + z -= (z*z - x) / (2 * x) + } + return z +} +

-The go command treats code belonging to package main as -an executable command and installs the package binary to the -GOPATH's bin subdirectory. +Now, test that the package compiles with go build:

+
+$ go build github.com/user/newmath
+
+

-Add a command named hello to the source tree. -First create the example/hello directory: +Or, if you are working in the package's source directory, just:

-$ cd $GOPATH/src/example
-$ mkdir hello
+$ go build
 

-Then create the file $GOPATH/src/example/hello/hello.go -containing the following Go code. +This won't produce an output file. To do that, you must use go +install, which places the package object inside the pkg +directory of the workspace. +

+ +

+After confirming that the newmath package builds, +modify your original hello.go (which is in +$GOPATH/src/github.com/user/hello) to use it:

-// Hello is a trivial example of a main package.
 package main
 
 import (
-        "example/newmath"
-        "fmt"
+	"fmt"
+
+	"github.com/user/newmath"
 )
 
 func main() {
-        fmt.Printf("Hello, world.  Sqrt(2) = %v\n", newmath.Sqrt(2))
+	fmt.Printf("Hello, world.  Sqrt(2) = %v\n", newmath.Sqrt(2))
 }
 

-Next, run go install, which builds and installs the binary to -$GOPATH/bin (or $GOBIN, if set; to simplify -presentation, this document assumes GOBIN is unset): +Whenever the go tool installs a package or binary, it also +installs whatever dependencies it has. So when you install the hello +program

-$ go install example/hello
+$ go install github.com/user/hello
 

-To run the program, invoke it by name as you would any other command: +the newmath package will be installed as well, automatically.

-
-$ $GOPATH/bin/hello
-Hello, world.  Sqrt(2) = 1.414213562373095
-
-

-If you added $HOME/mygo/bin to your PATH, you may omit -the path to the executable: +Running the new version of the program, you should see some numerical output:

-$ hello
+$ hello
 Hello, world.  Sqrt(2) = 1.414213562373095
 

-The workspace directory tree now looks like this: +After the steps above, your workspace should look like this:

 bin/
     hello              # command executable
 pkg/
-    linux_amd64/ 
-        example/
+    linux_amd64/       # this will reflect your OS and architecture
+        github.com/user/
             newmath.a  # package object
 src/
-    example/
+    github.com/user/
         hello/
             hello.go   # command source
         newmath/
@@ -351,13 +388,55 @@ src/
 

-The go command also provides a build command, which is -like install except it builds all objects in a temporary directory -and does not install them under pkg or bin. -When building a command an executable named after the last element of the -import path is written to the current directory. When building a package, -go build serves merely to test that the package and its -dependencies can be built. (The resulting package object is thrown away.) +Note that go install placed the newmath.a object in a +directory inside pkg/linux_amd64 that mirrors its source +directory. +This is so that future invocations of the go tool can find the +package object and avoid recompiling the package unnecessarily. +The linux_amd64 part is there to aid in cross-compilation, +and will reflect the operating system and architecture of your system. +

+ +

+Go command executables are statically linked; the package objects need not +be present to run Go programs. +

+ + +

Package names

+ +

+The first statement in a Go source file must be +

+ +
+package name
+
+ +

+where name is the package's default name for imports. +(All files in a package must use the same name.) +

+ +

+Go's convention is that the package name is the last element of the +import path: the package imported as "crypto/rot13" +should be named rot13. +

+ +

+Executable commands must always use package main. +

+ +

+There is no requirement that package names be unique +across all packages linked into a single binary, +only that the import paths (their full file names) be unique. +

+ +

+See Effective Go to learn more about +Go's naming conventions.

@@ -379,8 +458,8 @@ if the function calls a failure function such as t.Error or

Add a test to the newmath package by creating the file -$GOPATH/src/example/newmath/sqrt_test.go containing the following -Go code. +$GOPATH/src/github.com/user/newmath/sqrt_test.go containing the +following Go code.

@@ -397,12 +476,22 @@ func TestSqrt(t *testing.T) {
 

-Now run the test with go test: +Then run the test with go test: +

+ +
+$ go test github.com/user/newmath
+ok  	github.com/user/newmath 0.165s
+
+ +

+As always, if you are running the go tool from the package +directory, you can omit the package path:

-$ go test example/newmath
-ok  	example/newmath 0.165s
+$ go test
+ok  	github.com/user/newmath 0.165s
 

@@ -415,7 +504,7 @@ Run go help test and see t

An import path can describe how to obtain the package source code using a -revision control system such as Git or Mercurial. The go command uses +revision control system such as Git or Mercurial. The go tool uses this property to automatically fetch packages from remote repositories. For instance, the examples described in this document are also kept in a Mercurial repository hosted at Google Code, @@ -425,8 +514,8 @@ If you include the repository URL in the package's import path,

-$ go get code.google.com/p/go.example/hello
-$ $GOPATH/bin/hello
+$ go get code.google.com/p/go.example/hello
+$ $GOPATH/bin/hello
 Hello, world.  Sqrt(2) = 1.414213562373095
 
@@ -446,10 +535,10 @@ tree should now now look like this: bin/ hello # command executable pkg/ - linux_amd64/ + linux_amd64/ code.google.com/p/go.example/ newmath.a # package object - example/ + github.com/user/ newmath.a # package object src/ code.google.com/p/go.example/ @@ -458,7 +547,7 @@ src/ newmath/ sqrt.go # package source sqrt_test.go # test source - example/ + github.com/user/ hello/ hello.go # command source newmath/ @@ -480,12 +569,13 @@ import "code.google.com/p/go.example/newmath"

This convention is the easiest way to make your Go packages available for others to use. -The Go Community Wiki -has a list of external Go projects including programs and libraries. +The Go Wiki +and godoc.org +provide lists of external Go projects.

-For more information on using remote repositories with the go command, see +For more information on using remote repositories with the go tool, see go help remote.

diff --git a/doc/codewalk/markov.xml b/doc/codewalk/markov.xml index 7f1281817..76c448ac3 100644 --- a/doc/codewalk/markov.xml +++ b/doc/codewalk/markov.xml @@ -181,7 +181,7 @@ p == Prefix{"am", "not"}
one index to the left (if you consider zero as the leftmost index).
 p := Prefix{"I", "am"}
-copy(p, p[:1])
+copy(p, p[1:])
 // p == Prefix{"am", "am"}
We then assign the provided word to the last index of the slice: diff --git a/doc/effective_go.html b/doc/effective_go.html index decca34b5..a1e13c0f6 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -2466,7 +2466,7 @@ only to have them be needed again later. The blank identifier provides a workaround.

-This half-written program is has two unused imports +This half-written program has two unused imports (fmt and io) and an unused variable (fd), so it will not compile, but it would be nice to see if the diff --git a/doc/go1.1.html b/doc/go1.1.html index f1d490f41..fac922910 100644 --- a/doc/go1.1.html +++ b/doc/go1.1.html @@ -6,9 +6,41 @@

Introduction to Go 1.1

-TODO - - overview - - link back to Go 1 and also Go 1 Compatibility docs. +

+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. +

+ +

+This document summarizes the changes between Go 1 and Go 1.1. +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 +64-bit ints and Unicode literals +in particular. +

Changes to the language

@@ -62,7 +94,7 @@ a function literal closing over w:
 func (p []byte) (n int, err error) {
-	return w.Write(n, err)
+	return w.Write(p)
 }
 
@@ -75,7 +107,7 @@ is equivalent to a function with an extra first argument, a receiver of type
 func (w *bufio.Writer, p []byte) (n int, err error) {
-	return w.Write(n, err)
+	return w.Write(p)
 }
 
@@ -120,6 +152,17 @@ Such code can be identified by go vet.

Changes to the implementations and tools

+

Status of gccgo

+ +

+The GCC release schedule does not coincide with the Go release schedule, so some skew is inevitable in +gccgo's releases. +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 May 2013, we expect 4.8.1 of GCC to ship with a gccgo +providing a complete Go 1.1 implementaiton. +

+

Command-line flag parsing

@@ -169,6 +212,24 @@ would instead say: i := int(int32(x))

+

Heap size on 64-bit architectures

+ +

+On 64-bit architectures only, the maximum heap size has been enlarged substantially, +from a few gigabytes to several tens of gigabytes. +(The exact details depend on the system and may change.) +

+ +

+On 32-bit architectures, the heap size has not changed. +

+ +

+Updating: +This change should have no effect on existing programs beyond allowing them +to run with larger heaps. +

+

Unicode

@@ -224,6 +285,19 @@ Programs that depend on the old behavior should be modified to avoid the issue. The byte-order-mark change is strictly backward-compatible.

+

Race detector

+ +

+A major addition to the tools is a race detector, a way to find +bugs in programs caused by problems like concurrent changes to the same variable. +This new facility is built into the go tool. +For now, it is only available on Linux, Mac OS X, and Windows systems with +64-bit x86 processors. +To enable it, set the -race flag when building or testing your program +(for instance, go test -race). +The race detector is documented in a separate article. +

+

The gc assemblers

@@ -277,7 +351,7 @@ when $GOPATH and $GOROOT are set to the same value.

 $ GOPATH=$GOROOT go get code.google.com/p/foo/quxx
-warning: GOPATH set to GOROOT (/home/User/go) has no effect
+warning: GOPATH set to GOROOT (/home/you/go) has no effect
 package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath
 
@@ -320,17 +394,69 @@ To update pre-Go 1 code to Go 1.1, use a Go 1.0 tool chain to convert the code to Go 1.0 first.

+

Changes to the go run command

+ +

+The go run command now runs all files in the current working +directory if no file arguments are listed. Also, the go run +command now returns an error if test files are provided on the command line. In +this sense, "go run" replaces "go run *.go". +

+ +

Additional platforms

+ +

+The Go 1.1 tool chain adds experimental support for freebsd/arm, +netbsd/386, netbsd/amd64, netbsd/arm, +openbsd/386 and openbsd/amd64 platforms. +

+ +

+An ARMv6 or later processor is required for freebsd/arm or +netbsd/arm. +

+ +

+Go 1.1 adds experimental support for cgo on linux/arm. +

+ +

Cross compilation

+ +

+When cross-compiling, the go tool will disable cgo +support by default. +

+ +

+To explicitly enable cgo, set CGO_ENABLED=1. +

+

Performance

-TODO introduction +The performance of code compiled with the Go 1.1 gc tool suite should be noticeably +better for most Go programs. +Typical improvements relative to Go 1.0 seem to be about 30%-40%, sometimes +much more, but occasionally less or even non-existent. +There are too many small performance-driven tweaks through the tools and libraries +to list them all here, but the following major changes are worth noting:

    -
  • TODO better code generation (inlining, ...?)
  • -
  • TODO parallel gc
  • -
  • TODO more precise gc
  • -
  • TODO networking is more efficient (known to runtime)
  • +
  • The gc compilers generate better code in many cases, most noticeably for +floating point on the 32-bit Intel architecture.
  • +
  • The gc compilers do more in-lining, including for some operations +in the run-time such as append +and interface conversions.
  • +
  • There is a new implementation of Go maps with significant reduction in +memory footprint and CPU time.
  • +
  • The garbage collector has been made more parallel, which can reduce +latencies for programs running on multiple CPUs.
  • +
  • The garbage collector is also more precise, which costs a small amount of +CPU time but can reduce the size of the heap significantly, especially +on 32-bit architectures.
  • +
  • Due to tighter coupling of the run-time and network libraries, fewer +context switches are required on network operations.

Changes to the standard library

@@ -405,6 +531,26 @@ and methods.

+

+The data structures +IPAddr, +TCPAddr, and +UDPAddr +add a new string field called Zone. +Code using untagged composite literals (e.g. net.TCPAddr{ip, port}) +instead of tagged literals (net.TCPAddr{IP: ip, Port: port}) +will break due to the new field. +The Go 1 compatibility rules allow this change: client code must use tagged literals to avoid such breakages. +

+ +

+Updating: +To correct breakage caused by the new struct field, +go fix will rewrite code to add tags for these types. +More generally, go vet will identify composite literals that +should be revised to use field tags. +

+

reflect

@@ -448,7 +594,7 @@ and SliceOf construct new Types -from existing types, for example to construct a the type []T given +from existing types, for example to construct the type []T given only T.

@@ -553,6 +699,14 @@ so it implements the io.WriterTo interface. +
  • +The compress/gzip package has +a new Flush +method for its +Writer +type that flushes its underlying flate.Writer. +
  • +
  • The crypto/hmac package has a new function, Equal, to compare two MACs. @@ -567,7 +721,7 @@ and a new function
  • -The database/sql/ package +The database/sql package has a new Ping method for its @@ -588,7 +742,7 @@ may implement to improve performance. The encoding/json package's Decoder has a new method -Reader +Buffered to provide access to the remaining data in its buffer, as well as a new method UseNumber @@ -598,7 +752,7 @@ a string, rather than a float64.
  • -The endoding/xml package +The encoding/xml package has a new function, EscapeText, which writes escaped XML output, @@ -635,12 +789,17 @@ to format arbitrary Go source code.
  • The undocumented and only partially implemented "noescape" feature of the -html/template +html/template package has been removed; programs that depend on it will break.
  • -The io package now exports the +The image/jpeg package now +reads progressive JPEG files and handles a few more subsampling configurations. +
  • + +
  • +The io package now exports the io.ByteWriter interface to capture the common functionality of writing a byte at a time.
  • @@ -683,29 +842,99 @@ to define the boundary separator used to package the output.
  • The net package's -net/ListenUnixgram +ListenUnixgram function has changed return types: it now returns a -net/UnixConn +UnixConn rather than a -net/UDPConn, which was +UDPConn, which was clearly a mistake in Go 1.0. Since this API change fixes a bug, it is permitted by the Go 1 compatibility rules.
  • -The new net/http/cookiejar package provides the basics for managing HTTP cookies. +The net package includes a new type, +Dialer, to supply options to +Dial.
  • -
  • TODO: -net/http: ParseTime, CloseNotifier, Request.PostFormValue, ServeMux.Handler, Transport.CancelRequest +
  • +The net package adds support for +link-local IPv6 addresses with zone qualifiers, such as fe80::1%lo0. +The address structures IPAddr, +UDPAddr, and +TCPAddr +record the zone in a new field, and functions that expect string forms of these addresses, such as +Dial, +ResolveIPAddr, +ResolveUDPAddr, and +ResolveTCPAddr, +now accept the zone-qualified form.
  • -
  • TODO: -net/mail: ParseAddress, ParseAddressList +
  • +The net package adds +LookupNS to its suite of resolving functions. +LookupNS returns the NS records for a host name.
  • -
  • TODO: -net/smtp: Client.Hello +
  • +The net package adds protocol-specific +packet reading and writing methods to +IPConn +(ReadMsgIP +and WriteMsgIP) and +UDPConn +(ReadMsgUDP and +WriteMsgUDP). +These are specialized versions of PacketConn's +ReadFrom and WriteTo methods that provide access to out-of-band data associated +with the packets. +
  • + +
  • +The net package adds methods to +UnixConn to allow closing half of the connection +(CloseRead and +CloseWrite), +matching the existing methods of TCPConn. +
  • + +
  • +The net/http package includes several new additions. +ParseTime parses a time string, trying +several common HTTP time formats. +The PostFormValue method of +Request is like +FormValue but ignores URL parameters. +The CloseNotifier interface provides a mechanism +for a server handler to discover when a client has disconnected. +The ServeMux type now has a +Handler method to access a path's +Handler without executing it. +The Transport can now cancel an in-flight request with +CancelRequest. +Finally, the Transport is now more aggressive at closing TCP connections when +a Response.Body is closed before +being fully consumed. +
  • + +
  • +The new net/http/cookiejar package provides the basics for managing HTTP cookies. +
  • + +
  • +The net/mail package has two new functions, +ParseAddress and +ParseAddressList, +to parse RFC 5322-formatted mail addresses into +Address structures. +
  • + +
  • +The net/smtp package's +Client type has a new method, +Hello, +which transmits a HELO or EHLO message to the server.
  • @@ -716,17 +945,14 @@ has two new functions, which do ASCII-only trimming of leading and trailing spaces.
  • -
  • TODO: -net: DialOption, DialOpt, ListenUnixgram, LookupNS, IPConn.ReadMsgIP, IPConn.WriteMsgIP, UDPConn.ReadMsgUDP, UDPConn.WriteMsgUDP, UnixConn.CloseRead, UnixConn.CloseWrite -
  • -
  • -The new method os.FileMode.IsRegular makes it easy to ask if a file is a plain file. +The new method os.FileMode.IsRegular makes it easy to ask if a file is a plain file.
  • -The image/jpeg package now -reads progressive JPEG files and handles a few more subsampling configurations. +The os/signal package has a new function, +Stop, which stops the package delivering +any further signals to the channel.
  • @@ -764,7 +990,7 @@ The strings package has two new functio TrimPrefix and TrimSuffix -with self-evident properties, and the the new method +with self-evident properties, and the new method Reader.WriteTo so the Reader type now implements the @@ -777,8 +1003,11 @@ The syscall package has received many u
  • The testing package now automates the generation of allocation -statistics in benchmarks using the new -AllocsPerRun function and the +statistics in tests and benchmarks using the new +AllocsPerRun function. And the +ReportAllocs +method on testing.B will enable printing of +memory allocation statistics for the calling benchmark. It also introduces the AllocsPerOp method of BenchmarkResult. There is also a new @@ -796,7 +1025,6 @@ In the text/template and html/template packages, templates can now use parentheses to group the elements of pipelines, simplifying the construction of complex pipelines. -TODO: Link to example. Also, as part of the new parser, the Node interface got two new methods to provide better error reporting. @@ -810,12 +1038,12 @@ packages and there are safeguards to guarantee that.
  • -In the unicode/utf8 package, -the new function ValidRune reports whether the rune is a valid Unicode code point. -To be valid, a rune must be in range and not be a surrogate half. +The implementation of the unicode package has been updated to Unicode version 6.2.0.
  • -The implementation of the unicode package has been updated to Unicode version 6.2.0. +In the unicode/utf8 package, +the new function ValidRune reports whether the rune is a valid Unicode code point. +To be valid, a rune must be in range and not be a surrogate half.
  • diff --git a/doc/go_faq.html b/doc/go_faq.html index 3e742d9f7..63ad66c51 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -157,6 +157,12 @@ and so on. These cannot be addressed well by libraries or tools; a new language was called for.

    +

    +The article Go at Google +discusses the background and motivation behind the design of the Go language, +as well as providing more detail about many of the answers presented in this FAQ. +

    +

    What are Go's ancestors?

    @@ -216,6 +222,13 @@ document server running in a production configuration on Google App Engine.

    +

    +Other examples include the Vitess +system for large-scale SQL installations and Google's download server, dl.google.com, +which delivers Chrome binaries and other large installables such as apt-get +packages. +

    + @@ -394,6 +407,8 @@ for concurrency comes from Hoare's Communicating Sequential Processes, or CSP. Occam and Erlang are two well known languages that stem from CSP. Go's concurrency primitives derive from a different part of the family tree whose main contribution is the powerful notion of channels as first class objects. +Experience with several earlier languages has shown that the CSP model +fits well into a procedural language framework.

    @@ -874,11 +889,11 @@ There's a lot of history on that topic. Early on, maps and channels were syntactically pointers and it was impossible to declare or use a non-pointer instance. Also, we struggled with how arrays should work. Eventually we decided that the strict separation of pointers and -values made the language harder to use. Introducing reference types, -including slices to handle the reference form of arrays, resolved -these issues. Reference types add some regrettable complexity to the -language but they have a large effect on usability: Go became a more -productive, comfortable language when they were introduced. +values made the language harder to use. Changing these +types to act as references to the associated, shared data structures resolved +these issues. This change added some regrettable complexity to the +language but had a large effect on usability: Go became a more +productive, comfortable language when it was introduced.

    Writing Code

    @@ -1080,7 +1095,7 @@ There are several considerations. First, and most important, does the method need to modify the receiver? If it does, the receiver must be a pointer. -(Slices and maps are reference types, so their story is a little +(Slices and maps act as references, so their story is a little more subtle, but for instance to change the length of a slice in a method the receiver must still be a pointer.) In the examples above, if pointerMethod modifies @@ -1131,7 +1146,7 @@ of Effective Go for more details.

    -Why is int 32 bits on 64 bit machines?

    +What is the size of an int on a 64 bit machine?

    The sizes of int and uint are implementation-specific @@ -1148,12 +1163,6 @@ floating-point numbers. The default size of a floating-point constant is float64.

    -

    -At the moment, all implementations use 32-bit ints, an essentially arbitrary decision. -However, we expect that int will be increased to 64 bits on 64-bit -architectures in a future release of Go. -

    -

    How do I know whether a variable is allocated on the heap or the stack?

    @@ -1237,6 +1246,9 @@ run-time support to utilize more than one OS thread.

    Programs that perform parallel computation should benefit from an increase in GOMAXPROCS. +However, be aware that +concurrency +is not parallelism.

    @@ -1270,6 +1282,11 @@ should recognize such cases and optimize its use of OS threads. For now, GOMAXPROCS should be set on a per-application basis.

    +

    +For more detail on this topic see the talk entitled, +Concurrency +is not Parallelism. +

    Functions and Methods

    @@ -1503,9 +1520,11 @@ We considered writing gc, the original Go compiler, in Go itself bu elected not to do so because of the difficulties of bootstrapping and especially of open source distribution—you'd need a Go compiler to set up a Go environment. Gccgo, which came later, makes it possible to -consider writing a compiler in Go, which might well happen. (Go would be a +consider writing a compiler in Go, which might well happen. +(Go would be a fine language in which to implement a compiler; a native lexer and -parser are already available in the go package.) +parser are already available in the go package +and a type checker is in the works.)

    diff --git a/doc/go_spec.html b/doc/go_spec.html index 881d16656..214d1c0ac 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -837,9 +837,9 @@ multi-dimensional types.

    Slice types

    -A slice is a reference to a contiguous segment of an array and -contains a numbered sequence of elements from that array. A slice -type denotes the set of all slices of arrays of its element type. +A slice is a descriptor for a contiguous segment of an array and +provides access to a numbered sequence of elements from that array. +A slice type denotes the set of all slices of arrays of its element type. The value of an uninitialized slice is nil.

    @@ -5197,8 +5197,6 @@ of the memory.

    Making slices, maps and channels

    -Slices, maps and channels are reference types that do not require the -extra indirection of an allocation with new. The built-in function make takes a type T, which must be a slice, map or channel type, optionally followed by a type-specific list of expressions. diff --git a/doc/godocs.js b/doc/godocs.js index 5d12da131..6875f74d8 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -179,6 +179,13 @@ function fixFocus() { }).resize(); } +function toggleHash() { + var hash = $(window.location.hash); + if (hash.is('.toggle')) { + hash.addClass('toggleVisible').removeClass('toggle'); + } +} + $(document).ready(function() { bindSearchEvents(); generateTOC(); @@ -190,6 +197,7 @@ $(document).ready(function() { bindToggleLinks(".indexLink", ""); setupDropdownPlayground(); fixFocus(); + toggleHash(); }); })(); diff --git a/doc/install.html b/doc/install.html index 03b13c018..f2e21b441 100644 --- a/doc/install.html +++ b/doc/install.html @@ -3,25 +3,34 @@ "Path": "/doc/install" }--> -

    Introduction

    +

    Download the Go distribution

    -Go is an open source project with a BSD-style license. -There are two official Go compiler toolchains: the gc Go compiler -and the gccgo compiler that is part of the GNU C Compiler (GCC). + +Download Go +Click here to visit the downloads page +

    -The gc compiler is the more mature and well-tested of the two. -This page is about installing a binary distribution of the gc -compiler. +Click the link above to visit the +Go project's downloads page +and select the binary distribution that matches your operating system and +processor architecture.

    -For information about installing the gc compiler from source, see -Installing Go from source. -For information about installing gccgo, see -Setting up and using gccgo. +Official binary distributions are available for the FreeBSD, Linux, Mac OS X +(Snow Leopard, Lion, and Mountain Lion), NetBSD, and Windows operating systems +and the 32-bit (386) and 64-bit (amd64) x86 processor +architectures. +

    + +

    +If a binary distribution is not available for your combination of operating +system and architecture you may want to try +installing from source or +installing gccgo instead of gc.

    System requirements

    @@ -56,29 +65,6 @@ installed Xcode 4.3+, you can install it from the Components tab of the Downloads preferences panel.

    -

    Download the Go tools

    - -

    -Visit the -Go project's downloads page -and select the binary distribution that matches -your operating system and processor architecture. -

    - -

    -Official binary distributions are available -for the FreeBSD, Linux, Mac OS X (Snow Leopard/Lion), NetBSD, and Windows operating systems -and the 32-bit (386) and 64-bit (amd64) -x86 processor architectures. -

    - -

    -If a binary distribution is not available for your -OS/arch combination you may want to try -installing from source or -installing gccgo instead of gc. -

    -

    Install the Go tools

    diff --git a/doc/style.css b/doc/style.css index 3d881b03a..5c8e17a29 100644 --- a/doc/style.css +++ b/doc/style.css @@ -12,7 +12,7 @@ pre { line-height: 18px; } pre .comment { - color: #375EAB; + color: #006600; } pre .highlight, pre .highlight-comment, @@ -198,6 +198,9 @@ div#blog .read a { border: 1px solid #375EAB; background: #E0EBF5; } +.download { + width: 150px; +} div#menu { float: right; diff --git a/include/libc.h b/include/libc.h index fab1532f2..e10dde3ad 100644 --- a/include/libc.h +++ b/include/libc.h @@ -291,6 +291,7 @@ extern char* getgoroot(void); extern char* getgoversion(void); extern char* getgoarm(void); extern char* getgo386(void); +extern char* getgoextlinkenabled(void); extern char* mktempdir(void); extern void removeall(char*); diff --git a/include/plan9/libc.h b/include/plan9/libc.h index e6f9839c8..dcecc7c8b 100644 --- a/include/plan9/libc.h +++ b/include/plan9/libc.h @@ -18,6 +18,7 @@ char* getgoroot(void); char* getgoversion(void); char* getgoarm(void); char* getgo386(void); +char* getgoextlinkenabled(void); void flagcount(char*, char*, int*); void flagint32(char*, char*, int32*); diff --git a/lib/codereview/codereview.py b/lib/codereview/codereview.py index 11766fcb2..f839263c5 100644 --- a/lib/codereview/codereview.py +++ b/lib/codereview/codereview.py @@ -1762,7 +1762,8 @@ def gofmt(ui, repo, *pats, **opts): files = ChangedExistingFiles(ui, repo, pats, opts) files = gofmt_required(files) if not files: - return "no modified go files" + ui.status("no modified go files\n") + return cwd = os.getcwd() files = [RelativePath(repo.root + '/' + f, cwd) for f in files] try: diff --git a/lib/godoc/package.html b/lib/godoc/package.html index 33c2c2791..aefbef9fd 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -40,7 +40,7 @@ {{comment_html .Doc}} - {{example_html "" $.Examples $.FSet}} + {{example_html $ ""}}