1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // AIX linker isn't able to merge identical type descriptors coming from
8 // different objects. Thus, two rtypes might have two different pointers
9 // even if they are the same. Thus, instead of pointer equality, string
18 // rtypeEqual returns true if both rtypes are identical.
19 func rtypeEqual(t1
, t2
*rtype
) bool {
23 case t1
== nil || t2
== nil:
25 case t1
.kind
!= t2
.kind || t1
.hash
!= t2
.hash
:
28 return t1
.String() == t2
.String()
32 // typeEqual returns true if both Types are identical.
33 func typeEqual(t1
, t2 Type
) bool {
34 return rtypeEqual(t1
.common(), t2
.common())
37 // toType converts from a *rtype to a Type that can be returned
38 // to the client of package reflect. The only concern is that
39 // a nil *rtype must be replaced by a nil Type.
40 // On AIX, as type duplications can occur, it also ensure that
41 // multiple *rtype for the same type are coalesced into a single
44 var canonicalType
= make(map[string]Type
)
46 var canonicalTypeLock sync
.RWMutex
48 func canonicalize(t Type
) Type
{
53 canonicalTypeLock
.RLock()
54 if r
, ok
:= canonicalType
[s
]; ok
{
55 canonicalTypeLock
.RUnlock()
58 canonicalTypeLock
.RUnlock()
59 canonicalTypeLock
.Lock()
60 if r
, ok
:= canonicalType
[s
]; ok
{
61 canonicalTypeLock
.Unlock()
65 canonicalTypeLock
.Unlock()
69 func toType(p
*rtype
) Type
{
73 return canonicalize(p
)