Source file src/internal/pkgbits/version.go
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 5 package pkgbits 6 7 // Version indicates a version of a unified IR bitstream. 8 // Each Version indicates the addition, removal, or change of 9 // new data in the bitstream. 10 // 11 // These are serialized to disk and the interpretation remains fixed. 12 type Version uint32 13 14 const ( 15 // V0: initial prototype. 16 // 17 // All data that is not assigned a Field is in version V0 18 // and has not been deprecated. 19 V0 Version = iota 20 21 // V1: adds the Flags uint32 word 22 V1 23 24 // V2: removes unused legacy fields and supports type parameters for aliases. 25 // - remove the legacy "has init" bool from the public root 26 // - remove obj's "derived func instance" bool 27 // - add a TypeParamNames field to ObjAlias 28 // - remove derived info "needed" bool 29 V2 30 31 // V3: introduces a more compact format for composite literal element lists 32 // - negative lengths indicate that (some) elements may have keys 33 // - positive lengths indicate that no element has a key 34 // - a negative struct field index indicates an embedded field 35 V3 36 37 numVersions = iota 38 ) 39 40 // Field denotes a unit of data in the serialized unified IR bitstream. 41 // It is conceptually a like field in a structure. 42 // 43 // We only really need Fields when the data may or may not be present 44 // in a stream based on the Version of the bitstream. 45 // 46 // Unlike much of pkgbits, Fields are not serialized and 47 // can change values as needed. 48 type Field int 49 50 const ( 51 // Flags in a uint32 in the header of a bitstream 52 // that is used to indicate whether optional features are enabled. 53 Flags Field = iota 54 55 // Deprecated: HasInit was a bool indicating whether a package 56 // has any init functions. 57 HasInit 58 59 // Deprecated: DerivedFuncInstance was a bool indicating 60 // whether an object was a function instance. 61 DerivedFuncInstance 62 63 // ObjAlias has a list of TypeParamNames. 64 AliasTypeParamNames 65 66 // Deprecated: DerivedInfoNeeded was a bool indicating 67 // whether a type was a derived type. 68 DerivedInfoNeeded 69 70 // Composite literals use a more compact format for element lists. 71 CompactCompLiterals 72 73 numFields = iota 74 ) 75 76 // introduced is the version a field was added. 77 var introduced = [numFields]Version{ 78 Flags: V1, 79 AliasTypeParamNames: V2, 80 CompactCompLiterals: V3, 81 } 82 83 // removed is the version a field was removed in or 0 for fields 84 // that have not yet been deprecated. 85 // (So removed[f]-1 is the last version it is included in.) 86 var removed = [numFields]Version{ 87 HasInit: V2, 88 DerivedFuncInstance: V2, 89 DerivedInfoNeeded: V2, 90 } 91 92 // Has reports whether field f is present in a bitstream at version v. 93 func (v Version) Has(f Field) bool { 94 return introduced[f] <= v && (v < removed[f] || removed[f] == V0) 95 } 96