diff --git a/src/cmd/go.mod b/src/cmd/go.mod index 482c85e4ea..e9bc088f1f 100644 --- a/src/cmd/go.mod +++ b/src/cmd/go.mod @@ -3,7 +3,7 @@ module cmd go 1.23 require ( - github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 + github.com/google/pprof v0.0.0-20240528025155-186aa0362fba golang.org/x/arch v0.7.0 golang.org/x/build v0.0.0-20240222153247-cf4ed81bb19f golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9 @@ -15,7 +15,7 @@ require ( ) require ( - github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect + github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 // indirect golang.org/x/text v0.14.0 // indirect rsc.io/markdown v0.0.0-20240117044121-669d2fdf1650 // indirect ) diff --git a/src/cmd/go.sum b/src/cmd/go.sum index 6892b70f4d..19d4817a9d 100644 --- a/src/cmd/go.sum +++ b/src/cmd/go.sum @@ -1,25 +1,9 @@ -github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89 h1:aPflPkRFkVwbW6dmcVqfgwp1i+UWGFH6VgR1Jim5Ygc= -github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89/go.mod h1:GKljq0VrfU4D5yc+2qA6OVr8pmO/MBbPEWqWQ/oqGEs= -github.com/chromedp/chromedp v0.9.2 h1:dKtNz4kApb06KuSXoTQIyUC2TrA0fhGDwNZf3bcgfKw= -github.com/chromedp/chromedp v0.9.2/go.mod h1:LkSXJKONWTCHAfQasKFUZI+mxqS4tZqhmtGzzhLsnLs= -github.com/chromedp/sysutil v1.0.0 h1:+ZxhTpfpZlmchB58ih/LBHX52ky7w2VhQVKQMucy3Ic= -github.com/chromedp/sysutil v1.0.0/go.mod h1:kgWmDdq8fTzXYcKIBqIYvRRTnYb9aNS9moAV0xufSww= -github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= -github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= -github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og= -github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= -github.com/gobwas/ws v1.2.1 h1:F2aeBZrm2NDsc7vbovKrWSogd4wvfAxg0FQ89/iqOTk= -github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 h1:E/LAvt58di64hlYjx7AsNS6C/ysHWYo+2qPCZKTQhRo= -github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= -github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab h1:BA4a7pe6ZTd9F8kXETBoijjFJ/ntaa//1wiH9BZu4zU= -github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= -github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= -github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/google/pprof v0.0.0-20240528025155-186aa0362fba h1:ql1qNgCyOB7iAEk8JTNM+zJrgIbnyCKX/wdlyPufP5g= +github.com/google/pprof v0.0.0-20240528025155-186aa0362fba/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVWCNtNq/ewIX7HIKnELmEx2nDP42yskD/pi7QE= +github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw= github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= diff --git a/src/cmd/vendor/github.com/google/pprof/driver/driver.go b/src/cmd/vendor/github.com/google/pprof/driver/driver.go index d5860036c3..6cbf66939d 100644 --- a/src/cmd/vendor/github.com/google/pprof/driver/driver.go +++ b/src/cmd/vendor/github.com/google/pprof/driver/driver.go @@ -202,7 +202,7 @@ type Sym struct { // A UI manages user interactions. type UI interface { - // Read returns a line of text (a command) read from the user. + // ReadLine returns a line of text (a command) read from the user. // prompt is printed before reading the command. ReadLine(prompt string) (string, error) diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go index efa9167af7..ed87b7e6f8 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go @@ -433,10 +433,8 @@ func (b *binrep) openELF(name string, start, limit, offset uint64, relocationSym defer ef.Close() buildID := "" - if f, err := os.Open(name); err == nil { - if id, err := elfexec.GetBuildID(f); err == nil { - buildID = fmt.Sprintf("%x", id) - } + if id, err := elfexec.GetBuildID(ef); err == nil { + buildID = fmt.Sprintf("%x", id) } var ( diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go index 74ce8cb422..18941926c5 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go @@ -20,6 +20,7 @@ package driver import ( "bytes" "fmt" + "io" "os" "path/filepath" "regexp" @@ -118,7 +119,14 @@ func generateReport(p *profile.Profile, cmd []string, cfg config, o *plugin.Opti // Generate the report. dst := new(bytes.Buffer) - if err := report.Generate(dst, rpt, o.Obj); err != nil { + switch rpt.OutputFormat() { + case report.WebList: + // We need template expansion, so generate here instead of in report. + err = printWebList(dst, rpt, o.Obj) + default: + err = report.Generate(dst, rpt, o.Obj) + } + if err != nil { return err } src := dst @@ -155,6 +163,18 @@ func generateReport(p *profile.Profile, cmd []string, cfg config, o *plugin.Opti return out.Close() } +func printWebList(dst io.Writer, rpt *report.Report, obj plugin.ObjTool) error { + listing, err := report.MakeWebList(rpt, obj, -1) + if err != nil { + return err + } + legend := report.ProfileLabels(rpt) + return renderHTML(dst, "sourcelisting", rpt, nil, legend, webArgs{ + Standalone: true, + Listing: listing, + }) +} + func applyCommandOverrides(cmd string, outputFormat int, cfg config) config { // Some report types override the trim flag to false below. This is to make // sure the default heuristics of excluding insignificant nodes and edges diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go index 95204a394f..a94ddf6adb 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go @@ -493,7 +493,7 @@ func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http var f io.ReadCloser // First determine whether the source is a file, if not, it will be treated as a URL. - if _, openErr := os.Stat(source); openErr == nil { + if _, err = os.Stat(source); err == nil { if isPerfFile(source) { f, err = convertPerfData(source, ui) } else { diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.css b/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.css new file mode 100644 index 0000000000..c756ddfdcb --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.css @@ -0,0 +1,7 @@ +#graph { + cursor: grab; +} + +#graph:active { + cursor: grabbing; +} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.html b/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.html index a113549fc4..d17a0ea7d0 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.html +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/html/graph.html @@ -4,6 +4,7 @@
{{.File}}
{{"\n" -}} +{{"\n" -}}
+ {{printf " Total: %10s %10s (flat, cum) %s" .Flat .Cumulative .Percent -}}
+ {{range .Lines -}}{{"\n" -}}
+ {{/* source line */ -}}
+ {{printf " %6d" .Line}}{{" " -}}
+
+ {{- printf " %10s %10s %8s %s " .Flat .Cumulative "" .SrcLine -}}
+ {{"" -}}
+
+ {{if .Instructions -}}
+ {{/* instructions for this source line */ -}}
+ {{"" -}}
+ {{range .Instructions -}}
+ {{/* separate when we hit a new basic block */ -}}
+ {{if .NewBlock -}}{{printf " %8s %28s\n" "" "⋮"}}{{end -}}
+
+ {{/* inlined calls leading to this instruction */ -}}
+ {{range .InlinedCalls -}}
+ {{printf " %8s %10s %10s %8s " "" "" "" "" -}}
+ {{.SrcLine}}{{" " -}}
+ {{.FileBase}}:{{.Line}}{{"\n" -}}
+ {{end -}}
+
+ {{if not .Synthetic -}}
+ {{/* disassembled instruction */ -}}
+ {{printf " %8s %10s %10s %8x: %s " "" .Flat .Cumulative .Address .Disasm -}}
+ {{.FileLine}}{{"\n" -}}
+ {{end -}}
+ {{end -}}
+ {{"" -}}
+ {{end -}}
+ {{/* end of line */ -}}
+ {{end}}{{"\n" -}}
+ {{"\n" -}}
+ {{/* end of function */ -}}
+ {{end -}}
+ {{/* end of file */ -}}
+ {{end -}}
+
+ {{if not .Standalone}}{{"\n " -}}
+ %s
-
- Total: %10s %10s (flat, cum) %s
-`,
- template.HTMLEscapeString(name), template.HTMLEscapeString(path),
- rpt.formatValue(flatSum), rpt.formatValue(cumSum),
- measurement.Percentage(cumSum, rpt.total))
-}
-
-// printFunctionSourceLine prints a source line and the corresponding assembly.
-func printFunctionSourceLine(w io.Writer, lineNo int, flat, cum int64, lineContents string,
- assembly []assemblyInstruction, reader *sourceReader, rpt *Report) {
if len(assembly) == 0 {
- fmt.Fprintf(w,
- " %6d %10s %10s %8s %s \n",
- lineNo,
- valueOrDot(flat, rpt), valueOrDot(cum, rpt),
- "", template.HTMLEscapeString(lineContents))
- return
+ line.HTMLClass = "nop"
+ return line
}
nestedInfo := false
- cl := "deadsrc"
+ line.HTMLClass = "deadsrc"
for _, an := range assembly {
if len(an.inlineCalls) > 0 || an.instruction != synthAsm {
nestedInfo = true
- cl = "livesrc"
+ line.HTMLClass = "livesrc"
}
}
- fmt.Fprintf(w,
- " %6d %10s %10s %8s %s ",
- lineNo, cl,
- valueOrDot(flat, rpt), valueOrDot(cum, rpt),
- "", template.HTMLEscapeString(lineContents))
if nestedInfo {
srcIndent := indentation(lineContents)
- printNested(w, srcIndent, assembly, reader, rpt)
+ line.Instructions = makeWebListInstructions(srcIndent, assembly, reader, rpt)
}
- fmt.Fprintln(w)
+ return line
}
-func printNested(w io.Writer, srcIndent int, assembly []assemblyInstruction, reader *sourceReader, rpt *Report) {
- fmt.Fprint(w, "")
+func makeWebListInstructions(srcIndent int, assembly []assemblyInstruction, reader *sourceReader, rpt *Report) []WebListInstruction {
+ var result []WebListInstruction
var curCalls []callID
for i, an := range assembly {
- if an.startsBlock && i != 0 {
- // Insert a separator between discontiguous blocks.
- fmt.Fprintf(w, " %8s %28s\n", "", "⋮")
- }
-
var fileline string
if an.file != "" {
fileline = fmt.Sprintf("%s:%d", template.HTMLEscapeString(filepath.Base(an.file)), an.line)
}
- flat, cum := an.flat, an.cum
+ text := strings.Repeat(" ", srcIndent+4+4*len(an.inlineCalls)) + an.instruction
+ inst := WebListInstruction{
+ NewBlock: (an.startsBlock && i != 0),
+ Flat: valueOrDot(an.flat, rpt),
+ Cumulative: valueOrDot(an.cum, rpt),
+ Synthetic: (an.instruction == synthAsm),
+ Address: an.address,
+ Disasm: rightPad(text, 80),
+ FileLine: fileline,
+ }
- // Print inlined call context.
+ // Add inlined call context.
for j, c := range an.inlineCalls {
if j < len(curCalls) && curCalls[j] == c {
// Skip if same as previous instruction.
@@ -845,36 +866,18 @@ func printNested(w io.Writer, srcIndent int, assembly []assemblyInstruction, rea
if !ok {
fline = ""
}
- text := strings.Repeat(" ", srcIndent+4+4*j) + strings.TrimSpace(fline)
- fmt.Fprintf(w, " %8s %10s %10s %8s %s %s:%d\n",
- "", "", "", "",
- template.HTMLEscapeString(rightPad(text, 80)),
- template.HTMLEscapeString(filepath.Base(c.file)), c.line)
+ srcCode := strings.Repeat(" ", srcIndent+4+4*j) + strings.TrimSpace(fline)
+ inst.InlinedCalls = append(inst.InlinedCalls, WebListCall{
+ SrcLine: rightPad(srcCode, 80),
+ FileBase: filepath.Base(c.file),
+ Line: c.line,
+ })
}
curCalls = an.inlineCalls
- if an.instruction == synthAsm {
- continue
- }
- text := strings.Repeat(" ", srcIndent+4+4*len(curCalls)) + an.instruction
- fmt.Fprintf(w, " %8s %10s %10s %8x: %s %s\n",
- "", valueOrDot(flat, rpt), valueOrDot(cum, rpt), an.address,
- template.HTMLEscapeString(rightPad(text, 80)),
- // fileline should not be escaped since it was formed by appending
- // line number (just digits) to an escaped file name. Escaping here
- // would cause double-escaping of file name.
- fileline)
+
+ result = append(result, inst)
}
- fmt.Fprint(w, "")
-}
-
-// printFunctionClosing prints the end of a function in a weblist report.
-func printFunctionClosing(w io.Writer) {
- fmt.Fprintln(w, "")
-}
-
-// printPageClosing prints the end of the page in a weblist report.
-func printPageClosing(w io.Writer) {
- fmt.Fprintln(w, weblistPageClosing)
+ return result
}
// getSourceFromFile collects the sources of a function from a source
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/report/source_html.go b/src/cmd/vendor/github.com/google/pprof/internal/report/source_html.go
index 851693f1d0..614a5ee293 100644
--- a/src/cmd/vendor/github.com/google/pprof/internal/report/source_html.go
+++ b/src/cmd/vendor/github.com/google/pprof/internal/report/source_html.go
@@ -69,7 +69,3 @@ function pprof_toggle_asm(e) {
}
}
`
-
-const weblistPageClosing = `
-
-`
diff --git a/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go b/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go
index 5ca71ab8be..70b4047269 100644
--- a/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go
+++ b/src/cmd/vendor/github.com/google/pprof/internal/symbolizer/symbolizer.go
@@ -133,22 +133,80 @@ func doLocalSymbolize(prof *profile.Profile, fast, force bool, obj plugin.ObjToo
}
}
- mt, err := newMapping(prof, obj, ui, force)
- if err != nil {
- return err
+ functions := map[profile.Function]*profile.Function{}
+ addFunction := func(f *profile.Function) *profile.Function {
+ if fp := functions[*f]; fp != nil {
+ return fp
+ }
+ functions[*f] = f
+ f.ID = uint64(len(prof.Function)) + 1
+ prof.Function = append(prof.Function, f)
+ return f
}
- defer mt.close()
- functions := make(map[profile.Function]*profile.Function)
- for _, l := range mt.prof.Location {
- m := l.Mapping
- segment := mt.segments[m]
- if segment == nil {
- // Nothing to do.
+ missingBinaries := false
+ mappingLocs := map[*profile.Mapping][]*profile.Location{}
+ for _, l := range prof.Location {
+ mappingLocs[l.Mapping] = append(mappingLocs[l.Mapping], l)
+ }
+ for midx, m := range prof.Mapping {
+ locs := mappingLocs[m]
+ if len(locs) == 0 {
+ // The mapping is dangling and has no locations pointing to it.
continue
}
+ // Do not attempt to re-symbolize a mapping that has already been symbolized.
+ if !force && (m.HasFunctions || m.HasFilenames || m.HasLineNumbers) {
+ continue
+ }
+ if m.File == "" {
+ if midx == 0 {
+ ui.PrintErr("Main binary filename not available.")
+ continue
+ }
+ missingBinaries = true
+ continue
+ }
+ if m.Unsymbolizable() {
+ // Skip well-known system mappings
+ continue
+ }
+ if m.BuildID == "" {
+ if u, err := url.Parse(m.File); err == nil && u.IsAbs() && strings.Contains(strings.ToLower(u.Scheme), "http") {
+ // Skip mappings pointing to a source URL
+ continue
+ }
+ }
- stack, err := segment.SourceLine(l.Address)
+ name := filepath.Base(m.File)
+ if m.BuildID != "" {
+ name += fmt.Sprintf(" (build ID %s)", m.BuildID)
+ }
+ f, err := obj.Open(m.File, m.Start, m.Limit, m.Offset, m.KernelRelocationSymbol)
+ if err != nil {
+ ui.PrintErr("Local symbolization failed for ", name, ": ", err)
+ missingBinaries = true
+ continue
+ }
+ if fid := f.BuildID(); m.BuildID != "" && fid != "" && fid != m.BuildID {
+ ui.PrintErr("Local symbolization failed for ", name, ": build ID mismatch")
+ f.Close()
+ continue
+ }
+ symbolizeOneMapping(m, locs, f, addFunction)
+ f.Close()
+ }
+
+ if missingBinaries {
+ ui.PrintErr("Some binary filenames not available. Symbolization may be incomplete.\n" +
+ "Try setting PPROF_BINARY_PATH to the search path for local binaries.")
+ }
+ return nil
+}
+
+func symbolizeOneMapping(m *profile.Mapping, locs []*profile.Location, obj plugin.ObjFile, addFunction func(*profile.Function) *profile.Function) {
+ for _, l := range locs {
+ stack, err := obj.SourceLine(l.Address)
if err != nil || len(stack) == 0 {
// No answers from addr2line.
continue
@@ -166,18 +224,11 @@ func doLocalSymbolize(prof *profile.Profile, fast, force bool, obj plugin.ObjToo
if frame.Line != 0 {
m.HasLineNumbers = true
}
- f := &profile.Function{
+ f := addFunction(&profile.Function{
Name: frame.Func,
SystemName: frame.Func,
Filename: frame.File,
- }
- if fp := functions[*f]; fp != nil {
- f = fp
- } else {
- functions[*f] = f
- f.ID = uint64(len(mt.prof.Function)) + 1
- mt.prof.Function = append(mt.prof.Function, f)
- }
+ })
l.Line[i] = profile.Line{
Function: f,
Line: int64(frame.Line),
@@ -189,8 +240,6 @@ func doLocalSymbolize(prof *profile.Profile, fast, force bool, obj plugin.ObjToo
m.HasInlineFrames = true
}
}
-
- return nil
}
// Demangle updates the function names in a profile with demangled C++
@@ -294,87 +343,3 @@ func removeMatching(name string, start, end byte) string {
}
return name
}
-
-// newMapping creates a mappingTable for a profile.
-func newMapping(prof *profile.Profile, obj plugin.ObjTool, ui plugin.UI, force bool) (*mappingTable, error) {
- mt := &mappingTable{
- prof: prof,
- segments: make(map[*profile.Mapping]plugin.ObjFile),
- }
-
- // Identify used mappings
- mappings := make(map[*profile.Mapping]bool)
- for _, l := range prof.Location {
- mappings[l.Mapping] = true
- }
-
- missingBinaries := false
- for midx, m := range prof.Mapping {
- if !mappings[m] {
- continue
- }
-
- // Do not attempt to re-symbolize a mapping that has already been symbolized.
- if !force && (m.HasFunctions || m.HasFilenames || m.HasLineNumbers) {
- continue
- }
-
- if m.File == "" {
- if midx == 0 {
- ui.PrintErr("Main binary filename not available.")
- continue
- }
- missingBinaries = true
- continue
- }
-
- // Skip well-known system mappings
- if m.Unsymbolizable() {
- continue
- }
-
- // Skip mappings pointing to a source URL
- if m.BuildID == "" {
- if u, err := url.Parse(m.File); err == nil && u.IsAbs() && strings.Contains(strings.ToLower(u.Scheme), "http") {
- continue
- }
- }
-
- name := filepath.Base(m.File)
- if m.BuildID != "" {
- name += fmt.Sprintf(" (build ID %s)", m.BuildID)
- }
- f, err := obj.Open(m.File, m.Start, m.Limit, m.Offset, m.KernelRelocationSymbol)
- if err != nil {
- ui.PrintErr("Local symbolization failed for ", name, ": ", err)
- missingBinaries = true
- continue
- }
- if fid := f.BuildID(); m.BuildID != "" && fid != "" && fid != m.BuildID {
- ui.PrintErr("Local symbolization failed for ", name, ": build ID mismatch")
- f.Close()
- continue
- }
-
- mt.segments[m] = f
- }
- if missingBinaries {
- ui.PrintErr("Some binary filenames not available. Symbolization may be incomplete.\n" +
- "Try setting PPROF_BINARY_PATH to the search path for local binaries.")
- }
- return mt, nil
-}
-
-// mappingTable contains the mechanisms for symbolization of a
-// profile.
-type mappingTable struct {
- prof *profile.Profile
- segments map[*profile.Mapping]plugin.ObjFile
-}
-
-// close releases any external processes being used for the mapping.
-func (mt *mappingTable) close() {
- for _, segment := range mt.segments {
- segment.Close()
- }
-}
diff --git a/src/cmd/vendor/github.com/google/pprof/profile/profile.go b/src/cmd/vendor/github.com/google/pprof/profile/profile.go
index 62df80a556..5551eb0bfa 100644
--- a/src/cmd/vendor/github.com/google/pprof/profile/profile.go
+++ b/src/cmd/vendor/github.com/google/pprof/profile/profile.go
@@ -847,7 +847,7 @@ func (p *Profile) HasFileLines() bool {
// "[vdso]", [vsyscall]" and some others, see the code.
func (m *Mapping) Unsymbolizable() bool {
name := filepath.Base(m.File)
- return strings.HasPrefix(name, "[") || strings.HasPrefix(name, "linux-vdso") || strings.HasPrefix(m.File, "/dev/dri/")
+ return strings.HasPrefix(name, "[") || strings.HasPrefix(name, "linux-vdso") || strings.HasPrefix(m.File, "/dev/dri/") || m.File == "//anon"
}
// Copy makes a fully independent copy of a profile.
diff --git a/src/cmd/vendor/github.com/ianlancetaylor/demangle/ast.go b/src/cmd/vendor/github.com/ianlancetaylor/demangle/ast.go
index cdc98c3368..9e1fb0661d 100644
--- a/src/cmd/vendor/github.com/ianlancetaylor/demangle/ast.go
+++ b/src/cmd/vendor/github.com/ianlancetaylor/demangle/ast.go
@@ -59,6 +59,7 @@ func ASTToString(a AST, options ...Option) string {
enclosingParams: enclosingParams,
llvmStyle: llvmStyle,
max: max,
+ scopes: 1,
}
a.print(&ps)
s := ps.buf.String()
@@ -75,6 +76,17 @@ type printState struct {
llvmStyle bool
max int // maximum output length
+ // The scopes field is used to avoid unnecessary parentheses
+ // around expressions that use > (or >>). It is incremented if
+ // we output a parenthesis or something else that means that >
+ // or >> won't be treated as ending a template. It starts out
+ // as 1, and is set to 0 when we start writing template
+ // arguments. We add parentheses around expressions using > if
+ // scopes is 0. The effect is that an expression with > gets
+ // parentheses if used as a template argument that is not
+ // inside some other set of parentheses.
+ scopes int
+
buf strings.Builder
last byte // Last byte written to buffer.
@@ -132,6 +144,87 @@ func (ps *printState) print(a AST) {
ps.printing = ps.printing[:len(ps.printing)-1]
}
+// printList prints a list of AST values separated by commas,
+// optionally skipping some.
+func (ps *printState) printList(args []AST, skip func(AST) bool) {
+ first := true
+ for _, a := range args {
+ if skip != nil && skip(a) {
+ continue
+ }
+ if !first {
+ ps.writeString(", ")
+ }
+
+ needsParen := false
+ if ps.llvmStyle {
+ if p, ok := a.(hasPrec); ok {
+ if p.prec() >= precComma {
+ needsParen = true
+ }
+ }
+ }
+ if needsParen {
+ ps.startScope('(')
+ }
+
+ ps.print(a)
+
+ if needsParen {
+ ps.endScope(')')
+ }
+
+ first = false
+ }
+}
+
+// startScope starts a scope. This is used to decide whether we need
+// to parenthesize an expression using > or >>.
+func (ps *printState) startScope(b byte) {
+ ps.scopes++
+ ps.writeByte(b)
+}
+
+// endScope closes a scope.
+func (ps *printState) endScope(b byte) {
+ ps.scopes--
+ ps.writeByte(b)
+}
+
+// precedence is used for operator precedence. This is used to avoid
+// unnecessary parentheses when printing expressions in the LLVM style.
+type precedence int
+
+// The precedence values, in order from high to low.
+const (
+ precPrimary precedence = iota
+ precPostfix
+ precUnary
+ precCast
+ precPtrMem
+ precMul
+ precAdd
+ precShift
+ precSpaceship
+ precRel
+ precEqual
+ precAnd
+ precXor
+ precOr
+ precLogicalAnd
+ precLogicalOr
+ precCond
+ precAssign
+ precComma
+ precDefault
+)
+
+// hasPrec matches the AST nodes that have a prec method that returns
+// the node's precedence.
+type hasPrec interface {
+ prec() precedence
+}
+
// Name is an unqualified name.
type Name struct {
Name string
@@ -160,6 +253,10 @@ func (n *Name) goString(indent int, field string) string {
return fmt.Sprintf("%*s%s%s", indent, "", field, n.Name)
}
+func (n *Name) prec() precedence {
+ return precPrimary
+}
+
// Typed is a typed name.
type Typed struct {
Name AST
@@ -287,6 +384,10 @@ func (q *Qualified) goString(indent int, field string) string {
q.Name.goString(indent+2, "Name: "))
}
+func (q *Qualified) prec() precedence {
+ return precPrimary
+}
+
// Template is a template with arguments.
type Template struct {
Name AST
@@ -311,23 +412,18 @@ func (t *Template) print(ps *printState) {
ps.writeByte(' ')
}
+ scopes := ps.scopes
+ ps.scopes = 0
+
ps.writeByte('<')
- first := true
- for _, a := range t.Args {
- if ps.isEmpty(a) {
- continue
- }
- if !first {
- ps.writeString(", ")
- }
- ps.print(a)
- first = false
- }
- if ps.last == '>' {
+ ps.printList(t.Args, ps.isEmpty)
+ if ps.last == '>' && !ps.llvmStyle {
// Avoid syntactic ambiguity in old versions of C++.
ps.writeByte(' ')
}
ps.writeByte('>')
+
+ ps.scopes = scopes
}
func (t *Template) Traverse(fn func(AST) bool) {
@@ -460,6 +556,61 @@ func (la *LambdaAuto) goString(indent int, field string) string {
return fmt.Sprintf("%*s%sLambdaAuto: Index %d", indent, "", field, la.Index)
}
+// TemplateParamQualifiedArg is used when the mangled name includes
+// both the template parameter declaration and the template argument.
+// See https://github.com/itanium-cxx-abi/cxx-abi/issues/47.
+type TemplateParamQualifiedArg struct {
+ Param AST
+ Arg AST
+}
+
+func (tpqa *TemplateParamQualifiedArg) print(ps *printState) {
+ // We only demangle the actual template argument.
+ // That is what the LLVM demangler does.
+ // The parameter disambiguates the argument,
+ // but is hopefully not required by a human reader.
+ ps.print(tpqa.Arg)
+}
+
+func (tpqa *TemplateParamQualifiedArg) Traverse(fn func(AST) bool) {
+ if fn(tpqa) {
+ tpqa.Param.Traverse(fn)
+ tpqa.Arg.Traverse(fn)
+ }
+}
+
+func (tpqa *TemplateParamQualifiedArg) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(tpqa) {
+ return nil
+ }
+ param := tpqa.Param.Copy(fn, skip)
+ arg := tpqa.Arg.Copy(fn, skip)
+ if param == nil && arg == nil {
+ return fn(tpqa)
+ }
+ if param == nil {
+ param = tpqa.Param
+ }
+ if arg == nil {
+ arg = tpqa.Arg
+ }
+ tpqa = &TemplateParamQualifiedArg{Param: param, Arg: arg}
+ if r := fn(tpqa); r != nil {
+ return r
+ }
+ return tpqa
+}
+
+func (tpqa *TemplateParamQualifiedArg) GoString() string {
+ return tpqa.goString(0, "")
+}
+
+func (tpqa *TemplateParamQualifiedArg) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sTemplateParamQualifiedArg:\n%s\n%s", indent, "", field,
+ tpqa.Param.goString(indent+2, "Param: "),
+ tpqa.Arg.goString(indent+2, "Arg: "))
+}
+
// Qualifiers is an ordered list of type qualifiers.
type Qualifiers struct {
Qualifiers []AST
@@ -531,7 +682,7 @@ type Qualifier struct {
func (q *Qualifier) print(ps *printState) {
ps.writeString(q.Name)
if len(q.Exprs) > 0 {
- ps.writeByte('(')
+ ps.startScope('(')
first := true
for _, e := range q.Exprs {
if el, ok := e.(*ExprList); ok && len(el.Exprs) == 0 {
@@ -543,7 +694,7 @@ func (q *Qualifier) print(ps *printState) {
ps.print(e)
first = false
}
- ps.writeByte(')')
+ ps.endScope(')')
}
}
@@ -774,6 +925,10 @@ func (bt *BuiltinType) goString(indent int, field string) string {
return fmt.Sprintf("%*s%sBuiltinType: %s", indent, "", field, bt.Name)
}
+func (bt *BuiltinType) prec() precedence {
+ return precPrimary
+}
+
// printBase is common print code for types that are printed with a
// simple suffix.
func printBase(ps *printState, qual, base AST) {
@@ -1000,6 +1155,94 @@ func (it *ImaginaryType) goString(indent int, field string) string {
it.Base.goString(indent+2, ""))
}
+// SuffixType is an type with an arbitrary suffix.
+type SuffixType struct {
+ Base AST
+ Suffix string
+}
+
+func (st *SuffixType) print(ps *printState) {
+ printBase(ps, st, st.Base)
+}
+
+func (st *SuffixType) printInner(ps *printState) {
+ ps.writeByte(' ')
+ ps.writeString(st.Suffix)
+}
+
+func (st *SuffixType) Traverse(fn func(AST) bool) {
+ if fn(st) {
+ st.Base.Traverse(fn)
+ }
+}
+
+func (st *SuffixType) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(st) {
+ return nil
+ }
+ base := st.Base.Copy(fn, skip)
+ if base == nil {
+ return fn(st)
+ }
+ st = &SuffixType{Base: base, Suffix: st.Suffix}
+ if r := fn(st); r != nil {
+ return r
+ }
+ return st
+}
+
+func (st *SuffixType) GoString() string {
+ return st.goString(0, "")
+}
+
+func (st *SuffixType) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sSuffixType: %s\n%s", indent, "", field,
+ st.Suffix, st.Base.goString(indent+2, "Base: "))
+}
+
+// TransformedType is a builtin type with a template argument.
+type TransformedType struct {
+ Name string
+ Base AST
+}
+
+func (tt *TransformedType) print(ps *printState) {
+ ps.writeString(tt.Name)
+ ps.startScope('(')
+ ps.print(tt.Base)
+ ps.endScope(')')
+}
+
+func (tt *TransformedType) Traverse(fn func(AST) bool) {
+ if fn(tt) {
+ tt.Base.Traverse(fn)
+ }
+}
+
+func (tt *TransformedType) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(tt) {
+ return nil
+ }
+ base := tt.Base.Copy(fn, skip)
+ if base == nil {
+ return fn(tt)
+ }
+ tt = &TransformedType{Name: tt.Name, Base: base}
+ if r := fn(tt); r != nil {
+ return r
+ }
+ return tt
+}
+
+func (tt *TransformedType) GoString() string {
+ return tt.goString(0, "")
+}
+
+func (tt *TransformedType) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sTransformedType: %s\n%s", indent, "", field,
+ tt.Name, tt.Base.goString(indent+2, "Base: "))
+}
+
// VendorQualifier is a type qualified by a vendor-specific qualifier.
type VendorQualifier struct {
Qualifier AST
@@ -1102,9 +1345,10 @@ func (at *ArrayType) printDimension(ps *printState) {
}
ps.printOneInner(nil)
} else {
- ps.writeString(" (")
+ ps.writeByte(' ')
+ ps.startScope('(')
ps.printInner(false)
- ps.writeByte(')')
+ ps.endScope(')')
}
}
ps.writeString(space)
@@ -1212,16 +1456,16 @@ func (ft *FunctionType) printArgs(ps *printState) {
if space && ps.last != ' ' {
ps.writeByte(' ')
}
- ps.writeByte('(')
+ ps.startScope('(')
}
save := ps.printInner(true)
if paren {
- ps.writeByte(')')
+ ps.endScope(')')
}
- ps.writeByte('(')
+ ps.startScope('(')
if !ft.ForLocalName || ps.enclosingParams {
first := true
for _, a := range ft.Args {
@@ -1235,7 +1479,7 @@ func (ft *FunctionType) printArgs(ps *printState) {
first = false
}
}
- ps.writeByte(')')
+ ps.endScope(')')
ps.inner = save
ps.printInner(false)
@@ -1358,6 +1602,10 @@ func (fp *FunctionParam) goString(indent int, field string) string {
return fmt.Sprintf("%*s%sFunctionParam: %d", indent, "", field, fp.Index)
}
+func (fp *FunctionParam) prec() precedence {
+ return precPrimary
+}
+
// PtrMem is a pointer-to-member expression.
type PtrMem struct {
Class AST
@@ -1502,6 +1750,53 @@ func (bfp *BinaryFP) goString(indent int, field string) string {
return fmt.Sprintf("%*s%sBinaryFP: %d", indent, "", field, bfp.Bits)
}
+// BitIntType is the C++23 _BitInt(N) type.
+type BitIntType struct {
+ Size AST
+ Signed bool
+}
+
+func (bt *BitIntType) print(ps *printState) {
+ if !bt.Signed {
+ ps.writeString("unsigned ")
+ }
+ ps.writeString("_BitInt")
+ ps.startScope('(')
+ ps.print(bt.Size)
+ ps.endScope(')')
+}
+
+func (bt *BitIntType) Traverse(fn func(AST) bool) {
+ if fn(bt) {
+ bt.Size.Traverse(fn)
+ }
+}
+
+func (bt *BitIntType) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(bt) {
+ return nil
+ }
+ size := bt.Size.Copy(fn, skip)
+ if size == nil {
+ return fn(bt)
+ }
+ bt = &BitIntType{Size: size, Signed: bt.Signed}
+ if r := fn(bt); r != nil {
+ return r
+ }
+ return bt
+}
+
+func (bt *BitIntType) GoString() string {
+ return bt.goString(0, "")
+}
+
+func (bt *BitIntType) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sBitIntType: Signed: %t\n%s", indent, "", field,
+ bt.Signed,
+ bt.Size.goString(indent+2, "Size: "))
+}
+
// VectorType is a vector type.
type VectorType struct {
Dimension AST
@@ -1619,9 +1914,9 @@ func (dt *Decltype) print(ps *printState) {
if !ps.llvmStyle {
ps.writeString(" ")
}
- ps.writeString("(")
+ ps.startScope('(')
ps.print(dt.Expr)
- ps.writeByte(')')
+ ps.endScope(')')
}
func (dt *Decltype) Traverse(fn func(AST) bool) {
@@ -1656,7 +1951,8 @@ func (dt *Decltype) goString(indent int, field string) string {
// Operator is an operator.
type Operator struct {
- Name string
+ Name string
+ precedence precedence
}
func (op *Operator) print(ps *printState) {
@@ -1688,6 +1984,10 @@ func (op *Operator) goString(indent int, field string) string {
return fmt.Sprintf("%*s%sOperator: %s", indent, "", field, op.Name)
}
+func (op *Operator) prec() precedence {
+ return op.precedence
+}
+
// Constructor is a constructor.
type Constructor struct {
Name AST
@@ -2007,9 +2307,10 @@ type SizeofPack struct {
func (sp *SizeofPack) print(ps *printState) {
if ps.llvmStyle {
- ps.writeString("sizeof...(")
+ ps.writeString("sizeof...")
+ ps.startScope('(')
ps.print(sp.Pack)
- ps.writeByte(')')
+ ps.endScope(')')
} else {
ps.writeString(fmt.Sprintf("%d", len(sp.Pack.Args)))
}
@@ -2253,20 +2554,27 @@ func (nttp *NonTypeTemplateParam) goString(indent int, field string) string {
// TemplateTemplateParam is a template template parameter that appears
// in a lambda with explicit template parameters.
type TemplateTemplateParam struct {
- Name AST
- Params []AST
+ Name AST
+ Params []AST
+ Constraint AST
}
func (ttp *TemplateTemplateParam) print(ps *printState) {
+ scopes := ps.scopes
+ ps.scopes = 0
+
ps.writeString("template<")
- for i, param := range ttp.Params {
- if i > 0 {
- ps.writeString(", ")
- }
- ps.print(param)
- }
+ ps.printList(ttp.Params, nil)
ps.writeString("> typename ")
+
+ ps.scopes = scopes
+
ps.print(ttp.Name)
+
+ if ttp.Constraint != nil {
+ ps.writeString(" requires ")
+ ps.print(ttp.Constraint)
+ }
}
func (ttp *TemplateTemplateParam) Traverse(fn func(AST) bool) {
@@ -2275,6 +2583,9 @@ func (ttp *TemplateTemplateParam) Traverse(fn func(AST) bool) {
for _, param := range ttp.Params {
param.Traverse(fn)
}
+ if ttp.Constraint != nil {
+ ttp.Constraint.Traverse(fn)
+ }
}
}
@@ -2303,13 +2614,24 @@ func (ttp *TemplateTemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AS
}
}
+ var constraint AST
+ if ttp.Constraint != nil {
+ constraint = ttp.Constraint.Copy(fn, skip)
+ if constraint == nil {
+ constraint = ttp.Constraint
+ } else {
+ changed = true
+ }
+ }
+
if !changed {
return fn(ttp)
}
ttp = &TemplateTemplateParam{
- Name: name,
- Params: params,
+ Name: name,
+ Params: params,
+ Constraint: constraint,
}
if r := fn(ttp); r != nil {
return r
@@ -2328,9 +2650,76 @@ func (ttp *TemplateTemplateParam) goString(indent int, field string) string {
params.WriteByte('\n')
params.WriteString(p.goString(indent+4, fmt.Sprintf("%d: ", i)))
}
- return fmt.Sprintf("%*s%sTemplateTemplateParam:\n%s\n%s", indent, "", field,
+ var constraint string
+ if ttp.Constraint == nil {
+ constraint = fmt.Sprintf("%*sConstraint: nil", indent+2, "")
+ } else {
+ constraint = ttp.Constraint.goString(indent+2, "Constraint: ")
+ }
+ return fmt.Sprintf("%*s%sTemplateTemplateParam:\n%s\n%s\n%s", indent, "", field,
ttp.Name.goString(indent+2, "Name: "),
- params.String())
+ params.String(),
+ constraint)
+}
+
+// ConstrainedTypeTemplateParam is a constrained template type
+// parameter declaration.
+type ConstrainedTypeTemplateParam struct {
+ Name AST
+ Constraint AST
+}
+
+func (cttp *ConstrainedTypeTemplateParam) print(ps *printState) {
+ ps.inner = append(ps.inner, cttp)
+ ps.print(cttp.Constraint)
+ if len(ps.inner) > 0 {
+ ps.writeByte(' ')
+ ps.print(cttp.Name)
+ ps.inner = ps.inner[:len(ps.inner)-1]
+ }
+}
+
+func (cttp *ConstrainedTypeTemplateParam) printInner(ps *printState) {
+ ps.print(cttp.Name)
+}
+
+func (cttp *ConstrainedTypeTemplateParam) Traverse(fn func(AST) bool) {
+ if fn(cttp) {
+ cttp.Name.Traverse(fn)
+ cttp.Constraint.Traverse(fn)
+ }
+}
+
+func (cttp *ConstrainedTypeTemplateParam) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(cttp) {
+ return nil
+ }
+ name := cttp.Name.Copy(fn, skip)
+ constraint := cttp.Constraint.Copy(fn, skip)
+ if name == nil && constraint == nil {
+ return fn(cttp)
+ }
+ if name == nil {
+ name = cttp.Name
+ }
+ if constraint == nil {
+ constraint = cttp.Constraint
+ }
+ cttp = &ConstrainedTypeTemplateParam{Name: name, Constraint: constraint}
+ if r := fn(cttp); r != nil {
+ return r
+ }
+ return cttp
+}
+
+func (cttp *ConstrainedTypeTemplateParam) GoString() string {
+ return cttp.goString(0, "")
+}
+
+func (cttp *ConstrainedTypeTemplateParam) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sConstrainedTypeTemplateParam\n%s\n%s", indent, "", field,
+ cttp.Name.goString(indent+2, "Name: "),
+ cttp.Constraint.goString(indent+2, "Constraint: "))
}
// TemplateParamPack is a template parameter pack that appears in a
@@ -2431,6 +2820,10 @@ func (c *Cast) goString(indent int, field string) string {
c.To.goString(indent+2, "To: "))
}
+func (c *Cast) prec() precedence {
+ return precCast
+}
+
// The parenthesize function prints the string for val, wrapped in
// parentheses if necessary.
func parenthesize(ps *printState, val AST) {
@@ -2449,11 +2842,11 @@ func parenthesize(ps *printState, val AST) {
paren = true
}
if paren {
- ps.writeByte('(')
+ ps.startScope('(')
}
ps.print(val)
if paren {
- ps.writeByte(')')
+ ps.endScope(')')
}
}
@@ -2526,7 +2919,27 @@ func (u *Unary) print(ps *printState) {
}
if u.Suffix {
- parenthesize(ps, expr)
+ if ps.llvmStyle {
+ wantParens := true
+ opPrec := precUnary
+ if op != nil {
+ opPrec = op.precedence
+ }
+ if p, ok := expr.(hasPrec); ok {
+ if p.prec() < opPrec {
+ wantParens = false
+ }
+ }
+ if wantParens {
+ ps.startScope('(')
+ }
+ ps.print(expr)
+ if wantParens {
+ ps.endScope(')')
+ }
+ } else {
+ parenthesize(ps, expr)
+ }
}
if op != nil {
@@ -2535,9 +2948,9 @@ func (u *Unary) print(ps *printState) {
ps.writeByte(' ')
}
} else if c, ok := u.Op.(*Cast); ok {
- ps.writeByte('(')
+ ps.startScope('(')
ps.print(c.To)
- ps.writeByte(')')
+ ps.endScope(')')
} else {
ps.print(u.Op)
}
@@ -2549,21 +2962,45 @@ func (u *Unary) print(ps *printState) {
ps.print(expr)
} else if u.SizeofType {
// Always use parentheses for sizeof argument.
- ps.writeByte('(')
+ ps.startScope('(')
ps.print(expr)
- ps.writeByte(')')
+ ps.endScope(')')
} else if op != nil && op.Name == "__alignof__" {
// Always use parentheses for __alignof__ argument.
- ps.writeByte('(')
+ ps.startScope('(')
ps.print(expr)
- ps.writeByte(')')
+ ps.endScope(')')
} else if ps.llvmStyle {
- if op == nil || (op.Name != `operator"" ` && !isDelete) {
- ps.writeByte('(')
+ var wantParens bool
+ switch {
+ case op == nil:
+ wantParens = true
+ case op.Name == `operator"" `:
+ wantParens = false
+ case op.Name == "&":
+ wantParens = false
+ case isDelete:
+ wantParens = false
+ case op.Name == "alignof ":
+ wantParens = true
+ case op.Name == "sizeof ":
+ wantParens = true
+ case op.Name == "typeid ":
+ wantParens = true
+ default:
+ wantParens = true
+ if p, ok := expr.(hasPrec); ok {
+ if p.prec() < op.precedence {
+ wantParens = false
+ }
+ }
+ }
+ if wantParens {
+ ps.startScope('(')
}
ps.print(expr)
- if op == nil || (op.Name != `operator"" ` && !isDelete) {
- ps.writeByte(')')
+ if wantParens {
+ ps.endScope(')')
}
} else {
parenthesize(ps, expr)
@@ -2617,6 +3054,13 @@ func (u *Unary) goString(indent int, field string) string {
u.Expr.goString(indent+2, "Expr: "))
}
+func (u *Unary) prec() precedence {
+ if p, ok := u.Op.(hasPrec); ok {
+ return p.prec()
+ }
+ return precDefault
+}
+
// isDesignatedInitializer reports whether x is a designated
// initializer.
func isDesignatedInitializer(x AST) bool {
@@ -2654,11 +3098,19 @@ func (b *Binary) print(ps *printState) {
if op != nil && strings.Contains(op.Name, "cast") {
ps.writeString(op.Name)
+
+ scopes := ps.scopes
+ ps.scopes = 0
+
ps.writeByte('<')
ps.print(b.Left)
- ps.writeString(">(")
+ ps.writeString(">")
+
+ ps.scopes = scopes
+
+ ps.startScope('(')
ps.print(b.Right)
- ps.writeByte(')')
+ ps.endScope(')')
return
}
@@ -2691,22 +3143,21 @@ func (b *Binary) print(ps *printState) {
// Use an extra set of parentheses around an expression that
// uses the greater-than operator, so that it does not get
// confused with the '>' that ends template parameters.
- if op != nil && op.Name == ">" {
- ps.writeByte('(')
+ needsOuterParen := op != nil && (op.Name == ">" || op.Name == ">>")
+ if ps.llvmStyle && ps.scopes > 0 {
+ needsOuterParen = false
+ }
+ if needsOuterParen {
+ ps.startScope('(')
}
left := b.Left
skipParens := false
- skipBothParens := false
addSpaces := ps.llvmStyle
if ps.llvmStyle && op != nil {
switch op.Name {
- case ".", "->":
- skipBothParens = true
- addSpaces = false
- case "->*":
- skipParens = true
+ case ".", "->", "->*":
addSpaces = false
}
}
@@ -2730,12 +3181,26 @@ func (b *Binary) print(ps *printState) {
}
}
- if skipParens || skipBothParens {
+ if skipParens {
ps.print(left)
} else if ps.llvmStyle {
- ps.writeByte('(')
+ prec := precPrimary
+ if p, ok := left.(hasPrec); ok {
+ prec = p.prec()
+ }
+ needsParen := false
+ if prec > b.prec() {
+ needsParen = true
+ }
+ if needsParen {
+ ps.startScope('(')
+ }
+
ps.print(left)
- ps.writeByte(')')
+
+ if needsParen {
+ ps.endScope(')')
+ }
} else {
parenthesize(ps, left)
}
@@ -2749,7 +3214,7 @@ func (b *Binary) print(ps *printState) {
if op != nil {
if op.Name != "()" {
- if addSpaces {
+ if addSpaces && op.Name != "," {
ps.writeByte(' ')
}
ps.writeString(op.Name)
@@ -2761,18 +3226,30 @@ func (b *Binary) print(ps *printState) {
ps.print(b.Op)
}
- if skipBothParens {
+ if ps.llvmStyle {
+ prec := precPrimary
+ if p, ok := b.Right.(hasPrec); ok {
+ prec = p.prec()
+ }
+ needsParen := false
+ if prec >= b.prec() {
+ needsParen = true
+ }
+ if needsParen {
+ ps.startScope('(')
+ }
+
ps.print(b.Right)
- } else if ps.llvmStyle {
- ps.writeByte('(')
- ps.print(b.Right)
- ps.writeByte(')')
+
+ if needsParen {
+ ps.endScope(')')
+ }
} else {
parenthesize(ps, b.Right)
}
- if op != nil && op.Name == ">" {
- ps.writeByte(')')
+ if needsOuterParen {
+ ps.endScope(')')
}
}
@@ -2821,6 +3298,13 @@ func (b *Binary) goString(indent int, field string) string {
b.Right.goString(indent+2, "Right: "))
}
+func (b *Binary) prec() precedence {
+ if p, ok := b.Op.(hasPrec); ok {
+ return p.prec()
+ }
+ return precDefault
+}
+
// Trinary is the ?: trinary operation in an expression.
type Trinary struct {
Op AST
@@ -2852,15 +3336,71 @@ func (t *Trinary) print(ps *printState) {
return
}
- parenthesize(ps, t.First)
+ if ps.llvmStyle {
+ wantParens := true
+ opPrec := precPrimary
+ if op, ok := t.Op.(*Operator); ok {
+ opPrec = op.precedence
+ }
+ if p, ok := t.First.(hasPrec); ok {
+ if p.prec() < opPrec {
+ wantParens = false
+ }
+ }
+ if wantParens {
+ ps.startScope('(')
+ }
+ ps.print(t.First)
+ if wantParens {
+ ps.endScope(')')
+ }
+ } else {
+ parenthesize(ps, t.First)
+ }
+
if ps.llvmStyle {
ps.writeString(" ? ")
} else {
ps.writeByte('?')
}
- parenthesize(ps, t.Second)
+
+ if ps.llvmStyle {
+ wantParens := true
+ if p, ok := t.Second.(hasPrec); ok {
+ if p.prec() < precDefault {
+ wantParens = false
+ }
+ }
+ if wantParens {
+ ps.startScope('(')
+ }
+ ps.print(t.Second)
+ if wantParens {
+ ps.endScope(')')
+ }
+ } else {
+ parenthesize(ps, t.Second)
+ }
+
ps.writeString(" : ")
- parenthesize(ps, t.Third)
+
+ if ps.llvmStyle {
+ wantParens := true
+ if p, ok := t.Third.(hasPrec); ok {
+ if p.prec() < precAssign {
+ wantParens = false
+ }
+ }
+ if wantParens {
+ ps.startScope('(')
+ }
+ ps.print(t.Third)
+ if wantParens {
+ ps.endScope(')')
+ }
+ } else {
+ parenthesize(ps, t.Third)
+ }
}
func (t *Trinary) Traverse(fn func(AST) bool) {
@@ -2938,33 +3478,49 @@ func (f *Fold) print(ps *printState) {
}
}
foldParenthesize := func(a AST) {
- if _, ok := a.(*ArgumentPack); ok || !ps.llvmStyle {
- parenthesize(ps, a)
- } else {
+ if ps.llvmStyle {
+ prec := precDefault
+ if p, ok := a.(hasPrec); ok {
+ prec = p.prec()
+ }
+ needsParen := false
+ if prec > precCast {
+ needsParen = true
+ }
+ if needsParen {
+ ps.startScope('(')
+ }
ps.print(a)
+ if needsParen {
+ ps.endScope(')')
+ }
+ } else {
+ parenthesize(ps, a)
}
}
if f.Arg2 == nil {
if f.Left {
- ps.writeString("(...")
+ ps.startScope('(')
+ ps.writeString("...")
printOp()
foldParenthesize(f.Arg1)
- ps.writeString(")")
+ ps.endScope(')')
} else {
- ps.writeString("(")
+ ps.startScope('(')
foldParenthesize(f.Arg1)
printOp()
- ps.writeString("...)")
+ ps.writeString("...")
+ ps.endScope(')')
}
} else {
- ps.writeString("(")
+ ps.startScope('(')
foldParenthesize(f.Arg1)
printOp()
ps.writeString("...")
printOp()
foldParenthesize(f.Arg2)
- ps.writeString(")")
+ ps.endScope(')')
}
}
@@ -3109,11 +3665,11 @@ type PtrMemCast struct {
}
func (pmc *PtrMemCast) print(ps *printState) {
- ps.writeString("(")
+ ps.startScope('(')
ps.print(pmc.Type)
ps.writeString(")(")
ps.print(pmc.Expr)
- ps.writeString(")")
+ ps.endScope(')')
}
func (pmc *PtrMemCast) Traverse(fn func(AST) bool) {
@@ -3310,7 +3866,7 @@ func (l *Literal) print(ps *printState) {
ps.writeString("true")
return
}
- } else if b.Name == "decltype(nullptr)" && l.Val == "" {
+ } else if b.Name == "decltype(nullptr)" && (l.Val == "" || l.Val == "0") {
if ps.llvmStyle {
ps.writeString("nullptr")
} else {
@@ -3322,9 +3878,9 @@ func (l *Literal) print(ps *printState) {
}
}
- ps.writeByte('(')
+ ps.startScope('(')
ps.print(l.Type)
- ps.writeByte(')')
+ ps.endScope(')')
if isFloat {
ps.writeByte('[')
@@ -3373,6 +3929,10 @@ func (l *Literal) goString(indent int, field string) string {
indent+2, "", l.Val)
}
+func (l *Literal) prec() precedence {
+ return precPrimary
+}
+
// StringLiteral is a string literal.
type StringLiteral struct {
Type AST
@@ -3464,12 +4024,7 @@ type ExprList struct {
}
func (el *ExprList) print(ps *printState) {
- for i, e := range el.Exprs {
- if i > 0 {
- ps.writeString(", ")
- }
- ps.print(e)
- }
+ ps.printList(el.Exprs, nil)
}
func (el *ExprList) Traverse(fn func(AST) bool) {
@@ -3521,6 +4076,10 @@ func (el *ExprList) goString(indent int, field string) string {
return s
}
+func (el *ExprList) prec() precedence {
+ return precComma
+}
+
// InitializerList is an initializer list: an optional type with a
// list of expressions.
type InitializerList struct {
@@ -3631,9 +4190,11 @@ func (da *DefaultArg) goString(indent int, field string) string {
// Closure is a closure, or lambda expression.
type Closure struct {
- TemplateArgs []AST
- Types []AST
- Num int
+ TemplateArgs []AST
+ TemplateArgsConstraint AST
+ Types []AST
+ Num int
+ CallConstraint AST
}
func (cl *Closure) print(ps *printState) {
@@ -3654,23 +4215,30 @@ func (cl *Closure) print(ps *printState) {
func (cl *Closure) printTypes(ps *printState) {
if len(cl.TemplateArgs) > 0 {
+ scopes := ps.scopes
+ ps.scopes = 0
+
ps.writeString("<")
- for i, a := range cl.TemplateArgs {
- if i > 0 {
- ps.writeString(", ")
- }
- ps.print(a)
- }
+ ps.printList(cl.TemplateArgs, nil)
ps.writeString(">")
+
+ ps.scopes = scopes
}
- ps.writeString("(")
- for i, t := range cl.Types {
- if i > 0 {
- ps.writeString(", ")
- }
- ps.print(t)
+
+ if cl.TemplateArgsConstraint != nil {
+ ps.writeString(" requires ")
+ ps.print(cl.TemplateArgsConstraint)
+ ps.writeByte(' ')
+ }
+
+ ps.startScope('(')
+ ps.printList(cl.Types, nil)
+ ps.endScope(')')
+
+ if cl.CallConstraint != nil {
+ ps.writeString(" requires ")
+ ps.print(cl.CallConstraint)
}
- ps.writeString(")")
}
func (cl *Closure) Traverse(fn func(AST) bool) {
@@ -3678,9 +4246,15 @@ func (cl *Closure) Traverse(fn func(AST) bool) {
for _, a := range cl.TemplateArgs {
a.Traverse(fn)
}
+ if cl.TemplateArgsConstraint != nil {
+ cl.TemplateArgsConstraint.Traverse(fn)
+ }
for _, t := range cl.Types {
t.Traverse(fn)
}
+ if cl.CallConstraint != nil {
+ cl.CallConstraint.Traverse(fn)
+ }
}
}
@@ -3701,6 +4275,16 @@ func (cl *Closure) Copy(fn func(AST) AST, skip func(AST) bool) AST {
}
}
+ var templateArgsConstraint AST
+ if cl.TemplateArgsConstraint != nil {
+ templateArgsConstraint = cl.TemplateArgsConstraint.Copy(fn, skip)
+ if templateArgsConstraint == nil {
+ templateArgsConstraint = cl.TemplateArgsConstraint
+ } else {
+ changed = true
+ }
+ }
+
types := make([]AST, len(cl.Types))
for i, t := range cl.Types {
tc := t.Copy(fn, skip)
@@ -3712,10 +4296,26 @@ func (cl *Closure) Copy(fn func(AST) AST, skip func(AST) bool) AST {
}
}
+ var callConstraint AST
+ if cl.CallConstraint != nil {
+ callConstraint = cl.CallConstraint.Copy(fn, skip)
+ if callConstraint == nil {
+ callConstraint = cl.CallConstraint
+ } else {
+ changed = true
+ }
+ }
+
if !changed {
return fn(cl)
}
- cl = &Closure{TemplateArgs: args, Types: types, Num: cl.Num}
+ cl = &Closure{
+ TemplateArgs: args,
+ TemplateArgsConstraint: templateArgsConstraint,
+ Types: types,
+ Num: cl.Num,
+ CallConstraint: callConstraint,
+ }
if r := fn(cl); r != nil {
return r
}
@@ -3727,28 +4327,41 @@ func (cl *Closure) GoString() string {
}
func (cl *Closure) goString(indent int, field string) string {
- var args string
+ var args strings.Builder
if len(cl.TemplateArgs) == 0 {
- args = fmt.Sprintf("%*sTemplateArgs: nil", indent+2, "")
+ fmt.Fprintf(&args, "%*sTemplateArgs: nil", indent+2, "")
} else {
- args = fmt.Sprintf("%*sTemplateArgs:", indent+2, "")
+ fmt.Fprintf(&args, "%*sTemplateArgs:", indent+2, "")
for i, a := range cl.TemplateArgs {
- args += "\n"
- args += a.goString(indent+4, fmt.Sprintf("%d: ", i))
+ args.WriteByte('\n')
+ args.WriteString(a.goString(indent+4, fmt.Sprintf("%d: ", i)))
}
}
- var types string
+
+ var templateArgsConstraint string
+ if cl.TemplateArgsConstraint != nil {
+ templateArgsConstraint = "\n" + cl.TemplateArgsConstraint.goString(indent+2, "TemplateArgsConstraint: ")
+ }
+
+ var types strings.Builder
if len(cl.Types) == 0 {
- types = fmt.Sprintf("%*sTypes: nil", indent+2, "")
+ fmt.Fprintf(&types, "%*sTypes: nil", indent+2, "")
} else {
- types = fmt.Sprintf("%*sTypes:", indent+2, "")
+ fmt.Fprintf(&types, "%*sTypes:", indent+2, "")
for i, t := range cl.Types {
- types += "\n"
- types += t.goString(indent+4, fmt.Sprintf("%d: ", i))
+ types.WriteByte('\n')
+ types.WriteString(t.goString(indent+4, fmt.Sprintf("%d: ", i)))
}
}
- return fmt.Sprintf("%*s%sClosure: Num: %d\n%s\n%s", indent, "", field,
- cl.Num, args, types)
+
+ var callConstraint string
+ if cl.CallConstraint != nil {
+ callConstraint = "\n" + cl.CallConstraint.goString(indent+2, "CallConstraint: ")
+ }
+
+ return fmt.Sprintf("%*s%sClosure: Num: %d\n%s\n%s%s%s", indent, "", field,
+ cl.Num, args.String(), templateArgsConstraint, types.String(),
+ callConstraint)
}
// StructuredBindings is a structured binding declaration.
@@ -3758,12 +4371,7 @@ type StructuredBindings struct {
func (sb *StructuredBindings) print(ps *printState) {
ps.writeString("[")
- for i, b := range sb.Bindings {
- if i > 0 {
- ps.writeString(", ")
- }
- b.print(ps)
- }
+ ps.printList(sb.Bindings, nil)
ps.writeString("]")
}
@@ -3859,9 +4467,10 @@ type Clone struct {
func (c *Clone) print(ps *printState) {
ps.print(c.Base)
if ps.llvmStyle {
- ps.writeString(" (")
+ ps.writeByte(' ')
+ ps.startScope('(')
ps.writeString(c.Suffix)
- ps.writeByte(')')
+ ps.endScope(')')
} else {
ps.writeString(fmt.Sprintf(" [clone %s]", c.Suffix))
}
@@ -4011,14 +4620,7 @@ type EnableIf struct {
func (ei *EnableIf) print(ps *printState) {
ps.print(ei.Type)
ps.writeString(" [enable_if:")
- first := true
- for _, a := range ei.Args {
- if !first {
- ps.writeString(", ")
- }
- ps.print(a)
- first = false
- }
+ ps.printList(ei.Args, nil)
ps.writeString("]")
}
@@ -4079,6 +4681,518 @@ func (ei *EnableIf) goString(indent int, field string) string {
ei.Type.goString(indent+2, "Type: "), args)
}
+// ModuleName is a C++20 module.
+type ModuleName struct {
+ Parent AST
+ Name AST
+ IsPartition bool
+}
+
+func (mn *ModuleName) print(ps *printState) {
+ if mn.Parent != nil {
+ ps.print(mn.Parent)
+ }
+ if mn.IsPartition {
+ ps.writeByte(':')
+ } else if mn.Parent != nil {
+ ps.writeByte('.')
+ }
+ ps.print(mn.Name)
+}
+
+func (mn *ModuleName) Traverse(fn func(AST) bool) {
+ if fn(mn) {
+ mn.Parent.Traverse(fn)
+ mn.Name.Traverse(fn)
+ }
+}
+
+func (mn *ModuleName) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(mn) {
+ return nil
+ }
+ var parent AST
+ if mn.Parent != nil {
+ parent = mn.Parent.Copy(fn, skip)
+ }
+ name := mn.Name.Copy(fn, skip)
+ if parent == nil && name == nil {
+ return fn(mn)
+ }
+ if parent == nil {
+ parent = mn.Parent
+ }
+ if name == nil {
+ name = mn.Name
+ }
+ mn = &ModuleName{Parent: parent, Name: name, IsPartition: mn.IsPartition}
+ if r := fn(mn); r != nil {
+ return r
+ }
+ return mn
+}
+
+func (mn *ModuleName) GoString() string {
+ return mn.goString(0, "")
+}
+
+func (mn *ModuleName) goString(indent int, field string) string {
+ var parent string
+ if mn.Parent == nil {
+ parent = fmt.Sprintf("%*sParent: nil", indent+2, "")
+ } else {
+ parent = mn.Parent.goString(indent+2, "Parent: ")
+ }
+ return fmt.Sprintf("%*s%sModuleName: IsPartition: %t\n%s\n%s", indent, "", field,
+ mn.IsPartition, parent,
+ mn.Name.goString(indent+2, "Name: "))
+}
+
+// ModuleEntity is a name inside a module.
+type ModuleEntity struct {
+ Module AST
+ Name AST
+}
+
+func (me *ModuleEntity) print(ps *printState) {
+ ps.print(me.Name)
+ ps.writeByte('@')
+ ps.print(me.Module)
+}
+
+func (me *ModuleEntity) Traverse(fn func(AST) bool) {
+ if fn(me) {
+ me.Module.Traverse(fn)
+ me.Name.Traverse(fn)
+ }
+}
+
+func (me *ModuleEntity) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(me) {
+ return nil
+ }
+ module := me.Module.Copy(fn, skip)
+ name := me.Name.Copy(fn, skip)
+ if module == nil && name == nil {
+ return fn(me)
+ }
+ if module == nil {
+ module = me.Module
+ }
+ if name == nil {
+ name = me.Name
+ }
+ me = &ModuleEntity{Module: module, Name: name}
+ if r := fn(me); r != nil {
+ return r
+ }
+ return me
+}
+
+func (me *ModuleEntity) GoString() string {
+ return me.goString(0, "")
+}
+
+func (me *ModuleEntity) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sModuleEntity:\n%s\n%s", indent, "", field,
+ me.Module.goString(indent+2, "Module: "),
+ me.Name.goString(indent+2, "Name: "))
+}
+
+// Friend is a member like friend name.
+type Friend struct {
+ Name AST
+}
+
+func (f *Friend) print(ps *printState) {
+ ps.writeString("friend ")
+ ps.print(f.Name)
+}
+
+func (f *Friend) Traverse(fn func(AST) bool) {
+ if fn(f) {
+ f.Name.Traverse(fn)
+ }
+}
+
+func (f *Friend) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(f) {
+ return nil
+ }
+ name := f.Name.Copy(fn, skip)
+ if name == nil {
+ return fn(f)
+ }
+ f = &Friend{Name: name}
+ if r := fn(f); r != nil {
+ return r
+ }
+ return f
+}
+
+func (f *Friend) GoString() string {
+ return f.goString(0, "")
+}
+
+func (f *Friend) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sFriend:\n%s", indent, "", field,
+ f.Name.goString(indent+2, "Name: "))
+}
+
+// Constraint represents an AST with a constraint.
+type Constraint struct {
+ Name AST
+ Requires AST
+}
+
+func (c *Constraint) print(ps *printState) {
+ ps.print(c.Name)
+ ps.writeString(" requires ")
+ ps.print(c.Requires)
+}
+
+func (c *Constraint) Traverse(fn func(AST) bool) {
+ if fn(c) {
+ c.Name.Traverse(fn)
+ c.Requires.Traverse(fn)
+ }
+}
+
+func (c *Constraint) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(c) {
+ return nil
+ }
+ name := c.Name.Copy(fn, skip)
+ requires := c.Requires.Copy(fn, skip)
+ if name == nil && requires == nil {
+ return fn(c)
+ }
+ if name == nil {
+ name = c.Name
+ }
+ if requires == nil {
+ requires = c.Requires
+ }
+ c = &Constraint{Name: name, Requires: requires}
+ if r := fn(c); r != nil {
+ return r
+ }
+ return c
+}
+
+func (c *Constraint) GoString() string {
+ return c.goString(0, "")
+}
+
+func (c *Constraint) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sConstraint:\n%s\n%s", indent, "", field,
+ c.Name.goString(indent+2, "Name: "),
+ c.Requires.goString(indent+2, "Requires: "))
+}
+
+// RequiresExpr is a C++20 requires expression.
+type RequiresExpr struct {
+ Params []AST
+ Requirements []AST
+}
+
+func (re *RequiresExpr) print(ps *printState) {
+ ps.writeString("requires")
+ if len(re.Params) > 0 {
+ ps.writeByte(' ')
+ ps.startScope('(')
+ ps.printList(re.Params, nil)
+ ps.endScope(')')
+ }
+ ps.writeByte(' ')
+ ps.startScope('{')
+ for _, req := range re.Requirements {
+ ps.print(req)
+ }
+ ps.writeByte(' ')
+ ps.endScope('}')
+}
+
+func (re *RequiresExpr) Traverse(fn func(AST) bool) {
+ if fn(re) {
+ for _, p := range re.Params {
+ p.Traverse(fn)
+ }
+ for _, r := range re.Requirements {
+ r.Traverse(fn)
+ }
+ }
+}
+
+func (re *RequiresExpr) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(re) {
+ return nil
+ }
+
+ changed := false
+
+ var params []AST
+ if len(re.Params) > 0 {
+ params = make([]AST, len(re.Params))
+ for i, p := range re.Params {
+ pc := p.Copy(fn, skip)
+ if pc == nil {
+ params[i] = p
+ } else {
+ params[i] = pc
+ changed = true
+ }
+ }
+ }
+
+ requirements := make([]AST, len(re.Requirements))
+ for i, r := range re.Requirements {
+ rc := r.Copy(fn, skip)
+ if rc == nil {
+ requirements[i] = r
+ } else {
+ requirements[i] = rc
+ changed = true
+ }
+ }
+
+ if !changed {
+ return fn(re)
+ }
+
+ re = &RequiresExpr{Params: params, Requirements: requirements}
+ if r := fn(re); r != nil {
+ return r
+ }
+ return re
+}
+
+func (re *RequiresExpr) GoString() string {
+ return re.goString(0, "")
+}
+
+func (re *RequiresExpr) goString(indent int, field string) string {
+ var params strings.Builder
+ if len(re.Params) == 0 {
+ fmt.Fprintf(¶ms, "%*sParams: nil", indent+2, "")
+ } else {
+ fmt.Fprintf(¶ms, "%*sParams:", indent+2, "")
+ for i, p := range re.Params {
+ params.WriteByte('\n')
+ params.WriteString(p.goString(indent+4, fmt.Sprintf("%d: ", i)))
+ }
+ }
+
+ var requirements strings.Builder
+ fmt.Fprintf(&requirements, "%*sRequirements:", indent+2, "")
+ for i, r := range re.Requirements {
+ requirements.WriteByte('\n')
+ requirements.WriteString(r.goString(indent+4, fmt.Sprintf("%d: ", i)))
+ }
+
+ return fmt.Sprintf("%*s%sRequirements:\n%s\n%s", indent, "", field,
+ params.String(), requirements.String())
+}
+
+// ExprRequirement is a simple requirement in a requires expression.
+// This is an arbitrary expression.
+type ExprRequirement struct {
+ Expr AST
+ Noexcept bool
+ TypeReq AST
+}
+
+func (er *ExprRequirement) print(ps *printState) {
+ ps.writeByte(' ')
+ if er.Noexcept || er.TypeReq != nil {
+ ps.startScope('{')
+ }
+ ps.print(er.Expr)
+ if er.Noexcept || er.TypeReq != nil {
+ ps.endScope('}')
+ }
+ if er.Noexcept {
+ ps.writeString(" noexcept")
+ }
+ if er.TypeReq != nil {
+ ps.writeString(" -> ")
+ ps.print(er.TypeReq)
+ }
+ ps.writeByte(';')
+}
+
+func (er *ExprRequirement) Traverse(fn func(AST) bool) {
+ if fn(er) {
+ er.Expr.Traverse(fn)
+ if er.TypeReq != nil {
+ er.TypeReq.Traverse(fn)
+ }
+ }
+}
+
+func (er *ExprRequirement) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(er) {
+ return nil
+ }
+ expr := er.Expr.Copy(fn, skip)
+ var typeReq AST
+ if er.TypeReq != nil {
+ typeReq = er.TypeReq.Copy(fn, skip)
+ }
+ if expr == nil && typeReq == nil {
+ return fn(er)
+ }
+ if expr == nil {
+ expr = er.Expr
+ }
+ if typeReq == nil {
+ typeReq = er.TypeReq
+ }
+ er = &ExprRequirement{Expr: expr, TypeReq: typeReq}
+ if r := fn(er); r != nil {
+ return r
+ }
+ return er
+}
+
+func (er *ExprRequirement) GoString() string {
+ return er.goString(0, "")
+}
+
+func (er *ExprRequirement) goString(indent int, field string) string {
+ var typeReq string
+ if er.TypeReq != nil {
+ typeReq = "\n" + er.TypeReq.goString(indent+2, "TypeReq: ")
+ }
+
+ return fmt.Sprintf("%*s%sExprRequirement: Noexcept: %t\n%s%s", indent, "", field,
+ er.Noexcept,
+ er.Expr.goString(indent+2, "Expr: "),
+ typeReq)
+}
+
+// TypeRequirement is a type requirement in a requires expression.
+type TypeRequirement struct {
+ Type AST
+}
+
+func (tr *TypeRequirement) print(ps *printState) {
+ ps.writeString(" typename ")
+ ps.print(tr.Type)
+ ps.writeByte(';')
+}
+
+func (tr *TypeRequirement) Traverse(fn func(AST) bool) {
+ if fn(tr) {
+ tr.Type.Traverse(fn)
+ }
+}
+
+func (tr *TypeRequirement) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(tr) {
+ return nil
+ }
+ typ := tr.Type.Copy(fn, skip)
+ if typ == nil {
+ return fn(tr)
+ }
+ tr = &TypeRequirement{Type: typ}
+ if r := fn(tr); r != nil {
+ return r
+ }
+ return tr
+}
+
+func (tr *TypeRequirement) GoString() string {
+ return tr.goString(0, "")
+}
+
+func (tr *TypeRequirement) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sTypeRequirement:\n%s", indent, "", field,
+ tr.Type.goString(indent+2, ""))
+}
+
+// NestedRequirement is a nested requirement in a requires expression.
+type NestedRequirement struct {
+ Constraint AST
+}
+
+func (nr *NestedRequirement) print(ps *printState) {
+ ps.writeString(" requires ")
+ ps.print(nr.Constraint)
+ ps.writeByte(';')
+}
+
+func (nr *NestedRequirement) Traverse(fn func(AST) bool) {
+ if fn(nr) {
+ nr.Constraint.Traverse(fn)
+ }
+}
+
+func (nr *NestedRequirement) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(nr) {
+ return nil
+ }
+ constraint := nr.Constraint.Copy(fn, skip)
+ if constraint == nil {
+ return fn(nr)
+ }
+ nr = &NestedRequirement{Constraint: constraint}
+ if r := fn(nr); r != nil {
+ return r
+ }
+ return nr
+}
+
+func (nr *NestedRequirement) GoString() string {
+ return nr.goString(0, "")
+}
+
+func (nr *NestedRequirement) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sNestedRequirement:\n%s", indent, "", field,
+ nr.Constraint.goString(indent+2, ""))
+}
+
+// ExplicitObjectParameter represents a C++23 explicit object parameter.
+type ExplicitObjectParameter struct {
+ Base AST
+}
+
+func (eop *ExplicitObjectParameter) print(ps *printState) {
+ ps.writeString("this ")
+ ps.print(eop.Base)
+}
+
+func (eop *ExplicitObjectParameter) Traverse(fn func(AST) bool) {
+ if fn(eop) {
+ eop.Base.Traverse(fn)
+ }
+}
+
+func (eop *ExplicitObjectParameter) Copy(fn func(AST) AST, skip func(AST) bool) AST {
+ if skip(eop) {
+ return nil
+ }
+ base := eop.Base.Copy(fn, skip)
+ if base == nil {
+ return fn(eop)
+ }
+ eop = &ExplicitObjectParameter{Base: base}
+ if r := fn(eop); r != nil {
+ return r
+ }
+ return eop
+}
+
+func (eop *ExplicitObjectParameter) GoString() string {
+ return eop.goString(0, "")
+}
+
+func (eop *ExplicitObjectParameter) goString(indent int, field string) string {
+ return fmt.Sprintf("%*s%sExplicitObjectParameter:\n%s", indent, "", field,
+ eop.Base.goString(indent+2, ""))
+}
+
// Print the inner types.
func (ps *printState) printInner(prefixOnly bool) []AST {
var save []AST
diff --git a/src/cmd/vendor/github.com/ianlancetaylor/demangle/demangle.go b/src/cmd/vendor/github.com/ianlancetaylor/demangle/demangle.go
index 14e77a6ac4..4ca57e62a4 100644
--- a/src/cmd/vendor/github.com/ianlancetaylor/demangle/demangle.go
+++ b/src/cmd/vendor/github.com/ianlancetaylor/demangle/demangle.go
@@ -301,6 +301,8 @@ type state struct {
// a lambda, plus 1 so that 0 means not parsing a lambda.
lambdaTemplateLevel int
+ parsingConstraint bool // whether parsing a constraint expression
+
// Counts of template parameters without template arguments,
// for lambdas.
typeTemplateParamCount int
@@ -393,7 +395,7 @@ func (st *state) encoding(params bool, local forLocalNameType) AST {
return st.specialName()
}
- a := st.name()
+ a, explicitObjectParameter := st.name()
a = simplify(a)
if !params {
@@ -471,7 +473,12 @@ func (st *state) encoding(params bool, local forLocalNameType) AST {
enableIfArgs = st.templateArgs()
}
- ft := st.bareFunctionType(hasReturnType(a))
+ ft := st.bareFunctionType(hasReturnType(a), explicitObjectParameter)
+
+ var constraint AST
+ if len(st.str) > 0 && st.str[0] == 'Q' {
+ constraint = st.constraintExpr()
+ }
if template != nil {
st.templates = st.templates[:len(st.templates)-1]
@@ -512,6 +519,10 @@ func (st *state) encoding(params bool, local forLocalNameType) AST {
r = &EnableIf{Type: r, Args: enableIfArgs}
}
+ if constraint != nil {
+ r = &Constraint{Name: r, Requires: constraint}
+ }
+
return r
}
@@ -572,21 +583,26 @@ func (st *state) taggedName(a AST) AST {
//
//