Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream master into microsoft/main #247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func Equal(a, b []byte) bool {
}

// Compare returns an integer comparing two byte slices lexicographically.
// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
// A nil argument is equivalent to an empty slice.
func Compare(a, b []byte) int {
return bytealg.Compare(a, b)
Expand Down
15 changes: 13 additions & 2 deletions src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ func (g *genInst) getDictOrSubdict(declInfo *instInfo, n ir.Node, nameNode *ir.N
// yet. If so, it imports the body.
func checkFetchBody(nameNode *ir.Name) {
if nameNode.Func.Body == nil && nameNode.Func.Inl != nil {
// If there is no body yet but Func.Inl exists, then we can can
// If there is no body yet but Func.Inl exists, then we can
// import the whole generic body.
assert(nameNode.Func.Inl.Cost == 1 && nameNode.Sym().Pkg != types.LocalPkg)
typecheck.ImportBody(nameNode.Func)
Expand All @@ -638,7 +638,18 @@ func checkFetchBody(nameNode *ir.Name) {
// with the type arguments shapes. If the instantiated function is not already
// cached, then it calls genericSubst to create the new instantiation.
func (g *genInst) getInstantiation(nameNode *ir.Name, shapes []*types.Type, isMeth bool) *instInfo {
checkFetchBody(nameNode)
if nameNode.Func == nil {
// If nameNode.Func is nil, this must be a reference to a method of
// an imported instantiated type. We will have already called
// g.instantiateMethods() on the fully-instantiated type, so
// g.instInfoMap[sym] will be non-nil below.
rcvr := nameNode.Type().Recv()
if rcvr == nil || !deref(rcvr.Type).IsFullyInstantiated() {
base.FatalfAt(nameNode.Pos(), "Unexpected function instantiation %v with no body", nameNode)
}
} else {
checkFetchBody(nameNode)
}

// Convert any non-shape type arguments to their shape, so we can reduce the
// number of instantiations we have to generate. You can actually have a mix
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types2/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
// At least one type argument couldn't be inferred.
assert(targs != nil && index >= 0 && targs[index] == nil)
tpar := tparams[index]
check.errorf(pos, "cannot infer %s (%s) (%s)", tpar.obj.name, tpar.obj.pos, targs)
check.errorf(pos, "cannot infer %s (%s)", tpar.obj.name, tpar.obj.pos)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions src/crypto/x509/root_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"bytes"
macOS "crypto/x509/internal/macos"
"fmt"
"internal/godebug"
"os"
"strings"
)

var debugDarwinRoots = strings.Contains(os.Getenv("GODEBUG"), "x509roots=1")
var debugDarwinRoots = godebug.Get("x509roots") == "1"

func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
return nil, nil
Expand Down
4 changes: 1 addition & 3 deletions src/encoding/ascii85/ascii85.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ func (e *encoder) Write(p []byte) (n int, err error) {
}

// Trailing fringe.
for i := 0; i < len(p); i++ {
e.buf[i] = p[i]
}
copy(e.buf[:], p)
e.nbuf = len(p)
n += len(p)
return
Expand Down
4 changes: 1 addition & 3 deletions src/encoding/base32/base32.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ func (e *encoder) Write(p []byte) (n int, err error) {
}

// Trailing fringe.
for i := 0; i < len(p); i++ {
e.buf[i] = p[i]
}
copy(e.buf[:], p)
e.nbuf = len(p)
n += len(p)
return
Expand Down
4 changes: 1 addition & 3 deletions src/encoding/base64/base64.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ func (e *encoder) Write(p []byte) (n int, err error) {
}

// Trailing fringe.
for i := 0; i < len(p); i++ {
e.buf[i] = p[i]
}
copy(e.buf[:], p)
e.nbuf = len(p)
n += len(p)
return
Expand Down
16 changes: 14 additions & 2 deletions src/go/build/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var depsRules = `
io/fs
< embed;

unicode, fmt !< os, os/signal;
unicode, fmt !< net, os, os/signal;

os/signal, STR
< path/filepath
Expand All @@ -187,6 +187,8 @@ var depsRules = `
OS
< golang.org/x/sys/cpu;

os < internal/godebug;

# FMT is OS (which includes string routines) plus reflect and fmt.
# It does not include package log, which should be avoided in core packages.
strconv, unicode
Expand Down Expand Up @@ -352,6 +354,13 @@ var depsRules = `
golang.org/x/net/lif,
golang.org/x/net/route;

os, runtime, strconv, sync, unsafe,
internal/godebug
< internal/intern;

internal/bytealg, internal/intern, internal/itoa, math/bits, sort, strconv
< net/netip;

# net is unavoidable when doing any networking,
# so large dependencies must be kept out.
# This is a long-looking list but most of these
Expand All @@ -360,10 +369,12 @@ var depsRules = `
golang.org/x/net/dns/dnsmessage,
golang.org/x/net/lif,
golang.org/x/net/route,
internal/godebug,
internal/nettrace,
internal/poll,
internal/singleflight,
internal/race,
net/netip,
os
< net;

Expand Down Expand Up @@ -515,7 +526,8 @@ var depsRules = `
FMT, DEBUG, flag, runtime/trace, internal/sysinfo, math/rand
< testing;

FMT, crypto/sha256, encoding/json, go/ast, go/parser, go/token, math/rand, encoding/hex, crypto/sha256
FMT, crypto/sha256, encoding/json, go/ast, go/parser, go/token,
internal/godebug, math/rand, encoding/hex, crypto/sha256
< internal/fuzz;

internal/fuzz, internal/testlog, runtime/pprof, regexp
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
// At least one type argument couldn't be inferred.
assert(index >= 0 && targs[index] == nil)
tpar := tparams[index]
check.errorf(posn, _Todo, "cannot infer %s (%v) (%v)", tpar.obj.name, tpar.obj.pos, targs)
check.errorf(posn, _Todo, "cannot infer %s (%v)", tpar.obj.name, tpar.obj.pos)
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions src/go/types/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ func (obj *TypeName) IsAlias() bool {
return obj.pkg != nil || t.name != obj.name || t == universeByte || t == universeRune
case *Named:
return obj != t.obj
case *TypeParam:
return obj != t.obj
default:
return true
}
Expand Down
3 changes: 3 additions & 0 deletions src/go/types/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestIsAlias(t *testing.T) {
pkg := NewPackage("p", "p")
t1 := NewTypeName(0, pkg, "t1", nil)
n1 := NewNamed(t1, new(Struct), nil)
t5 := NewTypeName(0, pkg, "t5", nil)
NewTypeParam(t5, nil)
for _, test := range []struct {
name *TypeName
alias bool
Expand All @@ -43,6 +45,7 @@ func TestIsAlias(t *testing.T) {
{NewTypeName(0, nil, "int32", Typ[Int32]), false}, // type name refers to basic type with same name
{NewTypeName(0, pkg, "int32", Typ[Int32]), true}, // type name is declared in user-defined package (outside Universe)
{NewTypeName(0, nil, "rune", Typ[Rune]), true}, // type name refers to basic type rune which is an alias already
{t5, false}, // type name refers to type parameter and vice versa
} {
check(test.name, test.alias)
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/testdata/fixedbugs/issue45985.go2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package issue45985

// TODO(rFindley): this error should be on app[int] below.
func app[S /* ERROR "type S = S does not match" */ interface{ ~[]T }, T any](s S, e T) S {
func app[S /* ERROR "type S S does not match" */ interface{ ~[]T }, T any](s S, e T) S {
return append(s, e)
}

Expand Down
26 changes: 19 additions & 7 deletions src/internal/fuzz/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"internal/godebug"
"io"
"io/ioutil"
"math/bits"
Expand Down Expand Up @@ -316,6 +317,23 @@ func CoordinateFuzzing(ctx context.Context, opts CoordinateFuzzingOpts) (err err
// Update the coordinator's coverage mask and save the value.
inputSize := len(result.entry.Data)
if opts.CacheDir != "" {
// It is possible that the input that was discovered is already
// present in the corpus, but the worker produced a coverage map
// that still expanded our total coverage (this may happen due to
// flakiness in the coverage counters). In order to prevent adding
// duplicate entries to the corpus (and re-writing the file on
// disk), skip it if the on disk file already exists.
// TOOD(roland): this check is limited in that it will only be
// applied if we are using the CacheDir. Another option would be
// to iterate through the corpus and check if it is already present,
// which would catch cases where we are not caching entries.
// A slightly faster approach would be to keep some kind of map of
// entry hashes, which would allow us to avoid iterating through
// all entries.
_, err = os.Stat(result.entry.Path)
if err == nil {
continue
}
err := writeToCorpus(&result.entry, opts.CacheDir)
if err != nil {
stop(err)
Expand Down Expand Up @@ -1046,13 +1064,7 @@ var (

func shouldPrintDebugInfo() bool {
debugInfoOnce.Do(func() {
debug := strings.Split(os.Getenv("GODEBUG"), ",")
for _, f := range debug {
if f == "fuzzdebug=1" {
debugInfo = true
break
}
}
debugInfo = godebug.Get("fuzzdebug") == "1"
})
return debugInfo
}
34 changes: 34 additions & 0 deletions src/internal/godebug/godebug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package godebug parses the GODEBUG environment variable.
package godebug

import "os"

// Get returns the value for the provided GODEBUG key.
func Get(key string) string {
return get(os.Getenv("GODEBUG"), key)
}

// get returns the value part of key=value in s (a GODEBUG value).
func get(s, key string) string {
for i := 0; i < len(s)-len(key)-1; i++ {
if i > 0 && s[i-1] != ',' {
continue
}
afterKey := s[i+len(key):]
if afterKey[0] != '=' || s[i:i+len(key)] != key {
continue
}
val := afterKey[1:]
for i, b := range val {
if b == ',' {
return val[:i]
}
}
return val
}
return ""
}
34 changes: 34 additions & 0 deletions src/internal/godebug/godebug_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package godebug

import "testing"

func TestGet(t *testing.T) {
tests := []struct {
godebug string
key string
want string
}{
{"", "", ""},
{"", "foo", ""},
{"foo=bar", "foo", "bar"},
{"foo=bar,after=x", "foo", "bar"},
{"before=x,foo=bar,after=x", "foo", "bar"},
{"before=x,foo=bar", "foo", "bar"},
{",,,foo=bar,,,", "foo", "bar"},
{"foodecoy=wrong,foo=bar", "foo", "bar"},
{"foo=", "foo", ""},
{"foo", "foo", ""},
{",foo", "foo", ""},
{"foo=bar,baz", "loooooooong", ""},
}
for _, tt := range tests {
got := get(tt.godebug, tt.key)
if got != tt.want {
t.Errorf("get(%q, %q) = %q; want %q", tt.godebug, tt.key, got, tt.want)
}
}
}
Loading