Documentation
¶
Overview ¶
Package fix rewrites Go packages to use opaque version of the Go protocol buffer API.
Index ¶
Constants ¶
const ( // None means that no transforms to the code are applied. Useful for // gathering statistics about unmodified code. None = Level("none") // Green fixes are considered safe to submit without human review. Those // fixes preserve the behavior of the program. Green = Level("green") // Yellow fixes are safe to submit except for programs that depend on // unspecified behavior, internal details, code that goes against the // good coding style or guidelines, etc. // Yellow fixes should be reviewed. Yellow = Level("yellow") // Red fixes can change behavior of the program. Red fixes are proposed // when we can't prove that the fix is safe or when the fix results in // code that we don't consider readable. // Red fixes should go through extensive review and analysis. Red = Level("red") )
const ( // Unknown means the reason not nown or ambiguous Unknown unsafeReason = iota // PointerAlias means the rewrite removes pointer aliasing PointerAlias // SliceAlias means the rewrite removes slice aliasing SliceAlias // InexpressibleAPIUsage means the rewrite changes the behavior because // the original behavior cannot be expressed in the opaque API (this // usually leads to build failures). InexpressibleAPIUsage // PotentialBuildBreakage means the rewrite might induce a build breakage. PotentialBuildBreakage // EvalOrderChange means the evaluation order changes by the rewrite // (e.g. multi-assignments are rewritten into multiple single // assignments). EvalOrderChange // IncompleteRewrite means the rewrite is incomplete and further manual // changes are needed. In most cases a comment is left in the code. IncompleteRewrite // OneofFieldAccess means a oneof field is directly accessed in the // hybrid/open API. This cannot be expressed in the opaque API. OneofFieldAccess // ShallowCopy means the rewrite contains a shallow copy (before and // after) but shallow copies are unsafe in the opaque API. ShallowCopy // MaybeOneofChange means the rewrite produces code that might unset an // oneof field that was previously set to an invalid state (type set // but value not set). MaybeOneofChange // MaybeSemanticChange means the rewrite might produce invalid code // because identifier refer to different objects than before. MaybeSemanticChange // MaybeNilPointerDeref means the rewrite might produce code that leads // to nil pointer references that were not in the code before. MaybeNilPointerDeref )
Variables ¶
This section is empty.
Functions ¶
func NewSrc ¶
NewSrc creates a test Go package for test examples.
Tests can access:
a fake version of the proto package, "proto" a fake generated profile package, "pb" a fake proto2 object, "m2" a fake proto3 object, "m3"
Note that there's only one instance of "m2" and "m3". We may need more instances when the analysis is smart enough to do different rewrites for operations on two different objects than on a single one. Currently, for example:
m2.S = m2.S
is not recognized as having the same object on both sides. Hence we consider it as losing aliasing and clear semantics when rewritten as:
m2.SetS(m2.GetS())
newSrc doesn't introduce new access patterns recognized by the migration tool so that tests can rely on all returned accesses coming from code added in those tests.
Types ¶
type BuilderUseType ¶
type BuilderUseType int
BuilderUseType categorizes when builders instead of setters are used to rewrite struct literal initialization.
const ( // BuildersNowhere means never use builders BuildersNowhere BuilderUseType = 0 // BuildersEverywhere means always use builders BuildersEverywhere BuilderUseType = 1 // BuildersTestsOnly means use builders only in tests BuildersTestsOnly BuilderUseType = 2 // BuildersEverywhereExceptPromising means always use builders, except for // .go files that touch promising protos (many fleet-wide unmarshals). BuildersEverywhereExceptPromising BuilderUseType = 3 )
type ConfiguredPackage ¶
type ConfiguredPackage struct { Loader loader.Loader Pkg *loader.Package TypesToUpdate map[string]bool BuilderTypes map[string]bool BuilderLocations *ignore.List Levels []Level ProcessedFiles *syncset.Set ShowWork bool Testonly bool UseBuilders BuilderUseType }
ConfiguredPackage contains a package and all configuration necessary to rewrite the package.
func (*ConfiguredPackage) Fix ¶
func (cpkg *ConfiguredPackage) Fix() (Result, error)
Fix fixes a Go package.
type FixedFile ¶
type FixedFile struct { // Path to the file Path string OriginalCode string // Code before applying fixes. Code string // Code after applying fixes. Modified bool // Whether the file was modified by this tool. Generated bool // Whether the file is a generated file. Stats []*spb.Entry // List of proto accesses in Code (i.e. after applying rewrites). Drifted bool // Whether the file has drifted between CBT and HEAD. RedFixes map[unsafeReason]int // Number of fixes per unsafe category. }
FixedFile represents a single file after applying fixes.