Commit 9d77ad8d authored by Dave Cheney's avatar Dave Cheney

cmd/compile/internal/gc: type.go cleanup

Follow up to CL 20494 addressing Type.Copy and a few other tiny
cleanups.

Change-Id: I3d0913a9f50a22ac2fd802858b1a94c15c5cb1bc
Reviewed-on: https://go-review.googlesource.com/20501
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 2339b131
...@@ -180,13 +180,12 @@ func (t *Type) Copy() *Type { ...@@ -180,13 +180,12 @@ func (t *Type) Copy() *Type {
if t == nil { if t == nil {
return nil return nil
} }
nt := new(Type) nt := *t
*nt = *t
// TODO(mdempsky): Find out why this is necessary and explain. // TODO(mdempsky): Find out why this is necessary and explain.
if t.Orig == t { if t.Orig == t {
nt.Orig = nt nt.Orig = &nt
} }
return nt return &nt
} }
// Iter provides an abstraction for iterating across struct fields and // Iter provides an abstraction for iterating across struct fields and
...@@ -267,10 +266,7 @@ func (t *Type) SimpleString() string { ...@@ -267,10 +266,7 @@ func (t *Type) SimpleString() string {
func (t *Type) Equal(u ssa.Type) bool { func (t *Type) Equal(u ssa.Type) bool {
x, ok := u.(*Type) x, ok := u.(*Type)
if !ok { return ok && Eqtype(t, x)
return false
}
return Eqtype(t, x)
} }
// Compare compares types for purposes of the SSA back // Compare compares types for purposes of the SSA back
...@@ -368,20 +364,16 @@ func (t *Type) cmp(x *Type) ssa.Cmp { ...@@ -368,20 +364,16 @@ func (t *Type) cmp(x *Type) ssa.Cmp {
} }
} }
csym := t.Sym.cmpsym(x.Sym) if c := t.Sym.cmpsym(x.Sym); c != ssa.CMPeq {
if csym != ssa.CMPeq { return c
return csym
} }
if x.Sym != nil { if x.Sym != nil {
// Syms non-nil, if vargens match then equal. // Syms non-nil, if vargens match then equal.
if t.Vargen == x.Vargen { if t.Vargen != x.Vargen {
return ssa.CMPeq return cmpForNe(t.Vargen < x.Vargen)
} }
if t.Vargen < x.Vargen { return ssa.CMPeq
return ssa.CMPlt
}
return ssa.CMPgt
} }
// both syms nil, look at structure below. // both syms nil, look at structure below.
...@@ -481,8 +473,7 @@ func (t *Type) cmp(x *Type) ssa.Cmp { ...@@ -481,8 +473,7 @@ func (t *Type) cmp(x *Type) ssa.Cmp {
panic(e) panic(e)
} }
c := t.Down.cmp(x.Down) if c := t.Down.cmp(x.Down); c != ssa.CMPeq {
if c != ssa.CMPeq {
return c return c
} }
return t.Type.cmp(x.Type) return t.Type.cmp(x.Type)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment