eface

eface 结构体表示不包含任何方法的 interface{} 类型,包含指向底层数据和类型的两个指针
// go1.13.9 runtime/runtime2.go 197

  1. type eface struct {
  2. _type *_type
  3. data unsafe.Pointer
  4. }

iface

iface 结构体表示包含方法的接口;
// go1.13.9 runtime/runtime2.go 192

  1. type iface struct {
  2. tab *itab
  3. data unsafe.Pointer
  4. }

itab

// go1.13.9 runtime/runtime2.go 730

  1. type itab struct {
  2. inter *interfacetype
  3. _type *_type
  4. link *itab
  5. hash uint32 // copy of _type.hash. Used for type switches.
  6. bad bool // type does not implement interface
  7. inhash bool // has this itab been added to hash?
  8. unused [2]byte
  9. fun [1]uintptr // variable sized
  10. }

interfacetype

// go1.13.9 runtime/type.go 354

  1. type interfacetype struct {
  2. typ _type //类型
  3. pkgpath name // 包路径
  4. mhdr []imethod //接口定义的函数列表
  5. }

_type

  1. type _type struct {
  2. size uintptr // 类型大小
  3. ptrdata uintptr // size of memory prefix holding all pointers
  4. hash uint32 // 类型hash
  5. tflag tflag // 类型flag
  6. align uint8 // 类型对齐
  7. fieldalign uint8
  8. kind uint8 //类型
  9. alg *typeAlg
  10. // gcdata stores the GC type data for the garbage collector.
  11. // If the KindGCProg bit is set in kind, gcdata is a GC program.
  12. // Otherwise it is a ptrmask bitmap. See mbitmap.go for details.
  13. gcdata *byte
  14. str nameOff
  15. ptrToThis typeOff
  16. }

size类型占用的内存空间,为内存空间的分配提供信息;
hash 字段能够帮助我们快速确定类型是否相等