Skip to content

Commit

Permalink
[dev.boringcrypto] all: merge master into dev.boringcrypto
Browse files Browse the repository at this point in the history
Change-Id: If6b68df0c90464566e68de6807d15f4b8bec6219
  • Loading branch information
chressie committed Feb 8, 2022
2 parents e14fee5 + c856fbf commit 74d25c6
Show file tree
Hide file tree
Showing 122 changed files with 2,240 additions and 2,650 deletions.
6 changes: 0 additions & 6 deletions api/go1.18.txt
@@ -1,12 +1,6 @@
pkg bufio, method (*Writer) AvailableBuffer() []uint8
pkg bufio, method (ReadWriter) AvailableBuffer() []uint8
pkg bytes, func Cut([]uint8, []uint8) ([]uint8, []uint8, bool)
pkg constraints, type Complex interface {}
pkg constraints, type Float interface {}
pkg constraints, type Integer interface {}
pkg constraints, type Ordered interface {}
pkg constraints, type Signed interface {}
pkg constraints, type Unsigned interface {}
pkg crypto/tls, method (*Conn) NetConn() net.Conn
pkg debug/buildinfo, func Read(io.ReaderAt) (*debug.BuildInfo, error)
pkg debug/buildinfo, func ReadFile(string) (*debug.BuildInfo, error)
Expand Down
89 changes: 81 additions & 8 deletions doc/go1.18.html
Expand Up @@ -90,6 +90,39 @@ <h3 id="generics">Generics</h3>
</li>
</ul>

<p>
There are three experimental packages using generics that may be
useful.
These packages are in x/exp repository; their API is not covered by
the Go 1 guarantee and may change as we gain more experience with
generics.
<dl>
<dt><a href="https://pkg.go.dev/golang.org/x/exp/constraints"><code>golang.org/x/exp/constraints</code></a></dt>
<dd>
<p>
Constraints that are useful for generic code, such as
<a href="https://pkg.go.dev/golang.org/x/exp/constraints#Ordered"><code>constraints.Ordered</code></a>.
</p>
</dd>

<dt><a href="https://pkg.go.dev/golang.org/x/exp/slices"><code>golang.org/x/exp/slices</code></a></dt>
<dd>
<p>
A collection of generic functions that operate on slices of
any element type.
</p>
</dd>

<dt><a href="https://pkg.go.dev/golang.org/x/exp/maps"><code>golang.org/x/exp/maps</code></a></dt>
<dd>
<p>
A collection of generic functions that operate on maps of
any key or element type.
</p>
</dd>
</dl>
</p>

<p>
The current generics implementation has the following limitations:
<ul>
Expand Down Expand Up @@ -460,21 +493,21 @@ <h2 id="compiler">Compiler</h2>

<h2 id="linker">Linker</h2>

<p>
The linker emits <a href="https://tailscale.com/blog/go-linker/">far fewer relocations</a>.
As a result, most codebases will link faster, require less memory to link,
and generate smaller binaries.
Tools that process Go binaries should use Go 1.18's <code>debug/gosym</code> package
to transparently handle both old and new binaries.
</p>

<p><!-- CL 298610 -->
The new linker <code>-asan</code> option supports the
new <code>go</code> command <code>-asan</code> option.
</p>

<h2 id="library">Core library</h2>

<h3 id="constraints">New <code>constraints</code> package</h3>

<p><!-- CL 349709 -->
The new <a href="/pkg/constraints/"><code>constraints</code></a> package
defines a set of useful constraints that can be used with type parameters of
generic functions.
</p>

<h3 id="debug/buildinfo">New <code>debug/buildinfo</code> package</h3>

<p><!-- golang.org/issue/39301 -->
Expand Down Expand Up @@ -670,6 +703,46 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
</dd>
</dl><!-- crypto/tls -->

<dl id="crypto/x509"><dt><a href="/pkg/crypto/x509">crypto/x509</a></dt>
<dd>
<p><!-- CL 353132, CL 353403 -->
<a href="/pkg/crypto/x509/#Certificate.Verify"><code>Certificate.Verify</code></a>
now uses platform APIs to verify certificate validity on macOS and iOS when it
is called with a nil
<a href="/pkg/crypto/x509/#VerifyOpts.Roots"><code>VerifyOpts.Roots</code></a>
or when using the root pool returned from
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>.
</p>

<p><!-- CL 353589 -->
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>
is now available on Windows.
</p>

<p>
On Windows, macOS, and iOS, when a
<a href="/pkg/crypto/x509/#CertPool"><code>CertPool</code></a> returned by
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>
has additional certificates added to it,
<a href="/pkg/crypto/x509/#Certificate.Verify"><code>Certificate.Verify</code></a>
will do two verifications: one using the platform verifier APIs and the
system roots, and one using the Go verifier and the additional roots.
Chains returned by the platform verifier APIs will be prioritized.
</p>

<p>
<a href="/pkg/crypto/x509/#CertPool.Subjects"><code>CertPool.Subjects</code></a>
is deprecated. On Windows, macOS, and iOS the
<a href="/pkg/crypto/x509/#CertPool"><code>CertPool</code></a> returned by
<a href="/pkg/crypto/x509/#SystemCertPool"><code>SystemCertPool</code></a>
will return a pool which does not include system roots in the slice
returned by <code>Subjects</code>, as a static list can't appropriately
represent the platform policies and might not be available at all from the
platform APIs.
</p>
</dd>
</dl>

<dl id="debug/dwarf"><dt><a href="/pkg/debug/dwarf/">debug/dwarf</a></dt>
<dd>
<p><!-- CL 380714 -->
Expand Down
4 changes: 4 additions & 0 deletions misc/cgo/errors/badsym_test.go
Expand Up @@ -201,6 +201,10 @@ func cCompilerCmd(t *testing.T) []string {
if !lastSpace {
cc = append(cc, s[start:])
}

// Force reallocation (and avoid aliasing bugs) for tests that append to cc.
cc = cc[:len(cc):len(cc)]

return cc
}

Expand Down
5 changes: 5 additions & 0 deletions misc/cgo/test/test.go
Expand Up @@ -367,6 +367,11 @@ void init() {
// Cgo incorrectly computed the alignment of structs
// with no Go accessible fields as 0, and then panicked on
// modulo-by-zero computations.
// issue 50987
// disable arm64 GCC warnings
#cgo CFLAGS: -Wno-psabi -Wno-unknown-warning-option
typedef struct {
} foo;
Expand Down
30 changes: 3 additions & 27 deletions misc/cgo/testcarchive/carchive_test.go
Expand Up @@ -11,7 +11,6 @@ import (
"flag"
"fmt"
"io"
"io/fs"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -141,6 +140,9 @@ func testMain(m *testing.M) int {
libgodir = filepath.Join(GOPATH, "pkg", libbase, "testcarchive")
cc = append(cc, "-I", libgodir)

// Force reallocation (and avoid aliasing bugs) for parallel tests that append to cc.
cc = cc[:len(cc):len(cc)]

if GOOS == "windows" {
exeSuffix = ".exe"
}
Expand Down Expand Up @@ -248,29 +250,6 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) {

var badLineRegexp = regexp.MustCompile(`(?m)^#line [0-9]+ "/.*$`)

// checkIsExecutable verifies that exe exists and has execute permission.
//
// (https://golang.org/issue/49693 notes failures with "no such file or
// directory", so we want to double-check that the executable actually exists
// immediately after we build it in order to better understand that failure
// mode.)
func checkIsExecutable(t *testing.T, exe string) {
t.Helper()
fi, err := os.Stat(exe)
if err != nil {
t.Fatal(err)
}
if runtime.GOOS == "windows" {
// os.File doesn't check the "execute" permission on Windows files
// and as a result doesn't set that bit in a file's permissions.
// Assume that if the file exists it is “executable enough”.
return
}
if fi.Mode()&0111 == 0 {
t.Fatalf("%s is not executable: %0o", exe, fi.Mode()&fs.ModePerm)
}
}

// checkLineComments checks that the export header generated by
// -buildmode=c-archive doesn't have any absolute paths in the #line
// comments. We don't want those paths because they are unhelpful for
Expand Down Expand Up @@ -964,7 +943,6 @@ func TestSIGPROF(t *testing.T) {
if err != nil {
t.Fatal(err)
}
checkIsExecutable(t, "./testp6"+exeSuffix)

argv := cmdToRun("./testp6")
cmd = exec.Command(argv[0], argv[1:]...)
Expand Down Expand Up @@ -1113,7 +1091,6 @@ func TestManyCalls(t *testing.T) {
if err != nil {
t.Fatal(err)
}
checkIsExecutable(t, "./testp7"+exeSuffix)

argv := cmdToRun("./testp7")
cmd = exec.Command(argv[0], argv[1:]...)
Expand Down Expand Up @@ -1170,7 +1147,6 @@ func TestPreemption(t *testing.T) {
if err != nil {
t.Fatal(err)
}
checkIsExecutable(t, "./testp8"+exeSuffix)

argv := cmdToRun("./testp8")
cmd = exec.Command(argv[0], argv[1:]...)
Expand Down
3 changes: 3 additions & 0 deletions misc/cgo/testcshared/cshared_test.go
Expand Up @@ -117,6 +117,9 @@ func testMain(m *testing.M) int {
}
cc = append(cc, "-I", filepath.Join("pkg", libgodir))

// Force reallocation (and avoid aliasing bugs) for parallel tests that append to cc.
cc = cc[:len(cc):len(cc)]

if GOOS == "windows" {
exeSuffix = ".exe"
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/compile/internal/typecheck/subr.go
Expand Up @@ -1480,6 +1480,7 @@ func Shapify(t *types.Type, index int, tparam *types.Type) *types.Type {
s.SetUnderlying(u)
s.SetIsShape(true)
s.SetHasShape(true)
types.CalcSize(s)
name.SetType(s)
name.SetTypecheck(1)
submap[u] = s
Expand Down
58 changes: 58 additions & 0 deletions src/cmd/compile/internal/types2/api_test.go
Expand Up @@ -2369,3 +2369,61 @@ type Bad Bad // invalid type
}
}
}

func TestMissingMethodAlternative(t *testing.T) {
const src = `
package p
type T interface {
m()
}
type V0 struct{}
func (V0) m() {}
type V1 struct{}
type V2 struct{}
func (V2) m() int
type V3 struct{}
func (*V3) m()
type V4 struct{}
func (V4) M()
`

pkg, err := pkgFor("p.go", src, nil)
if err != nil {
t.Fatal(err)
}

T := pkg.Scope().Lookup("T").Type().Underlying().(*Interface)
lookup := func(name string) (*Func, bool) {
return MissingMethod(pkg.Scope().Lookup(name).Type(), T, true)
}

// V0 has method m with correct signature. Should not report wrongType.
method, wrongType := lookup("V0")
if method != nil || wrongType {
t.Fatalf("V0: got method = %v, wrongType = %v", method, wrongType)
}

checkMissingMethod := func(tname string, reportWrongType bool) {
method, wrongType := lookup(tname)
if method == nil || method.Name() != "m" || wrongType != reportWrongType {
t.Fatalf("%s: got method = %v, wrongType = %v", tname, method, wrongType)
}
}

// V1 has no method m. Should not report wrongType.
checkMissingMethod("V1", false)

// V2 has method m with wrong signature type (ignoring receiver). Should report wrongType.
checkMissingMethod("V2", true)

// V3 has no method m but it exists on *V3. Should report wrongType.
checkMissingMethod("V3", true)

// V4 has no method m but has M. Should not report wrongType.
checkMissingMethod("V4", false)
}
13 changes: 7 additions & 6 deletions src/cmd/compile/internal/types2/builtins.go
Expand Up @@ -142,9 +142,8 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
// cap(x)
// len(x)
mode := invalid
var typ Type
var val constant.Value
switch typ = arrayPtrDeref(under(x.typ)); t := typ.(type) {
switch t := arrayPtrDeref(under(x.typ)).(type) {
case *Basic:
if isString(t) && id == _Len {
if x.mode == constant_ {
Expand Down Expand Up @@ -201,17 +200,19 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
}
}

if mode == invalid && typ != Typ[Invalid] {
if mode == invalid && under(x.typ) != Typ[Invalid] {
check.errorf(x, invalidArg+"%s for %s", x, bin.name)
return
}

// record the signature before changing x.typ
if check.Types != nil && mode != constant_ {
check.recordBuiltinType(call.Fun, makeSig(Typ[Int], x.typ))
}

x.mode = mode
x.typ = Typ[Int]
x.val = val
if check.Types != nil && mode != constant_ {
check.recordBuiltinType(call.Fun, makeSig(x.typ, typ))
}

case _Close:
// close(c)
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/compile/internal/types2/builtins_test.go
Expand Up @@ -28,6 +28,8 @@ var builtinCalls = []struct {
{"cap", `var s [10]int; _ = cap(&s)`, `invalid type`}, // constant
{"cap", `var s []int64; _ = cap(s)`, `func([]int64) int`},
{"cap", `var c chan<-bool; _ = cap(c)`, `func(chan<- bool) int`},
{"cap", `type S []byte; var s S; _ = cap(s)`, `func(p.S) int`},
{"cap", `var s P; _ = cap(s)`, `func(P) int`},

{"len", `_ = len("foo")`, `invalid type`}, // constant
{"len", `var s string; _ = len(s)`, `func(string) int`},
Expand All @@ -36,6 +38,8 @@ var builtinCalls = []struct {
{"len", `var s []int64; _ = len(s)`, `func([]int64) int`},
{"len", `var c chan<-bool; _ = len(c)`, `func(chan<- bool) int`},
{"len", `var m map[string]float32; _ = len(m)`, `func(map[string]float32) int`},
{"len", `type S []byte; var s S; _ = len(s)`, `func(p.S) int`},
{"len", `var s P; _ = len(s)`, `func(P) int`},

{"close", `var c chan int; close(c)`, `func(chan int)`},
{"close", `var c chan<- chan string; close(c)`, `func(chan<- chan string)`},
Expand Down Expand Up @@ -159,7 +163,7 @@ func parseGenericSrc(path, src string) (*syntax.File, error) {
}

func testBuiltinSignature(t *testing.T, name, src0, want string) {
src := fmt.Sprintf(`package p; import "unsafe"; type _ unsafe.Pointer /* use unsafe */; func _[P any]() { %s }`, src0)
src := fmt.Sprintf(`package p; import "unsafe"; type _ unsafe.Pointer /* use unsafe */; func _[P ~[]byte]() { %s }`, src0)
f, err := parseGenericSrc("", src)
if err != nil {
t.Errorf("%s: %s", src0, err)
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/compile/internal/types2/errors.go
Expand Up @@ -167,8 +167,13 @@ func (check *Checker) markImports(pkg *Package) {
}
}

// check may be nil.
func (check *Checker) sprintf(format string, args ...interface{}) string {
return sprintf(check.qualifier, false, format, args...)
var qf Qualifier
if check != nil {
qf = check.qualifier
}
return sprintf(qf, false, format, args...)
}

func (check *Checker) report(err *error_) {
Expand Down

0 comments on commit 74d25c6

Please sign in to comment.