In Go 1, integer division by a constant zero produced a runtime panic:
func f(x int) int { return x/0 }
In Go 1.1, an integer division by constant zero is not a legal program, so it is a compile-time error.
TODO: more
In the gc tool chain, the compilers and linkers now use the
same command-line flag parsing rules as the Go flag package, a departure
from the traditional Unix flag parsing. This may affect scripts that invoke
the tool directly.
For example,
go tool 6c -Fw -Dfoo
must now be written
go tool 6c -F -w -D foo
.
The language allows the implementation to choose whether the int
type and uint
types are 32 or 64 bits. Previous Go implementations made int
and uint
32 bits on all systems. Both the gc and gccgo implementations (TODO: check that gccgo does) now make int
and uint
64 bits on 64-bit platforms such as AMD64/x86-64.
Among other things, this enables the allocation of slices with
more than 2 billion elements on 64-bit platforms.
Updating:
Most programs will be unaffected by this change.
Because Go does not allow implicit conversions between distinct
numeric types,
no programs will stop compiling due to this change.
However, programs that contain implicit assumptions
that int
is only 32 bits may change behavior.
For example, this code prints a positive number on 64-bit systems and
a negative one on 32-bit systems:
x := ^uint32(0) // x is 0xffffffff i := int(x) // i is -1 on 32-bit systems, 0xffffffff on 64-bit fmt.Println(i)
Portable code intending 32-bit sign extension (yielding -1 on all systems) would instead say:
i := int(int32(x))
To make it possible to represent code points greater than 65535 in UTF-16,
Unicode defines surrogate halves,
a range of code points to be used only in the assembly of large values, and only in UTF-16.
The code points in that surrogate range are illegal for any other purpose.
In Go 1.1, this constraint is honored by the compiler, libraries, and run-time:
a surrogate half is illegal as a rune value, when encoded as UTF-8, or when
encoded in isolation as UTF-16.
When encountered, for example in converting from a rune to UTF-8, it is
treated as an encoding error and will yield the replacement rune,
utf8.RuneError
,
U+FFFD.
This program,
import "fmt" func main() { fmt.Printf("%+q\n", string(0xD800)) }
printed "\ud800"
in Go 1.0, but prints "\ufffd"
in Go 1.1.
The Unicode byte order marks U+FFFE and U+FEFF, encoded in UTF-8, are now permitted as the first character of a Go source file. Even though their appearance in the byte-order-free UTF-8 encoding is clearly unnecessary, some editors add them as a kind of "magic number" identifying a UTF-8 encoded file.
Updating: Most programs will be unaffected by the surrogate change. Programs that depend on the old behavior should be modified to avoid the issue. The byte-order-mark change is strictly backwards- compatible.
Due to the int and TODO: OTHER changes, the placement of function arguments on the stack has changed. Functions written in assembly will need to be revised at least to adjust frame pointer offsets.
The go
tool has acquired several improvements which are intended to improve the experience for new Go users.
Firstly, when compiling, testing, or running Go code, the go
tool will now give more detailed errors messages, including a list of paths searched, when a package cannot be located.
$ go build foo/quxx can't load package: package foo/quxx: cannot find package "foo/quxx" in any of: /home/User/go/src/pkg/foo/quxx (from $GOROOT) /home/User/src/foo/quxx (from $GOPATH)
Secondly, the go get
command no longer allows $GOROOT
as the default destination when downloading package source. To use go get
command, a valid $GOPATH
is now required.
$ GOPATH= go get code.google.com/p/foo/quxx package code.google.com/p/foo/quxx: cannot download, $GOPATH not set. For more details see: go help gopath
Finally, as a result of the previous change, the go get
command will also fail 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 package code.google.com/p/foo/quxx: cannot download, $GOPATH must not be set to $GOROOT. For more details see: go help gopath
The go fix
command no longer applies fixes to update code from
before Go 1 to use Go 1 APIs. 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.
TODO introduction
TODO
Previous versions of the debug/elf package intentionally skipped over the first symbol in the ELF symbol table, since it is always an empty symbol. This symbol is no longer skipped since indexes into the symbol table returned by debug/elf, will be different to indexes into the original ELF symbol table. Any code that calls the debug/elf functions Symbols or ImportedSymbols may need to be adjusted to account for the additional symbol and the change in symbol offsets.
The protocol-specific resolvers were formerly
lax about the network name passed in. For example, although the documentation was clear
that the only valid networks for ResolveTCPAddr
are "tcp"
,
"tcp4"
, and "tcp6"
, the Go 1.0 implementation silently accepted
any string. The Go 1.1 implementation returns an error if the network is not one of those strings.
The same is true of the other protocol-specific resolvers ResolveIPAddr
, ResolveUDPAddr
, and
ResolveUnixAddr
.
The previous ListenUnixgram
returned UDPConn
as
a representation of the connection endpoint. The Go 1.1 implementation
returns UnixConn
to allow reading and writing
with ReadFrom
and WriteTo
methods on
the UnixConn
.
TODO:
reflect
: Select, ChanOf, MakeFunc, MapOf, SliceOf, Convert, Type.ConvertibleTo
TODO:
runtime
: BlockProfile
On FreeBSD, Linux, NetBSD, OS X and OpenBSD, previous versions of the time package returned times with microsecond precision. The Go 1.1 implementation of time on these systems now returns times with nanosecond precision. Code may exist that expects to be able to store such a time in an external format with only microsecond precision, read it back, and recover exactly the same time instant. In Go 1.1 the same time will not be recovered, since the external storage will have discarded nanoseconds. To address this case, there are two new methods of time.Time, Round and Truncate, that can be used to remove precision from a time before passing it to external storage.
TODO:
time
: ParseInLocation, Timer.Reset, Time.YearDay
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
$ go get code.google.com/p/go.exp/ssa
and then in Go source,
import "code.google.com/p/go.exp/ssa"
The following list summarizes a number of minor changes to the library, mostly additions. See the relevant package documentation for more information about each change.
bytes
package has two new functions,
TrimPrefix
and
TrimSuffix
,
with self-evident properties.
Also, the Buffer
type
has a new method
Grow
that
provides some control over memory allocation inside the buffer.
Finally, the
Reader
type now has a
WriteTo
method
so it implements the
io.WriterTo
interface.
crypto/hmac
package has a new function,
Equal
, to compare two MACs.
crypto/x509
: DecryptPEMBlock, EncryptPEMBlock etc.
database/sql/driver
: Queryer
database/sql
: Ping, SetMaxIdleConns
encoding/json
: Decoder.Buffered, UseNumber, Number
encoding/xml
: EscapeText Encoder.Indent
go/ast
package, a
new type CommentMap
and associated methods makes it easier to extract and process comments in Go programs.
go/doc
package,
the parser now keeps better track of stylized annotations such as TODO(joe)
throughout the code,
information that the godoc
command can filter or present according to the value of the -notes
flag.
go/format
: Node, Source
io.ByteWriter
interface to capture the common
functionality of writing a byte at a time.
log/syslog
package now provides better support
for OS-specific logging features.
math/big
package's
Int
type now has
now has methods
MarshalJSON
and
UnmarshalJSON
to convert to and from a JSON representation.
Also,
Int
can now convert directly to and from a uint64
using
Uint64
and
SetUint64
,
while
Rat
can do the same with float64
using
Float64
and
SetFloat64
.
mime/multipart
: Writer.SetBoundary
net/http
: ParseTime, CloseNotifier, Request.PostFormValue, ServeMux.Handler, Transport.CancelRequest
net/mail
: ParseAddress, ParseAddressList
net/smtp
: Client.Hello
net/textproto
: TrimBytes, TrimString
net
: DialOption, DialOpt, ListenUnixgram, LookupNS, IPConn.ReadMsgIP, IPConn.WriteMsgIP, UDPConn.ReadMsgUDP, UDPConn.WriteMsgUDP, UnixConn.CloseRead, UnixConn.CloseWrite
os.FileMode.IsRegular
makes it easy to ask if a file is a plain file.
pkg/image
: new subsamplings
regexp
package
now supports Unix-original leftmost-longest matches through the
Regexp.Longest
method, while
Regexp.Split
slices
strings into pieces based on separators defined by the regular expression.
runtime/debug
: FreeOSMemory, ReadGCStats, SetGCPercent
sort
package has a new function,
Reverse
.
Wrapping the argument of a call to
sort.Sort
with a call to Reverse
causes the sort order to be reversed.
strings
package has two new functions,
TrimPrefix
and
TrimSuffix
with self-evident properties, and the the new method
Reader.WriteTo
so the
Reader
type now implements the
io.WriterTo
interface.
syscall
package has received many updates to make it more inclusive of constants and system calls for each supported operating system.
testing
package now automates the generation of allocation
statistics in benchmarks using the new
AllocsPerRun
function and the
AllocsPerOp
method of
BenchmarkResult
.
There is also a new
Verbose
function to test the state of the -v
command-line flag,
and a new
Skip
method of
testing.B
and
testing.T
to simplify skipping an inappropriate test.
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.
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.
unicode
package has been updated to Unicode version 6.2.0.