From 095e0f48a19fa3bd7901f79420374b9cb50940e9 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Thu, 1 Oct 2020 12:03:27 +0200 Subject: cmd/compile: change mustHeapAlloc to return a reason why This change renames mustHeapAlloc to heapAllocReason, and changes it to return the reason why the argument must escape, so we don't have to re-deduce it in its callers just to print the escape reason. It also embeds isSmallMakeSlice body in heapAllocReason, since the former was only used by the latter, and deletes isSmallMakeSlice. An outdated TODO to remove smallintconst, which the TODO claimed was only used in one place, was also removed, since grepping shows we currently call smallintconst in 11 different places. Change-Id: I0bd11bf29b92c4126f5bb455877ff73217d5a155 Reviewed-on: https://go-review.googlesource.com/c/go/+/258678 Run-TryBot: Alberto Donizetti TryBot-Result: Go Bot Trust: Alberto Donizetti Trust: Cuong Manh Le Reviewed-by: Cuong Manh Le Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 1 - 1 file changed, 1 deletion(-) (limited to 'src/cmd/compile/internal/gc/const.go') diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index c0ed8192d9..d881be485e 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -1134,7 +1134,6 @@ func strlit(n *Node) string { return n.Val().U.(string) } -// TODO(gri) smallintconst is only used in one place - can we used indexconst? func smallintconst(n *Node) bool { if n.Op == OLITERAL && Isconst(n, CTINT) && n.Type != nil { switch simtype[n.Type.Etype] { -- cgit v1.2.1 From 46ab0c0c0474d38d9b924b2428f20c6da58c85fa Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 8 Oct 2020 20:33:36 +0700 Subject: cmd/compile: rename types.IdealFoo to types.UntypedFoo To be consistent with go/types. Passes toolstash-check. Change-Id: I5e02f529064a904310a164f8765082aa533cc799 Reviewed-on: https://go-review.googlesource.com/c/go/+/260699 Trust: Cuong Manh Le Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/cmd/compile/internal/gc/const.go') diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index d881be485e..b28c0fc8d0 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -1019,17 +1019,17 @@ func nodlit(v Val) *Node { func idealType(ct Ctype) *types.Type { switch ct { case CTSTR: - return types.Idealstring + return types.UntypedString case CTBOOL: - return types.Idealbool + return types.UntypedBool case CTINT: - return types.Idealint + return types.UntypedInt case CTRUNE: - return types.Idealrune + return types.UntypedRune case CTFLT: - return types.Idealfloat + return types.UntypedFloat case CTCPLX: - return types.Idealcomplex + return types.UntypedComplex case CTNIL: return types.Types[TNIL] } @@ -1080,17 +1080,17 @@ func defaultlit2(l *Node, r *Node, force bool) (*Node, *Node) { func ctype(t *types.Type) Ctype { switch t { - case types.Idealbool: + case types.UntypedBool: return CTBOOL - case types.Idealstring: + case types.UntypedString: return CTSTR - case types.Idealint: + case types.UntypedInt: return CTINT - case types.Idealrune: + case types.UntypedRune: return CTRUNE - case types.Idealfloat: + case types.UntypedFloat: return CTFLT - case types.Idealcomplex: + case types.UntypedComplex: return CTCPLX } Fatalf("bad type %v", t) @@ -1111,17 +1111,17 @@ func defaultType(t *types.Type) *types.Type { } switch t { - case types.Idealbool: + case types.UntypedBool: return types.Types[TBOOL] - case types.Idealstring: + case types.UntypedString: return types.Types[TSTRING] - case types.Idealint: + case types.UntypedInt: return types.Types[TINT] - case types.Idealrune: + case types.UntypedRune: return types.Runetype - case types.Idealfloat: + case types.UntypedFloat: return types.Types[TFLOAT64] - case types.Idealcomplex: + case types.UntypedComplex: return types.Types[TCOMPLEX128] } -- cgit v1.2.1 From e2931612b04e2ea6be337872c6f4a31c7d7dec54 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Mon, 12 Oct 2020 15:02:59 +0200 Subject: cmd/compile: rename strlit, Bool, and Int64 *Node accessors The Node type has shortcuts to access bool and int Values: func (n *Node) Int64() int64 for n.Val().U.(*Mpint).Int64() func (n *Node) Bool() bool for n.Val().U.(bool) I was convinced we didn't have one for string literal nodes, until I noticed that we do, it's just called strlit, it's not a method, and it's later in the file: func strlit(n *Node) string This change, for consistency: - Renames strlit to StringVal and makes it a *Node method - Renames Bool and Int64 to BoolVal and Int64Val - Moves StringVal near the other two Change-Id: I18e635384c35eb3a238fd52b1ccd322b1a74d733 Reviewed-on: https://go-review.googlesource.com/c/go/+/261361 Trust: Alberto Donizetti Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/cmd/compile/internal/gc/const.go') diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index b28c0fc8d0..b92c8d66b5 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -114,16 +114,16 @@ func (v Val) Interface() interface{} { type NilVal struct{} -// Int64 returns n as an int64. +// Int64Val returns n as an int64. // n must be an integer or rune constant. -func (n *Node) Int64() int64 { +func (n *Node) Int64Val() int64 { if !Isconst(n, CTINT) { - Fatalf("Int64(%v)", n) + Fatalf("Int64Val(%v)", n) } return n.Val().U.(*Mpint).Int64() } -// CanInt64 reports whether it is safe to call Int64() on n. +// CanInt64 reports whether it is safe to call Int64Val() on n. func (n *Node) CanInt64() bool { if !Isconst(n, CTINT) { return false @@ -131,18 +131,27 @@ func (n *Node) CanInt64() bool { // if the value inside n cannot be represented as an int64, the // return value of Int64 is undefined - return n.Val().U.(*Mpint).CmpInt64(n.Int64()) == 0 + return n.Val().U.(*Mpint).CmpInt64(n.Int64Val()) == 0 } -// Bool returns n as a bool. +// BoolVal returns n as a bool. // n must be a boolean constant. -func (n *Node) Bool() bool { +func (n *Node) BoolVal() bool { if !Isconst(n, CTBOOL) { - Fatalf("Bool(%v)", n) + Fatalf("BoolVal(%v)", n) } return n.Val().U.(bool) } +// StringVal returns the value of a literal string Node as a string. +// n must be a string constant. +func (n *Node) StringVal() string { + if !Isconst(n, CTSTR) { + Fatalf("StringVal(%v)", n) + } + return n.Val().U.(string) +} + // truncate float literal fv to 32-bit or 64-bit precision // according to type; return truncated value. func truncfltlit(oldv *Mpflt, t *types.Type) *Mpflt { @@ -612,7 +621,7 @@ func evconst(n *Node) { var strs []string i2 := i1 for i2 < len(s) && Isconst(s[i2], CTSTR) { - strs = append(strs, strlit(s[i2])) + strs = append(strs, s[i2].StringVal()) i2++ } @@ -635,7 +644,7 @@ func evconst(n *Node) { switch nl.Type.Etype { case TSTRING: if Isconst(nl, CTSTR) { - setintconst(n, int64(len(strlit(nl)))) + setintconst(n, int64(len(nl.StringVal()))) } case TARRAY: if !hascallchan(nl) { @@ -1129,11 +1138,6 @@ func defaultType(t *types.Type) *types.Type { return nil } -// strlit returns the value of a literal string Node as a string. -func strlit(n *Node) string { - return n.Val().U.(string) -} - func smallintconst(n *Node) bool { if n.Op == OLITERAL && Isconst(n, CTINT) && n.Type != nil { switch simtype[n.Type.Etype] { -- cgit v1.2.1