Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5500cbf
debug/elf: prevent offset overflow
callthingsoff Sep 25, 2025
6d51f93
runtime: jump instead of branch in netbsd/arm64 entry point
qmuntal Sep 29, 2025
d42d56b
encoding/xml: make use of reflect.TypeAssert
apocelipes Sep 24, 2025
fe3ba74
cmd/link: skip TestFlagW on platforms without DWARF symbol table
millerresearch Sep 27, 2025
ae8eba0
cmd/link: use correct length for pcln.cutab
ianlancetaylor Sep 29, 2025
047c2ab
cmd/link: don't pass -Wl,-S on Solaris
cherrymui Sep 26, 2025
4e9006a
crypto/tls: quote protocols in ALPN error message
rolandshoemaker Sep 29, 2025
4b77733
internal/syscall/windows: regenerate GetFileSizeEx
qmuntal Sep 29, 2025
eaf2345
cmd/link: use a .def file to mark exported symbols on Windows
qmuntal Sep 22, 2025
690fc2f
internal/poll: remove buf field from operation
qmuntal Sep 16, 2025
db3cb3f
runtime: correct reference to getStackMap in comment
ianlancetaylor Sep 29, 2025
db4fade
crypto/internal/fips140/mlkem: make CAST conditional
FiloSottile Sep 22, 2025
fc88e18
crypto/internal/fips140/entropy: add CPU jitter-based entropy source
FiloSottile Sep 11, 2025
75c87df
internal/poll: pass the I/O mode instead of an overlapped object in e…
qmuntal Sep 16, 2025
db10db6
internal/poll: remove operation fields from FD
qmuntal Sep 16, 2025
742f920
cmd/compile, runtime: always enable Wasm signext and satconv features
cherrymui Sep 29, 2025
6e95748
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_POINTER_TO_GOT in…
qmuntal Sep 12, 2025
7c8166d
cmd/link/internal/arm64: support Mach-O ARM64_RELOC_SUBTRACTOR in int…
qmuntal Sep 12, 2025
a846bb0
errors: add AsType
jub0bs Sep 29, 2025
300d9d2
runtime: initialise debug settings much earlier in startup process
9muir Sep 18, 2025
97da068
cmd/compile: eliminate nil checks on .dict arg
jakebailey Sep 8, 2025
08afc50
mime: extend "builtinTypes" to include a more complete list of common…
AidanWelch Sep 25, 2025
19cc102
mime: reduce allocs incurred by ParseMediaType
jub0bs Sep 22, 2025
fcb893f
cmd/compile/internal/ssa: remove redundant "type:" prefix check
fengyoulin Sep 5, 2025
4ff8a45
test/codegen: codify handling of floating point constants on arm64
4a6f656c Sep 15, 2025
c925715
runtime: unify ppc64/ppc64le library entry point
qmuntal Sep 24, 2025
eb1c7f6
runtime: move loong64 library entry point to os-agnostic file
qmuntal Sep 24, 2025
be0fed8
cmd/go/testdata/script/test_fuzz_fuzztime.txt: disable
adonovan Sep 30, 2025
3f451f2
testing/synctest: fix inverted test failure message in TestContextAft…
fgm Oct 1, 2025
8ad27fb
doc/go_spec.html: update date
adonovan Oct 1, 2025
a0d7e69
html/template,text/template: use errors.New instead of fmt.Errorf
apocelipes Oct 1, 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/51945.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg errors, func AsType[$0 error](error) ($0, bool) #51945
2 changes: 1 addition & 1 deletion doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Language version go1.25 (Feb 25, 2025)",
"Subtitle": "Language version go1.26 (Oct 1, 2025)",
"Path": "/ref/spec"
}-->

Expand Down
2 changes: 2 additions & 0 deletions doc/next/6-stdlib/99-minor/errors/51945.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The new [AsType] function is a generic version of [As]. It is type-safe, faster,
and, in most cases, easier to use.
75 changes: 31 additions & 44 deletions src/cmd/cgo/internal/testcshared/cshared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"cmd/cgo/internal/cgotest"
"cmp"
"debug/elf"
"debug/pe"
"encoding/binary"
Expand Down Expand Up @@ -272,7 +273,7 @@ func createHeaders() error {
// which results in the linkers output implib getting overwritten at each step. So instead build the
// import library the traditional way, using a def file.
err = os.WriteFile("libgo.def",
[]byte("LIBRARY libgo.dll\nEXPORTS\n\tDidInitRun\n\tDidMainRun\n\tDivu\n\tFromPkg\n\t_cgo_dummy_export\n"),
[]byte("LIBRARY libgo.dll\nEXPORTS\n\tDidInitRun\n\tDidMainRun\n\tDivu\n\tFromPkg\n"),
0644)
if err != nil {
return fmt.Errorf("unable to write def file: %v", err)
Expand Down Expand Up @@ -375,9 +376,23 @@ func TestExportedSymbols(t *testing.T) {
}
}

func checkNumberOfExportedFunctionsWindows(t *testing.T, prog string, exportedFunctions int, wantAll bool) {
func checkNumberOfExportedSymbolsWindows(t *testing.T, exportedSymbols int, wantAll bool) {
t.Parallel()
tmpdir := t.TempDir()

prog := `
package main
import "C"
func main() {}
`

for i := range exportedSymbols {
prog += fmt.Sprintf(`
//export GoFunc%d
func GoFunc%d() {}
`, i, i)
}

srcfile := filepath.Join(tmpdir, "test.go")
objfile := filepath.Join(tmpdir, "test.dll")
if err := os.WriteFile(srcfile, []byte(prog), 0666); err != nil {
Expand Down Expand Up @@ -443,18 +458,19 @@ func checkNumberOfExportedFunctionsWindows(t *testing.T, prog string, exportedFu
t.Fatalf("binary.Read failed: %v", err)
}

// Only the two exported functions and _cgo_dummy_export should be exported.
exportedSymbols = cmp.Or(exportedSymbols, 1) // _cgo_stub_export is exported if there are no other symbols exported

// NumberOfNames is the number of functions exported with a unique name.
// NumberOfFunctions can be higher than that because it also counts
// functions exported only by ordinal, a unique number asigned by the linker,
// and linkers might add an unknown number of their own ordinal-only functions.
if wantAll {
if e.NumberOfNames <= uint32(exportedFunctions) {
t.Errorf("got %d exported names, want > %d", e.NumberOfNames, exportedFunctions)
if e.NumberOfNames <= uint32(exportedSymbols) {
t.Errorf("got %d exported names, want > %d", e.NumberOfNames, exportedSymbols)
}
} else {
if e.NumberOfNames > uint32(exportedFunctions) {
t.Errorf("got %d exported names, want <= %d", e.NumberOfNames, exportedFunctions)
if e.NumberOfNames != uint32(exportedSymbols) {
t.Errorf("got %d exported names, want %d", e.NumberOfNames, exportedSymbols)
}
}
}
Expand All @@ -470,43 +486,14 @@ func TestNumberOfExportedFunctions(t *testing.T) {

t.Parallel()

const prog0 = `
package main

import "C"

func main() {
}
`

const prog2 = `
package main

import "C"

//export GoFunc
func GoFunc() {
println(42)
}

//export GoFunc2
func GoFunc2() {
println(24)
}

func main() {
}
`
// All programs export _cgo_dummy_export, so add 1 to the expected counts.
t.Run("OnlyExported/0", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog0, 0+1, false)
})
t.Run("OnlyExported/2", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog2, 2+1, false)
})
t.Run("All", func(t *testing.T) {
checkNumberOfExportedFunctionsWindows(t, prog2, 2+1, true)
})
for i := range 3 {
t.Run(fmt.Sprintf("OnlyExported/%d", i), func(t *testing.T) {
checkNumberOfExportedSymbolsWindows(t, i, false)
})
t.Run(fmt.Sprintf("All/%d", i), func(t *testing.T) {
checkNumberOfExportedSymbolsWindows(t, i, true)
})
}
}

// test1: shared library can be dynamically loaded and exported symbols are accessible.
Expand Down
6 changes: 1 addition & 5 deletions src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,8 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
}

// Build the wrapper function compiled by gcc.
gccExport := ""
if goos == "windows" {
gccExport = "__declspec(dllexport) "
}
var s strings.Builder
fmt.Fprintf(&s, "%s%s %s(", gccExport, gccResult, exp.ExpName)
fmt.Fprintf(&s, "%s %s(", gccResult, exp.ExpName)
if fn.Recv != nil {
s.WriteString(p.cgoType(fn.Recv.List[0].Type).C.String())
s.WriteString(" recv")
Expand Down
9 changes: 3 additions & 6 deletions src/cmd/compile/internal/ssa/_gen/Wasm.rules
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@
(ZeroExt32to64 x:(I64Load32U _ _)) => x
(ZeroExt16to(64|32) x:(I64Load16U _ _)) => x
(ZeroExt8to(64|32|16) x:(I64Load8U _ _)) => x
(SignExt32to64 x) && buildcfg.GOWASM.SignExt => (I64Extend32S x)
(SignExt8to(64|32|16) x) && buildcfg.GOWASM.SignExt => (I64Extend8S x)
(SignExt16to(64|32) x) && buildcfg.GOWASM.SignExt => (I64Extend16S x)
(SignExt32to64 x) => (I64ShrS (I64Shl x (I64Const [32])) (I64Const [32]))
(SignExt16to(64|32) x) => (I64ShrS (I64Shl x (I64Const [48])) (I64Const [48]))
(SignExt8to(64|32|16) x) => (I64ShrS (I64Shl x (I64Const [56])) (I64Const [56]))
(SignExt32to64 x) => (I64Extend32S x)
(SignExt8to(64|32|16) x) => (I64Extend8S x)
(SignExt16to(64|32) x) => (I64Extend16S x)
(ZeroExt32to64 x) => (I64And x (I64Const [0xffffffff]))
(ZeroExt16to(64|32) x) => (I64And x (I64Const [0xffff]))
(ZeroExt8to(64|32|16) x) => (I64And x (I64Const [0xff]))
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/ssa/_gen/generic.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,9 @@
&& warnRule(fe.Debug_checknil(), v, "removed nil check")
=> ptr

// .dict args are always non-nil.
(NilCheck ptr:(Arg {sym}) _) && isDictArgSym(sym) => ptr

// Nil checks of nil checks are redundant.
// See comment at the end of https://go-review.googlesource.com/c/go/+/537775.
(NilCheck ptr:(NilCheck _ _) _ ) => ptr
Expand Down
24 changes: 12 additions & 12 deletions src/cmd/compile/internal/ssa/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ package ssa

import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/logopt"
"cmd/compile/internal/reflectdata"
"cmd/compile/internal/rttype"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/s390x"
Expand Down Expand Up @@ -2057,12 +2059,12 @@ func isFixedLoad(v *Value, sym Sym, off int64) bool {
return false
}

if strings.HasPrefix(lsym.Name, "type:") {
if ti := lsym.TypeInfo(); ti != nil {
// Type symbols do not contain information about their fields, unlike the cases above.
// Hand-implement field accesses.
// TODO: can this be replaced with reflectdata.writeType and just use the code above?

t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
t := ti.Type.(*types.Type)

for _, f := range rttype.Type.Fields() {
if f.Offset == off && copyCompatibleType(v.Type, f.Type) {
Expand Down Expand Up @@ -2116,12 +2118,12 @@ func rewriteFixedLoad(v *Value, sym Sym, sb *Value, off int64) *Value {
base.Fatalf("fixedLoad data not known for %s:%d", sym, off)
}

if strings.HasPrefix(lsym.Name, "type:") {
if ti := lsym.TypeInfo(); ti != nil {
// Type symbols do not contain information about their fields, unlike the cases above.
// Hand-implement field accesses.
// TODO: can this be replaced with reflectdata.writeType and just use the code above?

t := (*lsym.Extra).(*obj.TypeInfo).Type.(*types.Type)
t := ti.Type.(*types.Type)

ptrSizedOpConst := OpConst64
if f.Config.PtrSize == 4 {
Expand Down Expand Up @@ -2611,10 +2613,7 @@ func isDirectType1(v *Value) bool {
return isDirectType2(v.Args[0])
case OpAddr:
lsym := v.Aux.(*obj.LSym)
if lsym.Extra == nil {
return false
}
if ti, ok := (*lsym.Extra).(*obj.TypeInfo); ok {
if ti := lsym.TypeInfo(); ti != nil {
return types.IsDirectIface(ti.Type.(*types.Type))
}
}
Expand Down Expand Up @@ -2647,10 +2646,7 @@ func isDirectIface1(v *Value, depth int) bool {
return isDirectIface2(v.Args[0], depth-1)
case OpAddr:
lsym := v.Aux.(*obj.LSym)
if lsym.Extra == nil {
return false
}
if ii, ok := (*lsym.Extra).(*obj.ItabInfo); ok {
if ii := lsym.ItabInfo(); ii != nil {
return types.IsDirectIface(ii.Type.(*types.Type))
}
case OpConstNil:
Expand Down Expand Up @@ -2744,3 +2740,7 @@ func panicBoundsCToAux(p PanicBoundsC) Aux {
func panicBoundsCCToAux(p PanicBoundsCC) Aux {
return p
}

func isDictArgSym(sym Sym) bool {
return sym.(*ir.Name).Sym().Name == typecheck.LocalDictName
}
Loading