Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
00ee186
crypto/internal/constanttime: expose intrinsics to the FIPS 140-3 pac…
FiloSottile Oct 29, 2025
361d51a
runtime: remove the pc field of _defer struct
fengyoulin Oct 31, 2025
5132158
bytes: add Buffer.Peek
icholy Oct 31, 2025
c555934
internal/profile: optimize Parse allocs
pymq Nov 2, 2025
e12d8a9
all: remove extra space in the comments
cuishuang Oct 31, 2025
eaf28a2
runtime: update outdated comments for deferprocStack
fengyoulin Oct 25, 2025
f93186f
cmd/go/internal/telemetrystats: count cgo usage
qmuntal Sep 26, 2025
0a95856
cmd/go: eliminate additional global variable
jitsu-net Oct 27, 2025
5f8fdb7
cmd/go: move functions to methods
jitsu-net Oct 29, 2025
17b5707
internal/runtime/cgobench: add cgo callback benchmark
mknyszek Oct 15, 2025
85bec79
cmd/go/testdata/script: loosen list_empty_importpath for freebsd
matloob Oct 28, 2025
0c4444e
cmd/internal/obj: support arm64 FMOVQ large offset encoding
amusman Nov 1, 2025
4d2b03d
crypto/tls: add BetterTLS test coverage
cpu Nov 3, 2025
aa94fdf
cmd/go: link to go.dev/doc/godebug for removed GODEBUG settings
mateusz834 Sep 8, 2025
43491f8
cmd/cgo: use the export'ed file/line in error messages
ariel-anieli Nov 1, 2025
b5353fd
runtime: don't panic in castogscanstatus
mknyszek Nov 3, 2025
c93cc60
runtime: allow Stack to traceback goroutines in syscall _Grunning window
mknyszek Oct 30, 2025
e2c6a20
runtime: avoid append in printint, printuint
rsc Nov 3, 2025
dadbac0
cmd/internal/obj/loong64: add VPERMI.W, XVPERMI.{W,V,Q} instruction s…
abner-chenc Oct 29, 2025
ad5e941
cmd/internal/obj/loong64: using {xv,v}slli.d to perform copying betwe…
abner-chenc Oct 30, 2025
9795c7b
internal/strconv: fix pow10 off-by-one in exponent result
rsc Nov 2, 2025
162ba6c
internal/strconv: add tests and benchmarks for ftoaFixed
rsc Nov 2, 2025
34fec51
internal/strconv: extract fixed-precision ftoa from ftoaryu.go
rsc Nov 1, 2025
9f6590f
encoding/pem: don't reslice in failure modes
rolandshoemaker Oct 27, 2025
6e165b4
cmd/compile: implement Avg64u, Hmul64, Hmul64u for wasm
rsc Nov 4, 2025
dd839f1
internal/strconv: handle %f with fixedFtoa when possible
rsc Nov 2, 2025
75b2bb1
cmd/cgo: drop pre-1.18 support
ianlancetaylor Nov 2, 2025
c7ccbdd
cmd/compile/internal/ssa: more aggressive on dead auto elim
fengyoulin Sep 11, 2025
8562386
runtime: amend doc for setPinned
callthingsoff Nov 3, 2025
a7d174c
cmd/compile/internal/ssa: simplify riscv64 FCLASSD rewrite rules
Nov 3, 2025
a5fe679
internal/syscall/windows: fix ReOpenFile sentinel error value
qmuntal Nov 3, 2025
16705b9
cmd/compile: faster liveness analysis in regalloc
DanielMorsing Aug 9, 2025
8e2bd26
cmd/link: add comments for SymKind values
ianlancetaylor Oct 28, 2025
61de3a9
cmd/link: remove unused SFILEPATH symbol kind
ianlancetaylor Oct 28, 2025
f5f1426
cmd/link: remove misleading comment
ianlancetaylor Oct 28, 2025
6914dd1
cmd/link: add and use new SymKind SFirstUnallocated
ianlancetaylor Oct 28, 2025
7347b54
cmd/link: don't generate .gosymtab section
ianlancetaylor Nov 2, 2025
0e1bd8b
cmd/link, runtime: don't store text start in pcHeader
ianlancetaylor Nov 3, 2025
9f3a108
os: ignore O_TRUNC errors on named pipes and terminal devices on Windows
qmuntal Oct 30, 2025
e31d383
removed goroutineProfile semaphore from goroutine leak profile collec…
VladSaiocUber Oct 24, 2025
590b52c
Removed Goexperiment flag.
VladSaiocUber Oct 27, 2025
89f02ee
Fixed accessing the goroutine leak profile through Lookup when experi…
VladSaiocUber Oct 27, 2025
cdb4053
Addressed comments.
VladSaiocUber Oct 30, 2025
77e0b31
Fixed comment.
VladSaiocUber Oct 30, 2025
233dd50
Use lock to prevent racy profile writes.
VladSaiocUber Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/next/73794.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg bytes, method (*Buffer) Peek(int) ([]uint8, error) #73794
2 changes: 2 additions & 0 deletions doc/next/6-stdlib/99-minor/bytes/73794.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The new [Buffer.Peek] method returns the next n bytes from the buffer without
advancing it.
12 changes: 12 additions & 0 deletions src/bytes/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ func (b *Buffer) String() string {
return string(b.buf[b.off:])
}

// Peek returns the next n bytes without advancing the buffer.
// If Peek returns fewer than n bytes, it also returns [io.EOF].
// The slice is only valid until the next call to a read or write method.
// The slice aliases the buffer content at least until the next buffer modification,
// so immediate changes to the slice will affect the result of future reads.
func (b *Buffer) Peek(n int) ([]byte, error) {
if b.Len() < n {
return b.buf[b.off:], io.EOF
}
return b.buf[b.off:n], nil
}

// empty reports whether the unread portion of the buffer is empty.
func (b *Buffer) empty() bool { return len(b.buf) <= b.off }

Expand Down
28 changes: 28 additions & 0 deletions src/bytes/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,34 @@ func TestReadString(t *testing.T) {
}
}

var peekTests = []struct {
buffer string
n int
expected string
err error
}{
{"", 0, "", nil},
{"aaa", 3, "aaa", nil},
{"foobar", 2, "fo", nil},
{"a", 2, "a", io.EOF},
}

func TestPeek(t *testing.T) {
for _, test := range peekTests {
buf := NewBufferString(test.buffer)
bytes, err := buf.Peek(test.n)
if string(bytes) != test.expected {
t.Errorf("expected %q, got %q", test.expected, bytes)
}
if err != test.err {
t.Errorf("expected error %v, got %v", test.err, err)
}
if buf.Len() != len(test.buffer) {
t.Errorf("bad length after peek: %d, want %d", buf.Len(), len(test.buffer))
}
}
}

func BenchmarkReadString(b *testing.B) {
const n = 32 << 10

Expand Down
2 changes: 1 addition & 1 deletion src/bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ func TestMap(t *testing.T) {
// Run a couple of awful growth/shrinkage tests
a := tenRunes('a')

// 1. Grow. This triggers two reallocations in Map.
// 1. Grow. This triggers two reallocations in Map.
maxRune := func(r rune) rune { return unicode.MaxRune }
m := Map(maxRune, []byte(a))
expect := tenRunes(unicode.MaxRune)
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/asm/internal/asm/testdata/arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
FMOVS F1, 0x44332211(R2) // FMOVS F1, 1144201745(R2)
FMOVD F1, 0x1007000(R2) // FMOVD F1, 16805888(R2)
FMOVD F1, 0x44332211(R2) // FMOVD F1, 1144201745(R2)
FMOVQ F1, 0x1003000(R2) // FMOVQ F1, 16789504(R2)
FMOVQ F1, 0x44332211(R2) // FMOVQ F1, 1144201745(R2)

MOVB 0x1000000(R1), R2 // MOVB 16777216(R1), R2
MOVB 0x44332211(R1), R2 // MOVB 1144201745(R1), R2
Expand All @@ -643,6 +645,8 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
FMOVS 0x44332211(R1), F2 // FMOVS 1144201745(R1), F2
FMOVD 0x1000000(R1), F2 // FMOVD 16777216(R1), F2
FMOVD 0x44332211(R1), F2 // FMOVD 1144201745(R1), F2
FMOVQ 0x1000000(R1), F2 // FMOVQ 16777216(R1), F2
FMOVQ 0x44332211(R1), F2 // FMOVQ 1144201745(R1), F2

// shifted or extended register offset.
MOVD (R2)(R6.SXTW), R4 // 44c866f8
Expand Down
14 changes: 13 additions & 1 deletion src/cmd/asm/internal/asm/testdata/loong64enc1.s
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,18 @@ lable2:
XVMOVQ X28.V[3], X8 // 88ef0377
XVMOVQ X27.V[0], X9 // 69e30377

//Move vector element to vector.
// Move vector element to vector.
VMOVQ V1.B[3], V9.B16 // 298cf772
VMOVQ V2.H[2], V8.H8 // 48c8f772
VMOVQ V3.W[1], V7.W4 // 67e4f772
VMOVQ V4.V[0], V6.V2 // 86f0f772

// Move vector register to vector register.
VMOVQ V1, V9 // 29002d73
VMOVQ V2, V8 // 48002d73
XVMOVQ X3, X7 // 67002d77
XVMOVQ X4, X6 // 86002d77

// Load data from memory and broadcast to each element of a vector register: VMOVQ offset(Rj), <Vd>.<T>
VMOVQ (R4), V0.B16 // 80008030
VMOVQ 1(R4), V0.B16 // 80048030
Expand Down Expand Up @@ -1017,6 +1023,12 @@ lable2:
XVSHUF4IV $8, X1, X2 // 22209c77
XVSHUF4IV $15, X1, X2 // 223c9c77

// VPERMIW, XVPERMI{W,V,Q} instructions
VPERMIW $0x1B, V1, V2 // VPERMIW $27, V1, V2 // 226ce473
XVPERMIW $0x2B, X1, X2 // XVPERMIW $43, X1, X2 // 22ace477
XVPERMIV $0x3B, X1, X2 // XVPERMIV $59, X1, X2 // 22ece877
XVPERMIQ $0x4B, X1, X2 // XVPERMIQ $75, X1, X2 // 222ced77

// [X]VSETEQZ.V, [X]VSETNEZ.V
VSETEQV V1, FCC0 // 20989c72
VSETNEV V1, FCC0 // 209c9c72
Expand Down
14 changes: 9 additions & 5 deletions src/cmd/cgo/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa

// everything else just recurs
default:
f.walkUnexpected(x, context, visit)
error_(token.NoPos, "unexpected type %T in walk", x)
panic("unexpected type")

case nil:

Expand Down Expand Up @@ -396,6 +397,9 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa
case *ast.IndexExpr:
f.walk(&n.X, ctxExpr, visit)
f.walk(&n.Index, ctxExpr, visit)
case *ast.IndexListExpr:
f.walk(&n.X, ctxExpr, visit)
f.walk(n.Indices, ctxExpr, visit)
case *ast.SliceExpr:
f.walk(&n.X, ctxExpr, visit)
if n.Low != nil {
Expand Down Expand Up @@ -434,8 +438,8 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa
case *ast.StructType:
f.walk(n.Fields, ctxField, visit)
case *ast.FuncType:
if tparams := funcTypeTypeParams(n); tparams != nil {
f.walk(tparams, ctxParam, visit)
if n.TypeParams != nil {
f.walk(n.TypeParams, ctxParam, visit)
}
f.walk(n.Params, ctxParam, visit)
if n.Results != nil {
Expand Down Expand Up @@ -524,8 +528,8 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa
f.walk(n.Values, ctxExpr, visit)
}
case *ast.TypeSpec:
if tparams := typeSpecTypeParams(n); tparams != nil {
f.walk(tparams, ctxParam, visit)
if n.TypeParams != nil {
f.walk(n.TypeParams, ctxParam, visit)
}
f.walk(&n.Type, ctxType, visit)

Expand Down
25 changes: 0 additions & 25 deletions src/cmd/cgo/ast_go1.go

This file was deleted.

32 changes: 0 additions & 32 deletions src/cmd/cgo/ast_go118.go

This file was deleted.

2 changes: 1 addition & 1 deletion src/cmd/cgo/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ environment variable when running the go tool: set it to 1 to enable
the use of cgo, and to 0 to disable it. The go tool will set the
build constraint "cgo" if cgo is enabled. The special import "C"
implies the "cgo" build constraint, as though the file also said
"//go:build cgo". Therefore, if cgo is disabled, files that import
"//go:build cgo". Therefore, if cgo is disabled, files that import
"C" will not be built by the go tool. (For more about build constraints
see https://golang.org/pkg/go/build/#hdr-Build_Constraints).

Expand Down
10 changes: 5 additions & 5 deletions src/cmd/cgo/gcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ func (p *Package) rewriteCall(f *File, call *Call) (string, bool) {
func (p *Package) needsPointerCheck(f *File, t ast.Expr, arg ast.Expr) bool {
// An untyped nil does not need a pointer check, and when
// _cgoCheckPointer returns the untyped nil the type assertion we
// are going to insert will fail. Easier to just skip nil arguments.
// are going to insert will fail. Easier to just skip nil arguments.
// TODO: Note that this fails if nil is shadowed.
if id, ok := arg.(*ast.Ident); ok && id.Name == "nil" {
return false
Expand Down Expand Up @@ -3010,7 +3010,7 @@ func (c *typeConv) FuncType(dtype *dwarf.FuncType, pos token.Pos) *FuncType {
for i, f := range dtype.ParamType {
// gcc's DWARF generator outputs a single DotDotDotType parameter for
// function pointers that specify no parameters (e.g. void
// (*__cgo_0)()). Treat this special case as void. This case is
// (*__cgo_0)()). Treat this special case as void. This case is
// invalid according to ISO C anyway (i.e. void (*__cgo_1)(...) is not
// legal).
if _, ok := f.(*dwarf.DotDotDotType); ok && i == 0 {
Expand Down Expand Up @@ -3081,7 +3081,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType, pos token.Pos) (expr *ast.Struct
off := int64(0)

// Rename struct fields that happen to be named Go keywords into
// _{keyword}. Create a map from C ident -> Go ident. The Go ident will
// _{keyword}. Create a map from C ident -> Go ident. The Go ident will
// be mangled. Any existing identifier that already has the same name on
// the C-side will cause the Go-mangled version to be prefixed with _.
// (e.g. in a struct with fields '_type' and 'type', the latter would be
Expand Down Expand Up @@ -3309,7 +3309,7 @@ func godefsFields(fld []*ast.Field) {
// fieldPrefix returns the prefix that should be removed from all the
// field names when generating the C or Go code. For generated
// C, we leave the names as is (tv_sec, tv_usec), since that's what
// people are used to seeing in C. For generated Go code, such as
// people are used to seeing in C. For generated Go code, such as
// package syscall's data structures, we drop a common prefix
// (so sec, usec, which will get turned into Sec, Usec for exporting).
func fieldPrefix(fld []*ast.Field) string {
Expand Down Expand Up @@ -3456,7 +3456,7 @@ func (c *typeConv) badCFType(dt *dwarf.TypedefType) bool {
// Tagged pointer support
// Low-bit set means tagged object, next 3 bits (currently)
// define the tagged object class, next 4 bits are for type
// information for the specific tagged object class. Thus,
// information for the specific tagged object class. Thus,
// the low byte is for type info, and the rest of a pointer
// (32 or 64-bit) is for payload, whatever the tagged class.
//
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/cgo/internal/test/buildid_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package cgotest

// Test that we have no more than one build ID. In the past we used
// Test that we have no more than one build ID. In the past we used
// to generate a separate build ID for each package using cgo, and the
// linker concatenated them all. We don't want that--we only want
// linker concatenated them all. We don't want that--we only want
// one.

import (
Expand Down Expand Up @@ -42,7 +42,7 @@ sections:
for len(d) > 0 {

// ELF standards differ as to the sizes in
// note sections. Both the GNU linker and
// note sections. Both the GNU linker and
// gold always generate 32-bit sizes, so that
// is what we assume here.

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/internal/test/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func nestedCall(f func()) {
callbackMutex.Unlock()

// Pass the address of i because the C function was written to
// take a pointer. We could pass an int if we felt like
// take a pointer. We could pass an int if we felt like
// rewriting the C code.
C.callback(unsafe.Pointer(&i))

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/internal/test/gcc68255/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.

// Test that it's OK to have C code that does nothing other than
// initialize a global variable. This used to fail with gccgo.
// initialize a global variable. This used to fail with gccgo.

package gcc68255

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cgo/internal/teststdio/testdata/fib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//go:build test_run

// Compute Fibonacci numbers with two goroutines
// that pass integers back and forth. No actual
// that pass integers back and forth. No actual
// concurrency, just threads and synchronization
// and foreign code on multiple pthreads.

Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ type File struct {
ExpFunc []*ExpFunc // exported functions for this file
Name map[string]*Name // map from Go name to Name
NamePos map[*Name]token.Pos // map from Name to position of the first reference
NoCallbacks map[string]bool // C function names that with #cgo nocallback directive
NoEscapes map[string]bool // C function names that with #cgo noescape directive
NoCallbacks map[string]bool // C function names with #cgo nocallback directive
NoEscapes map[string]bool // C function names with #cgo noescape directive
Edit *edit.Buffer

debugs []*debug // debug data from iterations of gccDebug. Initialized by File.loadDebug.
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,10 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
if !p.hasPointer(nil, atype, false) {
return
}

// Use the export'ed file/line in error messages.
pos := fset.Position(exp.Func.Pos())
fmt.Fprintf(fgo2, "//line %s:%d\n", pos.Filename, pos.Line)
fmt.Fprintf(fgo2, "\t_cgoCheckResult(a.r%d)\n", i)
})
}
Expand Down
16 changes: 8 additions & 8 deletions src/cmd/compile/internal/ssa/_gen/RISCV64.rules
Original file line number Diff line number Diff line change
Expand Up @@ -823,16 +823,16 @@
(F(MADD|NMADD|MSUB|NMSUB)D x y neg:(FNEGD z)) && neg.Uses == 1 => (F(MSUB|NMSUB|MADD|NMADD)D x y z)

// Test for -∞ (bit 0) using 64 bit classify instruction.
(FLTD x (FMOVDconst [c])) && float64ExactBits(c, -math.MaxFloat64) => (ANDI [1] (FCLASSD x))
(FLED (FMOVDconst [c]) x) && float64ExactBits(c, -math.MaxFloat64) => (SNEZ (ANDI <typ.Int64> [0xff &^ 1] (FCLASSD x)))
(FEQD x (FMOVDconst [c])) && float64ExactBits(c, math.Inf(-1)) => (ANDI [1] (FCLASSD x))
(FNED x (FMOVDconst [c])) && float64ExactBits(c, math.Inf(-1)) => (SEQZ (ANDI <typ.Int64> [1] (FCLASSD x)))
(FLTD x (FMOVDconst [-math.MaxFloat64])) => (ANDI [0b00_0000_0001] (FCLASSD x))
(FLED (FMOVDconst [-math.MaxFloat64]) x) => (SNEZ (ANDI <typ.Int64> [0b00_1111_1110] (FCLASSD x)))
(FEQD x (FMOVDconst [math.Inf(-1)])) => (ANDI [0b00_0000_0001] (FCLASSD x))
(FNED x (FMOVDconst [math.Inf(-1)])) => (SEQZ (ANDI <typ.Int64> [0b00_0000_0001] (FCLASSD x)))

// Test for +∞ (bit 7) using 64 bit classify instruction.
(FLTD (FMOVDconst [c]) x) && float64ExactBits(c, math.MaxFloat64) => (SNEZ (ANDI <typ.Int64> [1<<7] (FCLASSD x)))
(FLED x (FMOVDconst [c])) && float64ExactBits(c, math.MaxFloat64) => (SNEZ (ANDI <typ.Int64> [0xff &^ (1<<7)] (FCLASSD x)))
(FEQD x (FMOVDconst [c])) && float64ExactBits(c, math.Inf(1)) => (SNEZ (ANDI <typ.Int64> [1<<7] (FCLASSD x)))
(FNED x (FMOVDconst [c])) && float64ExactBits(c, math.Inf(1)) => (SEQZ (ANDI <typ.Int64> [1<<7] (FCLASSD x)))
(FLTD (FMOVDconst [math.MaxFloat64]) x) => (SNEZ (ANDI <typ.Int64> [0b00_1000_0000] (FCLASSD x)))
(FLED x (FMOVDconst [math.MaxFloat64])) => (SNEZ (ANDI <typ.Int64> [0b00_0111_1111] (FCLASSD x)))
(FEQD x (FMOVDconst [math.Inf(1)])) => (SNEZ (ANDI <typ.Int64> [0b00_1000_0000] (FCLASSD x)))
(FNED x (FMOVDconst [math.Inf(1)])) => (SEQZ (ANDI <typ.Int64> [0b00_1000_0000] (FCLASSD x)))

//
// Optimisations for rva22u64 and above.
Expand Down
Loading