embedlineno := n.Type.ForwardType().Embedlineno
l := n.Type.ForwardType().Copyto
- ptrBase := n.Type.PtrBase
- sliceOf := n.Type.SliceOf
+ cache := n.Type.Cache
// TODO(mdempsky): Fix Type rekinding.
*n.Type = *t
t.Nod = asTypesNode(n)
t.SetDeferwidth(false)
- t.PtrBase = ptrBase
- t.SliceOf = sliceOf
+ t.Cache = cache
// Propagate go:notinheap pragma from the Name to the Type.
if n.Name != nil && n.Name.Param != nil && n.Name.Param.Pragma&NotInHeap != 0 {
Nod *Node // canonical OTYPE node
Orig *Type // original type (type literal or predefined type)
- SliceOf *Type
- PtrBase *Type
+ // Cache of composite types, with this type being the element type.
+ Cache struct {
+ ptr *Type // *T, or nil
+ slice *Type // []T, or nil
+ }
Sym *Sym // symbol containing name, for named types
Vargen int32 // unique name for OTYPE/ONAME
// NewSlice returns the slice Type with element type elem.
func NewSlice(elem *Type) *Type {
- if t := elem.SliceOf; t != nil {
+ if t := elem.Cache.slice; t != nil {
if t.Elem() != elem {
Fatalf("elem mismatch")
}
t := New(TSLICE)
t.Extra = Slice{Elem: elem}
- elem.SliceOf = t
+ elem.Cache.slice = t
return t
}
Fatalf("NewPtr: pointer to elem Type is nil")
}
- if t := elem.PtrBase; t != nil {
+ if t := elem.Cache.ptr; t != nil {
if t.Elem() != elem {
Fatalf("NewPtr: elem mismatch")
}
t.Width = int64(Widthptr)
t.Align = uint8(Widthptr)
if NewPtrCacheEnabled {
- elem.PtrBase = t
+ elem.Cache.ptr = t
}
return t
}
return t.Etype == TPTR
}
+// IsPtrElem reports whether t is the element of a pointer (to t).
+func (t *Type) IsPtrElem() bool {
+ return t.Cache.ptr != nil
+}
+
// IsUnsafePtr reports whether t is an unsafe pointer.
func (t *Type) IsUnsafePtr() bool {
return t.Etype == TUNSAFEPTR