Skip to content

Commit e0ce965

Browse files
authored
Merge branch 'golang:master' into master
2 parents f397da8 + 4d1c255 commit e0ce965

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1327
-351
lines changed

api/go1.25.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pkg testing, method (*F) Output() io.Writer #59928
101101
pkg testing, method (*T) Attr(string, string) #43936
102102
pkg testing, method (*T) Output() io.Writer #59928
103103
pkg testing, type TB interface, Attr(string, string) #43936
104+
pkg testing, type TB interface, Output() io.Writer #59928
104105
pkg testing/fstest, method (MapFS) Lstat(string) (fs.FileInfo, error) #49580
105106
pkg testing/fstest, method (MapFS) ReadLink(string) (string, error) #49580
106107
pkg testing/synctest, func Test(*testing.T, func(*testing.T)) #67434

src/cmd/compile/internal/inline/inl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ func inlineCallCheck(callerfn *ir.Func, call *ir.CallExpr) (bool, bool) {
785785
if call.Op() != ir.OCALLFUNC {
786786
return false, false
787787
}
788-
if call.GoDefer {
788+
if call.GoDefer || call.NoInline {
789789
return false, false
790790
}
791791

src/cmd/compile/internal/inline/interleaved/interleaved.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,12 @@ func (s *inlClosureState) mark(n ir.Node) ir.Node {
279279

280280
ok := match(n)
281281

282-
ir.EditChildren(n, s.mark)
282+
// can't wrap TailCall's child into ParenExpr
283+
if t, ok := n.(*ir.TailCallStmt); ok {
284+
ir.EditChildren(t.Call, s.mark)
285+
} else {
286+
ir.EditChildren(n, s.mark)
287+
}
283288

284289
if ok {
285290
if p == nil {
@@ -317,23 +322,6 @@ func (s *inlClosureState) unparenthesize() {
317322
n = paren.X
318323
}
319324
ir.EditChildren(n, unparen)
320-
// special case for tail calls: if the tail call was inlined, transform
321-
// the tail call to a return stmt if the inlined function was not void,
322-
// otherwise replace it with the inlined expression followed by a return.
323-
if tail, ok := n.(*ir.TailCallStmt); ok {
324-
if inl, done := tail.Call.(*ir.InlinedCallExpr); done {
325-
if len(inl.ReturnVars) != 0 {
326-
ret := ir.NewReturnStmt(tail.Pos(), []ir.Node{inl})
327-
if len(inl.ReturnVars) > 1 {
328-
typecheck.RewriteMultiValueCall(ret, inl)
329-
}
330-
n = ret
331-
} else {
332-
ret := ir.NewReturnStmt(tail.Pos(), nil)
333-
n = ir.NewBlockStmt(tail.Pos(), []ir.Node{inl, ret})
334-
}
335-
}
336-
}
337325
return n
338326
}
339327
ir.EditChildren(s.fn, unparen)
@@ -370,9 +358,11 @@ func (s *inlClosureState) fixpoint() bool {
370358
}
371359

372360
func match(n ir.Node) bool {
373-
switch n.(type) {
361+
switch n := n.(type) {
374362
case *ir.CallExpr:
375363
return true
364+
case *ir.TailCallStmt:
365+
n.Call.NoInline = true // can't inline yet
376366
}
377367
return false
378368
}

src/cmd/compile/internal/ir/expr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ type CallExpr struct {
191191
KeepAlive []*Name // vars to be kept alive until call returns
192192
IsDDD bool
193193
GoDefer bool // whether this call is part of a go or defer statement
194+
NoInline bool // whether this call must not be inlined
194195
}
195196

196197
func NewCallExpr(pos src.XPos, op Op, fun Node, args []Node) *CallExpr {

src/cmd/compile/internal/ir/node_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ir/stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseClause) *SwitchStmt {
479479
// code generation to jump directly to another function entirely.
480480
type TailCallStmt struct {
481481
miniStmt
482-
Call Node // the underlying call
482+
Call *CallExpr // the underlying call
483483
}
484484

485485
func NewTailCallStmt(pos src.XPos, call *CallExpr) *TailCallStmt {

src/cmd/compile/internal/noder/doc.go

Lines changed: 111 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ determines its index in the series.
2525
SectionMeta
2626
SectionPosBase
2727
SectionPkg
28-
SectionName // TODO(markfreeman) Define.
29-
SectionType // TODO(markfreeman) Define.
30-
SectionObj // TODO(markfreeman) Define.
28+
SectionName
29+
SectionType
30+
SectionObj
3131
SectionObjExt // TODO(markfreeman) Define.
3232
SectionObjDict // TODO(markfreeman) Define.
3333
SectionBody // TODO(markfreeman) Define.
3434
.
3535
3636
# Sections
3737
A section is a series of elements of a type determined by the section's
38-
kind. Go constructs are mapped onto (potentially multiple) elements.
39-
Elements are accessed using an index relative to the start of the
40-
section.
38+
kind. Go constructs are mapped onto one or more elements with possibly
39+
different types; in that case, the elements are in different sections.
40+
41+
Elements are accessed using an element index relative to the start of
42+
the section.
4143
4244
RelElemIdx = Uint64 .
4345
@@ -47,6 +49,9 @@ outside the string section access string values by reference.
4749
4850
SectionString = { String } .
4951
52+
Note that despite being an element, a string does not begin with a
53+
reference table.
54+
5055
## Meta Section
5156
The meta section provides fundamental information for a package. It
5257
contains exactly two elements — a public root and a private root.
@@ -135,6 +140,97 @@ Note, a PkgRef is *not* equivalent to Ref[Pkg] due to an extra marker.
135140
Ref[Pkg]
136141
.
137142
143+
## Type Section
144+
The type section is a series of type definition elements.
145+
146+
SectionType = { TypeDef } .
147+
148+
A type definition can be in one of several formats, which are identified
149+
by their TypeSpec code.
150+
151+
TypeDef = RefTable
152+
[ Sync ]
153+
[ Sync ]
154+
Uint64 // denotes which TypeSpec to use
155+
TypeSpec
156+
.
157+
158+
TypeSpec = TypeSpecBasic // TODO(markfreeman): Define.
159+
| TypeSpecNamed // TODO(markfreeman): Define.
160+
| TypeSpecPointer // TODO(markfreeman): Define.
161+
| TypeSpecSlice // TODO(markfreeman): Define.
162+
| TypeSpecArray // TODO(markfreeman): Define.
163+
| TypeSpecChan // TODO(markfreeman): Define.
164+
| TypeSpecMap // TODO(markfreeman): Define.
165+
| TypeSpecSignature // TODO(markfreeman): Define.
166+
| TypeSpecStruct // TODO(markfreeman): Define.
167+
| TypeSpecInterface // TODO(markfreeman): Define.
168+
| TypeSpecUnion // TODO(markfreeman): Define.
169+
| TypeSpecTypeParam // TODO(markfreeman): Define.
170+
.
171+
172+
// TODO(markfreeman): Document the reader dictionary once we understand it more.
173+
To use a type elsewhere, a TypeUse is encoded.
174+
175+
TypeUse = [ Sync ]
176+
Bool // whether it is a derived type
177+
[ Uint64 ] // if derived, an index into the reader dictionary
178+
[ Ref[TypeDef] ] // else, a reference to the type
179+
.
180+
181+
## Object Sections
182+
Information about an object (e.g. variable, function, type name, etc.)
183+
is split into multiple elements in different sections. Those elements
184+
have the same section-relative element index.
185+
186+
### Name Section
187+
The name section holds a series of names.
188+
189+
SectionName = { Name } .
190+
191+
Names are elements holding qualified identifiers and type information
192+
for objects.
193+
194+
Name = RefTable
195+
[ Sync ]
196+
[ Sync ]
197+
PkgRef // the object's package
198+
StringRef // the object's package-local name
199+
[ Sync ]
200+
Uint64 // the object's type (e.g. Var, Func, etc.)
201+
.
202+
203+
### Definition Section
204+
The definition section holds definitions for objects defined by the target
205+
package; it does not contain definitions for imported objects.
206+
207+
SectionObj = { ObjectDef } .
208+
209+
Object definitions can be in one of several formats. To determine the correct
210+
format, the name section must be referenced; it contains a code indicating
211+
the object's type.
212+
213+
ObjectDef = RefTable
214+
[ Sync ]
215+
ObjectSpec
216+
.
217+
218+
ObjectSpec = ObjectSpecConst // TODO(markfreeman) Define.
219+
| ObjectSpecFunc // TODO(markfreeman) Define.
220+
| ObjectSpecAlias // TODO(markfreeman) Define.
221+
| ObjectSpecNamedType // TODO(markfreeman) Define.
222+
| ObjectSpecVar // TODO(markfreeman) Define.
223+
.
224+
225+
To use an object definition elsewhere, an ObjectUse is encoded.
226+
227+
ObjectUse = [ Sync ]
228+
[ Bool ]
229+
Ref[ObjectDef]
230+
Uint64 // the number of type arguments
231+
{ TypeUse } // references to the type arguments
232+
.
233+
138234
# References
139235
A reference table precedes every element. Each entry in the table
140236
contains a (section, index) pair denoting the location of the
@@ -152,10 +248,15 @@ referenced element.
152248
Elements encode references to other elements as an index in the
153249
reference table — not the location of the referenced element directly.
154250
155-
// TODO(markfreeman): Rename to RefUse.
156-
UseReloc = [ Sync ]
157-
RelElemIdx
158-
.
251+
RefTableIdx = Uint64 .
252+
253+
To do this, the Ref[T] primitive is used as below; note that this is
254+
the same shape as provided by package pkgbits, just with new
255+
interpretation applied.
256+
257+
Ref[T] = [ Sync ]
258+
RefTableIdx // the Uint64
259+
.
159260
160261
# Primitives
161262
Primitive encoding is handled separately by the pkgbits package. Check

src/cmd/compile/internal/noder/noder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func Renameinit() *types.Sym {
458458
func checkEmbed(decl *syntax.VarDecl, haveEmbed, withinFunc bool) error {
459459
switch {
460460
case !haveEmbed:
461-
return errors.New("go:embed only allowed in Go files that import \"embed\"")
461+
return errors.New("go:embed requires import \"embed\" (or import _ \"embed\", if package is not used)")
462462
case len(decl.NameList) > 1:
463463
return errors.New("go:embed cannot apply to multiple vars")
464464
case decl.Values != nil:

src/cmd/compile/internal/noder/reader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3996,11 +3996,12 @@ func addTailCall(pos src.XPos, fn *ir.Func, recv ir.Node, method *types.Field) {
39963996

39973997
if recv.Type() != nil && recv.Type().IsPtr() && method.Type.Recv().Type.IsPtr() &&
39983998
method.Embedded != 0 && !types.IsInterfaceMethod(method.Type) &&
3999+
!unifiedHaveInlineBody(ir.MethodExprName(dot).Func) &&
39994000
!(base.Ctxt.Arch.Name == "ppc64le" && base.Ctxt.Flag_dynlink) {
40004001
if base.Debug.TailCall != 0 {
40014002
base.WarnfAt(fn.Nname.Type().Recv().Type.Elem().Pos(), "tail call emitted for the method %v wrapper", method.Nname)
40024003
}
4003-
// Prefer OTAILCALL to reduce code size (the called method can be inlined).
4004+
// Prefer OTAILCALL to reduce code size (except the case when the called method can be inlined).
40044005
fn.Body.Append(ir.NewTailCallStmt(pos, call))
40054006
return
40064007
}

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ func (s *state) stmt(n ir.Node) {
19211921

19221922
case ir.OTAILCALL:
19231923
n := n.(*ir.TailCallStmt)
1924-
s.callResult(n.Call.(*ir.CallExpr), callTail)
1924+
s.callResult(n.Call, callTail)
19251925
call := s.mem()
19261926
b := s.endBlock()
19271927
b.Kind = ssa.BlockRetJmp // could use BlockExit. BlockRetJmp is mostly for clarity.

src/cmd/compile/internal/typecheck/stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ assignOK:
137137
if cr > len(rhs) {
138138
stmt := stmt.(*ir.AssignListStmt)
139139
stmt.SetOp(ir.OAS2FUNC)
140-
r := rhs[0]
140+
r := rhs[0].(*ir.CallExpr)
141141
rtyp := r.Type()
142142

143143
mismatched := false

src/cmd/compile/internal/types2/stdlib_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func TestStdFixed(t *testing.T) {
333333
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
334334
"issue52697.go", // types2 does not have constraints on stack size
335335
"issue73309.go", // this test requires GODEBUG=gotypesalias=1
336+
"issue73309b.go", // this test requires GODEBUG=gotypesalias=1
336337

337338
// These tests requires runtime/cgo.Incomplete, which is only available on some platforms.
338339
// However, types2 does not know about build constraints.

src/cmd/compile/internal/walk/stmt.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ func walkStmt(n ir.Node) ir.Node {
139139
n := n.(*ir.TailCallStmt)
140140

141141
var init ir.Nodes
142-
call := n.Call.(*ir.CallExpr)
143-
call.Fun = walkExpr(call.Fun, &init)
142+
n.Call.Fun = walkExpr(n.Call.Fun, &init)
144143

145144
if len(init) > 0 {
146145
init.Append(n)

src/cmd/dist/build.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ func cmdbootstrap() {
15161516
}
15171517

15181518
// To recap, so far we have built the new toolchain
1519-
// (cmd/asm, cmd/cgo, cmd/compile, cmd/link)
1519+
// (cmd/asm, cmd/cgo, cmd/compile, cmd/link, cmd/preprofile)
15201520
// using the Go bootstrap toolchain and go command.
15211521
// Then we built the new go command (as go_bootstrap)
15221522
// using the new toolchain and our own build logic (above).
@@ -1589,6 +1589,18 @@ func cmdbootstrap() {
15891589
os.Setenv("GOCACHE", oldgocache)
15901590
}
15911591

1592+
// Keep in sync with binExes in cmd/distpack/pack.go.
1593+
binExesIncludedInDistpack := []string{"cmd/go", "cmd/gofmt"}
1594+
1595+
// Keep in sync with the filter in cmd/distpack/pack.go.
1596+
toolsIncludedInDistpack := []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/cover", "cmd/link", "cmd/preprofile", "cmd/vet"}
1597+
1598+
// We could install all tools in "cmd", but is unnecessary because we will
1599+
// remove them in distpack, so instead install the tools that will actually
1600+
// be included in distpack, which is a superset of toolchain. Not installing
1601+
// the tools will help us test what happens when the tools aren't present.
1602+
toolsToInstall := slices.Concat(binExesIncludedInDistpack, toolsIncludedInDistpack)
1603+
15921604
if goos == oldgoos && goarch == oldgoarch {
15931605
// Common case - not setting up for cross-compilation.
15941606
timelog("build", "toolchain")
@@ -1605,9 +1617,9 @@ func cmdbootstrap() {
16051617
xprintf("\n")
16061618
}
16071619
xprintf("Building commands for host, %s/%s.\n", goos, goarch)
1608-
goInstall(toolenv(), goBootstrap, "cmd")
1609-
checkNotStale(toolenv(), goBootstrap, "cmd")
1610-
checkNotStale(toolenv(), gorootBinGo, "cmd")
1620+
goInstall(toolenv(), goBootstrap, toolsToInstall...)
1621+
checkNotStale(toolenv(), goBootstrap, toolsToInstall...)
1622+
checkNotStale(toolenv(), gorootBinGo, toolsToInstall...)
16111623

16121624
timelog("build", "target toolchain")
16131625
if vflag > 0 {
@@ -1621,12 +1633,12 @@ func cmdbootstrap() {
16211633
xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
16221634
}
16231635
goInstall(nil, goBootstrap, "std")
1624-
goInstall(toolenv(), goBootstrap, "cmd")
1636+
goInstall(toolenv(), goBootstrap, toolsToInstall...)
16251637
checkNotStale(toolenv(), goBootstrap, toolchain...)
16261638
checkNotStale(nil, goBootstrap, "std")
1627-
checkNotStale(toolenv(), goBootstrap, "cmd")
1639+
checkNotStale(toolenv(), goBootstrap, toolsToInstall...)
16281640
checkNotStale(nil, gorootBinGo, "std")
1629-
checkNotStale(toolenv(), gorootBinGo, "cmd")
1641+
checkNotStale(toolenv(), gorootBinGo, toolsToInstall...)
16301642
if debug {
16311643
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
16321644
checkNotStale(toolenv(), goBootstrap, toolchain...)
@@ -1677,7 +1689,7 @@ func cmdbootstrap() {
16771689

16781690
if distpack {
16791691
xprintf("Packaging archives for %s/%s.\n", goos, goarch)
1680-
run("", ShowOutput|CheckExit, pathf("%s/distpack", tooldir))
1692+
run("", ShowOutput|CheckExit, gorootBinGo, "tool", "distpack")
16811693
}
16821694

16831695
// Print trailing banner unless instructed otherwise.

src/cmd/distpack/pack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func main() {
171171
switch strings.TrimSuffix(path.Base(name), ".exe") {
172172
default:
173173
return false
174+
// Keep in sync with toolsIncludedInDistpack in cmd/dist/build.go.
174175
case "asm", "cgo", "compile", "cover", "link", "preprofile", "vet":
175176
}
176177
}
@@ -179,6 +180,7 @@ func main() {
179180

180181
// Add go and gofmt to bin, using cross-compiled binaries
181182
// if this is a cross-compiled distribution.
183+
// Keep in sync with binExesIncludedInDistpack in cmd/dist/build.go.
182184
binExes := []string{
183185
"go",
184186
"gofmt",

0 commit comments

Comments
 (0)