sync.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2021 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.
  4. package pkgbits
  5. import (
  6. "fmt"
  7. "strings"
  8. )
  9. // fmtFrames formats a backtrace for reporting reader/writer desyncs.
  10. func fmtFrames(pcs ...uintptr) []string {
  11. res := make([]string, 0, len(pcs))
  12. walkFrames(pcs, func(file string, line int, name string, offset uintptr) {
  13. // Trim package from function name. It's just redundant noise.
  14. name = strings.TrimPrefix(name, "cmd/compile/internal/noder.")
  15. res = append(res, fmt.Sprintf("%s:%v: %s +0x%v", file, line, name, offset))
  16. })
  17. return res
  18. }
  19. type frameVisitor func(file string, line int, name string, offset uintptr)
  20. // SyncMarker is an enum type that represents markers that may be
  21. // written to export data to ensure the reader and writer stay
  22. // synchronized.
  23. type SyncMarker int
  24. //go:generate stringer -type=SyncMarker -trimprefix=Sync
  25. const (
  26. _ SyncMarker = iota
  27. // Public markers (known to go/types importers).
  28. // Low-level coding markers.
  29. SyncEOF
  30. SyncBool
  31. SyncInt64
  32. SyncUint64
  33. SyncString
  34. SyncValue
  35. SyncVal
  36. SyncRelocs
  37. SyncReloc
  38. SyncUseReloc
  39. // Higher-level object and type markers.
  40. SyncPublic
  41. SyncPos
  42. SyncPosBase
  43. SyncObject
  44. SyncObject1
  45. SyncPkg
  46. SyncPkgDef
  47. SyncMethod
  48. SyncType
  49. SyncTypeIdx
  50. SyncTypeParamNames
  51. SyncSignature
  52. SyncParams
  53. SyncParam
  54. SyncCodeObj
  55. SyncSym
  56. SyncLocalIdent
  57. SyncSelector
  58. // Private markers (only known to cmd/compile).
  59. SyncPrivate
  60. SyncFuncExt
  61. SyncVarExt
  62. SyncTypeExt
  63. SyncPragma
  64. SyncExprList
  65. SyncExprs
  66. SyncExpr
  67. SyncExprType
  68. SyncAssign
  69. SyncOp
  70. SyncFuncLit
  71. SyncCompLit
  72. SyncDecl
  73. SyncFuncBody
  74. SyncOpenScope
  75. SyncCloseScope
  76. SyncCloseAnotherScope
  77. SyncDeclNames
  78. SyncDeclName
  79. SyncStmts
  80. SyncBlockStmt
  81. SyncIfStmt
  82. SyncForStmt
  83. SyncSwitchStmt
  84. SyncRangeStmt
  85. SyncCaseClause
  86. SyncCommClause
  87. SyncSelectStmt
  88. SyncDecls
  89. SyncLabeledStmt
  90. SyncUseObjLocal
  91. SyncAddLocal
  92. SyncLinkname
  93. SyncStmt1
  94. SyncStmtsEnd
  95. SyncLabel
  96. SyncOptLabel
  97. )