Skip to content

Commit dba4466

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b473ee0 + dad4f39 commit dba4466

File tree

40 files changed

+952
-292
lines changed

40 files changed

+952
-292
lines changed

api/next/70280.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pkg log/slog, method (Record) Source() *Source #70280

doc/go_spec.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7894,7 +7894,7 @@ <h3 id="Handling_panics">Handling panics</h3>
78947894
<p>
78957895
The <code>protect</code> function in the example below invokes
78967896
the function argument <code>g</code> and protects callers from
7897-
run-time panics raised by <code>g</code>.
7897+
run-time panics caused by <code>g</code>.
78987898
</p>
78997899

79007900
<pre>

doc/next/4-runtime.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
<!-- go.dev/issue/71517 -->
44

55
The message printed when a program exits due to an unhandled panic
6-
that was recovered and re-raised no longer repeats the text of
6+
that was recovered and repanicked no longer repeats the text of
77
the panic value.
88

99
Previously, a program which panicked with `panic("PANIC")`,
10-
recovered the panic, and then re-panicked with the original
10+
recovered the panic, and then repanicked with the original
1111
value would print:
1212

1313
panic: PANIC [recovered]
1414
panic: PANIC
1515

1616
This program will now print:
1717

18-
panic: PANIC [recovered, reraised]
18+
panic: PANIC [recovered, repanicked]
1919

2020
<!-- go.dev/issue/71546 -->
2121

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Record] now has a Source() method, returning its source location or nil if unavailable.

src/cmd/compile/internal/importer/ureader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ type readerTypeBound struct {
8484
boundIdx int
8585
}
8686

87-
func (pr *pkgReader) newReader(k pkgbits.RelocKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader {
87+
func (pr *pkgReader) newReader(k pkgbits.SectionKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader {
8888
return &reader{
8989
Decoder: pr.NewDecoder(k, idx, marker),
9090
p: pr,
9191
}
9292
}
9393

94-
func (pr *pkgReader) tempReader(k pkgbits.RelocKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader {
94+
func (pr *pkgReader) tempReader(k pkgbits.SectionKind, idx pkgbits.Index, marker pkgbits.SyncMarker) *reader {
9595
return &reader{
9696
Decoder: pr.TempDecoder(k, idx, marker),
9797
p: pr,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (l *linker) relocAll(pr *pkgReader, relocs []pkgbits.RelocEnt) []pkgbits.Re
5858

5959
// relocIdx ensures a single element is copied into the output export
6060
// data file, and returns the corresponding index in the output.
61-
func (l *linker) relocIdx(pr *pkgReader, k pkgbits.RelocKind, idx index) index {
61+
func (l *linker) relocIdx(pr *pkgReader, k pkgbits.SectionKind, idx index) index {
6262
assert(pr != nil)
6363

6464
absIdx := pr.AbsIdx(k, idx)
@@ -252,7 +252,7 @@ func (l *linker) exportBody(obj *ir.Name, local bool) {
252252

253253
// relocCommon copies the specified element from pr into w,
254254
// recursively relocating any referenced elements as well.
255-
func (l *linker) relocCommon(pr *pkgReader, w *pkgbits.Encoder, k pkgbits.RelocKind, idx index) {
255+
func (l *linker) relocCommon(pr *pkgReader, w *pkgbits.Encoder, k pkgbits.SectionKind, idx index) {
256256
r := pr.NewDecoderRaw(k, idx)
257257
w.Relocs = l.relocAll(pr, r.Relocs)
258258
io.Copy(&w.Data, &r.Data)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type pkgReaderIndex struct {
7474
synthetic func(pos src.XPos, r *reader)
7575
}
7676

77-
func (pri pkgReaderIndex) asReader(k pkgbits.RelocKind, marker pkgbits.SyncMarker) *reader {
77+
func (pri pkgReaderIndex) asReader(k pkgbits.SectionKind, marker pkgbits.SyncMarker) *reader {
7878
if pri.synthetic != nil {
7979
return &reader{synthetic: pri.synthetic}
8080
}
@@ -85,7 +85,7 @@ func (pri pkgReaderIndex) asReader(k pkgbits.RelocKind, marker pkgbits.SyncMarke
8585
return r
8686
}
8787

88-
func (pr *pkgReader) newReader(k pkgbits.RelocKind, idx index, marker pkgbits.SyncMarker) *reader {
88+
func (pr *pkgReader) newReader(k pkgbits.SectionKind, idx index, marker pkgbits.SyncMarker) *reader {
8989
return &reader{
9090
Decoder: pr.NewDecoder(k, idx, marker),
9191
p: pr,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (dict *writerDict) itabIdx(typInfo, ifaceInfo typeInfo) int {
367367
return idx
368368
}
369369

370-
func (pw *pkgWriter) newWriter(k pkgbits.RelocKind, marker pkgbits.SyncMarker) *writer {
370+
func (pw *pkgWriter) newWriter(k pkgbits.SectionKind, marker pkgbits.SyncMarker) *writer {
371371
return &writer{
372372
Encoder: pw.NewEncoder(k, marker),
373373
p: pw,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var nopos syntax.Pos
2020
// debugging/development support
2121
const debug = false // leave on during development
2222

23+
// position tracing for panics during type checking
24+
const tracePos = false // TODO(markfreeman): check performance implications
25+
2326
// _aliasAny changes the behavior of [Scope.Lookup] for "any" in the
2427
// [Universe] scope.
2528
//
@@ -178,7 +181,8 @@ type Checker struct {
178181
environment
179182

180183
// debugging
181-
indent int // indentation for tracing
184+
posStack []syntax.Pos // stack of source positions seen; used for panic tracing
185+
indent int // indentation for tracing
182186
}
183187

184188
// addDeclDep adds the dependency edge (check.decl -> to) if check.decl exists
@@ -396,6 +400,16 @@ func versionMax(a, b goVersion) goVersion {
396400
return b
397401
}
398402

403+
// pushPos pushes pos onto the pos stack.
404+
func (check *Checker) pushPos(pos syntax.Pos) {
405+
check.posStack = append(check.posStack, pos)
406+
}
407+
408+
// popPos pops from the pos stack.
409+
func (check *Checker) popPos() {
410+
check.posStack = check.posStack[:len(check.posStack)-1]
411+
}
412+
399413
// A bailout panic is used for early termination.
400414
type bailout struct{}
401415

@@ -405,6 +419,7 @@ func (check *Checker) handleBailout(err *error) {
405419
// normal return or early exit
406420
*err = check.firstErr
407421
default:
422+
// TODO(markfreeman): dump posStack if available
408423
// re-panic
409424
panic(p)
410425
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ func pathString(path []Object) string {
4848
// objDecl type-checks the declaration of obj in its respective (file) environment.
4949
// For the meaning of def, see Checker.definedType, in typexpr.go.
5050
func (check *Checker) objDecl(obj Object, def *TypeName) {
51+
if tracePos {
52+
check.pushPos(obj.Pos())
53+
defer func() {
54+
// If we're panicking, keep stack of source positions.
55+
if p := recover(); p != nil {
56+
panic(p)
57+
}
58+
check.popPos()
59+
}()
60+
}
61+
5162
if check.conf.Trace && obj.Type() == nil {
5263
if check.indent == 0 {
5364
fmt.Println() // empty line between top-level objects for readability

0 commit comments

Comments
 (0)