From f38a580a51cd2fc072aabc9dd45b9e0a85064c81 Mon Sep 17 00:00:00 2001
From: Michael Matloob
The
+Some operations (slice expressions,
+
+Examples of interfaces with
+Note that
@@ -3837,7 +3862,8 @@ a[low : high]
constructs a substring or slice. The core type of
-GOROOT function now returns the empty string
@@ -847,7 +847,6 @@ as well as support for rendering them to HTML, Markdown, and text.
but often easier to use: it returns an additional boolean reporting whether an equal value was found.
sync/atomic package
+ Go 1.19 introduces new types in the sync/atomic package
that make it easier to use atomic values, such as
atomic.Int64
and
From ab422f2749bc21514cb22d444bae460f5fa22376 Mon Sep 17 00:00:00 2001
From: Rhys Hiltner append and copy)
+rely on a slightly more loose form of core types which accept byte slices and strings.
+Specifically, if there are exactly two types, []byte and string,
+which are the underlying types of all types in the type set of interface T,
+the core type of T is called bytestring.
+bytestring core types:
+
+interface{ int } // int (same as ordinary core type)
+interface{ []byte | string } // bytestring
+interface{ ~[]byte | myString } // bytestring
+
+
+bytestring is not a real type; it cannot be used to declare
+variables are compose other types. It exists solely to describe the behavior of some
+operations that read from a sequence of bytes, which may be a byte slice or a string.
+Type identity
a must be a string, array, pointer to array, or slice.
+a must be a string, array, pointer to array, slice, or a
+bytestring.
The indices low and
high select which elements of operand a appear
in the result. The result has indices starting at 0 and length equal to
@@ -5469,7 +5495,7 @@ string(runes{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔"
type myRune rune
string([]myRune{0x266b, 0x266c}) // "\u266b\u266c" == "♫♬"
-myString([]myRune{0x1F30E}) // "\U0001f30e" == "🌎"
+myString([]myRune{0x1f30e}) // "\U0001f30e" == "🌎"
@@ -7197,8 +7223,9 @@ The values x are passed to a parameter of type ...E
and the respective parameter
passing rules apply.
As a special case, if the core type of s is []byte,
-append also accepts a second argument with core type string
-followed by .... This form appends the bytes of the string.
+append also accepts a second argument with core type
+bytestring followed by ....
+This form appends the bytes of the byte slice or string.
@@ -7235,8 +7262,9 @@ with identical element type.
The number of elements copied is the minimum of
len(src) and len(dst).
As a special case, if the destination's core type is []byte,
-copy also accepts a source argument with core type string.
-This form copies the bytes from the string into the byte slice.
+copy also accepts a source argument with core type
+ bytestring.
+This form copies the bytes from the byte slice or string into the byte slice.
@@ -7550,7 +7578,7 @@ and the Unicode replacement character U+FFFD.-Assume we have compiled a package containing the package clause +Consider a compiled a package containing the package clause
package math, which exports functionSin, and installed the compiled package in the file identified by"lib/math". From b004c739b525d354ea62f5caadd962de4569d96e Mon Sep 17 00:00:00 2001 From: Robert GriesemerDate: Tue, 21 Jun 2022 15:56:16 -0700 Subject: [PATCH 19/38] go/types, types2: fix parameter order dependence in type inference If we have more than two function arguments to a generic function, we may have arguments with named and unnamed types. If that is the case, permutate params and args such that the arguments with named types are first in the list. This way, independent of parameter ordering, the type inference will produce the same result. This extra step is not explicitly outlined in the spec yet but we all agree that (parameter) order independence is an invariant that we should uphold for type inference. As we move towards less operational and more descriptive rules for type inference, we will incorporate this property as well. The actual fix for this bug existed before 1.18 but was not enabled. This CL merely enables the fix (switches a flag) and adjusts some tests. Fixes #43056. Change-Id: Ie4e40cf8438dfd82fa94b78068e4f6f6f53f83e6 Reviewed-on: https://go-review.googlesource.com/c/go/+/413459 Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/types2/infer.go | 7 ++----- .../compile/internal/types2/testdata/examples/functions.go | 2 +- .../internal/types2/testdata/fixedbugs/issue43056.go | 4 ++-- src/go/types/infer.go | 7 ++----- src/go/types/testdata/examples/functions.go | 2 +- src/go/types/testdata/fixedbugs/issue43056.go | 4 ++-- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index b0c6a4fcea..8425cd6034 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -128,11 +128,8 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type, // named and unnamed types are passed to parameters with identical type, different types // (named vs underlying) may be inferred depending on the order of the arguments. // By ensuring that named types are seen first, order dependence is avoided and unification - // succeeds where it can. - // - // This code is disabled for now pending decision whether we want to address cases like - // these and make the spec on type inference more complicated (see issue #43056). - const enableArgSorting = false + // succeeds where it can (issue #43056). + const enableArgSorting = true if m := len(args); m >= 2 && enableArgSorting { // Determine indices of arguments with named and unnamed types. var named, unnamed []int diff --git a/src/cmd/compile/internal/types2/testdata/examples/functions.go b/src/cmd/compile/internal/types2/testdata/examples/functions.go index ef8953cb43..d50f79d11f 100644 --- a/src/cmd/compile/internal/types2/testdata/examples/functions.go +++ b/src/cmd/compile/internal/types2/testdata/examples/functions.go @@ -182,7 +182,7 @@ func _() { type myString string var s1 string g3(nil, "1", myString("2"), "3") - g3(&s1, "1", myString /* ERROR does not match */ ("2"), "3") + g3(& /* ERROR does not match */ s1, "1", myString("2"), "3") _ = s1 type myStruct struct{x int} diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue43056.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue43056.go index 35c7ef592d..8ff4e7f9b4 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue43056.go +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue43056.go @@ -14,7 +14,7 @@ func _() { var j func(F) f(i, j) - // f(j, i) // disabled for now + f(j, i) } // example from issue @@ -27,5 +27,5 @@ func _() { var j interface{ Equal(I) bool } g(i, j) - // g(j, i) // disabled for now + g(j, i) } diff --git a/src/go/types/infer.go b/src/go/types/infer.go index 1aa2612638..768efbf73b 100644 --- a/src/go/types/infer.go +++ b/src/go/types/infer.go @@ -128,11 +128,8 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type, // named and unnamed types are passed to parameters with identical type, different types // (named vs underlying) may be inferred depending on the order of the arguments. // By ensuring that named types are seen first, order dependence is avoided and unification - // succeeds where it can. - // - // This code is disabled for now pending decision whether we want to address cases like - // these and make the spec on type inference more complicated (see issue #43056). - const enableArgSorting = false + // succeeds where it can (issue #43056). + const enableArgSorting = true if m := len(args); m >= 2 && enableArgSorting { // Determine indices of arguments with named and unnamed types. var named, unnamed []int diff --git a/src/go/types/testdata/examples/functions.go b/src/go/types/testdata/examples/functions.go index 0af77267c5..1d30075c7c 100644 --- a/src/go/types/testdata/examples/functions.go +++ b/src/go/types/testdata/examples/functions.go @@ -182,7 +182,7 @@ func _() { type myString string var s1 string g3(nil, "1", myString("2"), "3") - g3(&s1, "1", myString /* ERROR does not match */ ("2"), "3") + g3(& /* ERROR does not match */ s1, "1", myString("2"), "3") type myStruct struct{x int} var s2 myStruct diff --git a/src/go/types/testdata/fixedbugs/issue43056.go b/src/go/types/testdata/fixedbugs/issue43056.go index 35c7ef592d..8ff4e7f9b4 100644 --- a/src/go/types/testdata/fixedbugs/issue43056.go +++ b/src/go/types/testdata/fixedbugs/issue43056.go @@ -14,7 +14,7 @@ func _() { var j func(F) f(i, j) - // f(j, i) // disabled for now + f(j, i) } // example from issue @@ -27,5 +27,5 @@ func _() { var j interface{ Equal(I) bool } g(i, j) - // g(j, i) // disabled for now + g(j, i) } From be0b2a393a5a7297a3c8f42ca7d5ad3e4b15dcbe Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 17 Jun 2022 10:32:52 -0400 Subject: [PATCH 20/38] cmd/trace: add basic documentation to main page This change adds rudimentary explanation of the various visualizations to main page of the trace server. There is clearly a vast amount one could write here, especially in the form of tutorials, but I've tried to restrict it to just basic conceptual overview. Change-Id: Id4dfe9d47f9b31ed5f8fe39f8b3a7c60c0ae8d5a Reviewed-on: https://go-review.googlesource.com/c/go/+/412876 Reviewed-by: Michael Pratt Run-TryBot: Alan Donovan TryBot-Result: Gopher Robot --- src/cmd/trace/main.go | 194 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 183 insertions(+), 11 deletions(-) diff --git a/src/cmd/trace/main.go b/src/cmd/trace/main.go index a30db9a012..11804d0b90 100644 --- a/src/cmd/trace/main.go +++ b/src/cmd/trace/main.go @@ -185,23 +185,195 @@ func httpMain(w http.ResponseWriter, r *http.Request) { var templMain = template.Must(template.New("").Parse(` + + cmd/trace: the Go trace event viewer
++ This web server provides various visualizations of an event log gathered during + the execution of a Go program that uses the runtime/trace package. +
+ +Event timelines for running goroutines
{{if $}} ++ Large traces are split into multiple sections of equal data size + (not duration) to avoid overwhelming the visualizer. +
+{{range $e := $}} - View trace ({{$e.Name}})
{{else}} - View trace
+- View trace ({{$e.Name}})
{{end}} -
+
++
{{end}} -Goroutine analysis- View trace
+
-Network blocking profile (⬇)
-Synchronization blocking profile (⬇)
-Syscall blocking profile (⬇)
-Scheduler latency profile (⬇)
-User-defined tasks
-User-defined regions
-Minimum mutator utilization
++ This view displays a timeline for each of the GOMAXPROCS logical + processors, showing which goroutine (if any) was running on that + logical processor at each moment. + + Each goroutine has an identifying number (e.g. G123), main function, + and color. + + A colored bar represents an uninterrupted span of execution. + + Execution of a goroutine may migrate from one logical processor to another, + causing a single colored bar to be horizontally continuous but + vertically displaced. +
++ Clicking on a span reveals information about it, such as its + duration, its causal predecessors and successors, and the stack trace + at the final moment when it yielded the logical processor, for example + because it made a system call or tried to acquire a mutex. + + Directly underneath each bar, a smaller bar or more commonly a fine + vertical line indicates an event occuring during its execution. + Some of these are related to garbage collection; most indicate that + a goroutine yielded its logical processor but then immediately resumed execution + on the same logical processor. Clicking on the event displays the stack trace + at the moment it occurred. +
++ The causal relationships between spans of goroutine execution + can be displayed by clicking the Flow Events button at the top. +
++ At the top ("STATS"), there are three additional timelines that + display statistical information. + + "Goroutines" is a time series of the count of existing goroutines; + clicking on it displays their breakdown by state at that moment: + running, runnable, or waiting. + + "Heap" is a time series of the amount of heap memory allocated (in orange) + and (in green) the allocation limit at which the next GC cycle will begin. + + "Threads" shows the number of kernel threads in existence: there is + always one kernel thread per logical processor, and additional threads + are created for calls to non-Go code such as a system call or a + function written in C. +
++ Above the event trace for the first logical processor are + traces for various runtime-internal events. + + The "GC" bar shows when the garbage collector is running, and in which stage. + Garbage collection may temporarily affect all the logical processors + and the other metrics. + + The "Network", "Timers", and "Syscalls" traces indicate events in + the runtime that cause goroutines to wake up. +
++ The visualization allows you to navigate events at scales ranging from several + seconds to a handful of nanoseconds. + + Consult the documentation for the Chromium Trace Event Profiling Tool + for help navigating the view. +
+ + ++ This view displays information about each set of goroutines that + shares the same main function. + + Clicking on a main function shows links to the four types of + blocking profile (see below) applied to that subset of goroutines. + + It also shows a table of specific goroutine instances, with various + execution statistics and a link to the event timeline for each one. + + The timeline displays only the selected goroutine and any others it + interacts with via block/unblock events. (The timeline is + goroutine-oriented rather than logical processor-oriented.) +
+ +Profiles
++ Each link below displays a global profile in zoomable graph form as + produced by pprof's "web" command. + + In addition there is a link to download the profile for offline + analysis with pprof. + + All four profiles represent causes of delay that prevent a goroutine + from running on a logical processor: because it was waiting for the network, + for a synchronization operation on a mutex or channel, for a system call, + or for a logical processor to become available. +
++
+ +- Network blocking profile (⬇)
+- Synchronization blocking profile (⬇)
+- Syscall blocking profile (⬇)
+- Scheduler latency profile (⬇)
+User-defined tasks and regions
++ The trace API allows a target program to annotate a region of code + within a goroutine, such as a key function, so that its performance + can be analyzed. + + Log events may be + associated with a region to record progress and relevant values. + + The API also allows annotation of higher-level + tasks, + which may involve work across many goroutines. +
++ The links below display, for each region and task, a histogram of its execution times. + + Each histogram bucket contains a sample trace that records the + sequence of events such as goroutine creations, log events, and + subregion start/end times. + + For each task, you can click through to a logical-processor or + goroutine-oriented view showing the tasks and regions on the + timeline. + + Such information may help uncover which steps in a region are + unexpectedly slow, or reveal relationships between the data values + logged in a request and its running time. +
+ + +Garbage collection metrics
+ ++ This chart indicates the maximum GC pause time (the largest x value + for which y is zero), and more generally, the fraction of time that + the processors are available to application goroutines ("mutators"), + for any time window of a specified size, in the worst case. +
`)) From 92c9b81447649d5a8ed38ca79b71640c099e0243 Mon Sep 17 00:00:00 2001 From: Ian Lance TaylorDate: Tue, 21 Jun 2022 15:17:22 -0700 Subject: [PATCH 21/38] net: don't set netGo = true on Windows with no cgo Windows can call the C DNS lookup routines even without cgo, so don't force it to use the Go routines in that scenario. No test because the test requires building the tools with CGO_ENABLED=0. For #33097 Fixes #53490 Change-Id: I3595a68e788be0d3bbd1bbd431836aca20a7d757 Reviewed-on: https://go-review.googlesource.com/c/go/+/413458 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/net/cgo_stub.go | 2 -- src/net/netgo.go | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/cgo_stub.go b/src/net/cgo_stub.go index cc84ca47ae..298d829f6f 100644 --- a/src/net/cgo_stub.go +++ b/src/net/cgo_stub.go @@ -8,8 +8,6 @@ package net import "context" -func init() { netGo = true } - type addrinfoErrno int func (eai addrinfoErrno) Error() string { return " " } diff --git a/src/net/netgo.go b/src/net/netgo.go index f91c91b614..75baa88035 100644 --- a/src/net/netgo.go +++ b/src/net/netgo.go @@ -2,7 +2,11 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build netgo +// Default netGo to true if the netgo build tag is being used, or the +// C library DNS routines are not available. Note that the C library +// routines are always available on Windows. + +//go:build netgo || (!cgo && !windows) package net From f5715181392c68d928c3152f8cf90fa9d4ee9e4e Mon Sep 17 00:00:00 2001 From: kkHAIKE Date: Wed, 11 May 2022 02:27:21 +0000 Subject: [PATCH 22/38] cmd/cgo: dont override declared struct type Fixes #52611 Change-Id: I835df8d6a98a37482446ec00af768c96fd8ee4fe GitHub-Last-Rev: ea54dd69eef90eaf1641889039344fff70158ece GitHub-Pull-Request: golang/go#52733 Reviewed-on: https://go-review.googlesource.com/c/go/+/404497 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Dexter Ouyang Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Alex Rakoczy TryBot-Result: Gopher Robot --- misc/cgo/test/testdata/issue52611.go | 13 +++++++++++++ misc/cgo/test/testdata/issue52611a/a.go | 16 ++++++++++++++++ misc/cgo/test/testdata/issue52611a/b.go | 11 +++++++++++ misc/cgo/test/testdata/issue52611b/a.go | 11 +++++++++++ misc/cgo/test/testdata/issue52611b/b.go | 16 ++++++++++++++++ src/cmd/cgo/gcc.go | 5 +++++ 6 files changed, 72 insertions(+) create mode 100644 misc/cgo/test/testdata/issue52611.go create mode 100644 misc/cgo/test/testdata/issue52611a/a.go create mode 100644 misc/cgo/test/testdata/issue52611a/b.go create mode 100644 misc/cgo/test/testdata/issue52611b/a.go create mode 100644 misc/cgo/test/testdata/issue52611b/b.go diff --git a/misc/cgo/test/testdata/issue52611.go b/misc/cgo/test/testdata/issue52611.go new file mode 100644 index 0000000000..32d22403ab --- /dev/null +++ b/misc/cgo/test/testdata/issue52611.go @@ -0,0 +1,13 @@ +// Copyright 2022 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. + +// Issue 52611: inconsistent compiler behaviour when compiling a C.struct. +// No runtime test; just make sure it compiles. + +package cgotest + +import ( + _ "cgotest/issue52611a" + _ "cgotest/issue52611b" +) diff --git a/misc/cgo/test/testdata/issue52611a/a.go b/misc/cgo/test/testdata/issue52611a/a.go new file mode 100644 index 0000000000..0764688ec4 --- /dev/null +++ b/misc/cgo/test/testdata/issue52611a/a.go @@ -0,0 +1,16 @@ +// Copyright 2022 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 issue52611a + +/* +typedef struct Foo { + int X; +} Foo; +*/ +import "C" + +func GetX1(foo *C.struct_Foo) int32 { + return int32(foo.X) +} diff --git a/misc/cgo/test/testdata/issue52611a/b.go b/misc/cgo/test/testdata/issue52611a/b.go new file mode 100644 index 0000000000..74a50c5dea --- /dev/null +++ b/misc/cgo/test/testdata/issue52611a/b.go @@ -0,0 +1,11 @@ +// Copyright 2022 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 issue52611a + +import "C" + +func GetX2(foo *C.struct_Foo) int32 { + return int32(foo.X) +} diff --git a/misc/cgo/test/testdata/issue52611b/a.go b/misc/cgo/test/testdata/issue52611b/a.go new file mode 100644 index 0000000000..730b52f5e9 --- /dev/null +++ b/misc/cgo/test/testdata/issue52611b/a.go @@ -0,0 +1,11 @@ +// Copyright 2022 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 issue52611b + +import "C" + +func GetX1(bar *C.struct_Bar) int32 { + return int32(bar.X) +} diff --git a/misc/cgo/test/testdata/issue52611b/b.go b/misc/cgo/test/testdata/issue52611b/b.go new file mode 100644 index 0000000000..d304175395 --- /dev/null +++ b/misc/cgo/test/testdata/issue52611b/b.go @@ -0,0 +1,16 @@ +// Copyright 2022 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 issue52611b + +/* +typedef struct Bar { + int X; +} Bar; +*/ +import "C" + +func GetX2(bar *C.struct_Bar) int32 { + return int32(bar.X) +} diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 4dff5e2b1c..3cb01ba382 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -2551,6 +2551,11 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ t.Go = name // publish before recursive calls goIdent[name.Name] = name if dt.ByteSize < 0 { + // Don't override old type + if _, ok := typedef[name.Name]; ok { + break + } + // Size calculation in c.Struct/c.Opaque will die with size=-1 (unknown), // so execute the basic things that the struct case would do // other than try to determine a Go representation. From 606c6c371ad3d089d59d15393f7c49b063fc0eca Mon Sep 17 00:00:00 2001 From: shaoliming Date: Fri, 17 Jun 2022 05:01:26 +0000 Subject: [PATCH 23/38] encoding/xml: check nil pointer in DecodeElement Fixes #53350 Change-Id: Id5e1f4016db5f1d4349ee1a76a9dfe3aeae83cee GitHub-Last-Rev: 45add121612a8144c2525828bd7386c4adb05174 GitHub-Pull-Request: golang/go#53407 Reviewed-on: https://go-review.googlesource.com/c/go/+/412634 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Alex Rakoczy --- src/encoding/xml/read.go | 4 ++++ src/encoding/xml/read_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/encoding/xml/read.go b/src/encoding/xml/read.go index 565d9a8bea..257591262f 100644 --- a/src/encoding/xml/read.go +++ b/src/encoding/xml/read.go @@ -148,6 +148,10 @@ func (d *Decoder) DecodeElement(v any, start *StartElement) error { if val.Kind() != reflect.Pointer { return errors.New("non-pointer passed to Unmarshal") } + + if val.IsNil() { + return errors.New("nil pointer passed to Unmarshal") + } return d.unmarshal(val.Elem(), start) } diff --git a/src/encoding/xml/read_test.go b/src/encoding/xml/read_test.go index 391fe731a8..6ef55de77b 100644 --- a/src/encoding/xml/read_test.go +++ b/src/encoding/xml/read_test.go @@ -1079,3 +1079,18 @@ func TestUnmarshalWhitespaceAttrs(t *testing.T) { t.Fatalf("whitespace attrs: Unmarshal:\nhave: %#+v\nwant: %#+v", v, want) } } + +// golang.org/issues/53350 +func TestUnmarshalIntoNil(t *testing.T) { + type T struct { + A int `xml:"A"` + } + + var nilPointer *T + err := Unmarshal([]byte(" 1 "), nilPointer) + + if err == nil { + t.Fatalf("no error in unmarshalling") + } + +} From 6bad7e82430bb1eb927a2901f44f9664637db27d Mon Sep 17 00:00:00 2001 From: Ian Lance TaylorDate: Fri, 17 Jun 2022 13:38:07 -0700 Subject: [PATCH 24/38] compress/gzip: always close bodyReader in Example_compressingReader For #53362 Fixes #53414 Change-Id: I352164e70c136eed210c7ee4ceba5dc631f81f94 Reviewed-on: https://go-review.googlesource.com/c/go/+/412955 Auto-Submit: Ian Lance Taylor Reviewed-by: Joseph Tsai Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Alex Rakoczy TryBot-Result: Gopher Robot --- src/compress/gzip/example_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compress/gzip/example_test.go b/src/compress/gzip/example_test.go index 27aae152d4..1ba4080ea0 100644 --- a/src/compress/gzip/example_test.go +++ b/src/compress/gzip/example_test.go @@ -160,6 +160,10 @@ func Example_compressingReader() { // httpWriter is the body of the HTTP request, as an io.Writer. bodyReader, httpWriter := io.Pipe() + // Make sure that bodyReader is always closed, so that the + // goroutine below will always exit. + defer bodyReader.Close() + // gzipWriter compresses data to httpWriter. gzipWriter := gzip.NewWriter(httpWriter) @@ -197,7 +201,6 @@ func Example_compressingReader() { // Note that passing req to http.Client.Do promises that it // will close the body, in this case bodyReader. - // That ensures that the goroutine will exit. resp, err := ts.Client().Do(req) if err != nil { log.Fatal(err) From 4045b1bc3f97a47274ef1da2bf6d29f5ce1c7b88 Mon Sep 17 00:00:00 2001 From: Wayne Zuo Date: Thu, 16 Jun 2022 11:05:39 +0800 Subject: [PATCH 25/38] cmd/compile: fix assert condition in generic method call Fixes #53406. Change-Id: If7ae39ec1042a792d82a0a2de96d168c22d8ab71 Reviewed-on: https://go-review.googlesource.com/c/go/+/412614 Reviewed-by: Keith Randall Reviewed-by: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Alex Rakoczy Auto-Submit: Alex Rakoczy Reviewed-by: Keith Randall Run-TryBot: Wayne Zuo --- src/cmd/compile/internal/noder/stencil.go | 12 +++++++++--- test/typeparam/issue53406.go | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test/typeparam/issue53406.go diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index eeb503811c..d463c850f3 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -208,9 +208,15 @@ func (g *genInst) scanForGenCalls(decl ir.Node) { st := g.getInstantiation(gf, targs, true).fun dictValue, usingSubdict := g.getDictOrSubdict(declInfo, n, gf, targs, true) - // We have to be using a subdictionary, since this is - // a generic method call. - assert(usingSubdict) + if hasShapeTypes(targs) { + // We have to be using a subdictionary, since this is + // a generic method call. + assert(usingSubdict) + } else { + // We should use main dictionary, because the receiver is + // an instantiation already, see issue #53406. + assert(!usingSubdict) + } // Transform to a function call, by appending the // dictionary and the receiver to the args. diff --git a/test/typeparam/issue53406.go b/test/typeparam/issue53406.go new file mode 100644 index 0000000000..90fe78fb6f --- /dev/null +++ b/test/typeparam/issue53406.go @@ -0,0 +1,22 @@ +// compile + +// Copyright 2022 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 main + +func main() { + f[int]() +} + +func f[T1 any]() { + var x Outer[T1, int] + x.M() +} + +type Outer[T1, T2 any] struct{ Inner[T2] } + +type Inner[_ any] int + +func (Inner[_]) M() {} From 111cdb58487f1a3d2bd82be14a90837f31a3e320 Mon Sep 17 00:00:00 2001 From: Guoqi Chen Date: Wed, 15 Jun 2022 19:07:24 +0800 Subject: [PATCH 26/38] all: update to current golang.org/x/sys revision go get -d golang.org/x/sys@6c1b26c55098eae66ce95ab7c3712ab6cbfff2b7 go mod tidy go mod vendor This fixes the problem of the second return value in syscall on linux/loong64. Change-Id: I8018ae96f4e5ca9779b2c053cdccc6b2866bf0de Reviewed-on: https://go-review.googlesource.com/c/go/+/412274 Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor Run-TryBot: Bryan Mills Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/cmd/go.mod | 2 +- src/cmd/go.sum | 4 +-- .../golang.org/x/sys/unix/asm_linux_loong64.s | 4 +-- .../golang.org/x/sys/unix/ifreq_linux.go | 9 +----- .../golang.org/x/sys/unix/syscall_solaris.go | 1 + .../x/sys/unix/zerrors_linux_386.go | 2 +- .../x/sys/unix/zerrors_linux_amd64.go | 2 +- .../x/sys/unix/zerrors_linux_arm.go | 2 +- .../x/sys/unix/zerrors_linux_arm64.go | 2 +- .../x/sys/unix/zerrors_linux_loong64.go | 2 +- .../x/sys/unix/zerrors_linux_mips.go | 2 +- .../x/sys/unix/zerrors_linux_mips64.go | 2 +- .../x/sys/unix/zerrors_linux_mips64le.go | 2 +- .../x/sys/unix/zerrors_linux_mipsle.go | 2 +- .../x/sys/unix/zerrors_linux_ppc.go | 2 +- .../x/sys/unix/zerrors_linux_ppc64.go | 2 +- .../x/sys/unix/zerrors_linux_ppc64le.go | 2 +- .../x/sys/unix/zerrors_linux_riscv64.go | 2 +- .../x/sys/unix/zerrors_linux_s390x.go | 2 +- .../x/sys/unix/zerrors_linux_sparc64.go | 2 +- .../x/sys/unix/zsyscall_solaris_amd64.go | 14 +++++++++ .../golang.org/x/sys/unix/ztypes_linux_386.go | 2 +- .../x/sys/unix/ztypes_linux_amd64.go | 2 +- .../golang.org/x/sys/unix/ztypes_linux_arm.go | 2 +- .../x/sys/unix/ztypes_linux_arm64.go | 2 +- .../x/sys/unix/ztypes_linux_loong64.go | 2 +- .../x/sys/unix/ztypes_linux_mips.go | 2 +- .../x/sys/unix/ztypes_linux_mips64.go | 2 +- .../x/sys/unix/ztypes_linux_mips64le.go | 2 +- .../x/sys/unix/ztypes_linux_mipsle.go | 2 +- .../golang.org/x/sys/unix/ztypes_linux_ppc.go | 2 +- .../x/sys/unix/ztypes_linux_ppc64.go | 2 +- .../x/sys/unix/ztypes_linux_ppc64le.go | 2 +- .../x/sys/unix/ztypes_linux_riscv64.go | 2 +- .../x/sys/unix/ztypes_linux_s390x.go | 2 +- .../x/sys/unix/ztypes_linux_sparc64.go | 2 +- .../x/sys/unix/ztypes_openbsd_386.go | 8 ++--- .../x/sys/unix/ztypes_openbsd_amd64.go | 8 ++--- .../x/sys/unix/ztypes_openbsd_arm.go | 8 ++--- .../x/sys/unix/ztypes_openbsd_arm64.go | 8 ++--- .../x/sys/unix/ztypes_openbsd_mips64.go | 8 ++--- src/cmd/vendor/modules.txt | 2 +- src/go.mod | 2 +- src/go.sum | 4 +-- .../golang.org/x/sys/cpu/cpu_gccgo_x86.c | 29 ++++++++----------- src/vendor/modules.txt | 2 +- 46 files changed, 88 insertions(+), 85 deletions(-) diff --git a/src/cmd/go.mod b/src/cmd/go.mod index 04c2523a09..8230a3e453 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -7,7 +7,7 @@ require ( golang.org/x/arch v0.0.0-20220412001346-fc48f9fe4c15 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 - golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a + golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 golang.org/x/tools v0.1.11-0.20220516163903-1e55371df567 ) diff --git a/src/cmd/go.sum b/src/cmd/go.sum index fc81e159e5..435c3cce3b 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -10,8 +10,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVD golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4= golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a h1:N2T1jUrTQE9Re6TFF5PhvEHXHCguynGhKjWVsIUt5cY= -golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 h1:PgOr27OhUx2IRqGJ2RxAWI4dJQ7bi9cSrB82uzFzfUA= +golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 h1:EH1Deb8WZJ0xc0WK//leUHXcX9aLE5SymusoTmMZye8= golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/tools v0.1.11-0.20220516163903-1e55371df567 h1:MksUZ/zlU+pMbsq1Sw16gK6E1aWzD0rLE+eS2SxF24Y= diff --git a/src/cmd/vendor/golang.org/x/sys/unix/asm_linux_loong64.s b/src/cmd/vendor/golang.org/x/sys/unix/asm_linux_loong64.s index 6abd48eef0..565357288a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/asm_linux_loong64.s +++ b/src/cmd/vendor/golang.org/x/sys/unix/asm_linux_loong64.s @@ -30,7 +30,7 @@ TEXT ·SyscallNoError(SB),NOSPLIT,$0-48 MOVV trap+0(FP), R11 // syscall entry SYSCALL MOVV R4, r1+32(FP) - MOVV R5, r2+40(FP) + MOVV R0, r2+40(FP) // r2 is not used. Always set to 0 JAL runtime·exitsyscall(SB) RET @@ -50,5 +50,5 @@ TEXT ·RawSyscallNoError(SB),NOSPLIT,$0-48 MOVV trap+0(FP), R11 // syscall entry SYSCALL MOVV R4, r1+32(FP) - MOVV R5, r2+40(FP) + MOVV R0, r2+40(FP) // r2 is not used. Always set to 0 RET diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ifreq_linux.go b/src/cmd/vendor/golang.org/x/sys/unix/ifreq_linux.go index 934af313c3..15721a5104 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ifreq_linux.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ifreq_linux.go @@ -8,7 +8,6 @@ package unix import ( - "bytes" "unsafe" ) @@ -45,13 +44,7 @@ func NewIfreq(name string) (*Ifreq, error) { // Name returns the interface name associated with the Ifreq. func (ifr *Ifreq) Name() string { - // BytePtrToString requires a NULL terminator or the program may crash. If - // one is not present, just return the empty string. - if !bytes.Contains(ifr.raw.Ifrn[:], []byte{0x00}) { - return "" - } - - return BytePtrToString(&ifr.raw.Ifrn[0]) + return ByteSliceToString(ifr.raw.Ifrn[:]) } // According to netdevice(7), only AF_INET addresses are returned for numerous diff --git a/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go b/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go index 5c2003cec6..932996c75b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/syscall_solaris.go @@ -618,6 +618,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys Getpriority(which int, who int) (n int, err error) //sysnb Getrlimit(which int, lim *Rlimit) (err error) //sysnb Getrusage(who int, rusage *Rusage) (err error) +//sysnb Getsid(pid int) (sid int, err error) //sysnb Gettimeofday(tv *Timeval) (err error) //sysnb Getuid() (uid int) //sys Kill(pid int, signum syscall.Signal) (err error) diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go index 234fd4a5d1..1b305fab1b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_386.go @@ -5,7 +5,7 @@ // +build 386,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go index 58619b7589..6bcdef5dd6 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_amd64.go @@ -5,7 +5,7 @@ // +build amd64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go index 3a64ff59dc..e65df0f8d1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm.go @@ -5,7 +5,7 @@ // +build arm,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go index abe0b92578..c7021115aa 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_arm64.go @@ -5,7 +5,7 @@ // +build arm64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go index ebc5f3218e..0d83a1cd45 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_loong64.go @@ -5,7 +5,7 @@ // +build loong64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go index 14d7a84399..7f44a495b7 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips.go @@ -5,7 +5,7 @@ // +build mips,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go index 99e7c4ac0b..2f92b4e48e 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64.go @@ -5,7 +5,7 @@ // +build mips64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go index 496364c33c..f5367a966b 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go @@ -5,7 +5,7 @@ // +build mips64le,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go index 3e40830857..2e22337d7c 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go @@ -5,7 +5,7 @@ // +build mipsle,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go index 1151a7dfab..858c4f30f5 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc.go @@ -5,7 +5,7 @@ // +build ppc,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go index ed17f249e7..af2a7ba6e6 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go @@ -5,7 +5,7 @@ // +build ppc64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go index d84a37c1ac..eaa2eb8e24 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go @@ -5,7 +5,7 @@ // +build ppc64le,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go index 5cafba83f6..faaa9f0637 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go @@ -5,7 +5,7 @@ // +build riscv64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go index 6d122da41c..0d161f0b75 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_s390x.go @@ -5,7 +5,7 @@ // +build s390x,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go index 6bd19e51db..4fd497a3e3 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go @@ -5,7 +5,7 @@ // +build sparc64,linux // Code generated by cmd/cgo -godefs; DO NOT EDIT. -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/_const.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include _const.go package unix diff --git a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go index d12f4fbfea..fdf53f8daf 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go @@ -66,6 +66,7 @@ import ( //go:cgo_import_dynamic libc_getpriority getpriority "libc.so" //go:cgo_import_dynamic libc_getrlimit getrlimit "libc.so" //go:cgo_import_dynamic libc_getrusage getrusage "libc.so" +//go:cgo_import_dynamic libc_getsid getsid "libc.so" //go:cgo_import_dynamic libc_gettimeofday gettimeofday "libc.so" //go:cgo_import_dynamic libc_getuid getuid "libc.so" //go:cgo_import_dynamic libc_kill kill "libc.so" @@ -202,6 +203,7 @@ import ( //go:linkname procGetpriority libc_getpriority //go:linkname procGetrlimit libc_getrlimit //go:linkname procGetrusage libc_getrusage +//go:linkname procGetsid libc_getsid //go:linkname procGettimeofday libc_gettimeofday //go:linkname procGetuid libc_getuid //go:linkname procKill libc_kill @@ -339,6 +341,7 @@ var ( procGetpriority, procGetrlimit, procGetrusage, + procGetsid, procGettimeofday, procGetuid, procKill, @@ -1044,6 +1047,17 @@ func Getrusage(who int, rusage *Rusage) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func Getsid(pid int) (sid int, err error) { + r0, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&procGetsid)), 1, uintptr(pid), 0, 0, 0, 0, 0) + sid = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Gettimeofday(tv *Timeval) (err error) { _, _, e1 := rawSysvicall6(uintptr(unsafe.Pointer(&procGettimeofday)), 1, uintptr(unsafe.Pointer(tv)), 0, 0, 0, 0, 0) if e1 != 0 { diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_386.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_386.go index 5314092568..4948362f2c 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_386.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m32 linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build 386 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go index b02ab83dbd..f64345e0e2 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_amd64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -m64 linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build amd64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go index 9e6871d2e0..72469c79e7 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build arm && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go index b732d12559..68f072283a 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_arm64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build arm64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go index 61fbb24f8d..090ae46c67 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_loong64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build loong64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go index 5310f71ea5..03604cca13 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build mips && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go index 219bbb1267..fe57a7b265 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build mips64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go index be9432da54..3f0db4da81 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build mips64le && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go index d0155a42e6..70ecd3b239 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build mipsle && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go index 01c17bcc6f..4e700120db 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build ppc && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go index 944a9c3c78..34a57c6992 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build ppc64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go index 5d2c90e1ce..6b84a47296 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build ppc64le && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go index e173cb5157..c4a305fe2e 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build riscv64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go index 6106715d5c..a1f1e4c9e1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_s390x.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include -fsigned-char linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build s390x && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go index ca7b37b4b5..df95ebf3a1 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go @@ -1,4 +1,4 @@ -// cgo -godefs -- -Wall -Werror -static -I/tmp/include /build/unix/linux/types.go | go run mkpost.go +// cgo -godefs -- -Wall -Werror -static -I/tmp/include linux/types.go | go run mkpost.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build sparc64 && linux diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go index baf5fe6504..2ed718ca06 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_386.go @@ -94,10 +94,10 @@ type Statfs_t struct { F_namemax uint32 F_owner uint32 F_ctime uint64 - F_fstypename [16]int8 - F_mntonname [90]int8 - F_mntfromname [90]int8 - F_mntfromspec [90]int8 + F_fstypename [16]byte + F_mntonname [90]byte + F_mntfromname [90]byte + F_mntfromspec [90]byte Pad_cgo_0 [2]byte Mount_info [160]byte } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go index e21ae8ecfa..b4fb97ebe6 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go @@ -96,10 +96,10 @@ type Statfs_t struct { F_namemax uint32 F_owner uint32 F_ctime uint64 - F_fstypename [16]int8 - F_mntonname [90]int8 - F_mntfromname [90]int8 - F_mntfromspec [90]int8 + F_fstypename [16]byte + F_mntonname [90]byte + F_mntfromname [90]byte + F_mntfromspec [90]byte _ [2]byte Mount_info [160]byte } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go index f190651cd9..2c4675040e 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go @@ -98,10 +98,10 @@ type Statfs_t struct { F_namemax uint32 F_owner uint32 F_ctime uint64 - F_fstypename [16]int8 - F_mntonname [90]int8 - F_mntfromname [90]int8 - F_mntfromspec [90]int8 + F_fstypename [16]byte + F_mntonname [90]byte + F_mntfromname [90]byte + F_mntfromspec [90]byte _ [2]byte Mount_info [160]byte } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go index 84747c582c..ddee045147 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go @@ -94,10 +94,10 @@ type Statfs_t struct { F_namemax uint32 F_owner uint32 F_ctime uint64 - F_fstypename [16]int8 - F_mntonname [90]int8 - F_mntfromname [90]int8 - F_mntfromspec [90]int8 + F_fstypename [16]byte + F_mntonname [90]byte + F_mntfromname [90]byte + F_mntfromspec [90]byte _ [2]byte Mount_info [160]byte } diff --git a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go index ac5c8b6370..eb13d4e8bf 100644 --- a/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go +++ b/src/cmd/vendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go @@ -94,10 +94,10 @@ type Statfs_t struct { F_namemax uint32 F_owner uint32 F_ctime uint64 - F_fstypename [16]int8 - F_mntonname [90]int8 - F_mntfromname [90]int8 - F_mntfromspec [90]int8 + F_fstypename [16]byte + F_mntonname [90]byte + F_mntfromname [90]byte + F_mntfromspec [90]byte _ [2]byte Mount_info [160]byte } diff --git a/src/cmd/vendor/modules.txt b/src/cmd/vendor/modules.txt index 1280a9e701..4e4b5b6343 100644 --- a/src/cmd/vendor/modules.txt +++ b/src/cmd/vendor/modules.txt @@ -40,7 +40,7 @@ golang.org/x/mod/zip # golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 ## explicit golang.org/x/sync/semaphore -# golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a +# golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 ## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader golang.org/x/sys/plan9 diff --git a/src/go.mod b/src/go.mod index 2b4d8b4b75..94380d6567 100644 --- a/src/go.mod +++ b/src/go.mod @@ -8,6 +8,6 @@ require ( ) require ( - golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect + golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 // indirect golang.org/x/text v0.3.8-0.20220509174342-b4bca84b0361 // indirect ) diff --git a/src/go.sum b/src/go.sum index 5c710268b8..a54b0565bd 100644 --- a/src/go.sum +++ b/src/go.sum @@ -2,7 +2,7 @@ golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8 h1:y+mHpWoQJNAHt26Nhh6JP7 golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20220517181318-183a9ca12b87 h1:cCR+9mKLOGyX4Zx+uBZDXEDAQsvKQ/XbW4vreG5v1jU= golang.org/x/net v0.0.0-20220517181318-183a9ca12b87/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a h1:N2T1jUrTQE9Re6TFF5PhvEHXHCguynGhKjWVsIUt5cY= -golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 h1:PgOr27OhUx2IRqGJ2RxAWI4dJQ7bi9cSrB82uzFzfUA= +golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.8-0.20220509174342-b4bca84b0361 h1:h+pU/hCb7sEApigI6eII3/Emx5ZHaFWS+nulUp0Az/k= golang.org/x/text v0.3.8-0.20220509174342-b4bca84b0361/go.mod h1:5O0TPrbzDRCcAYs9rc2W4CFPmVHJfNFe8tESfECPJPE= diff --git a/src/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c b/src/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c index e363c7d131..a4605e6d12 100644 --- a/src/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c +++ b/src/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c @@ -7,6 +7,7 @@ #include #include +#include // Need to wrap __get_cpuid_count because it's declared as static. int @@ -17,27 +18,21 @@ gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf, return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx); } +#pragma GCC diagnostic ignored "-Wunknown-pragmas" +#pragma GCC push_options +#pragma GCC target("xsave") +#pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function) + // xgetbv reads the contents of an XCR (Extended Control Register) // specified in the ECX register into registers EDX:EAX. // Currently, the only supported value for XCR is 0. -// -// TODO: Replace with a better alternative: -// -// #include -// -// #pragma GCC target("xsave") -// -// void gccgoXgetbv(uint32_t *eax, uint32_t *edx) { -// unsigned long long x = _xgetbv(0); -// *eax = x & 0xffffffff; -// *edx = (x >> 32) & 0xffffffff; -// } -// -// Note that _xgetbv is defined starting with GCC 8. void gccgoXgetbv(uint32_t *eax, uint32_t *edx) { - __asm(" xorl %%ecx, %%ecx\n" - " xgetbv" - : "=a"(*eax), "=d"(*edx)); + uint64_t v = _xgetbv(0); + *eax = v & 0xffffffff; + *edx = v >> 32; } + +#pragma clang attribute pop +#pragma GCC pop_options diff --git a/src/vendor/modules.txt b/src/vendor/modules.txt index d0fe779a5c..dfb87abf13 100644 --- a/src/vendor/modules.txt +++ b/src/vendor/modules.txt @@ -19,7 +19,7 @@ golang.org/x/net/idna golang.org/x/net/lif golang.org/x/net/nettest golang.org/x/net/route -# golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a +# golang.org/x/sys v0.0.0-20220614162138-6c1b26c55098 ## explicit; go 1.17 golang.org/x/sys/cpu # golang.org/x/text v0.3.8-0.20220509174342-b4bca84b0361 From aca37d16a5a5c1d24e374245f0e5b6404379db96 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 22 Jun 2022 15:19:54 -0400 Subject: [PATCH 27/38] cmd/go: avoid indexing modules in GOROOT Scanning GOROOT modules for changes appears to be causing Windows builders to time out in x/tools tests. We may try a per-package index instead, but for now just skip GOROOT modules (as we do for main modules). Fixes #53493. Change-Id: Ic5bb90b4ce173a24fc6564e85fcde96e1f9b975f Reviewed-on: https://go-review.googlesource.com/c/go/+/413634 TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Michael Matloob --- src/cmd/go/go_test.go | 14 ------- src/cmd/go/internal/modindex/read.go | 58 ++++++---------------------- 2 files changed, 11 insertions(+), 61 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index bbcecf2b2e..b39a62f3e4 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -18,7 +18,6 @@ import ( "io" "io/fs" "log" - "math/rand" "os" "os/exec" "path/filepath" @@ -129,19 +128,6 @@ func TestMain(m *testing.M) { } os.Setenv("CMDGO_TEST_RUN_MAIN", "true") - if strings.HasPrefix(runtime.Version(), "devel ") && godebug.Get("goindexsalt") == "" { - // We're going to execute a lot of cmd/go tests, so set a consistent salt - // via GODEBUG so that the modindex package can avoid walking an entire - // GOROOT module whenever it tries to use an index for that module. - indexSalt := rand.Int63() - v := os.Getenv("GODEBUG") - if v == "" { - os.Setenv("GODEBUG", fmt.Sprintf("goindexsalt=%d", indexSalt)) - } else { - os.Setenv("GODEBUG", fmt.Sprintf("%s,goindexsalt=%d", v, indexSalt)) - } - } - // $GO_GCFLAGS a compiler debug flag known to cmd/dist, make.bash, etc. // It is not a standard go command flag; use os.Getenv, not cfg.Getenv. if os.Getenv("GO_GCFLAGS") != "" { diff --git a/src/cmd/go/internal/modindex/read.go b/src/cmd/go/internal/modindex/read.go index e5761af679..ea1ebb07c2 100644 --- a/src/cmd/go/internal/modindex/read.go +++ b/src/cmd/go/internal/modindex/read.go @@ -15,7 +15,6 @@ import ( "internal/godebug" "internal/goroot" "internal/unsafeheader" - "io/fs" "math" "path" "path/filepath" @@ -29,7 +28,6 @@ import ( "cmd/go/internal/base" "cmd/go/internal/cache" "cmd/go/internal/cfg" - "cmd/go/internal/fsys" "cmd/go/internal/imports" "cmd/go/internal/par" "cmd/go/internal/str" @@ -55,63 +53,29 @@ var fcache par.Cache var salt = godebug.Get("goindexsalt") +// moduleHash returns an ActionID corresponding to the state of the module +// located at filesystem path modroot. func moduleHash(modroot string, ismodcache bool) (cache.ActionID, error) { // We expect modules stored within the module cache to be checksummed and // immutable, and we expect released modules within GOROOT to change only // infrequently (when the Go version changes). - if !ismodcache && !str.HasFilePathPrefix(modroot, cfg.GOROOT) { + if !ismodcache { // The contents of this module may change over time. We don't want to pay // the cost to detect changes and re-index whenever they occur, so just // don't index it at all. + // + // Note that this is true even for modules in GOROOT/src: non-release builds + // of the Go toolchain may have arbitrary development changes on top of the + // commit reported by runtime.Version, or could be completly artificial due + // to lacking a `git` binary (like "devel gomote.XXXXX", as synthesized by + // "gomote push" as of 2022-06-15). (Release builds shouldn't have + // modifications, but we don't want to use a behavior for releases that we + // haven't tested during development.) return cache.ActionID{}, ErrNotIndexed } h := cache.NewHash("moduleIndex") fmt.Fprintf(h, "module index %s %s %s %v\n", runtime.Version(), salt, indexVersion, modroot) - - if str.HasFilePathPrefix(modroot, cfg.GOROOT) && strings.HasPrefix(runtime.Version(), "devel ") && salt == "" { - // This copy of the standard library is a development version, not a - // release. It could be based on a Git commit (like - // "devel go1.19-2a78e8afc0 Wed Jun 15 00:06:24 2022 +0000") with or - // without changes on top of that commit, or it could be completly - // artificial due to lacking a `git` binary (like "devel gomote.XXXXX", as - // synthesized by "gomote push" as of 2022-06-15). - // - // If the user provided a unique salt via GODEBUG, we can trust that it is - // unique and just go with it. Otherwise, we compute an inexpensive hash of - // its files using mtimes so that during development we can continue to - // exercise the logic for cached GOROOT indexes. - // - // mtimes may be granular, imprecise, and loosely updated (see - // https://apenwarr.ca/log/20181113), but we don't expect Go contributors to - // be mucking around with the import graphs in GOROOT often enough for mtime - // collisions to matter essentially ever. - // - // Note that fsys.Walk walks paths in deterministic order, so this hash - // should be completely deterministic if the files are unchanged. - err := fsys.Walk(modroot, func(path string, info fs.FileInfo, err error) error { - if err := moduleWalkErr(modroot, path, info, err); err != nil { - return err - } - - if info.IsDir() { - return nil - } - fmt.Fprintf(h, "file %v %v\n", info.Name(), info.ModTime()) - if info.Mode()&fs.ModeSymlink != 0 { - targ, err := fsys.Stat(path) - if err != nil { - return err - } - fmt.Fprintf(h, "target %v %v\n", targ.Name(), targ.ModTime()) - } - return nil - }) - if err != nil { - return cache.ActionID{}, err - } - } - return h.Sum(), nil } From bdab4cf47a47b69caacad6fd7ff6ab27bb22ab1c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 21 Jun 2022 18:11:32 -0700 Subject: [PATCH 28/38] cmd/go, cmd/link: support failure to create _cgo_import.go For a package that uses cgo, the file _cgo_import.go is created to record information required for internal linking: the non-Go dynamic symbols and libraries that the package depends on. Generating this information sometimes fails, because it can require recreating all the dependencies of all transitively imported packages. And the information is rarely needed, since by default we use external linking when there are packages outside of the standard library that use cgo. With this CL, if generating _cgo_import.go fails, we don't report an error. Instead, we mark the package as requiring external linking, by adding an empty file named "dynimportfail" into the generated archive. If the linker sees a file with that name, it rejects an attempt to use internal linking. Fixes #52863 Change-Id: Ie586e6753a5b67e49bb14533cd7603d9defcf0ea Reviewed-on: https://go-review.googlesource.com/c/go/+/413460 Run-TryBot: Ian Lance Taylor Reviewed-by: Bryan Mills Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/cmd/cgo/doc.go | 10 ++++ src/cmd/go/internal/work/exec.go | 45 ++++++++++++---- src/cmd/go/testdata/script/cgo_undef.txt | 68 ++++++++++++++++++++++++ src/cmd/link/internal/ld/config.go | 9 ++++ src/cmd/link/internal/ld/lib.go | 9 ++++ 5 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 src/cmd/go/testdata/script/cgo_undef.txt diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 4c62c5d70e..7fb6179e26 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -753,6 +753,16 @@ presented to cmd/link as part of a larger program, contains: _go_.o # gc-compiled object for _cgo_gotypes.go, _cgo_import.go, *.cgo1.go _all.o # gcc-compiled object for _cgo_export.c, *.cgo2.c +If there is an error generating the _cgo_import.go file, then, instead +of adding _cgo_import.go to the package, the go tool adds an empty +file named dynimportfail. The _cgo_import.go file is only needed when +using internal linking mode, which is not the default when linking +programs that use cgo (as described below). If the linker sees a file +named dynimportfail it reports an error if it has been told to use +internal linking mode. This approach is taken because generating +_cgo_import.go requires doing a full C link of the package, which can +fail for reasons that are irrelevant when using external linking mode. + The final program will be a dynamic executable, so that cmd/link can avoid needing to process arbitrary .o files. It only needs to process the .o files generated from C files that cgo writes, and those are much more diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 2becc6d946..c88b315d2c 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2405,6 +2405,7 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s } // gccld runs the gcc linker to create an executable from a set of object files. +// Any error output is only displayed for BuildN or BuildX. func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flags []string, objs []string) error { var cmd []string if len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0 { @@ -2450,11 +2451,8 @@ func (b *Builder) gccld(a *Action, p *load.Package, objdir, outfile string, flag save = append(save, line) } out = bytes.Join(save, nil) - if len(out) > 0 { + if len(out) > 0 && (cfg.BuildN || cfg.BuildX) { b.showOutput(nil, dir, p.ImportPath, b.processOutput(out)) - if err != nil { - err = errPrintedOutput - } } } return err @@ -2913,10 +2911,16 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo switch cfg.BuildToolchainName { case "gc": importGo := objdir + "_cgo_import.go" - if err := b.dynimport(a, p, objdir, importGo, cgoExe, cflags, cgoLDFLAGS, outObj); err != nil { + dynOutGo, dynOutObj, err := b.dynimport(a, p, objdir, importGo, cgoExe, cflags, cgoLDFLAGS, outObj) + if err != nil { return nil, nil, err } - outGo = append(outGo, importGo) + if dynOutGo != "" { + outGo = append(outGo, dynOutGo) + } + if dynOutObj != "" { + outObj = append(outObj, dynOutObj) + } case "gccgo": defunC := objdir + "_cgo_defun.c" @@ -3011,11 +3015,13 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo // dynimport creates a Go source file named importGo containing // //go:cgo_import_dynamic directives for each symbol or library // dynamically imported by the object files outObj. -func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe string, cflags, cgoLDFLAGS, outObj []string) error { +// dynOutGo, if not empty, is a new Go file to build as part of the package. +// dynOutObj, if not empty, is a new file to add to the generated archive. +func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe string, cflags, cgoLDFLAGS, outObj []string) (dynOutGo, dynOutObj string, err error) { cfile := objdir + "_cgo_main.c" ofile := objdir + "_cgo_main.o" if err := b.gcc(a, p, objdir, ofile, cflags, cfile); err != nil { - return err + return "", "", err } // Gather .syso files from this package and all (transitive) dependencies. @@ -3060,7 +3066,22 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe } } if err := b.gccld(a, p, objdir, dynobj, ldflags, linkobj); err != nil { - return err + // We only need this information for internal linking. + // If this link fails, mark the object as requiring + // external linking. This link can fail for things like + // syso files that have unexpected dependencies. + // cmd/link explicitly looks for the name "dynimportfail". + // See issue #52863. + fail := objdir + "dynimportfail" + if cfg.BuildN || cfg.BuildX { + b.Showcmd("", "echo > %s", fail) + } + if !cfg.BuildN { + if err := os.WriteFile(fail, nil, 0666); err != nil { + return "", "", err + } + } + return "", fail, nil } // cgo -dynimport @@ -3068,7 +3089,11 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe if p.Standard && p.ImportPath == "runtime/cgo" { cgoflags = []string{"-dynlinker"} // record path to dynamic linker } - return b.run(a, base.Cwd(), p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags) + err = b.run(a, base.Cwd(), p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags) + if err != nil { + return "", "", err + } + return importGo, "", nil } // Run SWIG on all SWIG input files. diff --git a/src/cmd/go/testdata/script/cgo_undef.txt b/src/cmd/go/testdata/script/cgo_undef.txt new file mode 100644 index 0000000000..30034fbac1 --- /dev/null +++ b/src/cmd/go/testdata/script/cgo_undef.txt @@ -0,0 +1,68 @@ +# Issue 52863. + +# We manually create a .syso and a .a file in package a, +# such that the .syso file only works when linked against the .a file. +# Package a has #cgo LDFLAGS to make this happen. +# +# Package c imports package a, and uses cgo itself. +# The generation of the _cgo_import.go for package c will fail, +# because it won't know that it has to link against a/libb.a +# (because we don't gather the #cgo LDFLAGS from all transitively +# imported packages). +# +# The _cgo_import.go file is only needed for internal linking. +# When generating _cgo_import.go for package c fails, an ordinary +# external link should still work. But an internal link is expected +# to fail, because the failure to create _cgo_import.go should cause +# the linker to report an inability to internally link. + +[short] skip +[!cgo] skip +[!exec:ar] skip + +cc -c -o a/b.syso b/b.c +cc -c -o b/lib.o b/lib.c +exec ar rc a/libb.a b/lib.o +go build +! go build -ldflags=-linkmode=internal +stderr 'some packages could not be built to support internal linking.*m/c|requires external linking|does not support internal cgo' + +-- go.mod -- +module m + +-- a/a.go -- +package a + +// #cgo LDFLAGS: -L. -lb +// extern int CFn(int); +import "C" + +func GoFn(v int) int { return int(C.CFn(C.int(v))) } + +-- b/b.c -- +extern int LibFn(int); +int CFn(int i) { return LibFn(i); } + +-- b/lib.c -- +int LibFn(int i) { return i; } + +-- c/c.go -- +package c + +// static int D(int i) { return i; } +import "C" + +import "m/a" + +func Fn(i int) (int, int) { + return a.GoFn(i), int(C.D(C.int(i))) +} + +-- main.go -- +package main + +import "m/c" + +func main() { + println(c.Fn(0)) +} diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go index 6d19b8b5bb..4dd43a16ab 100644 --- a/src/cmd/link/internal/ld/config.go +++ b/src/cmd/link/internal/ld/config.go @@ -246,6 +246,15 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) { return true, "some input objects have an unrecognized file format" } + if len(dynimportfail) > 0 { + // This error means that we were unable to generate + // the _cgo_import.go file for some packages. + // This typically means that there are some dependencies + // that the cgo tool could not figure out. + // See issue #52863. + return true, fmt.Sprintf("some packages could not be built to support internal linking (%v)", dynimportfail) + } + return false, "" } diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 9a5d89a6f7..a3d8202e2c 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -344,6 +344,11 @@ var ( // to support internal linking mode. externalobj = false + // dynimportfail is a list of packages for which generating + // the dynimport file, _cgo_import.go, failed. If there are + // any of these objects, we must link externally. Issue 52863. + dynimportfail []string + // unknownObjFormat is set to true if we see an object whose // format we don't recognize. unknownObjFormat = false @@ -1030,6 +1035,10 @@ func loadobjfile(ctxt *Link, lib *sym.Library) { continue } + if arhdr.name == "dynimportfail" { + dynimportfail = append(dynimportfail, lib.Pkg) + } + // Skip other special (non-object-file) sections that // build tools may have added. Such sections must have // short names so that the suffix is not truncated. From 2a3b467d5f8de04a3493b7ab8cd886e109bd9283 Mon Sep 17 00:00:00 2001 From: Dmitri Goutnik Date: Sat, 7 May 2022 16:10:16 -0500 Subject: [PATCH 29/38] cmd/go: make module .zip files group/world readable os.CreateTemp in downloadZip leaves downloaded .zip files readable only by the owner. Make them group/world readable. Fixes #52765 Change-Id: Iace13e4ad813201a533a1a5fc0c6d9b2e5349a42 Reviewed-on: https://go-review.googlesource.com/c/go/+/404854 Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills --- src/cmd/go/internal/modfetch/fetch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go index 426df9bc04..2e8c4c8aca 100644 --- a/src/cmd/go/internal/modfetch/fetch.go +++ b/src/cmd/go/internal/modfetch/fetch.go @@ -242,7 +242,7 @@ func downloadZip(ctx context.Context, mod module.Version, zipfile string) (err e // contents of the file (by hashing it) before we commit it. Because the file // is zip-compressed, we need an actual file — or at least an io.ReaderAt — to // validate it: we can't just tee the stream as we write it. - f, err := os.CreateTemp(filepath.Dir(zipfile), tmpPattern) + f, err := tempFile(filepath.Dir(zipfile), filepath.Base(zipfile), 0666) if err != nil { return err } From ff17b7d0d42af12ca1ad766a135d9951029027ea Mon Sep 17 00:00:00 2001 From: Wayne Zuo Date: Tue, 7 Jun 2022 09:12:21 +0800 Subject: [PATCH 30/38] cmd/compile: don't use dictionary convert to shaped empty interface Fixes: #53254 Change-Id: I3153d6ebb9f25957b09363f45c5cd4651ee84c2d Reviewed-on: https://go-review.googlesource.com/c/go/+/410655 Reviewed-by: Matthew Dempsky Run-TryBot: Wayne Zuo TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/stencil.go | 4 ++-- test/typeparam/issue53254.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/typeparam/issue53254.go diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index d463c850f3..89869c77d6 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1349,7 +1349,7 @@ func (g *genInst) dictPass(info *instInfo) { mce := m.(*ir.ConvExpr) // Note: x's argument is still typed as a type parameter. // m's argument now has an instantiated type. - if mce.X.Type().HasShape() || m.Type().HasShape() { + if mce.X.Type().HasShape() || (m.Type().HasShape() && !m.Type().IsEmptyInterface()) { m = convertUsingDictionary(info, info.dictParam, m.Pos(), mce.X, m, m.Type()) } case ir.ODOTTYPE, ir.ODOTTYPE2: @@ -1446,7 +1446,7 @@ func findDictType(info *instInfo, t *types.Type) int { // instantiated node of the CONVIFACE node or XDOT node (for a bound method call) that is causing the // conversion. func convertUsingDictionary(info *instInfo, dictParam *ir.Name, pos src.XPos, v ir.Node, in ir.Node, dst *types.Type) ir.Node { - assert(v.Type().HasShape() || in.Type().HasShape()) + assert(v.Type().HasShape() || (in.Type().HasShape() && !in.Type().IsEmptyInterface())) assert(dst.IsInterface()) if v.Type().IsInterface() { diff --git a/test/typeparam/issue53254.go b/test/typeparam/issue53254.go new file mode 100644 index 0000000000..afc0f18471 --- /dev/null +++ b/test/typeparam/issue53254.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2022 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 main + +type Interface[T any] interface { +} + +func F[T any]() Interface[T] { + var i int + return i +} + +func main() { + F[int]() +} From 2e773a3894fba7af744090d7d42968f4993018e2 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 22 Jun 2022 16:02:45 -0700 Subject: [PATCH 31/38] test: add test that causes gofrontend crash For #52846 Change-Id: I763f81def97b53277396c123c524f7b8193ea35e Reviewed-on: https://go-review.googlesource.com/c/go/+/413694 Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- test/fixedbugs/issue52846.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/fixedbugs/issue52846.go diff --git a/test/fixedbugs/issue52846.go b/test/fixedbugs/issue52846.go new file mode 100644 index 0000000000..747fc885b4 --- /dev/null +++ b/test/fixedbugs/issue52846.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2022 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. + +// Issue 52846: gofrontend crashed with alias as map key type + +package p + +type S struct { + F string +} + +type A = S + +var M = map[A]int{A{""}: 0} From 15605ca827723d568f780402d03b29842fd20eec Mon Sep 17 00:00:00 2001 From: tulip Date: Wed, 22 Jun 2022 00:42:29 +0800 Subject: [PATCH 32/38] embed: document additional file name restrictions For #44486 Change-Id: I66af9f7a9f95489a41fd6710e50bdd7878f78b85 Reviewed-on: https://go-review.googlesource.com/c/go/+/413494 Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- src/embed/embed.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/embed/embed.go b/src/embed/embed.go index cbe2d398fb..c54b961d15 100644 --- a/src/embed/embed.go +++ b/src/embed/embed.go @@ -91,6 +91,7 @@ // It can only be used with variables at package scope, not with local variables. // // Patterns must not match files outside the package's module, such as ‘.git/*’ or symbolic links. +// Patterns must not match files whose names include the special punctuation characters " * < > ? ` ' | / \ and :. // Matches for empty directories are ignored. After that, each pattern in a //go:embed line // must match at least one file or non-empty directory. // From de5329f1de4cd4a938323012910310e548b2d936 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 23 Jun 2022 14:11:59 -0400 Subject: [PATCH 33/38] debug/dwarf: handle malformed line table with bad program offset Touch up the line table reader to ensure that it can detect and reject an invalid program offset field in the table header. Fixes #53329. Change-Id: Ia8d684e909af3aca3014b4a3d0dfd431e3f5a9f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/413814 Run-TryBot: Than McIntosh TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/debug/dwarf/line.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/debug/dwarf/line.go b/src/debug/dwarf/line.go index bb281fbdd9..4df4a1751f 100644 --- a/src/debug/dwarf/line.go +++ b/src/debug/dwarf/line.go @@ -215,7 +215,11 @@ func (r *LineReader) readHeader(compDir string) error { } else { headerLength = Offset(buf.uint32()) } - r.programOffset = buf.off + headerLength + programOffset := buf.off + headerLength + if programOffset > r.endOffset { + return DecodeError{"line", hdrOffset, fmt.Sprintf("malformed line table: program offset %d exceeds end offset %d", programOffset, r.endOffset)} + } + r.programOffset = programOffset r.minInstructionLength = int(buf.uint8()) if r.version >= 4 { // [DWARF4 6.2.4] From d38f1d13fa413436d38d86fe86d6a146be44bb84 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 23 Jun 2022 17:23:39 -0700 Subject: [PATCH 34/38] doc/go1.19: Linux race detector now requires glibc 2.17 Fixes #53522 Change-Id: Ibed838d358a733d26a6c3d89446d7fadb1012961 Reviewed-on: https://go-review.googlesource.com/c/go/+/413876 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot --- doc/go1.19.html | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/go1.19.html b/doc/go1.19.html index b323b0d182..53c11bd26e 100644 --- a/doc/go1.19.html +++ b/doc/go1.19.html @@ -807,6 +807,7 @@ as well as support for rendering them to HTML, Markdown, and text. Compared to v2, it is now typically 1.5x to 2x faster, uses half as much memory, and it supports an unlimited number of goroutines. + On Linux, the race detector now requires at least glibc version 2.17. From 3e58ef6cc7dfaf2cf3b593e728f7f62391030114 Mon Sep 17 00:00:00 2001 From: Robert Griesemer
Date: Thu, 23 Jun 2022 20:54:52 -0700 Subject: [PATCH 35/38] go/types, types2: better errors for == when type sets are empty For #51525. Change-Id: I3762bc4a48a1aaab3b006b1ad1400f866892243c Reviewed-on: https://go-review.googlesource.com/c/go/+/413934 TryBot-Result: Gopher Robot Run-TryBot: Robert Griesemer Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/predicates.go | 12 +++++++++++- .../types2/testdata/fixedbugs/issue48712.go | 14 +++++++------- .../types2/testdata/fixedbugs/issue51525.go | 16 ++++++++++++++++ .../internal/types2/testdata/spec/comparisons.go | 16 ++++++++-------- src/go/types/predicates.go | 12 +++++++++++- src/go/types/testdata/fixedbugs/issue48712.go | 14 +++++++------- src/go/types/testdata/fixedbugs/issue51525.go | 16 ++++++++++++++++ src/go/types/testdata/spec/comparisons.go | 16 ++++++++-------- 8 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/fixedbugs/issue51525.go create mode 100644 src/go/types/testdata/fixedbugs/issue51525.go diff --git a/src/cmd/compile/internal/types2/predicates.go b/src/cmd/compile/internal/types2/predicates.go index f7b5b16204..c4d11dcac4 100644 --- a/src/cmd/compile/internal/types2/predicates.go +++ b/src/cmd/compile/internal/types2/predicates.go @@ -147,7 +147,17 @@ func comparable(T Type, dynamic bool, seen map[Type]bool, reportf func(string, . } return true case *Interface: - return dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) + if dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) { + return true + } + if reportf != nil { + if t.typeSet().IsEmpty() { + reportf("empty type set") + } else { + reportf("incomparable types in type set") + } + } + // fallthrough } return false } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48712.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48712.go index ab397560a8..63ce7bc510 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48712.go +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48712.go @@ -23,18 +23,18 @@ func _[P comparable](x P, y any) { } func _[P any](x, y P) { - _ = x /* ERROR type parameter P is not comparable with == */ == x - _ = x /* ERROR type parameter P is not comparable with == */ == y - _ = y /* ERROR type parameter P is not comparable with == */ == x - _ = y /* ERROR type parameter P is not comparable with == */ == y + _ = x /* ERROR incomparable types in type set */ == x + _ = x /* ERROR incomparable types in type set */ == y + _ = y /* ERROR incomparable types in type set */ == x + _ = y /* ERROR incomparable types in type set */ == y _ = x /* ERROR type parameter P is not comparable with < */ < y } func _[P any](x P, y any) { - _ = x /* ERROR type parameter P is not comparable with == */ == x - _ = x /* ERROR type parameter P is not comparable with == */ == y - _ = y == x // ERROR type parameter P is not comparable with == + _ = x /* ERROR incomparable types in type set */ == x + _ = x /* ERROR incomparable types in type set */ == y + _ = y == x // ERROR incomparable types in type set _ = y == y _ = x /* ERROR type parameter P is not comparable with < */ < y diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51525.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51525.go new file mode 100644 index 0000000000..af1d1e6063 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue51525.go @@ -0,0 +1,16 @@ +// Copyright 2022 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 p + +func _[T interface { + int + string +}](x T) { + _ = x /* ERROR empty type set */ == x +} + +func _[T interface{ int | []byte }](x T) { + _ = x /* ERROR incomparable types in type set */ == x +} diff --git a/src/cmd/compile/internal/types2/testdata/spec/comparisons.go b/src/cmd/compile/internal/types2/testdata/spec/comparisons.go index 62c95d47d7..2a7598a581 100644 --- a/src/cmd/compile/internal/types2/testdata/spec/comparisons.go +++ b/src/cmd/compile/internal/types2/testdata/spec/comparisons.go @@ -40,7 +40,7 @@ func _() { _ = m /* ERROR map can only be compared to nil */ == m _ = c == c - _ = b /* ERROR mismatched types */ == nil + _ = b /* ERROR mismatched types */ == nil _ = a /* ERROR mismatched types */ == nil _ = l == nil _ = s /* ERROR mismatched types */ == nil @@ -73,7 +73,7 @@ func _[ J comparable, M map[string]int, C chan int, -] ( +]( b B, a A, l L, @@ -86,14 +86,14 @@ func _[ c C, ) { _ = b == b - _ = a /* ERROR type parameter A is not comparable with == */ == a - _ = l /* ERROR type parameter L is not comparable with == */ == l - _ = s /* ERROR type parameter S is not comparable with == */ == s + _ = a /* ERROR incomparable types in type set */ == a + _ = l /* ERROR incomparable types in type set */ == l + _ = s /* ERROR incomparable types in type set */ == s _ = p == p - _ = f /* ERROR type parameter F is not comparable with == */ == f - _ = i /* ERROR type parameter I is not comparable with == */ == i + _ = f /* ERROR incomparable types in type set */ == f + _ = i /* ERROR incomparable types in type set */ == i _ = j == j - _ = m /* ERROR type parameter M is not comparable with == */ == m + _ = m /* ERROR incomparable types in type set */ == m _ = c == c _ = b /* ERROR mismatched types */ == nil diff --git a/src/go/types/predicates.go b/src/go/types/predicates.go index 25db4acf4a..aaf4dd52fc 100644 --- a/src/go/types/predicates.go +++ b/src/go/types/predicates.go @@ -149,7 +149,17 @@ func comparable(T Type, dynamic bool, seen map[Type]bool, reportf func(string, . } return true case *Interface: - return dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) + if dynamic && !isTypeParam(T) || t.typeSet().IsComparable(seen) { + return true + } + if reportf != nil { + if t.typeSet().IsEmpty() { + reportf("empty type set") + } else { + reportf("incomparable types in type set") + } + } + // fallthrough } return false } diff --git a/src/go/types/testdata/fixedbugs/issue48712.go b/src/go/types/testdata/fixedbugs/issue48712.go index ab397560a8..63ce7bc510 100644 --- a/src/go/types/testdata/fixedbugs/issue48712.go +++ b/src/go/types/testdata/fixedbugs/issue48712.go @@ -23,18 +23,18 @@ func _[P comparable](x P, y any) { } func _[P any](x, y P) { - _ = x /* ERROR type parameter P is not comparable with == */ == x - _ = x /* ERROR type parameter P is not comparable with == */ == y - _ = y /* ERROR type parameter P is not comparable with == */ == x - _ = y /* ERROR type parameter P is not comparable with == */ == y + _ = x /* ERROR incomparable types in type set */ == x + _ = x /* ERROR incomparable types in type set */ == y + _ = y /* ERROR incomparable types in type set */ == x + _ = y /* ERROR incomparable types in type set */ == y _ = x /* ERROR type parameter P is not comparable with < */ < y } func _[P any](x P, y any) { - _ = x /* ERROR type parameter P is not comparable with == */ == x - _ = x /* ERROR type parameter P is not comparable with == */ == y - _ = y == x // ERROR type parameter P is not comparable with == + _ = x /* ERROR incomparable types in type set */ == x + _ = x /* ERROR incomparable types in type set */ == y + _ = y == x // ERROR incomparable types in type set _ = y == y _ = x /* ERROR type parameter P is not comparable with < */ < y diff --git a/src/go/types/testdata/fixedbugs/issue51525.go b/src/go/types/testdata/fixedbugs/issue51525.go new file mode 100644 index 0000000000..af1d1e6063 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue51525.go @@ -0,0 +1,16 @@ +// Copyright 2022 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 p + +func _[T interface { + int + string +}](x T) { + _ = x /* ERROR empty type set */ == x +} + +func _[T interface{ int | []byte }](x T) { + _ = x /* ERROR incomparable types in type set */ == x +} diff --git a/src/go/types/testdata/spec/comparisons.go b/src/go/types/testdata/spec/comparisons.go index 62c95d47d7..2a7598a581 100644 --- a/src/go/types/testdata/spec/comparisons.go +++ b/src/go/types/testdata/spec/comparisons.go @@ -40,7 +40,7 @@ func _() { _ = m /* ERROR map can only be compared to nil */ == m _ = c == c - _ = b /* ERROR mismatched types */ == nil + _ = b /* ERROR mismatched types */ == nil _ = a /* ERROR mismatched types */ == nil _ = l == nil _ = s /* ERROR mismatched types */ == nil @@ -73,7 +73,7 @@ func _[ J comparable, M map[string]int, C chan int, -] ( +]( b B, a A, l L, @@ -86,14 +86,14 @@ func _[ c C, ) { _ = b == b - _ = a /* ERROR type parameter A is not comparable with == */ == a - _ = l /* ERROR type parameter L is not comparable with == */ == l - _ = s /* ERROR type parameter S is not comparable with == */ == s + _ = a /* ERROR incomparable types in type set */ == a + _ = l /* ERROR incomparable types in type set */ == l + _ = s /* ERROR incomparable types in type set */ == s _ = p == p - _ = f /* ERROR type parameter F is not comparable with == */ == f - _ = i /* ERROR type parameter I is not comparable with == */ == i + _ = f /* ERROR incomparable types in type set */ == f + _ = i /* ERROR incomparable types in type set */ == i _ = j == j - _ = m /* ERROR type parameter M is not comparable with == */ == m + _ = m /* ERROR incomparable types in type set */ == m _ = c == c _ = b /* ERROR mismatched types */ == nil From 73475ef0350e84b35a6aa1b593448a9497b62440 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 23 Jun 2022 17:53:01 -0700 Subject: [PATCH 36/38] go/types, types2: print qualified object names in cycle errors Fixes #50788. Change-Id: Id1ed7d9c0687e3005e28598373fd5634178c78ca Reviewed-on: https://go-review.googlesource.com/c/go/+/413895 Reviewed-by: Ian Lance Taylor Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/decl.go | 22 ++++++++++++++++++---- src/go/types/decl.go | 22 ++++++++++++++++++---- test/fixedbugs/issue50788.dir/a.go | 9 +++++++++ test/fixedbugs/issue50788.dir/b.go | 9 +++++++++ test/fixedbugs/issue50788.go | 7 +++++++ 5 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 test/fixedbugs/issue50788.dir/a.go create mode 100644 test/fixedbugs/issue50788.dir/b.go create mode 100644 test/fixedbugs/issue50788.go diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index 0bc5f9f3e1..1db28fc002 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -5,6 +5,7 @@ package types2 import ( + "bytes" "cmd/compile/internal/syntax" "fmt" "go/constant" @@ -303,11 +304,23 @@ loop: // cycleError reports a declaration cycle starting with // the object in cycle that is "first" in the source. func (check *Checker) cycleError(cycle []Object) { + // name returns the (possibly qualified) object name. + // This is needed because with generic types, cycles + // may refer to imported types. See issue #50788. + // TODO(gri) Thus functionality is used elsewhere. Factor it out. + name := func(obj Object) string { + var buf bytes.Buffer + writePackage(&buf, obj.Pkg(), check.qualifier) + buf.WriteString(obj.Name()) + return buf.String() + } + // TODO(gri) Should we start with the last (rather than the first) object in the cycle // since that is the earliest point in the source where we start seeing the // cycle? That would be more consistent with other error messages. i := firstInSrc(cycle) obj := cycle[i] + objName := name(obj) // If obj is a type alias, mark it as valid (not broken) in order to avoid follow-on errors. tname, _ := obj.(*TypeName) if tname != nil && tname.IsAlias() { @@ -315,19 +328,20 @@ func (check *Checker) cycleError(cycle []Object) { } var err error_ if tname != nil && check.conf.CompilerErrorMessages { - err.errorf(obj, "invalid recursive type %s", obj.Name()) + err.errorf(obj, "invalid recursive type %s", objName) } else { - err.errorf(obj, "illegal cycle in declaration of %s", obj.Name()) + err.errorf(obj, "illegal cycle in declaration of %s", objName) } for range cycle { - err.errorf(obj, "%s refers to", obj.Name()) + err.errorf(obj, "%s refers to", objName) i++ if i >= len(cycle) { i = 0 } obj = cycle[i] + objName = name(obj) } - err.errorf(obj, "%s", obj.Name()) + err.errorf(obj, "%s", objName) check.report(&err) } diff --git a/src/go/types/decl.go b/src/go/types/decl.go index c176042852..829aee74b3 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -5,6 +5,7 @@ package types import ( + "bytes" "fmt" "go/ast" "go/constant" @@ -302,30 +303,43 @@ loop: // cycleError reports a declaration cycle starting with // the object in cycle that is "first" in the source. func (check *Checker) cycleError(cycle []Object) { + // name returns the (possibly qualified) object name. + // This is needed because with generic types, cycles + // may refer to imported types. See issue #50788. + // TODO(gri) Thus functionality is used elsewhere. Factor it out. + name := func(obj Object) string { + var buf bytes.Buffer + writePackage(&buf, obj.Pkg(), check.qualifier) + buf.WriteString(obj.Name()) + return buf.String() + } + // TODO(gri) Should we start with the last (rather than the first) object in the cycle // since that is the earliest point in the source where we start seeing the // cycle? That would be more consistent with other error messages. i := firstInSrc(cycle) obj := cycle[i] + objName := name(obj) // If obj is a type alias, mark it as valid (not broken) in order to avoid follow-on errors. tname, _ := obj.(*TypeName) if tname != nil && tname.IsAlias() { check.validAlias(tname, Typ[Invalid]) } if tname != nil && compilerErrorMessages { - check.errorf(obj, _InvalidDeclCycle, "invalid recursive type %s", obj.Name()) + check.errorf(obj, _InvalidDeclCycle, "invalid recursive type %s", objName) } else { - check.errorf(obj, _InvalidDeclCycle, "illegal cycle in declaration of %s", obj.Name()) + check.errorf(obj, _InvalidDeclCycle, "illegal cycle in declaration of %s", objName) } for range cycle { - check.errorf(obj, _InvalidDeclCycle, "\t%s refers to", obj.Name()) // secondary error, \t indented + check.errorf(obj, _InvalidDeclCycle, "\t%s refers to", objName) // secondary error, \t indented i++ if i >= len(cycle) { i = 0 } obj = cycle[i] + objName = name(obj) } - check.errorf(obj, _InvalidDeclCycle, "\t%s", obj.Name()) + check.errorf(obj, _InvalidDeclCycle, "\t%s", objName) } // firstInSrc reports the index of the object with the "smallest" diff --git a/test/fixedbugs/issue50788.dir/a.go b/test/fixedbugs/issue50788.dir/a.go new file mode 100644 index 0000000000..0f786d494c --- /dev/null +++ b/test/fixedbugs/issue50788.dir/a.go @@ -0,0 +1,9 @@ +// Copyright 2022 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 a + +type T[P any] struct { + _ P +} diff --git a/test/fixedbugs/issue50788.dir/b.go b/test/fixedbugs/issue50788.dir/b.go new file mode 100644 index 0000000000..e17afc7b43 --- /dev/null +++ b/test/fixedbugs/issue50788.dir/b.go @@ -0,0 +1,9 @@ +// Copyright 2022 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 b + +import "./a" + +type T a.T[T] // ERROR "invalid recursive type T\n.*T refers to\n.*a\.T refers to\n.*T" diff --git a/test/fixedbugs/issue50788.go b/test/fixedbugs/issue50788.go new file mode 100644 index 0000000000..24d0eb002a --- /dev/null +++ b/test/fixedbugs/issue50788.go @@ -0,0 +1,7 @@ +// errorcheckdir + +// Copyright 2022 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 ignored From b9c4d94fdbe0c9e11a1e604cf321614b90a1d882 Mon Sep 17 00:00:00 2001 From: Sean Liao Date: Tue, 22 Mar 2022 22:00:22 +0000 Subject: [PATCH 37/38] cmd/go/internal/list: update help info with Deprecated field Also align Retracted documentation with actual type of []string Fixes #51876 Change-Id: I3b34e53424aa7ee5330eb71adac23510fff91798 Reviewed-on: https://go-review.googlesource.com/c/go/+/394677 Reviewed-by: Dmitri Shuralyov Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov --- src/cmd/go/alldocs.go | 27 ++++++++++++++------------- src/cmd/go/internal/list/list.go | 27 ++++++++++++++------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index d770ad82e5..fdb7a085b0 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -930,19 +930,20 @@ // applied to a Go struct, but now a Module struct: // // type Module struct { -// Path string // module path -// Version string // module version -// Versions []string // available module versions (with -versions) -// Replace *Module // replaced by this module -// Time *time.Time // time version was created -// Update *Module // available update, if any (with -u) -// Main bool // is this the main module? -// Indirect bool // is this module only an indirect dependency of main module? -// Dir string // directory holding files for this module, if any -// GoMod string // path to go.mod file used when loading this module, if any -// GoVersion string // go version used in module -// Retracted string // retraction information, if any (with -retracted or -u) -// Error *ModuleError // error loading module +// Path string // module path +// Version string // module version +// Versions []string // available module versions +// Replace *Module // replaced by this module +// Time *time.Time // time version was created +// Update *Module // available update (with -u) +// Main bool // is this the main module? +// Indirect bool // module is only indirectly needed by main module +// Dir string // directory holding local copy of files, if any +// GoMod string // path to go.mod file describing module, if any +// GoVersion string // go version used in module +// Retracted []string // retraction information, if any (with -retracted or -u) +// Deprecated string // deprecation message, if any (with -u) +// Error *ModuleError // error loading module // } // // type ModuleError struct { diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 770127c1cd..9c651f2bf3 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -222,19 +222,20 @@ When listing modules, the -f flag still specifies a format template applied to a Go struct, but now a Module struct: type Module struct { - Path string // module path - Version string // module version - Versions []string // available module versions (with -versions) - Replace *Module // replaced by this module - Time *time.Time // time version was created - Update *Module // available update, if any (with -u) - Main bool // is this the main module? - Indirect bool // is this module only an indirect dependency of main module? - Dir string // directory holding files for this module, if any - GoMod string // path to go.mod file used when loading this module, if any - GoVersion string // go version used in module - Retracted string // retraction information, if any (with -retracted or -u) - Error *ModuleError // error loading module + Path string // module path + Version string // module version + Versions []string // available module versions + Replace *Module // replaced by this module + Time *time.Time // time version was created + Update *Module // available update (with -u) + Main bool // is this the main module? + Indirect bool // module is only indirectly needed by main module + Dir string // directory holding local copy of files, if any + GoMod string // path to go.mod file describing module, if any + GoVersion string // go version used in module + Retracted []string // retraction information, if any (with -retracted or -u) + Deprecated string // deprecation message, if any (with -u) + Error *ModuleError // error loading module } type ModuleError struct { From 5a1c5b8ae741df2d5c53f328c57a84d85ae6c44a Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Thu, 23 Jun 2022 15:46:29 -0400 Subject: [PATCH 38/38] cmd/go: add per-package indexing for modules outside mod cache Packages outside the module cache including the standard library will be indexed individually rather than as a whole module. For #52876 Change-Id: I142dad6a790e9e8eb4dc6430a588fbfa86552e49 Reviewed-on: https://go-review.googlesource.com/c/go/+/413815 Reviewed-by: Michael Matloob Run-TryBot: Michael Matloob Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/internal/load/pkg.go | 4 +- src/cmd/go/internal/modindex/index_format.txt | 13 +- src/cmd/go/internal/modindex/read.go | 252 ++++++++++++++---- src/cmd/go/internal/modindex/scan.go | 10 +- src/cmd/go/internal/modindex/write.go | 18 +- src/cmd/go/internal/modload/import.go | 6 +- src/cmd/go/internal/modload/load.go | 4 +- src/cmd/go/internal/modload/search.go | 8 +- 8 files changed, 244 insertions(+), 71 deletions(-) diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 1a7b9d235d..95a06a325d 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -878,8 +878,8 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo buildMode = build.ImportComment } if modroot := modload.PackageModRoot(ctx, r.path); modroot != "" { - if mi, err := modindex.Get(modroot); err == nil { - data.p, data.err = mi.Import(cfg.BuildContext, mi.RelPath(r.dir), buildMode) + if rp, err := modindex.GetPackage(modroot, r.dir); err == nil { + data.p, data.err = rp.Import(cfg.BuildContext, buildMode) goto Happy } else if !errors.Is(err, modindex.ErrNotIndexed) { base.Fatalf("go: %v", err) diff --git a/src/cmd/go/internal/modindex/index_format.txt b/src/cmd/go/internal/modindex/index_format.txt index 3768eea6c7..c74b1d458b 100644 --- a/src/cmd/go/internal/modindex/index_format.txt +++ b/src/cmd/go/internal/modindex/index_format.txt @@ -7,6 +7,8 @@ Strings are written into the string table at the end of the file. Each string is null-terminated. String offsets are relative to the start of the string table. Bools are written as uint32s: 0 for false and 1 for true. +The following is the format for a full module: + “go index v0\n” str uint32 - offset of string table n uint32 - number of packages @@ -40,7 +42,16 @@ for each RawPackage: position - file, offset, line, column - uint32 [string table] -// parseError struct +The following is the format for a single indexed package: + +“go index v0\n” +str uint32 - offset of string table +for the single RawPackage: + [same RawPackage format as above] +[string table] + +The following is the definition of the json-serialized parseError struct: + type parseError struct { ErrorList *scanner.ErrorList // non-nil if the error was an ErrorList, nil otherwise ErrorString string // non-empty for all other cases diff --git a/src/cmd/go/internal/modindex/read.go b/src/cmd/go/internal/modindex/read.go index ea1ebb07c2..65a1ecf6dc 100644 --- a/src/cmd/go/internal/modindex/read.go +++ b/src/cmd/go/internal/modindex/read.go @@ -23,11 +23,13 @@ import ( "sort" "strings" "sync" + "time" "unsafe" "cmd/go/internal/base" "cmd/go/internal/cache" "cmd/go/internal/cfg" + "cmd/go/internal/fsys" "cmd/go/internal/imports" "cmd/go/internal/par" "cmd/go/internal/str" @@ -39,20 +41,16 @@ import ( // module index. var enabled bool = godebug.Get("goindex") != "0" -// ModuleIndex represents and encoded module index file. It is used to +// Module represents and encoded module index file. It is used to // do the equivalent of build.Import of packages in the module and answer other // questions based on the index file's data. -type ModuleIndex struct { +type Module struct { modroot string od offsetDecoder packages map[string]int // offsets of each package packagePaths []string // paths to package directories relative to modroot; these are the keys of packages } -var fcache par.Cache - -var salt = godebug.Get("goindexsalt") - // moduleHash returns an ActionID corresponding to the state of the module // located at filesystem path modroot. func moduleHash(modroot string, ismodcache bool) (cache.ActionID, error) { @@ -75,7 +73,45 @@ func moduleHash(modroot string, ismodcache bool) (cache.ActionID, error) { } h := cache.NewHash("moduleIndex") - fmt.Fprintf(h, "module index %s %s %s %v\n", runtime.Version(), salt, indexVersion, modroot) + fmt.Fprintf(h, "module index %s %s %v\n", runtime.Version(), indexVersion, modroot) + return h.Sum(), nil +} + +const modTimeCutoff = 2 * time.Second + +// dirHash returns an ActionID corresponding to the state of the package +// located at filesystem path pkgdir. +func dirHash(pkgdir string) (cache.ActionID, error) { + h := cache.NewHash("moduleIndex") + fmt.Fprintf(h, "package %s %s %v\n", runtime.Version(), indexVersion, pkgdir) + entries, err := fsys.ReadDir(pkgdir) + if err != nil { + // pkgdir might not be a directory. give up on hashing. + return cache.ActionID{}, ErrNotIndexed + } + cutoff := time.Now().Add(-modTimeCutoff) + for _, info := range entries { + if info.IsDir() { + continue + } + + if !info.Mode().IsRegular() { + return cache.ActionID{}, ErrNotIndexed + } + // To avoid problems for very recent files where a new + // write might not change the mtime due to file system + // mtime precision, reject caching if a file was read that + // is less than modTimeCutoff old. + // + // This is the same strategy used for hashing test inputs. + // See hashOpen in cmd/go/internal/test/test.go for the + // corresponding code. + if info.ModTime().After(cutoff) { + return cache.ActionID{}, ErrNotIndexed + } + + fmt.Fprintf(h, "file %v %v %v\n", info.Name(), info.ModTime(), info.Size()) + } return h.Sum(), nil } @@ -83,31 +119,61 @@ var modrootCache par.Cache var ErrNotIndexed = errors.New("not in module index") -// Get returns the ModuleIndex for the module rooted at modroot. +var ( + errDisabled = fmt.Errorf("%w: module indexing disabled", ErrNotIndexed) + errNotFromModuleCache = fmt.Errorf("%w: not from module cache", ErrNotIndexed) +) + +// GetPackage returns the IndexPackage for the package at the given path. // It will return ErrNotIndexed if the directory should be read without // using the index, for instance because the index is disabled, or the packgae // is not in a module. -func Get(modroot string) (*ModuleIndex, error) { - if !enabled || cache.DefaultDir() == "off" || cfg.BuildMod == "vendor" { - return nil, ErrNotIndexed +func GetPackage(modroot, pkgdir string) (*IndexPackage, error) { + mi, err := GetModule(modroot) + if err == nil { + return mi.Package(relPath(pkgdir, modroot)), nil } - if modroot == "" { - panic("modindex.Get called with empty modroot") + if !errors.Is(err, errNotFromModuleCache) { + return nil, err } - modroot = filepath.Clean(modroot) - isModCache := str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) - return openIndex(modroot, isModCache) + return openIndexPackage(modroot, pkgdir) } -// openIndex returns the module index for modPath. +// GetModule returns the Module for the given modroot. +// It will return ErrNotIndexed if the directory should be read without +// using the index, for instance because the index is disabled, or the packgae +// is not in a module. +func GetModule(modroot string) (*Module, error) { + if !enabled || cache.DefaultDir() == "off" { + return nil, errDisabled + } + if modroot == "" { + panic("modindex.GetPackage called with empty modroot") + } + if cfg.BuildMod == "vendor" { + // Even if the main module is in the module cache, + // its vendored dependencies are not loaded from their + // usual cached locations. + return nil, errNotFromModuleCache + } + modroot = filepath.Clean(modroot) + if !str.HasFilePathPrefix(modroot, cfg.GOMODCACHE) { + return nil, errNotFromModuleCache + } + return openIndexModule(modroot, true) +} + +var mcache par.Cache + +// openIndexModule returns the module index for modPath. // It will return ErrNotIndexed if the module can not be read // using the index because it contains symlinks. -func openIndex(modroot string, ismodcache bool) (*ModuleIndex, error) { +func openIndexModule(modroot string, ismodcache bool) (*Module, error) { type result struct { - mi *ModuleIndex + mi *Module err error } - r := fcache.Do(modroot, func() any { + r := mcache.Do(modroot, func() any { id, err := moduleHash(modroot, ismodcache) if err != nil { return result{nil, err} @@ -133,8 +199,38 @@ func openIndex(modroot string, ismodcache bool) (*ModuleIndex, error) { return r.mi, r.err } -// fromBytes returns a *ModuleIndex given the encoded representation. -func fromBytes(moddir string, data []byte) (mi *ModuleIndex, err error) { +var pcache par.Cache + +func openIndexPackage(modroot, pkgdir string) (*IndexPackage, error) { + type result struct { + pkg *IndexPackage + err error + } + r := pcache.Do(pkgdir, func() any { + id, err := dirHash(pkgdir) + if err != nil { + return result{nil, err} + } + data, _, err := cache.Default().GetMmap(id) + if err != nil { + // Couldn't read from index. Assume we couldn't read from + // the index because the package hasn't been indexed yet. + data = indexPackage(modroot, pkgdir) + if err = cache.Default().PutBytes(id, data); err != nil { + return result{nil, err} + } + } + pkg, err := packageFromBytes(modroot, data) + if err != nil { + return result{nil, err} + } + return result{pkg, nil} + }).(result) + return r.pkg, r.err +} + +// fromBytes returns a *Module given the encoded representation. +func fromBytes(moddir string, data []byte) (mi *Module, err error) { if !enabled { panic("use of index") } @@ -184,7 +280,7 @@ func fromBytes(moddir string, data []byte) (mi *ModuleIndex, err error) { packages[packagePaths[i]] = packageOffsets[i] } - return &ModuleIndex{ + return &Module{ moddir, offsetDecoder{data, st}, packages, @@ -192,21 +288,60 @@ func fromBytes(moddir string, data []byte) (mi *ModuleIndex, err error) { }, nil } +// packageFromBytes returns a *IndexPackage given the encoded representation. +func packageFromBytes(modroot string, data []byte) (p *IndexPackage, err error) { + if !enabled { + panic("use of package index when not enabled") + } + + // SetPanicOnFault's errors _may_ satisfy this interface. Even though it's not guaranteed + // that all its errors satisfy this interface, we'll only check for these errors so that + // we don't suppress panics that could have been produced from other sources. + type addrer interface { + Addr() uintptr + } + + // set PanicOnFault to true so that we can catch errors on the initial reads of the slice, + // in case it's mmapped (the common case). + old := debug.SetPanicOnFault(true) + defer func() { + debug.SetPanicOnFault(old) + if e := recover(); e != nil { + if _, ok := e.(addrer); ok { + // This panic was almost certainly caused by SetPanicOnFault. + err = fmt.Errorf("error reading module index: %v", e) + return + } + // The panic was likely not caused by SetPanicOnFault. + panic(e) + } + }() + + gotVersion, unread, _ := bytes.Cut(data, []byte{'\n'}) + if string(gotVersion) != indexVersion { + return nil, fmt.Errorf("bad index version string: %q", gotVersion) + } + stringTableOffset, unread := binary.LittleEndian.Uint32(unread[:4]), unread[4:] + st := newStringTable(data[stringTableOffset:]) + d := &decoder{unread, st} + p = decodePackage(d, offsetDecoder{data, st}) + p.modroot = modroot + return p, nil +} + // Returns a list of directory paths, relative to the modroot, for // packages contained in the module index. -func (mi *ModuleIndex) Packages() []string { +func (mi *Module) Packages() []string { return mi.packagePaths } -// RelPath returns the path relative to the module's root. -func (mi *ModuleIndex) RelPath(path string) string { - return str.TrimFilePathPrefix(filepath.Clean(path), mi.modroot) // mi.modroot is already clean +// relPath returns the path relative to the module's root. +func relPath(path, modroot string) string { + return str.TrimFilePathPrefix(filepath.Clean(path), filepath.Clean(modroot)) } -// ImportPackage is the equivalent of build.Import given the information in ModuleIndex. -func (mi *ModuleIndex) Import(bctxt build.Context, relpath string, mode build.ImportMode) (p *build.Package, err error) { - rp := mi.indexPackage(relpath) - +// Import is the equivalent of build.Import given the information in Module. +func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *build.Package, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("error reading module index: %v", e) @@ -218,7 +353,7 @@ func (mi *ModuleIndex) Import(bctxt build.Context, relpath string, mode build.Im p = &build.Package{} p.ImportPath = "." - p.Dir = filepath.Join(mi.modroot, rp.dir) + p.Dir = filepath.Join(rp.modroot, rp.dir) var pkgerr error switch ctxt.Compiler { @@ -236,7 +371,7 @@ func (mi *ModuleIndex) Import(bctxt build.Context, relpath string, mode build.Im inTestdata := func(sub string) bool { return strings.Contains(sub, "/testdata/") || strings.HasSuffix(sub, "/testdata") || str.HasPathPrefix(sub, "testdata") } - if !inTestdata(relpath) { + if !inTestdata(rp.dir) { // In build.go, p.Root should only be set in the non-local-import case, or in // GOROOT or GOPATH. Since module mode only calls Import with path set to "." // and the module index doesn't apply outside modules, the GOROOT case is @@ -248,8 +383,8 @@ func (mi *ModuleIndex) Import(bctxt build.Context, relpath string, mode build.Im if ctxt.GOROOT != "" && str.HasFilePathPrefix(p.Dir, cfg.GOROOTsrc) && p.Dir != cfg.GOROOTsrc { p.Root = ctxt.GOROOT p.Goroot = true - modprefix := str.TrimFilePathPrefix(mi.modroot, cfg.GOROOTsrc) - p.ImportPath = relpath + modprefix := str.TrimFilePathPrefix(rp.modroot, cfg.GOROOTsrc) + p.ImportPath = rp.dir if modprefix != "" { p.ImportPath = filepath.Join(modprefix, p.ImportPath) } @@ -521,20 +656,21 @@ func IsStandardPackage(goroot_, compiler, path string) bool { reldir = str.TrimFilePathPrefix(reldir, "cmd") modroot = filepath.Join(modroot, "cmd") } - mod, err := Get(modroot) - if err != nil { + if _, err := GetPackage(modroot, filepath.Join(modroot, reldir)); err == nil { + // Note that goroot.IsStandardPackage doesn't check that the directory + // actually contains any go files-- merely that it exists. GetPackage + // returning a nil error is enough for us to know the directory exists. + return true + } else if errors.Is(err, ErrNotIndexed) { + // Fall back because package isn't indexable. (Probably because + // a file was modified recently) return goroot.IsStandardPackage(goroot_, compiler, path) } - - pkgs := mod.Packages() - i := sort.SearchStrings(pkgs, reldir) - return i != len(pkgs) && pkgs[i] == reldir + return false } // IsDirWithGoFiles is the equivalent of fsys.IsDirWithGoFiles using the information in the index. -func (mi *ModuleIndex) IsDirWithGoFiles(relpath string) (_ bool, err error) { - rp := mi.indexPackage(relpath) - +func (rp *IndexPackage) IsDirWithGoFiles() (_ bool, err error) { defer func() { if e := recover(); e != nil { err = fmt.Errorf("error reading module index: %v", e) @@ -549,9 +685,7 @@ func (mi *ModuleIndex) IsDirWithGoFiles(relpath string) (_ bool, err error) { } // ScanDir implements imports.ScanDir using the information in the index. -func (mi *ModuleIndex) ScanDir(path string, tags map[string]bool) (sortedImports []string, sortedTestImports []string, err error) { - rp := mi.indexPackage(path) - +func (rp *IndexPackage) ScanDir(tags map[string]bool) (sortedImports []string, sortedTestImports []string, err error) { // TODO(matloob) dir should eventually be relative to indexed directory // TODO(matloob): skip reading raw package and jump straight to data we need? @@ -639,20 +773,22 @@ func shouldBuild(sf *sourceFile, tags map[string]bool) bool { return true } -// index package holds the information needed to access information in the -// index about a package. -type indexPackage struct { +// IndexPackage holds the information needed to access information in the +// index needed to load a package in a specific directory. +type IndexPackage struct { error error dir string // directory of the package relative to the modroot + modroot string + // Source files sourceFiles []*sourceFile } var errCannotFindPackage = errors.New("cannot find package") -// indexPackage returns an indexPackage constructed using the information in the ModuleIndex. -func (mi *ModuleIndex) indexPackage(path string) *indexPackage { +// Package returns an IndexPackage constructed using the information in the Module. +func (mi *Module) Package(path string) *IndexPackage { defer func() { if e := recover(); e != nil { base.Fatalf("error reading module index: %v", e) @@ -660,12 +796,18 @@ func (mi *ModuleIndex) indexPackage(path string) *indexPackage { }() offset, ok := mi.packages[path] if !ok { - return &indexPackage{error: fmt.Errorf("%w %q in:\n\t%s", errCannotFindPackage, path, filepath.Join(mi.modroot, path))} + return &IndexPackage{error: fmt.Errorf("%w %q in:\n\t%s", errCannotFindPackage, path, filepath.Join(mi.modroot, path))} } // TODO(matloob): do we want to lock on the module index? d := mi.od.decoderAt(offset) - rp := new(indexPackage) + p := decodePackage(d, mi.od) + p.modroot = mi.modroot + return p +} + +func decodePackage(d *decoder, od offsetDecoder) *IndexPackage { + rp := new(IndexPackage) if errstr := d.string(); errstr != "" { rp.error = errors.New(errstr) } @@ -675,7 +817,7 @@ func (mi *ModuleIndex) indexPackage(path string) *indexPackage { for i := uint32(0); i < numSourceFiles; i++ { offset := d.uint32() rp.sourceFiles[i] = &sourceFile{ - od: mi.od.offsetDecoderAt(offset), + od: od.offsetDecoderAt(offset), } } return rp diff --git a/src/cmd/go/internal/modindex/scan.go b/src/cmd/go/internal/modindex/scan.go index d1f73dbb53..eb84bf8d89 100644 --- a/src/cmd/go/internal/modindex/scan.go +++ b/src/cmd/go/internal/modindex/scan.go @@ -65,7 +65,15 @@ func indexModule(modroot string) ([]byte, error) { if err != nil { return nil, err } - return encodeModule(packages), nil + return encodeModuleBytes(packages), nil +} + +// indexModule indexes the package at the given directory and returns its +// encoded representation. It returns ErrNotIndexed if the package can't +// be indexed. +func indexPackage(modroot, pkgdir string) []byte { + p := importRaw(modroot, relPath(pkgdir, modroot)) + return encodePackageBytes(p) } // rawPackage holds the information from each package that's needed to diff --git a/src/cmd/go/internal/modindex/write.go b/src/cmd/go/internal/modindex/write.go index 0c3123a46f..3408248bd9 100644 --- a/src/cmd/go/internal/modindex/write.go +++ b/src/cmd/go/internal/modindex/write.go @@ -11,9 +11,9 @@ import ( const indexVersion = "go index v0" -// encodeModule produces the encoded representation of the module index. -// encodeModule may modify the packages slice. -func encodeModule(packages []*rawPackage) []byte { +// encodeModuleBytes produces the encoded representation of the module index. +// encodeModuleBytes may modify the packages slice. +func encodeModuleBytes(packages []*rawPackage) []byte { e := newEncoder() e.Bytes([]byte(indexVersion)) e.Bytes([]byte{'\n'}) @@ -39,6 +39,18 @@ func encodeModule(packages []*rawPackage) []byte { return e.b } +func encodePackageBytes(p *rawPackage) []byte { + e := newEncoder() + e.Bytes([]byte(indexVersion)) + e.Bytes([]byte{'\n'}) + stringTableOffsetPos := e.Pos() // fill this at the end + e.Uint32(0) // string table offset + encodePackage(e, p) + e.IntAt(e.Pos(), stringTableOffsetPos) + e.Bytes(e.stringTable) + return e.b +} + func encodePackage(e *encoder, p *rawPackage) { e.String(p.error) e.String(p.dir) diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index f7810ca5c6..f2c7592a28 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -657,11 +657,11 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile // We don't care about build tags, not even "+build ignore". // We're just looking for a plausible directory. res := haveGoFilesCache.Do(dir, func() any { - // modindex.Get will return ErrNotIndexed for any directories which + // modindex.GetPackage will return ErrNotIndexed for any directories which // are reached through a symlink, so that they will be handled by // fsys.IsDirWithGoFiles below. - if mi, err := modindex.Get(mdir); err == nil { - isDirWithGoFiles, err := mi.IsDirWithGoFiles(mi.RelPath(dir)) + if ip, err := modindex.GetPackage(mdir, dir); err == nil { + isDirWithGoFiles, err := ip.IsDirWithGoFiles() return goFilesEntry{isDirWithGoFiles, err} } else if !errors.Is(err, modindex.ErrNotIndexed) { return goFilesEntry{err: err} diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index b2c3ba2633..ba85dc2438 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -2102,8 +2102,8 @@ func (ld *loader) checkTidyCompatibility(ctx context.Context, rs *Requirements) // may see these legacy imports. We drop them so that the module // search does not look for modules to try to satisfy them. func scanDir(modroot string, dir string, tags map[string]bool) (imports_, testImports []string, err error) { - if mi, mierr := modindex.Get(modroot); mierr == nil { - imports_, testImports, err = mi.ScanDir(mi.RelPath(dir), tags) + if ip, mierr := modindex.GetPackage(modroot, dir); mierr == nil { + imports_, testImports, err = ip.ScanDir(tags) goto Happy } else if !errors.Is(mierr, modindex.ErrNotIndexed) { return nil, nil, mierr diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go index d9d7711d06..856390a0f2 100644 --- a/src/cmd/go/internal/modload/search.go +++ b/src/cmd/go/internal/modload/search.go @@ -195,7 +195,7 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f } modPrefix = mod.Path } - if mi, err := modindex.Get(root); err == nil { + if mi, err := modindex.GetModule(root); err == nil { walkFromIndex(mi, modPrefix, isMatch, treeCanMatch, tags, have, addPkg) continue } else if !errors.Is(err, modindex.ErrNotIndexed) { @@ -213,9 +213,9 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f } // walkFromIndex matches packages in a module using the module index. modroot -// is the module's root directory on disk, index is the ModuleIndex for the +// is the module's root directory on disk, index is the modindex.Module for the // module, and importPathRoot is the module's path prefix. -func walkFromIndex(index *modindex.ModuleIndex, importPathRoot string, isMatch, treeCanMatch func(string) bool, tags, have map[string]bool, addPkg func(string)) { +func walkFromIndex(index *modindex.Module, importPathRoot string, isMatch, treeCanMatch func(string) bool, tags, have map[string]bool, addPkg func(string)) { loopPackages: for _, reldir := range index.Packages() { // Avoid .foo, _foo, and testdata subdirectory trees. @@ -252,7 +252,7 @@ loopPackages: if !have[name] { have[name] = true if isMatch(name) { - if _, _, err := index.ScanDir(reldir, tags); err != imports.ErrNoGo { + if _, _, err := index.Package(reldir).ScanDir(tags); err != imports.ErrNoGo { addPkg(name) } }