go/src/cmd/compile/internal/gc/fmt.go

1957 lines
43 KiB
Go
Raw Normal View History

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gc
import (
"fmt"
"strconv"
"strings"
"unicode/utf8"
)
// A FmtFlag value is a set of flags (or 0).
// They control how the Xconv functions format their values.
// See the respective function's documentation for details.
type FmtFlag int
const ( // fmt.Format flag/prec or verb
FmtLeft FmtFlag = 1 << iota // '-'
FmtSharp // '#'
FmtSign // '+'
FmtUnsigned // internal use only (historic: u flag)
FmtShort // verb == 'S' (historic: h flag)
FmtLong // verb == 'L' (historic: l flag)
FmtComma // '.' (== hasPrec) (historic: , flag)
FmtByte // '0' (historic: hh flag)
)
// fmtFlag computes the (internal) FmtFlag
// value given the fmt.State and format verb.
func fmtFlag(s fmt.State, verb rune) FmtFlag {
var flag FmtFlag
if s.Flag('-') {
flag |= FmtLeft
}
if s.Flag('#') {
flag |= FmtSharp
}
if s.Flag('+') {
flag |= FmtSign
}
if s.Flag(' ') {
Fatalf("FmtUnsigned in format string")
}
if _, ok := s.Precision(); ok {
flag |= FmtComma
}
if s.Flag('0') {
flag |= FmtByte
}
switch verb {
case 'S':
flag |= FmtShort
case 'L':
flag |= FmtLong
}
return flag
}
// Format conversions:
// TODO(gri) verify these; eliminate those not used anymore
//
// %v Op Node opcodes
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// Flags: #: print Go syntax (automatic unless mode == FDbg)
//
// %j *Node Node details
// Flags: 0: suppresses things not relevant until walk
//
// %v *Val Constant values
//
// %v *Sym Symbols
// %S unqualified identifier in any mode
// Flags: +,- #: mode (see below)
// 0: in export mode: unqualified identifier if exported, qualified if not
//
// %v *Type Types
// %S omit "func" and receiver in function types
// %L definition instead of name.
// Flags: +,- #: mode (see below)
// ' ' (only in -/Sym mode) print type identifiers wit package name instead of prefix.
//
// %v *Node Nodes
// %S (only in +/debug mode) suppress recursion
// %L (only in Error mode) print "foo (type Bar)"
// Flags: +,- #: mode (see below)
//
// %v Nodes Node lists
// Flags: those of *Node
// .: separate items with ',' instead of ';'
// *Sym, *Type, and *Node types use the flags below to set the format mode
const (
FErr = iota
FDbg
FTypeId
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
FTypeIdName // same as FTypeId, but use package name instead of prefix
)
// The mode flags '+', '-', and '#' are sticky; they persist through
// recursions of *Node, *Type, and *Sym values. The ' ' flag is
// sticky only on *Type recursions and only used in %-/*Sym mode.
//
// Example: given a *Sym: %+v %#v %-v print an identifier properly qualified for debug/export/internal mode
// Useful format combinations:
// TODO(gri): verify these
//
// *Node, Nodes:
// %+v multiline recursive debug dump of *Node/Nodes
// %+S non-recursive debug dump
//
// *Node:
// %#v Go format
// %L "foo (type Bar)" for error messages
//
// *Type:
// %#v Go format
// %#L type definition instead of name
// %#S omit"func" and receiver in function signature
//
// %-v type identifiers
// %-S type identifiers without "func" and arg names in type signatures (methodsym)
// %- v type identifiers with package name instead of prefix (typesym, dcommontype, typehash)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// update returns the results of applying f to mode.
func (f FmtFlag) update(mode fmtMode) (FmtFlag, fmtMode) {
switch {
case f&FmtSign != 0:
mode = FDbg
case f&FmtSharp != 0:
// ignore (textual export format no longer supported)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
case f&FmtUnsigned != 0:
mode = FTypeIdName
case f&FmtLeft != 0:
mode = FTypeId
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
f &^= FmtSharp | FmtLeft | FmtSign
return f, mode
}
var goopnames = []string{
OADDR: "&",
OADD: "+",
OADDSTR: "+",
OALIGNOF: "unsafe.Alignof",
OANDAND: "&&",
OANDNOT: "&^",
OAND: "&",
OAPPEND: "append",
OAS: "=",
OAS2: "=",
OBREAK: "break",
OCALL: "function call", // not actual syntax
OCAP: "cap",
OCASE: "case",
OCLOSE: "close",
OCOMPLEX: "complex",
OCOM: "^",
OCONTINUE: "continue",
OCOPY: "copy",
ODELETE: "delete",
ODEFER: "defer",
ODIV: "/",
OEQ: "==",
OFALL: "fallthrough",
OFOR: "for",
OFORUNTIL: "foruntil", // not actual syntax; used to avoid off-end pointer live on backedge.892
OGE: ">=",
OGOTO: "goto",
OGT: ">",
OIF: "if",
OIMAG: "imag",
OIND: "*",
OLEN: "len",
OLE: "<=",
OLSH: "<<",
OLT: "<",
OMAKE: "make",
OMINUS: "-",
OMOD: "%",
OMUL: "*",
ONEW: "new",
ONE: "!=",
ONOT: "!",
OOFFSETOF: "unsafe.Offsetof",
OOROR: "||",
OOR: "|",
OPANIC: "panic",
OPLUS: "+",
OPRINTN: "println",
OPRINT: "print",
ORANGE: "range",
OREAL: "real",
ORECV: "<-",
ORECOVER: "recover",
ORETURN: "return",
ORSH: ">>",
OSELECT: "select",
OSEND: "<-",
OSIZEOF: "unsafe.Sizeof",
OSUB: "-",
OSWITCH: "switch",
OXOR: "^",
OXFALL: "fallthrough",
}
func (o Op) String() string {
return fmt.Sprint(o)
}
func (o Op) GoString() string {
return fmt.Sprintf("%#v", o)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (o Op) format(s fmt.State, verb rune, mode fmtMode) {
switch verb {
case 'v':
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
o.oconv(s, fmtFlag(s, verb), mode)
default:
fmt.Fprintf(s, "%%!%c(Op=%d)", verb, int(o))
}
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (o Op) oconv(s fmt.State, flag FmtFlag, mode fmtMode) {
if flag&FmtSharp != 0 || mode != FDbg {
if o >= 0 && int(o) < len(goopnames) && goopnames[o] != "" {
fmt.Fprint(s, goopnames[o])
return
}
}
if o >= 0 && int(o) < len(opnames) && opnames[o] != "" {
fmt.Fprint(s, opnames[o])
return
}
fmt.Fprintf(s, "O-%d", int(o))
}
var classnames = []string{
"Pxxx",
"PEXTERN",
"PAUTO",
cmd/compile: fix liveness computation for heap-escaped parameters The liveness computation of parameters generally was never correct, but forcing all parameters to be live throughout the function covered up that problem. The new SSA back end is too clever: even though it currently keeps the parameter values live throughout the function, it may find optimizations that mean the current values are not written back to the original parameter stack slots immediately or ever (for example if a parameter is set to nil, SSA constant propagation may replace all later uses of the parameter with a constant nil, eliminating the need to write the nil value back to the stack slot), so the liveness code must now track the actual operations on the stack slots, exposing these problems. One small problem in the handling of arguments is that nodarg can return ONAME PPARAM nodes with adjusted offsets, so that there are actually multiple *Node pointers for the same parameter in the instruction stream. This might be possible to correct, but not in this CL. For now, we fix this by using n.Orig instead of n when considering PPARAM and PPARAMOUT nodes. The major problem in the handling of arguments is general confusion in the liveness code about the meaning of PPARAM|PHEAP and PPARAMOUT|PHEAP nodes, especially as contrasted with PAUTO|PHEAP. The difference between these two is that when a local variable "moves" to the heap, it's really just allocated there to start with; in contrast, when an argument moves to the heap, the actual data has to be copied there from the stack at the beginning of the function, and when a result "moves" to the heap the value in the heap has to be copied back to the stack when the function returns This general confusion is also present in the SSA back end. The PHEAP bit worked decently when I first introduced it 7 years ago (!) in 391425ae. The back end did nothing sophisticated, and in particular there was no analysis at all: no escape analysis, no liveness analysis, and certainly no SSA back end. But the complications caused in the various downstream consumers suggest that this should be a detail kept mainly in the front end. This CL therefore eliminates both the PHEAP bit and even the idea of "heap variables" from the back ends. First, it replaces the PPARAM|PHEAP, PPARAMOUT|PHEAP, and PAUTO|PHEAP variable classes with the single PAUTOHEAP, a pseudo-class indicating a variable maintained on the heap and available by indirecting a local variable kept on the stack (a plain PAUTO). Second, walkexpr replaces all references to PAUTOHEAP variables with indirections of the corresponding PAUTO variable. The back ends and the liveness code now just see plain indirected variables. This may actually produce better code, but the real goal here is to eliminate these little-used and somewhat suspect code paths in the back end analyses. The OPARAM node type goes away too. A followup CL will do the same to PPARAMREF. I'm not sure that the back ends (SSA in particular) are handling those right either, and with the framework established in this CL that change is trivial and the result clearly more correct. Fixes #15747. Change-Id: I2770b1ce3cbc93981bfc7166be66a9da12013d74 Reviewed-on: https://go-review.googlesource.com/23393 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-25 01:33:24 -04:00
"PAUTOHEAP",
"PPARAM",
"PPARAMOUT",
"PFUNC",
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
type (
fmtMode int
fmtNodeErr Node
fmtNodeDbg Node
fmtNodeTypeId Node
fmtNodeTypeIdName Node
fmtOpErr Op
fmtOpDbg Op
fmtOpTypeId Op
fmtOpTypeIdName Op
fmtTypeErr Type
fmtTypeDbg Type
fmtTypeTypeId Type
fmtTypeTypeIdName Type
fmtSymErr Sym
fmtSymDbg Sym
fmtSymTypeId Sym
fmtSymTypeIdName Sym
fmtNodesErr Nodes
fmtNodesDbg Nodes
fmtNodesTypeId Nodes
fmtNodesTypeIdName Nodes
)
func (n *fmtNodeErr) Format(s fmt.State, verb rune) { (*Node)(n).format(s, verb, FErr) }
func (n *fmtNodeDbg) Format(s fmt.State, verb rune) { (*Node)(n).format(s, verb, FDbg) }
func (n *fmtNodeTypeId) Format(s fmt.State, verb rune) { (*Node)(n).format(s, verb, FTypeId) }
func (n *fmtNodeTypeIdName) Format(s fmt.State, verb rune) { (*Node)(n).format(s, verb, FTypeIdName) }
func (n *Node) Format(s fmt.State, verb rune) { n.format(s, verb, FErr) }
func (o fmtOpErr) Format(s fmt.State, verb rune) { Op(o).format(s, verb, FErr) }
func (o fmtOpDbg) Format(s fmt.State, verb rune) { Op(o).format(s, verb, FDbg) }
func (o fmtOpTypeId) Format(s fmt.State, verb rune) { Op(o).format(s, verb, FTypeId) }
func (o fmtOpTypeIdName) Format(s fmt.State, verb rune) { Op(o).format(s, verb, FTypeIdName) }
func (o Op) Format(s fmt.State, verb rune) { o.format(s, verb, FErr) }
func (t *fmtTypeErr) Format(s fmt.State, verb rune) { (*Type)(t).format(s, verb, FErr) }
func (t *fmtTypeDbg) Format(s fmt.State, verb rune) { (*Type)(t).format(s, verb, FDbg) }
func (t *fmtTypeTypeId) Format(s fmt.State, verb rune) { (*Type)(t).format(s, verb, FTypeId) }
func (t *fmtTypeTypeIdName) Format(s fmt.State, verb rune) { (*Type)(t).format(s, verb, FTypeIdName) }
func (t *Type) Format(s fmt.State, verb rune) { t.format(s, verb, FErr) }
func (y *fmtSymErr) Format(s fmt.State, verb rune) { (*Sym)(y).format(s, verb, FErr) }
func (y *fmtSymDbg) Format(s fmt.State, verb rune) { (*Sym)(y).format(s, verb, FDbg) }
func (y *fmtSymTypeId) Format(s fmt.State, verb rune) { (*Sym)(y).format(s, verb, FTypeId) }
func (y *fmtSymTypeIdName) Format(s fmt.State, verb rune) { (*Sym)(y).format(s, verb, FTypeIdName) }
func (y *Sym) Format(s fmt.State, verb rune) { y.format(s, verb, FErr) }
func (n fmtNodesErr) Format(s fmt.State, verb rune) { (Nodes)(n).format(s, verb, FErr) }
func (n fmtNodesDbg) Format(s fmt.State, verb rune) { (Nodes)(n).format(s, verb, FDbg) }
func (n fmtNodesTypeId) Format(s fmt.State, verb rune) { (Nodes)(n).format(s, verb, FTypeId) }
func (n fmtNodesTypeIdName) Format(s fmt.State, verb rune) { (Nodes)(n).format(s, verb, FTypeIdName) }
func (n Nodes) Format(s fmt.State, verb rune) { n.format(s, verb, FErr) }
func (m fmtMode) Fprintf(s fmt.State, format string, args ...interface{}) {
m.prepareArgs(args)
fmt.Fprintf(s, format, args...)
}
func (m fmtMode) Sprintf(format string, args ...interface{}) string {
m.prepareArgs(args)
return fmt.Sprintf(format, args...)
}
func (m fmtMode) Sprint(args ...interface{}) string {
m.prepareArgs(args)
return fmt.Sprint(args...)
}
func (m fmtMode) prepareArgs(args []interface{}) {
switch m {
case FErr:
for i, arg := range args {
switch arg := arg.(type) {
case Op:
args[i] = fmtOpErr(arg)
case *Node:
args[i] = (*fmtNodeErr)(arg)
case *Type:
args[i] = (*fmtTypeErr)(arg)
case *Sym:
args[i] = (*fmtSymErr)(arg)
case Nodes:
args[i] = fmtNodesErr(arg)
case Val, int32, int64, string, EType:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// OK: printing these types doesn't depend on mode
default:
Fatalf("mode.prepareArgs type %T", arg)
}
}
case FDbg:
for i, arg := range args {
switch arg := arg.(type) {
case Op:
args[i] = fmtOpDbg(arg)
case *Node:
args[i] = (*fmtNodeDbg)(arg)
case *Type:
args[i] = (*fmtTypeDbg)(arg)
case *Sym:
args[i] = (*fmtSymDbg)(arg)
case Nodes:
args[i] = fmtNodesDbg(arg)
case Val, int32, int64, string, EType:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// OK: printing these types doesn't depend on mode
default:
Fatalf("mode.prepareArgs type %T", arg)
}
}
case FTypeId:
for i, arg := range args {
switch arg := arg.(type) {
case Op:
args[i] = fmtOpTypeId(arg)
case *Node:
args[i] = (*fmtNodeTypeId)(arg)
case *Type:
args[i] = (*fmtTypeTypeId)(arg)
case *Sym:
args[i] = (*fmtSymTypeId)(arg)
case Nodes:
args[i] = fmtNodesTypeId(arg)
case Val, int32, int64, string, EType:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// OK: printing these types doesn't depend on mode
default:
Fatalf("mode.prepareArgs type %T", arg)
}
}
case FTypeIdName:
for i, arg := range args {
switch arg := arg.(type) {
case Op:
args[i] = fmtOpTypeIdName(arg)
case *Node:
args[i] = (*fmtNodeTypeIdName)(arg)
case *Type:
args[i] = (*fmtTypeTypeIdName)(arg)
case *Sym:
args[i] = (*fmtSymTypeIdName)(arg)
case Nodes:
args[i] = fmtNodesTypeIdName(arg)
case Val, int32, int64, string, EType:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// OK: printing these types doesn't depend on mode
default:
Fatalf("mode.prepareArgs type %T", arg)
}
}
default:
Fatalf("mode.prepareArgs mode %d", m)
}
}
func (n *Node) format(s fmt.State, verb rune, mode fmtMode) {
switch verb {
case 'v', 'S', 'L':
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.nconv(s, fmtFlag(s, verb), mode)
case 'j':
n.jconv(s, fmtFlag(s, verb))
default:
fmt.Fprintf(s, "%%!%c(*Node=%p)", verb, n)
}
}
// *Node details
func (n *Node) jconv(s fmt.State, flag FmtFlag) {
c := flag & FmtShort
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if c == 0 && n.Addable() {
fmt.Fprintf(s, " a(%v)", n.Addable())
}
if c == 0 && n.Name != nil && n.Name.Vargen != 0 {
fmt.Fprintf(s, " g(%d)", n.Name.Vargen)
}
if n.Pos.IsKnown() {
fmt.Fprintf(s, " l(%d)", n.Pos.Line())
}
if c == 0 && n.Xoffset != BADWIDTH {
fmt.Fprintf(s, " x(%d)", n.Xoffset)
}
if n.Class != 0 {
cmd/compile: fix liveness computation for heap-escaped parameters The liveness computation of parameters generally was never correct, but forcing all parameters to be live throughout the function covered up that problem. The new SSA back end is too clever: even though it currently keeps the parameter values live throughout the function, it may find optimizations that mean the current values are not written back to the original parameter stack slots immediately or ever (for example if a parameter is set to nil, SSA constant propagation may replace all later uses of the parameter with a constant nil, eliminating the need to write the nil value back to the stack slot), so the liveness code must now track the actual operations on the stack slots, exposing these problems. One small problem in the handling of arguments is that nodarg can return ONAME PPARAM nodes with adjusted offsets, so that there are actually multiple *Node pointers for the same parameter in the instruction stream. This might be possible to correct, but not in this CL. For now, we fix this by using n.Orig instead of n when considering PPARAM and PPARAMOUT nodes. The major problem in the handling of arguments is general confusion in the liveness code about the meaning of PPARAM|PHEAP and PPARAMOUT|PHEAP nodes, especially as contrasted with PAUTO|PHEAP. The difference between these two is that when a local variable "moves" to the heap, it's really just allocated there to start with; in contrast, when an argument moves to the heap, the actual data has to be copied there from the stack at the beginning of the function, and when a result "moves" to the heap the value in the heap has to be copied back to the stack when the function returns This general confusion is also present in the SSA back end. The PHEAP bit worked decently when I first introduced it 7 years ago (!) in 391425ae. The back end did nothing sophisticated, and in particular there was no analysis at all: no escape analysis, no liveness analysis, and certainly no SSA back end. But the complications caused in the various downstream consumers suggest that this should be a detail kept mainly in the front end. This CL therefore eliminates both the PHEAP bit and even the idea of "heap variables" from the back ends. First, it replaces the PPARAM|PHEAP, PPARAMOUT|PHEAP, and PAUTO|PHEAP variable classes with the single PAUTOHEAP, a pseudo-class indicating a variable maintained on the heap and available by indirecting a local variable kept on the stack (a plain PAUTO). Second, walkexpr replaces all references to PAUTOHEAP variables with indirections of the corresponding PAUTO variable. The back ends and the liveness code now just see plain indirected variables. This may actually produce better code, but the real goal here is to eliminate these little-used and somewhat suspect code paths in the back end analyses. The OPARAM node type goes away too. A followup CL will do the same to PPARAMREF. I'm not sure that the back ends (SSA in particular) are handling those right either, and with the framework established in this CL that change is trivial and the result clearly more correct. Fixes #15747. Change-Id: I2770b1ce3cbc93981bfc7166be66a9da12013d74 Reviewed-on: https://go-review.googlesource.com/23393 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-25 01:33:24 -04:00
if int(n.Class) < len(classnames) {
fmt.Fprintf(s, " class(%s)", classnames[n.Class])
} else {
fmt.Fprintf(s, " class(%d?)", n.Class)
}
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Colas() {
fmt.Fprintf(s, " colas(%v)", n.Colas())
}
if n.Name != nil && n.Name.Funcdepth != 0 {
fmt.Fprintf(s, " f(%d)", n.Name.Funcdepth)
}
if n.Func != nil && n.Func.Depth != 0 {
fmt.Fprintf(s, " ff(%d)", n.Func.Depth)
}
switch n.Esc {
case EscUnknown:
break
case EscHeap:
fmt.Fprint(s, " esc(h)")
case EscNone:
fmt.Fprint(s, " esc(no)")
case EscNever:
if c == 0 {
fmt.Fprint(s, " esc(N)")
}
default:
fmt.Fprintf(s, " esc(%d)", n.Esc)
}
if e, ok := n.Opt().(*NodeEscState); ok && e.Loopdepth != 0 {
fmt.Fprintf(s, " ld(%d)", e.Loopdepth)
}
if c == 0 && n.Typecheck != 0 {
fmt.Fprintf(s, " tc(%d)", n.Typecheck)
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Isddd() {
fmt.Fprintf(s, " isddd(%v)", n.Isddd())
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Implicit() {
fmt.Fprintf(s, " implicit(%v)", n.Implicit())
}
if n.Embedded != 0 {
fmt.Fprintf(s, " embedded(%d)", n.Embedded)
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Addrtaken() {
fmt.Fprint(s, " addrtaken")
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Assigned() {
fmt.Fprint(s, " assigned")
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Bounded() {
fmt.Fprint(s, " bounded")
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.NonNil() {
fmt.Fprint(s, " nonnil")
}
if c == 0 && n.HasCall() {
fmt.Fprintf(s, " hascall")
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if c == 0 && n.Used() {
fmt.Fprintf(s, " used(%v)", n.Used())
}
}
func (v Val) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
v.vconv(s, fmtFlag(s, verb))
default:
fmt.Fprintf(s, "%%!%c(Val=%T)", verb, v)
}
}
func (v Val) vconv(s fmt.State, flag FmtFlag) {
switch u := v.U.(type) {
case *Mpint:
if !u.Rune {
if flag&FmtSharp != 0 {
fmt.Fprint(s, bconv(u, FmtSharp))
return
}
fmt.Fprint(s, bconv(u, 0))
return
}
switch x := u.Int64(); {
case ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'':
fmt.Fprintf(s, "'%c'", int(x))
case 0 <= x && x < 1<<16:
fmt.Fprintf(s, "'\\u%04x'", uint(int(x)))
case 0 <= x && x <= utf8.MaxRune:
fmt.Fprintf(s, "'\\U%08x'", uint64(x))
default:
fmt.Fprintf(s, "('\\x00' + %v)", u)
}
case *Mpflt:
if flag&FmtSharp != 0 {
fmt.Fprint(s, fconv(u, 0))
return
}
fmt.Fprint(s, fconv(u, FmtSharp))
return
case *Mpcplx:
switch {
case flag&FmtSharp != 0:
fmt.Fprintf(s, "(%v+%vi)", &u.Real, &u.Imag)
case v.U.(*Mpcplx).Real.CmpFloat64(0) == 0:
fmt.Fprintf(s, "%vi", fconv(&u.Imag, FmtSharp))
case v.U.(*Mpcplx).Imag.CmpFloat64(0) == 0:
fmt.Fprint(s, fconv(&u.Real, FmtSharp))
case v.U.(*Mpcplx).Imag.CmpFloat64(0) < 0:
fmt.Fprintf(s, "(%v%vi)", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp))
default:
fmt.Fprintf(s, "(%v+%vi)", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp))
}
case string:
fmt.Fprint(s, strconv.Quote(u))
case bool:
fmt.Fprint(s, u)
case *NilVal:
fmt.Fprint(s, "nil")
default:
fmt.Fprintf(s, "<ctype=%d>", v.Ctype())
}
}
/*
s%,%,\n%g
s%\n+%\n%g
s%^[ ]*T%%g
s%,.*%%g
s%.+% [T&] = "&",%g
s%^ ........*\]%&~%g
s%~ %%g
*/
var etnames = []string{
Txxx: "Txxx",
TINT: "INT",
TUINT: "UINT",
TINT8: "INT8",
TUINT8: "UINT8",
TINT16: "INT16",
TUINT16: "UINT16",
TINT32: "INT32",
TUINT32: "UINT32",
TINT64: "INT64",
TUINT64: "UINT64",
TUINTPTR: "UINTPTR",
TFLOAT32: "FLOAT32",
TFLOAT64: "FLOAT64",
TCOMPLEX64: "COMPLEX64",
TCOMPLEX128: "COMPLEX128",
TBOOL: "BOOL",
TPTR32: "PTR32",
TPTR64: "PTR64",
TFUNC: "FUNC",
TARRAY: "ARRAY",
TSLICE: "SLICE",
TSTRUCT: "STRUCT",
TCHAN: "CHAN",
TMAP: "MAP",
TINTER: "INTER",
TFORW: "FORW",
TSTRING: "STRING",
TUNSAFEPTR: "TUNSAFEPTR",
TANY: "ANY",
TIDEAL: "TIDEAL",
TNIL: "TNIL",
TBLANK: "TBLANK",
TFUNCARGS: "TFUNCARGS",
TCHANARGS: "TCHANARGS",
TDDDFIELD: "TDDDFIELD",
}
func (et EType) String() string {
if int(et) < len(etnames) && etnames[et] != "" {
return etnames[et]
}
return fmt.Sprintf("E-%d", et)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (s *Sym) symfmt(flag FmtFlag, mode fmtMode) string {
if s.Pkg != nil && flag&FmtShort == 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FErr: // This is for the user
if s.Pkg == builtinpkg || s.Pkg == localpkg {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return s.Name
}
// If the name was used by multiple packages, display the full path,
if s.Pkg.Name != "" && numImport[s.Pkg.Name] > 1 {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return fmt.Sprintf("%q.%s", s.Pkg.Path, s.Name)
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return s.Pkg.Name + "." + s.Name
case FDbg:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return s.Pkg.Name + "." + s.Name
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
case FTypeIdName:
return s.Pkg.Name + "." + s.Name // dcommontype, typehash
case FTypeId:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return s.Pkg.Prefix + "." + s.Name // (methodsym), typesym, weaksym
}
}
if flag&FmtByte != 0 {
// FmtByte (hh) implies FmtShort (h)
// skip leading "type." in method name
name := s.Name
if i := strings.LastIndex(name, "."); i >= 0 {
name = name[i+1:]
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FDbg {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return fmt.Sprintf("@%q.%s", s.Pkg.Path, name)
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return name
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return s.Name
}
var basicnames = []string{
TINT: "int",
TUINT: "uint",
TINT8: "int8",
TUINT8: "uint8",
TINT16: "int16",
TUINT16: "uint16",
TINT32: "int32",
TUINT32: "uint32",
TINT64: "int64",
TUINT64: "uint64",
TUINTPTR: "uintptr",
TFLOAT32: "float32",
TFLOAT64: "float64",
TCOMPLEX64: "complex64",
TCOMPLEX128: "complex128",
TBOOL: "bool",
TANY: "any",
TSTRING: "string",
TNIL: "nil",
TIDEAL: "untyped number",
TBLANK: "blank",
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
func (t *Type) typefmt(flag FmtFlag, mode fmtMode, depth int) string {
if t == nil {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "<T>"
}
if t == bytetype || t == runetype {
// in %-T mode collapse rune and byte with their originals.
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FTypeIdName, FTypeId:
t = Types[t.Etype]
default:
return t.Sym.sconv(FmtShort, mode)
}
}
if t == errortype {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "error"
}
// Unless the 'l' flag was specified, if the type has a name, just print that name.
if flag&FmtLong == 0 && t.Sym != nil && t != Types[t.Etype] {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FTypeId, FTypeIdName:
if flag&FmtShort != 0 {
if t.Vargen != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return mode.Sprintf("%v·%d", t.Sym.sconv(FmtShort, mode), t.Vargen)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return t.Sym.sconv(FmtShort, mode)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FTypeIdName {
return t.Sym.sconv(FmtUnsigned, mode)
}
if t.Sym.Pkg == localpkg && t.Vargen != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return mode.Sprintf("%v·%d", t.Sym, t.Vargen)
}
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return t.Sym.modeString(mode)
}
if int(t.Etype) < len(basicnames) && basicnames[t.Etype] != "" {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
prefix := ""
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr && (t == idealbool || t == idealstring) {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
prefix = "untyped "
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return prefix + basicnames[t.Etype]
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FDbg {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return t.Etype.String() + "-" + t.typefmt(flag, 0, depth)
}
switch t.Etype {
case TPTR32, TPTR64:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FTypeId, FTypeIdName:
if flag&FmtShort != 0 {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "*" + t.Elem().tconv(FmtShort, mode, depth)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
}
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "*" + t.Elem().modeString(mode, depth)
case TARRAY:
if t.isDDDArray() {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "[...]" + t.Elem().modeString(mode, depth)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "[" + strconv.FormatInt(t.NumElem(), 10) + "]" + t.Elem().modeString(mode, depth)
case TSLICE:
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "[]" + t.Elem().modeString(mode, depth)
case TCHAN:
switch t.ChanDir() {
case Crecv:
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "<-chan " + t.Elem().modeString(mode, depth)
case Csend:
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "chan<- " + t.Elem().modeString(mode, depth)
}
if t.Elem() != nil && t.Elem().IsChan() && t.Elem().Sym == nil && t.Elem().ChanDir() == Crecv {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "chan (" + t.Elem().modeString(mode, depth) + ")"
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "chan " + t.Elem().modeString(mode, depth)
case TMAP:
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "map[" + t.Key().modeString(mode, depth) + "]" + t.Val().modeString(mode, depth)
case TINTER:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
if t.IsEmptyInterface() {
return "interface {}"
}
buf := make([]byte, 0, 64)
buf = append(buf, "interface {"...)
for i, f := range t.Fields().Slice() {
if i != 0 {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ';')
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ' ')
switch {
case f.Sym == nil:
// Check first that a symbol is defined for this type.
// Wrong interface definitions may have types lacking a symbol.
break
case exportname(f.Sym.Name):
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
buf = append(buf, f.Sym.sconv(FmtShort, mode)...)
default:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
buf = append(buf, f.Sym.sconv(FmtUnsigned, mode)...)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, f.Type.tconv(FmtShort, mode, depth)...)
}
if t.NumFields() != 0 {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ' ')
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, '}')
return string(buf)
case TFUNC:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf := make([]byte, 0, 64)
if flag&FmtShort != 0 {
// no leading func
} else {
if t.Recv() != nil {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, "method"...)
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, t.Recvs().modeString(mode, depth)...)
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ' ')
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, "func"...)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, t.Params().modeString(mode, depth)...)
switch t.Results().NumFields() {
case 0:
// nothing to do
case 1:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ' ')
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, t.Results().Field(0).Type.modeString(mode, depth)...) // struct->field->field's type
default:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
buf = append(buf, ' ')
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, t.Results().modeString(mode, depth)...)
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return string(buf)
case TSTRUCT:
cmd/compile: shrink gc.Type in half Many of Type's fields are etype-specific. This CL organizes them into their own auxiliary types, duplicating a few fields as necessary, and adds an Extra field to hold them. It also sorts the remaining fields for better struct packing. It also improves documentation for most fields. This reduces the size of Type at the cost of some extra allocations. There's no CPU impact; memory impact below. It also makes the natural structure of Type clearer. Passes toolstash -cmp on all architectures. Ideas for future work in this vein: (1) Width and Align probably only need to be stored for Struct and Array types. The refactoring to accomplish this would hopefully also eliminate TFUNCARGS and TCHANARGS entirely. (2) Maplineno is sparsely used and could probably better be stored in a separate map[*Type]int32, with mapqueue updated to store both a Node and a line number. (3) The Printed field may be removable once the old (non-binary) importer/exported has been removed. (4) StructType's fields field could be changed from *[]*Field to []*Field, which would remove a common allocation. (5) I believe that Type.Nod can be moved to ForwardType. Separate CL. name old alloc/op new alloc/op delta Template 57.9MB ± 0% 55.9MB ± 0% -3.43% (p=0.000 n=50+50) Unicode 38.3MB ± 0% 37.8MB ± 0% -1.39% (p=0.000 n=50+50) GoTypes 185MB ± 0% 180MB ± 0% -2.56% (p=0.000 n=50+50) Compiler 824MB ± 0% 806MB ± 0% -2.19% (p=0.000 n=50+50) name old allocs/op new allocs/op delta Template 486k ± 0% 497k ± 0% +2.25% (p=0.000 n=50+50) Unicode 377k ± 0% 379k ± 0% +0.55% (p=0.000 n=50+50) GoTypes 1.39M ± 0% 1.42M ± 0% +1.63% (p=0.000 n=50+50) Compiler 5.52M ± 0% 5.57M ± 0% +0.84% (p=0.000 n=47+50) Change-Id: I828488eeb74902b013d5ae4cf844de0b6c0dfc87 Reviewed-on: https://go-review.googlesource.com/21611 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-01 20:11:30 -07:00
if m := t.StructType().Map; m != nil {
mt := m.MapType()
// Format the bucket struct for map[x]y as map.bucket[x]y.
// This avoids a recursive print that generates very long names.
cmd/compile: shrink gc.Type in half Many of Type's fields are etype-specific. This CL organizes them into their own auxiliary types, duplicating a few fields as necessary, and adds an Extra field to hold them. It also sorts the remaining fields for better struct packing. It also improves documentation for most fields. This reduces the size of Type at the cost of some extra allocations. There's no CPU impact; memory impact below. It also makes the natural structure of Type clearer. Passes toolstash -cmp on all architectures. Ideas for future work in this vein: (1) Width and Align probably only need to be stored for Struct and Array types. The refactoring to accomplish this would hopefully also eliminate TFUNCARGS and TCHANARGS entirely. (2) Maplineno is sparsely used and could probably better be stored in a separate map[*Type]int32, with mapqueue updated to store both a Node and a line number. (3) The Printed field may be removable once the old (non-binary) importer/exported has been removed. (4) StructType's fields field could be changed from *[]*Field to []*Field, which would remove a common allocation. (5) I believe that Type.Nod can be moved to ForwardType. Separate CL. name old alloc/op new alloc/op delta Template 57.9MB ± 0% 55.9MB ± 0% -3.43% (p=0.000 n=50+50) Unicode 38.3MB ± 0% 37.8MB ± 0% -1.39% (p=0.000 n=50+50) GoTypes 185MB ± 0% 180MB ± 0% -2.56% (p=0.000 n=50+50) Compiler 824MB ± 0% 806MB ± 0% -2.19% (p=0.000 n=50+50) name old allocs/op new allocs/op delta Template 486k ± 0% 497k ± 0% +2.25% (p=0.000 n=50+50) Unicode 377k ± 0% 379k ± 0% +0.55% (p=0.000 n=50+50) GoTypes 1.39M ± 0% 1.42M ± 0% +1.63% (p=0.000 n=50+50) Compiler 5.52M ± 0% 5.57M ± 0% +0.84% (p=0.000 n=47+50) Change-Id: I828488eeb74902b013d5ae4cf844de0b6c0dfc87 Reviewed-on: https://go-review.googlesource.com/21611 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-01 20:11:30 -07:00
if mt.Bucket == t {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "map.bucket[" + m.Key().modeString(mode, depth) + "]" + m.Val().modeString(mode, depth)
}
cmd/compile: shrink gc.Type in half Many of Type's fields are etype-specific. This CL organizes them into their own auxiliary types, duplicating a few fields as necessary, and adds an Extra field to hold them. It also sorts the remaining fields for better struct packing. It also improves documentation for most fields. This reduces the size of Type at the cost of some extra allocations. There's no CPU impact; memory impact below. It also makes the natural structure of Type clearer. Passes toolstash -cmp on all architectures. Ideas for future work in this vein: (1) Width and Align probably only need to be stored for Struct and Array types. The refactoring to accomplish this would hopefully also eliminate TFUNCARGS and TCHANARGS entirely. (2) Maplineno is sparsely used and could probably better be stored in a separate map[*Type]int32, with mapqueue updated to store both a Node and a line number. (3) The Printed field may be removable once the old (non-binary) importer/exported has been removed. (4) StructType's fields field could be changed from *[]*Field to []*Field, which would remove a common allocation. (5) I believe that Type.Nod can be moved to ForwardType. Separate CL. name old alloc/op new alloc/op delta Template 57.9MB ± 0% 55.9MB ± 0% -3.43% (p=0.000 n=50+50) Unicode 38.3MB ± 0% 37.8MB ± 0% -1.39% (p=0.000 n=50+50) GoTypes 185MB ± 0% 180MB ± 0% -2.56% (p=0.000 n=50+50) Compiler 824MB ± 0% 806MB ± 0% -2.19% (p=0.000 n=50+50) name old allocs/op new allocs/op delta Template 486k ± 0% 497k ± 0% +2.25% (p=0.000 n=50+50) Unicode 377k ± 0% 379k ± 0% +0.55% (p=0.000 n=50+50) GoTypes 1.39M ± 0% 1.42M ± 0% +1.63% (p=0.000 n=50+50) Compiler 5.52M ± 0% 5.57M ± 0% +0.84% (p=0.000 n=47+50) Change-Id: I828488eeb74902b013d5ae4cf844de0b6c0dfc87 Reviewed-on: https://go-review.googlesource.com/21611 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-01 20:11:30 -07:00
if mt.Hmap == t {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "map.hdr[" + m.Key().modeString(mode, depth) + "]" + m.Val().modeString(mode, depth)
}
cmd/compile: shrink gc.Type in half Many of Type's fields are etype-specific. This CL organizes them into their own auxiliary types, duplicating a few fields as necessary, and adds an Extra field to hold them. It also sorts the remaining fields for better struct packing. It also improves documentation for most fields. This reduces the size of Type at the cost of some extra allocations. There's no CPU impact; memory impact below. It also makes the natural structure of Type clearer. Passes toolstash -cmp on all architectures. Ideas for future work in this vein: (1) Width and Align probably only need to be stored for Struct and Array types. The refactoring to accomplish this would hopefully also eliminate TFUNCARGS and TCHANARGS entirely. (2) Maplineno is sparsely used and could probably better be stored in a separate map[*Type]int32, with mapqueue updated to store both a Node and a line number. (3) The Printed field may be removable once the old (non-binary) importer/exported has been removed. (4) StructType's fields field could be changed from *[]*Field to []*Field, which would remove a common allocation. (5) I believe that Type.Nod can be moved to ForwardType. Separate CL. name old alloc/op new alloc/op delta Template 57.9MB ± 0% 55.9MB ± 0% -3.43% (p=0.000 n=50+50) Unicode 38.3MB ± 0% 37.8MB ± 0% -1.39% (p=0.000 n=50+50) GoTypes 185MB ± 0% 180MB ± 0% -2.56% (p=0.000 n=50+50) Compiler 824MB ± 0% 806MB ± 0% -2.19% (p=0.000 n=50+50) name old allocs/op new allocs/op delta Template 486k ± 0% 497k ± 0% +2.25% (p=0.000 n=50+50) Unicode 377k ± 0% 379k ± 0% +0.55% (p=0.000 n=50+50) GoTypes 1.39M ± 0% 1.42M ± 0% +1.63% (p=0.000 n=50+50) Compiler 5.52M ± 0% 5.57M ± 0% +0.84% (p=0.000 n=47+50) Change-Id: I828488eeb74902b013d5ae4cf844de0b6c0dfc87 Reviewed-on: https://go-review.googlesource.com/21611 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-01 20:11:30 -07:00
if mt.Hiter == t {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return "map.iter[" + m.Key().modeString(mode, depth) + "]" + m.Val().modeString(mode, depth)
}
Fatalf("unknown internal map type")
}
buf := make([]byte, 0, 64)
if t.IsFuncArgStruct() {
buf = append(buf, '(')
var flag1 FmtFlag
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FTypeId, FTypeIdName, FErr:
// no argument names on function signature, and no "noescape"/"nosplit" tags
flag1 = FmtShort
}
for i, f := range t.Fields().Slice() {
if i != 0 {
buf = append(buf, ", "...)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, fldconv(f, flag1, mode, depth)...)
}
buf = append(buf, ')')
} else {
buf = append(buf, "struct {"...)
for i, f := range t.Fields().Slice() {
if i != 0 {
buf = append(buf, ';')
}
buf = append(buf, ' ')
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
buf = append(buf, fldconv(f, FmtLong, mode, depth)...)
}
if t.NumFields() != 0 {
buf = append(buf, ' ')
}
buf = append(buf, '}')
}
return string(buf)
case TFORW:
if t.Sym != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return "undefined " + t.Sym.modeString(mode)
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "undefined"
case TUNSAFEPTR:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "unsafe.Pointer"
case TDDDFIELD:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
return mode.Sprintf("%v <%v> %v", t.Etype, t.Sym, t.DDDField())
case Txxx:
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "Txxx"
}
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
// Don't know how to handle - fall back to detailed prints.
return mode.Sprintf("%v <%v>", t.Etype, t.Sym)
}
// Statements which may be rendered with a simplestmt as init.
func stmtwithinit(op Op) bool {
switch op {
case OIF, OFOR, OFORUNTIL, OSWITCH:
return true
}
return false
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) stmtfmt(s fmt.State, mode fmtMode) {
// some statements allow for an init, but at most one,
// but we may have an arbitrary number added, eg by typecheck
// and inlining. If it doesn't fit the syntax, emit an enclosing
// block starting with the init statements.
// if we can just say "for" n->ninit; ... then do so
simpleinit := n.Ninit.Len() == 1 && n.Ninit.First().Ninit.Len() == 0 && stmtwithinit(n.Op)
// otherwise, print the inits as separate statements
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
complexinit := n.Ninit.Len() != 0 && !simpleinit && (mode != FErr)
// but if it was for if/for/switch, put in an extra surrounding block to limit the scope
extrablock := complexinit && stmtwithinit(n.Op)
if extrablock {
fmt.Fprint(s, "{")
}
if complexinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v; ", n.Ninit)
}
switch n.Op {
case ODCL:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "var %v %v", n.Left.Sym, n.Left.Type)
case ODCLFIELD:
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v %v", n.Left, n.Right)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Right)
}
// Don't export "v = <N>" initializing statements, hope they're always
cmd/compile: export inlined function bodies Completed implementation for exporting inlined functions using the new binary export format. This change passes (export GO_GCFLAGS=-newexport; make all.bash) but for gc's builtin_test.go which we need to adjust before enabling this code by default. For a high-level description of the export format see the comment at the top of bexport.go. Major changes: 1) The export format for the platform independent export data changed: When we export inlined function bodies, additional objects (other functions, types, etc.) that are referred to by the function bodies will need to be exported. While this doesn't affect the platform-independent portion directly, it adds more objects to the exportlist while we are exporting. Instead of trying to sort the objects into groups, just export objects as they appear in the export list. This is slightly less compact (one extra byte per object), but it is simpler and much more flexible. 2) The export format contains now three sections: 1) The plat- form independent objects, 2) the objects pulled in for export via inlined function bodies, and 3) the inlined function bodies. 3) Completed the exporting and importing code for inlined function bodies. The format is completely compiler-specific and easily changeable w/o affecting other tools. There is still quite a bit of room for denser encoding. This can happen at any time in the future. This change contains also the adjustments for go/internal/gcimporter, necessary because of the export format change 1) mentioned above. For #13241. Change-Id: I86bca0bd984b12ccf13d0d30892e6e25f6d04ed5 Reviewed-on: https://go-review.googlesource.com/21172 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-18 17:21:32 -07:00
// preceded by the DCL which will be re-parsed and typechecked to reproduce
// the "v = <N>" again.
case OAS:
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Colas() && !complexinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v := %v", n.Left, n.Right)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v = %v", n.Left, n.Right)
}
case OASOP:
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Implicit() {
if Op(n.Etype) == OADD {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v++", n.Left)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v--", n.Left)
}
break
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v %#v= %v", n.Left, Op(n.Etype), n.Right)
case OAS2:
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Colas() && !complexinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%.v := %.v", n.List, n.Rlist)
break
}
fallthrough
case OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%.v = %.v", n.List, n.Rlist)
case ORETURN:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "return %.v", n.List)
case ORETJMP:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "retjmp %v", n.Sym)
case OPROC:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "go %v", n.Left)
case ODEFER:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "defer %v", n.Left)
case OIF:
if simpleinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "if %v; %v { %v }", n.Ninit.First(), n.Left, n.Nbody)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "if %v { %v }", n.Left, n.Nbody)
}
if n.Rlist.Len() != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " else { %v }", n.Rlist)
}
case OFOR, OFORUNTIL:
opname := "for"
if n.Op == OFORUNTIL {
opname = "foruntil"
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr { // TODO maybe only if FmtShort, same below
fmt.Fprintf(s, "%s loop", opname)
break
}
fmt.Fprint(s, opname)
if simpleinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v;", n.Ninit.First())
} else if n.Right != nil {
fmt.Fprint(s, " ;")
}
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v", n.Left)
}
if n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "; %v", n.Right)
} else if simpleinit {
fmt.Fprint(s, ";")
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " { %v }", n.Nbody)
case ORANGE:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
fmt.Fprint(s, "for loop")
break
}
if n.List.Len() == 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "for range %v { %v }", n.Right, n.Nbody)
break
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "for %.v = range %v { %v }", n.List, n.Right, n.Nbody)
case OSELECT, OSWITCH:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
mode.Fprintf(s, "%v statement", n.Op)
break
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v", n.Op)
if simpleinit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v;", n.Ninit.First())
}
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v ", n.Left)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " { %v }", n.List)
case OXCASE:
if n.List.Len() != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "case %.v", n.List)
} else {
fmt.Fprint(s, "default")
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ": %v", n.Nbody)
case OCASE:
switch {
case n.Left != nil:
// single element
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "case %v", n.Left)
case n.List.Len() > 0:
// range
if n.List.Len() != 2 {
Fatalf("bad OCASE list length %d", n.List.Len())
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "case %v..%v", n.List.First(), n.List.Second())
default:
fmt.Fprint(s, "default")
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ": %v", n.Nbody)
case OBREAK,
OCONTINUE,
OGOTO,
OFALL,
OXFALL:
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v %v", n.Op, n.Left)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v", n.Op)
}
case OEMPTY:
break
case OLABEL:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v: ", n.Left)
}
if extrablock {
fmt.Fprint(s, "}")
}
}
var opprec = []int{
OALIGNOF: 8,
OAPPEND: 8,
OARRAYBYTESTR: 8,
OARRAYLIT: 8,
OSLICELIT: 8,
OARRAYRUNESTR: 8,
OCALLFUNC: 8,
OCALLINTER: 8,
OCALLMETH: 8,
OCALL: 8,
OCAP: 8,
OCLOSE: 8,
OCONVIFACE: 8,
OCONVNOP: 8,
OCONV: 8,
OCOPY: 8,
ODELETE: 8,
cmd/internal/gc: inline runtime.getg This more closely restores what the old C runtime did. (In C, g was an 'extern register' with the same effective implementation as in this CL.) On a late 2012 MacBookPro10,2, best of 5 old vs best of 5 new: benchmark old ns/op new ns/op delta BenchmarkBinaryTree17 4981312777 4463426605 -10.40% BenchmarkFannkuch11 3046495712 3006819428 -1.30% BenchmarkFmtFprintfEmpty 89.3 79.8 -10.64% BenchmarkFmtFprintfString 284 262 -7.75% BenchmarkFmtFprintfInt 282 262 -7.09% BenchmarkFmtFprintfIntInt 480 448 -6.67% BenchmarkFmtFprintfPrefixedInt 382 358 -6.28% BenchmarkFmtFprintfFloat 529 486 -8.13% BenchmarkFmtManyArgs 1849 1773 -4.11% BenchmarkGobDecode 12835963 11794385 -8.11% BenchmarkGobEncode 10527170 10288422 -2.27% BenchmarkGzip 436109569 438422516 +0.53% BenchmarkGunzip 110121663 109843648 -0.25% BenchmarkHTTPClientServer 81930 85446 +4.29% BenchmarkJSONEncode 24638574 24280603 -1.45% BenchmarkJSONDecode 93022423 85753546 -7.81% BenchmarkMandelbrot200 4703899 4735407 +0.67% BenchmarkGoParse 5319853 5086843 -4.38% BenchmarkRegexpMatchEasy0_32 151 151 +0.00% BenchmarkRegexpMatchEasy0_1K 452 453 +0.22% BenchmarkRegexpMatchEasy1_32 131 132 +0.76% BenchmarkRegexpMatchEasy1_1K 761 722 -5.12% BenchmarkRegexpMatchMedium_32 228 224 -1.75% BenchmarkRegexpMatchMedium_1K 63751 64296 +0.85% BenchmarkRegexpMatchHard_32 3188 3238 +1.57% BenchmarkRegexpMatchHard_1K 95396 96756 +1.43% BenchmarkRevcomp 661587262 687107364 +3.86% BenchmarkTemplate 108312598 104008540 -3.97% BenchmarkTimeParse 453 459 +1.32% BenchmarkTimeFormat 475 441 -7.16% The garbage benchmark from the benchmarks subrepo gets 2.6% faster as well. Change-Id: I320aeda332db81012688b26ffab23f6581c59cfa Reviewed-on: https://go-review.googlesource.com/8460 Reviewed-by: Rick Hudson <rlh@golang.org> Run-TryBot: Rick Hudson <rlh@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2015-04-03 12:23:28 -04:00
OGETG: 8,
OLEN: 8,
OLITERAL: 8,
OMAKESLICE: 8,
OMAKE: 8,
OMAPLIT: 8,
ONAME: 8,
ONEW: 8,
ONONAME: 8,
OOFFSETOF: 8,
OPACK: 8,
OPANIC: 8,
OPAREN: 8,
OPRINTN: 8,
OPRINT: 8,
ORUNESTR: 8,
OSIZEOF: 8,
OSTRARRAYBYTE: 8,
OSTRARRAYRUNE: 8,
OSTRUCTLIT: 8,
OTARRAY: 8,
OTCHAN: 8,
OTFUNC: 8,
OTINTER: 8,
OTMAP: 8,
OTSTRUCT: 8,
OINDEXMAP: 8,
OINDEX: 8,
OSLICE: 8,
OSLICESTR: 8,
OSLICEARR: 8,
OSLICE3: 8,
OSLICE3ARR: 8,
ODOTINTER: 8,
ODOTMETH: 8,
ODOTPTR: 8,
ODOTTYPE2: 8,
ODOTTYPE: 8,
ODOT: 8,
OXDOT: 8,
OCALLPART: 8,
OPLUS: 7,
ONOT: 7,
OCOM: 7,
OMINUS: 7,
OADDR: 7,
OIND: 7,
ORECV: 7,
OMUL: 6,
ODIV: 6,
OMOD: 6,
OLSH: 6,
ORSH: 6,
OAND: 6,
OANDNOT: 6,
OADD: 5,
OSUB: 5,
OOR: 5,
OXOR: 5,
OEQ: 4,
OLT: 4,
OLE: 4,
OGE: 4,
OGT: 4,
ONE: 4,
OCMPSTR: 4,
OCMPIFACE: 4,
OSEND: 3,
OANDAND: 2,
OOROR: 1,
// Statements handled by stmtfmt
OAS: -1,
OAS2: -1,
OAS2DOTTYPE: -1,
OAS2FUNC: -1,
OAS2MAPR: -1,
OAS2RECV: -1,
OASOP: -1,
OBREAK: -1,
OCASE: -1,
OCONTINUE: -1,
ODCL: -1,
ODCLFIELD: -1,
ODEFER: -1,
OEMPTY: -1,
OFALL: -1,
OFOR: -1,
OFORUNTIL: -1,
OGOTO: -1,
OIF: -1,
OLABEL: -1,
OPROC: -1,
ORANGE: -1,
ORETURN: -1,
OSELECT: -1,
OSWITCH: -1,
OXCASE: -1,
OXFALL: -1,
OEND: 0,
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) {
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
for n != nil && n.Implicit() && (n.Op == OIND || n.Op == OADDR) {
n = n.Left
}
if n == nil {
fmt.Fprint(s, "<N>")
return
}
nprec := opprec[n.Op]
if n.Op == OTYPE && n.Sym != nil {
nprec = 8
}
if prec > nprec {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v)", n)
return
}
switch n.Op {
case OPAREN:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v)", n.Left)
case ODDDARG:
fmt.Fprint(s, "... argument")
case OLITERAL: // this is a bit of a mess
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
if n.Orig != nil && n.Orig != n {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Orig.exprfmt(s, prec, mode)
return
}
if n.Sym != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, n.Sym.modeString(mode))
return
}
}
if n.Val().Ctype() == CTNIL && n.Orig != nil && n.Orig != n {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Orig.exprfmt(s, prec, mode)
return
}
if n.Type != nil && n.Type.Etype != TIDEAL && n.Type.Etype != TNIL && n.Type != idealbool && n.Type != idealstring {
// Need parens when type begins with what might
// be misinterpreted as a unary operator: * or <-.
if n.Type.IsPtr() || (n.Type.IsChan() && n.Type.ChanDir() == Crecv) {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v)(%v)", n.Type, n.Val())
return
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v(%v)", n.Type, n.Val())
return
}
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Val())
// Special case: name used as local variable in export.
// _ becomes ~b%d internally; print as _ for export
case ONAME:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr && n.Sym != nil && n.Sym.Name[0] == '~' && n.Sym.Name[1] == 'b' {
fmt.Fprint(s, "_")
return
}
fallthrough
case OPACK, ONONAME:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, n.Sym.modeString(mode))
case OTYPE:
if n.Type == nil && n.Sym != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, n.Sym.modeString(mode))
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Type)
case OTARRAY:
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "[]%v", n.Left)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "[]%v", n.Right) // happens before typecheck
case OTMAP:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "map[%v]%v", n.Left, n.Right)
case OTCHAN:
switch ChanDir(n.Etype) {
case Crecv:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "<-chan %v", n.Left)
case Csend:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "chan<- %v", n.Left)
default:
if n.Left != nil && n.Left.Op == OTCHAN && n.Left.Sym == nil && ChanDir(n.Left.Etype) == Crecv {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "chan (%v)", n.Left)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "chan %v", n.Left)
}
}
case OTSTRUCT:
fmt.Fprint(s, "<struct>")
case OTINTER:
fmt.Fprint(s, "<inter>")
case OTFUNC:
fmt.Fprint(s, "<func>")
case OCLOSURE:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
fmt.Fprint(s, "func literal")
return
}
if n.Nbody.Len() != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v { %v }", n.Type, n.Nbody)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v { %v }", n.Type, n.Func.Closure.Nbody)
case OCOMPLIT:
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
ptrlit := n.Right != nil && n.Right.Implicit() && n.Right.Type != nil && n.Right.Type.IsPtr()
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Right != nil && n.Right.Type != nil && !n.Implicit() {
if ptrlit {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "&%v literal", n.Right.Type.Elem())
return
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v literal", n.Right.Type)
return
}
}
fmt.Fprint(s, "composite literal")
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v{ %.v })", n.Right, n.List)
case OPTRLIT:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "&%v", n.Left)
case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr {
mode.Fprintf(s, "%v literal", n.Type)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v{ %.v })", n.Type, n.List)
case OKEY:
if n.Left != nil && n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v:%v", n.Left, n.Right)
return
}
if n.Left == nil && n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ":%v", n.Right)
return
}
if n.Left != nil && n.Right == nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v:", n.Left)
return
}
fmt.Fprint(s, ":")
cmd/compile: add OSTRUCTKEY for keyed struct literals Previously, we used OKEY nodes to represent keyed struct literal elements. The field names were represented by an ONAME node, but this is clumsy because it's the only remaining case where ONAME was used to represent a bare identifier and not a variable. This CL introduces a new OSTRUCTKEY node op for use in struct literals. These ops instead store the field name in the node's own Sym field. This is similar in spirit to golang.org/cl/20890. Significant reduction in allocations for struct literal heavy code like package unicode: name old time/op new time/op delta Template 345ms ± 6% 341ms ± 6% ~ (p=0.141 n=29+28) Unicode 200ms ± 9% 184ms ± 7% -7.77% (p=0.000 n=29+30) GoTypes 1.04s ± 3% 1.05s ± 3% ~ (p=0.096 n=30+30) Compiler 4.47s ± 9% 4.49s ± 6% ~ (p=0.890 n=29+29) name old user-ns/op new user-ns/op delta Template 523M ±13% 516M ±17% ~ (p=0.400 n=29+30) Unicode 334M ±27% 314M ±30% ~ (p=0.093 n=30+30) GoTypes 1.53G ±10% 1.52G ±10% ~ (p=0.572 n=30+30) Compiler 6.28G ± 7% 6.34G ±11% ~ (p=0.300 n=30+30) name old alloc/op new alloc/op delta Template 44.5MB ± 0% 44.4MB ± 0% -0.35% (p=0.000 n=27+30) Unicode 39.2MB ± 0% 34.5MB ± 0% -11.79% (p=0.000 n=26+30) GoTypes 125MB ± 0% 125MB ± 0% -0.12% (p=0.000 n=29+30) Compiler 515MB ± 0% 515MB ± 0% -0.10% (p=0.000 n=29+30) name old allocs/op new allocs/op delta Template 426k ± 0% 424k ± 0% -0.39% (p=0.000 n=29+30) Unicode 374k ± 0% 323k ± 0% -13.67% (p=0.000 n=29+30) GoTypes 1.21M ± 0% 1.21M ± 0% -0.14% (p=0.000 n=29+29) Compiler 4.40M ± 0% 4.39M ± 0% -0.13% (p=0.000 n=29+30) Passes toolstash/buildall. Change-Id: Iba4ee765dd1748f67e52fcade1cd75c9f6e13fa9 Reviewed-on: https://go-review.googlesource.com/30974 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-12 15:48:18 -07:00
case OSTRUCTKEY:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v:%v", n.Sym, n.Left)
cmd/compile: add OSTRUCTKEY for keyed struct literals Previously, we used OKEY nodes to represent keyed struct literal elements. The field names were represented by an ONAME node, but this is clumsy because it's the only remaining case where ONAME was used to represent a bare identifier and not a variable. This CL introduces a new OSTRUCTKEY node op for use in struct literals. These ops instead store the field name in the node's own Sym field. This is similar in spirit to golang.org/cl/20890. Significant reduction in allocations for struct literal heavy code like package unicode: name old time/op new time/op delta Template 345ms ± 6% 341ms ± 6% ~ (p=0.141 n=29+28) Unicode 200ms ± 9% 184ms ± 7% -7.77% (p=0.000 n=29+30) GoTypes 1.04s ± 3% 1.05s ± 3% ~ (p=0.096 n=30+30) Compiler 4.47s ± 9% 4.49s ± 6% ~ (p=0.890 n=29+29) name old user-ns/op new user-ns/op delta Template 523M ±13% 516M ±17% ~ (p=0.400 n=29+30) Unicode 334M ±27% 314M ±30% ~ (p=0.093 n=30+30) GoTypes 1.53G ±10% 1.52G ±10% ~ (p=0.572 n=30+30) Compiler 6.28G ± 7% 6.34G ±11% ~ (p=0.300 n=30+30) name old alloc/op new alloc/op delta Template 44.5MB ± 0% 44.4MB ± 0% -0.35% (p=0.000 n=27+30) Unicode 39.2MB ± 0% 34.5MB ± 0% -11.79% (p=0.000 n=26+30) GoTypes 125MB ± 0% 125MB ± 0% -0.12% (p=0.000 n=29+30) Compiler 515MB ± 0% 515MB ± 0% -0.10% (p=0.000 n=29+30) name old allocs/op new allocs/op delta Template 426k ± 0% 424k ± 0% -0.39% (p=0.000 n=29+30) Unicode 374k ± 0% 323k ± 0% -13.67% (p=0.000 n=29+30) GoTypes 1.21M ± 0% 1.21M ± 0% -0.14% (p=0.000 n=29+29) Compiler 4.40M ± 0% 4.39M ± 0% -0.13% (p=0.000 n=29+30) Passes toolstash/buildall. Change-Id: Iba4ee765dd1748f67e52fcade1cd75c9f6e13fa9 Reviewed-on: https://go-review.googlesource.com/30974 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-12 15:48:18 -07:00
case OCALLPART:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
if n.Right == nil || n.Right.Sym == nil {
fmt.Fprint(s, ".<nil>")
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ".%0S", n.Right.Sym)
case OXDOT, ODOT, ODOTPTR, ODOTINTER, ODOTMETH:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
if n.Sym == nil {
fmt.Fprint(s, ".<nil>")
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ".%0S", n.Sym)
case ODOTTYPE, ODOTTYPE2:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
if n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ".(%v)", n.Right)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, ".(%v)", n.Type)
case OINDEX, OINDEXMAP:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
mode.Fprintf(s, "[%v]", n.Right)
case OSLICE, OSLICESTR, OSLICEARR, OSLICE3, OSLICE3ARR:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
fmt.Fprint(s, "[")
low, high, max := n.SliceBounds()
if low != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, low.modeString(mode))
}
fmt.Fprint(s, ":")
if high != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, high.modeString(mode))
}
if n.Op.IsSlice3() {
fmt.Fprint(s, ":")
if max != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, max.modeString(mode))
}
}
fmt.Fprint(s, "]")
case OCOPY, OCOMPLEX:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v(%v, %v)", n.Op, n.Left, n.Right)
case OCONV,
OCONVIFACE,
OCONVNOP,
OARRAYBYTESTR,
OARRAYRUNESTR,
OSTRARRAYBYTE,
OSTRARRAYRUNE,
ORUNESTR:
if n.Type == nil || n.Type.Sym == nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v)", n.Type)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Type)
}
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%v)", n.Left)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%.v)", n.List)
}
case OREAL,
OIMAG,
OAPPEND,
OCAP,
OCLOSE,
ODELETE,
OLEN,
OMAKE,
ONEW,
OPANIC,
ORECOVER,
OALIGNOF,
OOFFSETOF,
OSIZEOF,
OPRINT,
OPRINTN:
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v(%v)", n.Op, n.Left)
return
}
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Isddd() {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v(%.v...)", n.Op, n.List)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v(%.v)", n.Op, n.List)
cmd/internal/gc: inline runtime.getg This more closely restores what the old C runtime did. (In C, g was an 'extern register' with the same effective implementation as in this CL.) On a late 2012 MacBookPro10,2, best of 5 old vs best of 5 new: benchmark old ns/op new ns/op delta BenchmarkBinaryTree17 4981312777 4463426605 -10.40% BenchmarkFannkuch11 3046495712 3006819428 -1.30% BenchmarkFmtFprintfEmpty 89.3 79.8 -10.64% BenchmarkFmtFprintfString 284 262 -7.75% BenchmarkFmtFprintfInt 282 262 -7.09% BenchmarkFmtFprintfIntInt 480 448 -6.67% BenchmarkFmtFprintfPrefixedInt 382 358 -6.28% BenchmarkFmtFprintfFloat 529 486 -8.13% BenchmarkFmtManyArgs 1849 1773 -4.11% BenchmarkGobDecode 12835963 11794385 -8.11% BenchmarkGobEncode 10527170 10288422 -2.27% BenchmarkGzip 436109569 438422516 +0.53% BenchmarkGunzip 110121663 109843648 -0.25% BenchmarkHTTPClientServer 81930 85446 +4.29% BenchmarkJSONEncode 24638574 24280603 -1.45% BenchmarkJSONDecode 93022423 85753546 -7.81% BenchmarkMandelbrot200 4703899 4735407 +0.67% BenchmarkGoParse 5319853 5086843 -4.38% BenchmarkRegexpMatchEasy0_32 151 151 +0.00% BenchmarkRegexpMatchEasy0_1K 452 453 +0.22% BenchmarkRegexpMatchEasy1_32 131 132 +0.76% BenchmarkRegexpMatchEasy1_1K 761 722 -5.12% BenchmarkRegexpMatchMedium_32 228 224 -1.75% BenchmarkRegexpMatchMedium_1K 63751 64296 +0.85% BenchmarkRegexpMatchHard_32 3188 3238 +1.57% BenchmarkRegexpMatchHard_1K 95396 96756 +1.43% BenchmarkRevcomp 661587262 687107364 +3.86% BenchmarkTemplate 108312598 104008540 -3.97% BenchmarkTimeParse 453 459 +1.32% BenchmarkTimeFormat 475 441 -7.16% The garbage benchmark from the benchmarks subrepo gets 2.6% faster as well. Change-Id: I320aeda332db81012688b26ffab23f6581c59cfa Reviewed-on: https://go-review.googlesource.com/8460 Reviewed-by: Rick Hudson <rlh@golang.org> Run-TryBot: Rick Hudson <rlh@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2015-04-03 12:23:28 -04:00
case OCALL, OCALLFUNC, OCALLINTER, OCALLMETH, OGETG:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if n.Isddd() {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%.v...)", n.List)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "(%.v)", n.List)
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
if n.List.Len() != 0 { // pre-typecheck
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "make(%v, %.v)", n.Type, n.List)
return
}
if n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "make(%v, %v, %v)", n.Type, n.Left, n.Right)
return
}
if n.Left != nil && (n.Op == OMAKESLICE || !n.Left.Type.IsUntyped()) {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "make(%v, %v)", n.Type, n.Left)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "make(%v)", n.Type)
// Unary
case OPLUS,
OMINUS,
OADDR,
OCOM,
OIND,
ONOT,
ORECV:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%#v", n.Op)
if n.Left.Op == n.Op {
fmt.Fprint(s, " ")
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec+1, mode)
// Binary
case OADD,
OAND,
OANDAND,
OANDNOT,
ODIV,
OEQ,
OGE,
OGT,
OLE,
OLT,
OLSH,
OMOD,
OMUL,
ONE,
OOR,
OOROR,
ORSH,
OSEND,
OSUB,
OXOR:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
mode.Fprintf(s, " %#v ", n.Op)
n.Right.exprfmt(s, nprec+1, mode)
case OADDSTR:
i := 0
for _, n1 := range n.List.Slice() {
if i != 0 {
fmt.Fprint(s, " + ")
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n1.exprfmt(s, nprec, mode)
i++
}
case OCMPSTR, OCMPIFACE:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.Left.exprfmt(s, nprec, mode)
// TODO(marvin): Fix Node.EType type union.
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %#v ", Op(n.Etype))
n.Right.exprfmt(s, nprec+1, mode)
default:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "<node %v>", n.Op)
}
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) nodefmt(s fmt.State, flag FmtFlag, mode fmtMode) {
t := n.Type
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
// We almost always want the original, except in export mode for literals.
// This saves the importer some work, and avoids us having to redo some
// special casing for package unsafe.
if n.Op != OLITERAL && n.Orig != nil {
n = n.Orig
}
if flag&FmtLong != 0 && t != nil {
if t.Etype == TNIL {
fmt.Fprint(s, "nil")
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v (type %v)", n, t)
}
return
}
// TODO inlining produces expressions with ninits. we can't print these yet.
if opprec[n.Op] < 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.stmtfmt(s, mode)
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.exprfmt(s, 0, mode)
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) nodedump(s fmt.State, flag FmtFlag, mode fmtMode) {
recur := flag&FmtShort == 0
if recur {
indent(s)
if dumpdepth > 40 {
fmt.Fprint(s, "...")
return
}
if n.Ninit.Len() != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-init%v", n.Op, n.Ninit)
indent(s)
}
}
switch n.Op {
default:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v%j", n.Op, n)
case OINDREGSP:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-SP%j", n.Op, n)
case OLITERAL:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-%v%j", n.Op, n.Val(), n)
case ONAME, ONONAME:
if n.Sym != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-%v%j", n.Op, n.Sym, n)
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v%j", n.Op, n)
}
if recur && n.Type == nil && n.Name != nil && n.Name.Param != nil && n.Name.Param.Ntype != nil {
indent(s)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-ntype%v", n.Op, n.Name.Param.Ntype)
}
case OASOP:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-%v%j", n.Op, Op(n.Etype), n)
case OTYPE:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v %v%j type=%v", n.Op, n.Sym, n, n.Type)
if recur && n.Type == nil && n.Name.Param.Ntype != nil {
indent(s)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-ntype%v", n.Op, n.Name.Param.Ntype)
}
}
if n.Sym != nil && n.Op != ONAME {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v", n.Sym)
}
if n.Type != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, " %v", n.Type)
}
if recur {
if n.Left != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Left)
}
if n.Right != nil {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v", n.Right)
}
if n.List.Len() != 0 {
indent(s)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-list%v", n.Op, n.List)
}
if n.Rlist.Len() != 0 {
indent(s)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-rlist%v", n.Op, n.Rlist)
}
if n.Nbody.Len() != 0 {
indent(s)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
mode.Fprintf(s, "%v-body%v", n.Op, n.Nbody)
}
}
}
// "%S" suppresses qualifying with package
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (s *Sym) format(f fmt.State, verb rune, mode fmtMode) {
switch verb {
case 'v', 'S':
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(f, s.sconv(fmtFlag(f, verb), mode))
cmd/compile: make internal objects directly print to printer Internal objects that satisfy the Printable interface can print directly to a printer w/o going through the conversion to a string first. Made printer.f understand and special-case %v so that Printable objects use the printer directly. This is work in progress and we may end up doing something else eventually (perhaps using fmt.Formatter) - or even undo these changes if this exploration doesn't get us to a significantly better place. Allocations numbers relative to commit c85b77c (still up, but reduced from most recent change): name old time/op new time/op delta Template 307ms ± 4% 315ms ± 4% +2.55% (p=0.000 n=29+29) Unicode 164ms ± 4% 165ms ± 4% ~ (p=0.057 n=30+30) GoTypes 1.01s ± 3% 1.03s ± 3% +1.72% (p=0.000 n=30+30) Compiler 5.49s ± 1% 5.62s ± 2% +2.31% (p=0.000 n=30+28) name old user-ns/op new user-ns/op delta Template 397M ± 3% 406M ± 6% +2.21% (p=0.000 n=28+30) Unicode 225M ± 4% 226M ± 3% ~ (p=0.230 n=29+30) GoTypes 1.31G ± 3% 1.34G ± 5% +2.79% (p=0.000 n=30+30) Compiler 7.39G ± 2% 7.50G ± 2% +1.43% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 47.5MB ± 0% +1.48% (p=0.000 n=29+28) Unicode 37.8MB ± 0% 38.1MB ± 0% +0.64% (p=0.000 n=30+28) GoTypes 143MB ± 0% 145MB ± 0% +1.72% (p=0.000 n=30+30) Compiler 683MB ± 0% 706MB ± 0% +3.31% (p=0.000 n=30+29) name old allocs/op new allocs/op delta Template 444k ± 0% 481k ± 0% +8.38% (p=0.000 n=30+30) Unicode 369k ± 0% 379k ± 0% +2.74% (p=0.000 n=30+30) GoTypes 1.35M ± 0% 1.50M ± 0% +10.78% (p=0.000 n=30+30) Compiler 5.66M ± 0% 6.25M ± 0% +10.31% (p=0.000 n=29+29) For #16897. Change-Id: I37f95ab60508018ee6d29a98d238482b60e3e4b5 Reviewed-on: https://go-review.googlesource.com/28072 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-29 17:56:15 -07:00
default:
fmt.Fprintf(f, "%%!%c(*Sym=%p)", verb, s)
}
}
cmd/compile: make internal objects directly print to printer Internal objects that satisfy the Printable interface can print directly to a printer w/o going through the conversion to a string first. Made printer.f understand and special-case %v so that Printable objects use the printer directly. This is work in progress and we may end up doing something else eventually (perhaps using fmt.Formatter) - or even undo these changes if this exploration doesn't get us to a significantly better place. Allocations numbers relative to commit c85b77c (still up, but reduced from most recent change): name old time/op new time/op delta Template 307ms ± 4% 315ms ± 4% +2.55% (p=0.000 n=29+29) Unicode 164ms ± 4% 165ms ± 4% ~ (p=0.057 n=30+30) GoTypes 1.01s ± 3% 1.03s ± 3% +1.72% (p=0.000 n=30+30) Compiler 5.49s ± 1% 5.62s ± 2% +2.31% (p=0.000 n=30+28) name old user-ns/op new user-ns/op delta Template 397M ± 3% 406M ± 6% +2.21% (p=0.000 n=28+30) Unicode 225M ± 4% 226M ± 3% ~ (p=0.230 n=29+30) GoTypes 1.31G ± 3% 1.34G ± 5% +2.79% (p=0.000 n=30+30) Compiler 7.39G ± 2% 7.50G ± 2% +1.43% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 47.5MB ± 0% +1.48% (p=0.000 n=29+28) Unicode 37.8MB ± 0% 38.1MB ± 0% +0.64% (p=0.000 n=30+28) GoTypes 143MB ± 0% 145MB ± 0% +1.72% (p=0.000 n=30+30) Compiler 683MB ± 0% 706MB ± 0% +3.31% (p=0.000 n=30+29) name old allocs/op new allocs/op delta Template 444k ± 0% 481k ± 0% +8.38% (p=0.000 n=30+30) Unicode 369k ± 0% 379k ± 0% +2.74% (p=0.000 n=30+30) GoTypes 1.35M ± 0% 1.50M ± 0% +10.78% (p=0.000 n=30+30) Compiler 5.66M ± 0% 6.25M ± 0% +10.31% (p=0.000 n=29+29) For #16897. Change-Id: I37f95ab60508018ee6d29a98d238482b60e3e4b5 Reviewed-on: https://go-review.googlesource.com/28072 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-29 17:56:15 -07:00
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (s *Sym) String() string { return s.sconv(0, FErr) }
func (s *Sym) modeString(mode fmtMode) string { return s.sconv(0, mode) }
// See #16897 before changing the implementation of sconv.
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (s *Sym) sconv(flag FmtFlag, mode fmtMode) string {
if flag&FmtLong != 0 {
panic("linksymfmt")
}
if s == nil {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "<S>"
}
if s.Name == "_" {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "_"
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
flag, mode = flag.update(mode)
return s.symfmt(flag, mode)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
func (t *Type) String() string {
// This is an external entry point, so we pass depth 0 to tconv.
// The implementation of tconv (including typefmt and fldconv)
// must take care not to use a type in a formatting string
// to avoid resetting the recursion counter.
return t.tconv(0, FErr, 0)
}
func (t *Type) modeString(mode fmtMode, depth int) string {
return t.tconv(0, mode, depth)
}
// ShortString generates a short description of t.
// It is used in autogenerated method names, reflection,
// and itab names.
func (t *Type) ShortString() string {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return t.tconv(FmtLeft, FErr, 0)
}
// LongString generates a complete description of t.
// It is useful for reflection,
// or when a unique fingerprint or hash of a type is required.
func (t *Type) LongString() string {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
return t.tconv(FmtLeft|FmtUnsigned, FErr, 0)
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
func fldconv(f *Field, flag FmtFlag, mode fmtMode, depth int) string {
if f == nil {
return "<T>"
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
flag, mode = flag.update(mode)
if mode == FTypeIdName {
flag |= FmtUnsigned
}
var name string
if flag&FmtShort == 0 {
s := f.Sym
// Take the name from the original, lest we substituted it with ~r%d or ~b%d.
// ~r%d is a (formerly) unnamed result.
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FErr && f.Nname != nil {
if f.Nname.Orig != nil {
s = f.Nname.Orig.Sym
if s != nil && s.Name[0] == '~' {
if s.Name[1] == 'r' { // originally an unnamed result
s = nil
} else if s.Name[1] == 'b' { // originally the blank identifier _
s = lookup("_")
}
}
} else {
s = nil
}
}
if s != nil && f.Embedded == 0 {
if f.Funarg != FunargNone {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
name = f.Nname.modeString(mode)
} else if flag&FmtLong != 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
name = mode.Sprintf("%0S", s)
if !exportname(name) && flag&FmtUnsigned == 0 {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
name = s.modeString(mode) // qualify non-exported names (used on structs, not on funarg)
}
} else {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
name = s.modeString(mode)
}
}
}
var typ string
cmd/compile: pack bool fields in Node, Name, Func and Type structs to bitsets This reduces compiler memory usage by up to 4% - see compilebench results below. name old time/op new time/op delta Template 245ms ± 4% 241ms ± 2% -1.88% (p=0.029 n=10+10) Unicode 126ms ± 3% 124ms ± 3% ~ (p=0.105 n=10+10) GoTypes 805ms ± 2% 813ms ± 3% ~ (p=0.515 n=8+10) Compiler 3.95s ± 2% 3.83s ± 1% -2.96% (p=0.000 n=9+10) MakeBash 47.4s ± 4% 46.6s ± 1% -1.59% (p=0.028 n=9+10) name old user-ns/op new user-ns/op delta Template 324M ± 5% 326M ± 3% ~ (p=0.935 n=10+10) Unicode 186M ± 5% 178M ±10% ~ (p=0.067 n=9+10) GoTypes 1.08G ± 7% 1.09G ± 4% ~ (p=0.956 n=10+10) Compiler 5.34G ± 4% 5.31G ± 1% ~ (p=0.501 n=10+8) name old alloc/op new alloc/op delta Template 41.0MB ± 0% 39.8MB ± 0% -3.03% (p=0.000 n=10+10) Unicode 32.3MB ± 0% 31.0MB ± 0% -4.13% (p=0.000 n=10+10) GoTypes 119MB ± 0% 116MB ± 0% -2.39% (p=0.000 n=10+10) Compiler 499MB ± 0% 487MB ± 0% -2.48% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 380k ± 1% 379k ± 1% ~ (p=0.436 n=10+10) Unicode 324k ± 1% 324k ± 0% ~ (p=0.853 n=10+10) GoTypes 1.15M ± 0% 1.15M ± 0% ~ (p=0.481 n=10+10) Compiler 4.41M ± 0% 4.41M ± 0% -0.12% (p=0.007 n=10+10) name old text-bytes new text-bytes delta HelloSize 623k ± 0% 623k ± 0% ~ (all equal) CmdGoSize 6.64M ± 0% 6.64M ± 0% ~ (all equal) name old data-bytes new data-bytes delta HelloSize 5.81k ± 0% 5.81k ± 0% ~ (all equal) CmdGoSize 238k ± 0% 238k ± 0% ~ (all equal) name old bss-bytes new bss-bytes delta HelloSize 134k ± 0% 134k ± 0% ~ (all equal) CmdGoSize 152k ± 0% 152k ± 0% ~ (all equal) name old exe-bytes new exe-bytes delta HelloSize 967k ± 0% 967k ± 0% ~ (all equal) CmdGoSize 10.2M ± 0% 10.2M ± 0% ~ (all equal) Change-Id: I1f40af738254892bd6c8ba2eb43390b175753d52 Reviewed-on: https://go-review.googlesource.com/37445 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-27 19:56:38 +02:00
if f.Isddd() {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
typ = "..." + f.Type.Elem().modeString(mode, depth)
} else {
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
typ = f.Type.modeString(mode, depth)
}
str := typ
if name != "" {
str = name + " " + typ
}
if flag&FmtShort == 0 && f.Funarg == FunargNone && f.Note != "" {
str += " " + strconv.Quote(f.Note)
}
return str
}
// "%L" print definition, not name
// "%S" omit 'func' and receiver from function types, short type names
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (t *Type) format(s fmt.State, verb rune, mode fmtMode) {
switch verb {
case 'v', 'S', 'L':
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
// This is an external entry point, so we pass depth 0 to tconv.
// See comments in Type.String.
fmt.Fprint(s, t.tconv(fmtFlag(s, verb), mode, 0))
default:
fmt.Fprintf(s, "%%!%c(*Type=%p)", verb, t)
}
}
// See #16897 before changing the implementation of tconv.
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
func (t *Type) tconv(flag FmtFlag, mode fmtMode, depth int) string {
if t == nil {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "<T>"
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
if depth > 100 {
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return "<...>"
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
flag, mode = flag.update(mode)
if mode == FTypeIdName {
flag |= FmtUnsigned
}
cmd/compile: eliminate use of Trecur in formatting routines CL 38147 eliminated package gc globals in formatting routines. However, tconv still used the Type field Trecur to avoid infinite recursion when formatting recursive interfaces types such as (test/fixedbugs398.go): type i1 interface { F() interface { i1 } } type i2 interface { F() interface { i2 } } This CL changes the recursion prevention to use a parameter, and threads it through the formatting routines. Because this fundamentally limits the embedding depth of all types, it sets the depth limit to be much higher. In practice, it is unlikely to impact any code at all, one way or the other. The remaining uses of Type.Trecur are boolean in nature. A future CL will change Type.Trecur to be a boolean flag. The removal of a couple of mode.Sprintf calls makes this a very minor net performance improvement: name old alloc/op new alloc/op delta Template 40.0MB ± 0% 40.0MB ± 0% -0.13% (p=0.032 n=5+5) Unicode 30.0MB ± 0% 29.9MB ± 0% ~ (p=0.310 n=5+5) GoTypes 114MB ± 0% 113MB ± 0% -0.25% (p=0.008 n=5+5) SSA 856MB ± 0% 855MB ± 0% -0.04% (p=0.008 n=5+5) Flate 25.5MB ± 0% 25.4MB ± 0% -0.27% (p=0.008 n=5+5) GoParser 31.9MB ± 0% 31.9MB ± 0% ~ (p=0.222 n=5+5) Reflect 79.0MB ± 0% 78.6MB ± 0% -0.45% (p=0.008 n=5+5) Tar 26.8MB ± 0% 26.7MB ± 0% -0.25% (p=0.032 n=5+5) XML 42.4MB ± 0% 42.4MB ± 0% ~ (p=0.151 n=5+5) name old allocs/op new allocs/op delta Template 395k ± 0% 391k ± 0% -1.00% (p=0.008 n=5+5) Unicode 321k ± 1% 319k ± 0% -0.56% (p=0.008 n=5+5) GoTypes 1.16M ± 0% 1.14M ± 0% -1.61% (p=0.008 n=5+5) SSA 7.63M ± 0% 7.60M ± 0% -0.30% (p=0.008 n=5+5) Flate 239k ± 0% 234k ± 0% -1.94% (p=0.008 n=5+5) GoParser 320k ± 0% 317k ± 1% -0.86% (p=0.008 n=5+5) Reflect 1.00M ± 0% 0.98M ± 0% -2.17% (p=0.016 n=4+5) Tar 255k ± 1% 251k ± 0% -1.35% (p=0.008 n=5+5) XML 398k ± 0% 395k ± 0% -0.89% (p=0.008 n=5+5) Updates #15756 Change-Id: Id23e647d347aa841f9a69d51f7d2d7d27b259239 Reviewed-on: https://go-review.googlesource.com/38797 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-29 16:28:51 -07:00
str := t.typefmt(flag, mode, depth+1)
cmd/compile: reduce allocs to c85b77c (pre-fmt.go change) levels Linker and reflect info generation (reflect.go) relies on formatting of types (tconv). The fmt.Format based approach introduces extra allocations, which matter in those cases. Resurrected sconv and tconv code from commit c85b77c (fmt.go only); and adjusted it slightly. The formatter-based approach is still used throughout the rest of the compiler, but reflect.go now uses the tconv method that simply returns the desired string. (The timing data below may not be accurate; I've included it only for comparison with the numbers in issue #16897). name old time/op new time/op delta Template 297ms ± 2% 288ms ± 3% -3.12% (p=0.000 n=27+29) Unicode 155ms ± 5% 150ms ± 5% -3.26% (p=0.000 n=30+30) GoTypes 1.00s ± 3% 0.95s ± 3% -4.51% (p=0.000 n=28+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.65% (p=0.000 n=28+30) Unicode 37.9MB ± 0% 37.8MB ± 0% -0.24% (p=0.000 n=29+30) GoTypes 144MB ± 0% 143MB ± 0% -0.68% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 469k ± 0% 446k ± 0% -5.01% (p=0.000 n=29+30) Unicode 375k ± 0% 369k ± 0% -1.62% (p=0.000 n=30+28) GoTypes 1.47M ± 0% 1.37M ± 0% -6.29% (p=0.000 n=30+30) The code for sconv/tconv in fmt.go now closely match the code from c85b77c again; except that the functions are now methods. Removing the use of the bytes.Buffer in tconv and special-caseing interface{} has helped a small amount as well: name old time/op new time/op delta Template 299ms ± 3% 288ms ± 3% -3.83% (p=0.000 n=29+29) Unicode 156ms ± 5% 150ms ± 5% -3.56% (p=0.000 n=30+30) GoTypes 960ms ± 2% 954ms ± 3% -0.58% (p=0.037 n=26+29) name old alloc/op new alloc/op delta Template 46.6MB ± 0% 46.5MB ± 0% -0.22% (p=0.000 n=30+30) Unicode 37.8MB ± 0% 37.8MB ± 0% ~ (p=0.075 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.31% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 447k ± 0% 446k ± 0% -0.28% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% -0.03% (p=0.032 n=30+28) GoTypes 1.38M ± 0% 1.37M ± 0% -0.35% (p=0.000 n=29+30) Comparison between c85b77c and now (see issue #16897): name old time/op new time/op delta Template 307ms ± 4% 288ms ± 3% -6.24% (p=0.000 n=29+29) Unicode 164ms ± 4% 150ms ± 5% -8.20% (p=0.000 n=30+30) GoTypes 1.01s ± 3% 0.95s ± 3% -5.72% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 46.5MB ± 0% -0.66% (p=0.000 n=29+30) Unicode 37.8MB ± 0% 37.8MB ± 0% -0.13% (p=0.000 n=30+30) GoTypes 143MB ± 0% 143MB ± 0% -0.11% (p=0.000 n=30+30) name old allocs/op new allocs/op delta Template 444k ± 0% 446k ± 0% +0.48% (p=0.000 n=30+30) Unicode 369k ± 0% 369k ± 0% +0.09% (p=0.000 n=30+28) GoTypes 1.35M ± 0% 1.37M ± 0% +1.47% (p=0.000 n=30+30) There's still a small increase (< 1.5%) for GoTypes but pending a complete rewrite of fmt.go, this seems ok again. Fixes #16897. Change-Id: I7e0e56cd1b9f981252eded917f5752259d402354 Reviewed-on: https://go-review.googlesource.com/29087 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-09-12 13:44:43 -07:00
return str
cmd/compile: make internal objects directly print to printer Internal objects that satisfy the Printable interface can print directly to a printer w/o going through the conversion to a string first. Made printer.f understand and special-case %v so that Printable objects use the printer directly. This is work in progress and we may end up doing something else eventually (perhaps using fmt.Formatter) - or even undo these changes if this exploration doesn't get us to a significantly better place. Allocations numbers relative to commit c85b77c (still up, but reduced from most recent change): name old time/op new time/op delta Template 307ms ± 4% 315ms ± 4% +2.55% (p=0.000 n=29+29) Unicode 164ms ± 4% 165ms ± 4% ~ (p=0.057 n=30+30) GoTypes 1.01s ± 3% 1.03s ± 3% +1.72% (p=0.000 n=30+30) Compiler 5.49s ± 1% 5.62s ± 2% +2.31% (p=0.000 n=30+28) name old user-ns/op new user-ns/op delta Template 397M ± 3% 406M ± 6% +2.21% (p=0.000 n=28+30) Unicode 225M ± 4% 226M ± 3% ~ (p=0.230 n=29+30) GoTypes 1.31G ± 3% 1.34G ± 5% +2.79% (p=0.000 n=30+30) Compiler 7.39G ± 2% 7.50G ± 2% +1.43% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 47.5MB ± 0% +1.48% (p=0.000 n=29+28) Unicode 37.8MB ± 0% 38.1MB ± 0% +0.64% (p=0.000 n=30+28) GoTypes 143MB ± 0% 145MB ± 0% +1.72% (p=0.000 n=30+30) Compiler 683MB ± 0% 706MB ± 0% +3.31% (p=0.000 n=30+29) name old allocs/op new allocs/op delta Template 444k ± 0% 481k ± 0% +8.38% (p=0.000 n=30+30) Unicode 369k ± 0% 379k ± 0% +2.74% (p=0.000 n=30+30) GoTypes 1.35M ± 0% 1.50M ± 0% +10.78% (p=0.000 n=30+30) Compiler 5.66M ± 0% 6.25M ± 0% +10.31% (p=0.000 n=29+29) For #16897. Change-Id: I37f95ab60508018ee6d29a98d238482b60e3e4b5 Reviewed-on: https://go-review.googlesource.com/28072 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-29 17:56:15 -07:00
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) String() string { return fmt.Sprint(n) }
func (n *Node) modeString(mode fmtMode) string { return mode.Sprint(n) }
// "%L" suffix with "(type %T)" where possible
// "%+S" in debug mode, don't recurse, no multiline output
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (n *Node) nconv(s fmt.State, flag FmtFlag, mode fmtMode) {
if n == nil {
fmt.Fprint(s, "<N>")
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
flag, mode = flag.update(mode)
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
switch mode {
case FErr:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.nodefmt(s, flag, mode)
case FDbg:
dumpdepth++
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
n.nodedump(s, flag, mode)
dumpdepth--
default:
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
Fatalf("unhandled %%N mode: %d", mode)
}
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (l Nodes) format(s fmt.State, verb rune, mode fmtMode) {
switch verb {
case 'v':
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
l.hconv(s, fmtFlag(s, verb), mode)
cmd/compile: make internal objects directly print to printer Internal objects that satisfy the Printable interface can print directly to a printer w/o going through the conversion to a string first. Made printer.f understand and special-case %v so that Printable objects use the printer directly. This is work in progress and we may end up doing something else eventually (perhaps using fmt.Formatter) - or even undo these changes if this exploration doesn't get us to a significantly better place. Allocations numbers relative to commit c85b77c (still up, but reduced from most recent change): name old time/op new time/op delta Template 307ms ± 4% 315ms ± 4% +2.55% (p=0.000 n=29+29) Unicode 164ms ± 4% 165ms ± 4% ~ (p=0.057 n=30+30) GoTypes 1.01s ± 3% 1.03s ± 3% +1.72% (p=0.000 n=30+30) Compiler 5.49s ± 1% 5.62s ± 2% +2.31% (p=0.000 n=30+28) name old user-ns/op new user-ns/op delta Template 397M ± 3% 406M ± 6% +2.21% (p=0.000 n=28+30) Unicode 225M ± 4% 226M ± 3% ~ (p=0.230 n=29+30) GoTypes 1.31G ± 3% 1.34G ± 5% +2.79% (p=0.000 n=30+30) Compiler 7.39G ± 2% 7.50G ± 2% +1.43% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 47.5MB ± 0% +1.48% (p=0.000 n=29+28) Unicode 37.8MB ± 0% 38.1MB ± 0% +0.64% (p=0.000 n=30+28) GoTypes 143MB ± 0% 145MB ± 0% +1.72% (p=0.000 n=30+30) Compiler 683MB ± 0% 706MB ± 0% +3.31% (p=0.000 n=30+29) name old allocs/op new allocs/op delta Template 444k ± 0% 481k ± 0% +8.38% (p=0.000 n=30+30) Unicode 369k ± 0% 379k ± 0% +2.74% (p=0.000 n=30+30) GoTypes 1.35M ± 0% 1.50M ± 0% +10.78% (p=0.000 n=30+30) Compiler 5.66M ± 0% 6.25M ± 0% +10.31% (p=0.000 n=29+29) For #16897. Change-Id: I37f95ab60508018ee6d29a98d238482b60e3e4b5 Reviewed-on: https://go-review.googlesource.com/28072 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-29 17:56:15 -07:00
default:
fmt.Fprintf(s, "%%!%c(Nodes)", verb)
}
}
cmd/compile: make internal objects directly print to printer Internal objects that satisfy the Printable interface can print directly to a printer w/o going through the conversion to a string first. Made printer.f understand and special-case %v so that Printable objects use the printer directly. This is work in progress and we may end up doing something else eventually (perhaps using fmt.Formatter) - or even undo these changes if this exploration doesn't get us to a significantly better place. Allocations numbers relative to commit c85b77c (still up, but reduced from most recent change): name old time/op new time/op delta Template 307ms ± 4% 315ms ± 4% +2.55% (p=0.000 n=29+29) Unicode 164ms ± 4% 165ms ± 4% ~ (p=0.057 n=30+30) GoTypes 1.01s ± 3% 1.03s ± 3% +1.72% (p=0.000 n=30+30) Compiler 5.49s ± 1% 5.62s ± 2% +2.31% (p=0.000 n=30+28) name old user-ns/op new user-ns/op delta Template 397M ± 3% 406M ± 6% +2.21% (p=0.000 n=28+30) Unicode 225M ± 4% 226M ± 3% ~ (p=0.230 n=29+30) GoTypes 1.31G ± 3% 1.34G ± 5% +2.79% (p=0.000 n=30+30) Compiler 7.39G ± 2% 7.50G ± 2% +1.43% (p=0.000 n=30+29) name old alloc/op new alloc/op delta Template 46.8MB ± 0% 47.5MB ± 0% +1.48% (p=0.000 n=29+28) Unicode 37.8MB ± 0% 38.1MB ± 0% +0.64% (p=0.000 n=30+28) GoTypes 143MB ± 0% 145MB ± 0% +1.72% (p=0.000 n=30+30) Compiler 683MB ± 0% 706MB ± 0% +3.31% (p=0.000 n=30+29) name old allocs/op new allocs/op delta Template 444k ± 0% 481k ± 0% +8.38% (p=0.000 n=30+30) Unicode 369k ± 0% 379k ± 0% +2.74% (p=0.000 n=30+30) GoTypes 1.35M ± 0% 1.50M ± 0% +10.78% (p=0.000 n=30+30) Compiler 5.66M ± 0% 6.25M ± 0% +10.31% (p=0.000 n=29+29) For #16897. Change-Id: I37f95ab60508018ee6d29a98d238482b60e3e4b5 Reviewed-on: https://go-review.googlesource.com/28072 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2016-08-29 17:56:15 -07:00
func (n Nodes) String() string {
return fmt.Sprint(n)
}
// Flags: all those of %N plus '.': separate with comma's instead of semicolons.
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
func (l Nodes) hconv(s fmt.State, flag FmtFlag, mode fmtMode) {
if l.Len() == 0 && mode == FDbg {
fmt.Fprint(s, "<nil>")
return
}
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
flag, mode = flag.update(mode)
sep := "; "
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
if mode == FDbg {
sep = "\n"
} else if flag&FmtComma != 0 {
sep = ", "
}
for i, n := range l.Slice() {
cmd/compile: eliminate fmtmode and fmtpkgpfx globals The fmtmode and fmtpkgpfx globals stand in the way of making the compiler more concurrent (#15756). This CL removes them. The natural way to eliminate a global is to explicitly thread it as a parameter through all function calls. However, most of the functions in gc/fmt.go get called indirectly, by way of fmt format strings, so there's nowhere natural to add a parameter. Since there are only a few fmtmode modes, use named types to distinguish between modes. For example, fmtNodeErr, fmtNodeDbg, and fmtNodeTypeId are all gc.Node, but they print in different modes. Varying the type allows us to thread mode through fmt. Handle fmtpkgpfx by converting it to a printing mode, FTypeIdName, and using the same type-based approach. To avoid a loss of readability and danger of bugs from introducing conversions at all call sites, instead add a helper that systematically modifies the args. The only remaining gc/fmt.go global is dumpdepth. Since that is used for debugging only, it that can be handled with a global mutex, or some similarly basic, if inefficient, protection. Passes toolstash -cmp. No compiler performance impact. For future reference, other options for threading state that were considered and rejected: * Wrapping values in structs, such as: type fmtNode struct { n *Node mode fmtMode } This reduces the proliferation of types, and supports easily adding extra local parameters. However, putting such a struct into an interface{} allocates. This is unacceptable in this particular area of code. * Passing state via precision, such as: fmt.Fprintf("%*v", mode, n) where mode is the state encoded as an integer. This avoids extra allocations, but it is out of keeping with the intended semantics of precision, and is less readable. * Modify the fmt package to support setting/getting context via fmt.State. Unavailable due to Go 1 compatibility, and probably the wrong solution anyway. * Give up on package fmt. This would be a huge readability regression and cause high code churn. * Attempt a de-novo rewrite that circumvents these problems. Too high a risk of bugs, with insufficient reward for the effort, particularly since long term plans call for elimination of gc.Node. Change-Id: Iea2440d5a34a938e64273707de27e3a897cb41d1 Reviewed-on: https://go-review.googlesource.com/38147 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-07 16:14:32 -08:00
fmt.Fprint(s, n.modeString(mode))
if i+1 < l.Len() {
fmt.Fprint(s, sep)
}
}
}
func dumplist(s string, l Nodes) {
fmt.Printf("%s%+v\n", s, l)
}
func Dump(s string, n *Node) {
fmt.Printf("%s [%p]%+v\n", s, n, n)
}
// TODO(gri) make variable local somehow
var dumpdepth int
// indent prints indentation to s.
func indent(s fmt.State) {
fmt.Fprint(s, "\n")
for i := 0; i < dumpdepth; i++ {
fmt.Fprint(s, ". ")
}
}