mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: cleanup for concrete types - walk
An automated rewrite will add concrete type assertions after a test of n.Op(), when n can be safely type-asserted (meaning, n is not reassigned a different type, n is not reassigned and then used outside the scope of the type assertion, and so on). This sequence of CLs handles the code that the automated rewrite does not: adding specific types to function arguments, adjusting code not to call n.Left() etc when n may have multiple representations, and so on. This CL focuses on walk.go. Passes buildall w/ toolstash -cmp. Change-Id: I7aab57e4077cf10da1994625575c5e42ad114a9c Reviewed-on: https://go-review.googlesource.com/c/go/+/277921 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
0b9cb63b8d
commit
27aba22651
4 changed files with 351 additions and 330 deletions
|
|
@ -805,7 +805,7 @@ func eqfield(p ir.Node, q ir.Node, field *types.Sym) ir.Node {
|
||||||
// memequal(s.ptr, t.ptr, len(s))
|
// memequal(s.ptr, t.ptr, len(s))
|
||||||
// which can be used to construct string equality comparison.
|
// which can be used to construct string equality comparison.
|
||||||
// eqlen must be evaluated before eqmem, and shortcircuiting is required.
|
// eqlen must be evaluated before eqmem, and shortcircuiting is required.
|
||||||
func eqstring(s, t ir.Node) (eqlen, eqmem ir.Node) {
|
func eqstring(s, t ir.Node) (eqlen *ir.BinaryExpr, eqmem *ir.CallExpr) {
|
||||||
s = conv(s, types.Types[types.TSTRING])
|
s = conv(s, types.Types[types.TSTRING])
|
||||||
t = conv(t, types.Types[types.TSTRING])
|
t = conv(t, types.Types[types.TSTRING])
|
||||||
sptr := ir.Nod(ir.OSPTR, s, nil)
|
sptr := ir.Nod(ir.OSPTR, s, nil)
|
||||||
|
|
@ -815,14 +815,13 @@ func eqstring(s, t ir.Node) (eqlen, eqmem ir.Node) {
|
||||||
|
|
||||||
fn := syslook("memequal")
|
fn := syslook("memequal")
|
||||||
fn = substArgTypes(fn, types.Types[types.TUINT8], types.Types[types.TUINT8])
|
fn = substArgTypes(fn, types.Types[types.TUINT8], types.Types[types.TUINT8])
|
||||||
call := ir.Nod(ir.OCALL, fn, nil)
|
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, []ir.Node{sptr, tptr, ir.Copy(slen)})
|
||||||
call.PtrList().Append(sptr, tptr, ir.Copy(slen))
|
call = typecheck(call, ctxExpr|ctxMultiOK).(*ir.CallExpr)
|
||||||
call1 := typecheck(call, ctxExpr|ctxMultiOK)
|
|
||||||
|
|
||||||
cmp := ir.Nod(ir.OEQ, slen, tlen)
|
cmp := ir.NewBinaryExpr(base.Pos, ir.OEQ, slen, tlen)
|
||||||
cmp1 := typecheck(cmp, ctxExpr)
|
cmp = typecheck(cmp, ctxExpr).(*ir.BinaryExpr)
|
||||||
cmp.SetType(types.Types[types.TBOOL])
|
cmp.SetType(types.Types[types.TBOOL])
|
||||||
return cmp1, call1
|
return cmp, call
|
||||||
}
|
}
|
||||||
|
|
||||||
// eqinterface returns the nodes
|
// eqinterface returns the nodes
|
||||||
|
|
@ -831,7 +830,7 @@ func eqstring(s, t ir.Node) (eqlen, eqmem ir.Node) {
|
||||||
// ifaceeq(s.tab, s.data, t.data) (or efaceeq(s.typ, s.data, t.data), as appropriate)
|
// ifaceeq(s.tab, s.data, t.data) (or efaceeq(s.typ, s.data, t.data), as appropriate)
|
||||||
// which can be used to construct interface equality comparison.
|
// which can be used to construct interface equality comparison.
|
||||||
// eqtab must be evaluated before eqdata, and shortcircuiting is required.
|
// eqtab must be evaluated before eqdata, and shortcircuiting is required.
|
||||||
func eqinterface(s, t ir.Node) (eqtab, eqdata ir.Node) {
|
func eqinterface(s, t ir.Node) (eqtab *ir.BinaryExpr, eqdata *ir.CallExpr) {
|
||||||
if !types.Identical(s.Type(), t.Type()) {
|
if !types.Identical(s.Type(), t.Type()) {
|
||||||
base.Fatalf("eqinterface %v %v", s.Type(), t.Type())
|
base.Fatalf("eqinterface %v %v", s.Type(), t.Type())
|
||||||
}
|
}
|
||||||
|
|
@ -853,14 +852,13 @@ func eqinterface(s, t ir.Node) (eqtab, eqdata ir.Node) {
|
||||||
sdata.SetTypecheck(1)
|
sdata.SetTypecheck(1)
|
||||||
tdata.SetTypecheck(1)
|
tdata.SetTypecheck(1)
|
||||||
|
|
||||||
call := ir.Nod(ir.OCALL, fn, nil)
|
call := ir.NewCallExpr(base.Pos, ir.OCALL, fn, []ir.Node{stab, sdata, tdata})
|
||||||
call.PtrList().Append(stab, sdata, tdata)
|
call = typecheck(call, ctxExpr|ctxMultiOK).(*ir.CallExpr)
|
||||||
call1 := typecheck(call, ctxExpr|ctxMultiOK)
|
|
||||||
|
|
||||||
cmp := ir.Nod(ir.OEQ, stab, ttab)
|
cmp := ir.NewBinaryExpr(base.Pos, ir.OEQ, stab, ttab)
|
||||||
cmp1 := typecheck(cmp, ctxExpr)
|
cmp = typecheck(cmp, ctxExpr).(*ir.BinaryExpr)
|
||||||
cmp1.SetType(types.Types[types.TBOOL])
|
cmp.SetType(types.Types[types.TBOOL])
|
||||||
return cmp1, call1
|
return cmp, call
|
||||||
}
|
}
|
||||||
|
|
||||||
// eqmem returns the node
|
// eqmem returns the node
|
||||||
|
|
|
||||||
|
|
@ -192,8 +192,8 @@ type Arch struct {
|
||||||
var thearch Arch
|
var thearch Arch
|
||||||
|
|
||||||
var (
|
var (
|
||||||
staticuint64s,
|
staticuint64s *ir.Name
|
||||||
zerobase ir.Node
|
zerobase *ir.Name
|
||||||
|
|
||||||
assertE2I,
|
assertE2I,
|
||||||
assertE2I2,
|
assertE2I2,
|
||||||
|
|
|
||||||
|
|
@ -943,7 +943,7 @@ func oaslit(n ir.Node, init *ir.Nodes) bool {
|
||||||
return false
|
return false
|
||||||
|
|
||||||
case ir.OSTRUCTLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
|
case ir.OSTRUCTLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT:
|
||||||
if vmatch1(n.Left(), n.Right()) {
|
if refersToCommonName(n.Left(), n.Right()) {
|
||||||
// not a special composite literal assignment
|
// not a special composite literal assignment
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue