version.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2024 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. // Version indicates a version of a unified IR bitstream.
  6. // Each Version indicates the addition, removal, or change of
  7. // new data in the bitstream.
  8. //
  9. // These are serialized to disk and the interpretation remains fixed.
  10. type Version uint32
  11. const (
  12. // V0: initial prototype.
  13. //
  14. // All data that is not assigned a Field is in version V0
  15. // and has not been deprecated.
  16. V0 Version = iota
  17. // V1: adds the Flags uint32 word
  18. V1
  19. // V2: removes unused legacy fields and supports type parameters for aliases.
  20. // - remove the legacy "has init" bool from the public root
  21. // - remove obj's "derived func instance" bool
  22. // - add a TypeParamNames field to ObjAlias
  23. // - remove derived info "needed" bool
  24. V2
  25. numVersions = iota
  26. )
  27. // Field denotes a unit of data in the serialized unified IR bitstream.
  28. // It is conceptually a like field in a structure.
  29. //
  30. // We only really need Fields when the data may or may not be present
  31. // in a stream based on the Version of the bitstream.
  32. //
  33. // Unlike much of pkgbits, Fields are not serialized and
  34. // can change values as needed.
  35. type Field int
  36. const (
  37. // Flags in a uint32 in the header of a bitstream
  38. // that is used to indicate whether optional features are enabled.
  39. Flags Field = iota
  40. // Deprecated: HasInit was a bool indicating whether a package
  41. // has any init functions.
  42. HasInit
  43. // Deprecated: DerivedFuncInstance was a bool indicating
  44. // whether an object was a function instance.
  45. DerivedFuncInstance
  46. // ObjAlias has a list of TypeParamNames.
  47. AliasTypeParamNames
  48. // Deprecated: DerivedInfoNeeded was a bool indicating
  49. // whether a type was a derived type.
  50. DerivedInfoNeeded
  51. numFields = iota
  52. )
  53. // introduced is the version a field was added.
  54. var introduced = [numFields]Version{
  55. Flags: V1,
  56. AliasTypeParamNames: V2,
  57. }
  58. // removed is the version a field was removed in or 0 for fields
  59. // that have not yet been deprecated.
  60. // (So removed[f]-1 is the last version it is included in.)
  61. var removed = [numFields]Version{
  62. HasInit: V2,
  63. DerivedFuncInstance: V2,
  64. DerivedInfoNeeded: V2,
  65. }
  66. // Has reports whether field f is present in a bitstream at version v.
  67. func (v Version) Has(f Field) bool {
  68. return introduced[f] <= v && (v < removed[f] || removed[f] == V0)
  69. }