CodeVetter · Repo Unpack · Data flow
golang/go
End-to-end: user args → cmd/go/main → toolchain.Select (may re-exec a downloaded toolchain) → load.Package resolution via go.mod/go.work → modload computes the build list with MVS, fetching modules through modfetch (GOPROXY → zip → sumdb/go.sum verify → modcache) or vcs direct → work.Builder builds an action DAG (compile/cgo/cover/vet/link actions) keyed by sha256 action IDs against the build cache → cmd/compile turns source through noder/typecheck/inline/escape/walk into SSA and object files → cmd/link consumes objects+importcfg and emits the binary. At runtime, compiled binaries start in runtime.main which enables GC and runs init tasks before main.main.
- Package loading produces load.Package structs; PackagePublic fields are declared part of the go command's public API for 'go list -json' and must stay in sync with list.go.
- Module graph resolution: modload.Init loads go.mod/go.work, LoadPackages resolves import patterns to modules; the toolchain module itself is special-cased (ErrToolchain on Download).
- Module fetch path: Fetcher.Download → downloadCache.Do (dedup) → download → checkMod verifies against go.sum and the checksum database → unzip into GOMODCACHE; a TooNewError is raised if the module's go directive exceeds the local toolchain.
- Non-proxy resolution goes through cmd/go/internal/vcs: vcsList = [hg, git, svn, fossil], each a Cmd describing binary name, schemes, root-detection; IsSecure gates insecure schemes (https/git+ssh/svn+ssh/ssh allowed; GIT_ALLOW_PROTOCOL overrides for git).
- Build action graph: Builder.Do assigns DFS post-order priorities, each action's cache key is buildActionID hashing inputs/flags/toolchain IDs; cache hits short-circuit compile steps; cgo, cover, vet, link are distinct action types.
- Compiler pipeline in gc.Main: noder.LoadPackage (parse+typecheck via types2 machinery) → bloop markings → interleaved.DevirtualizeAndInlinePackage (with optional PGO profile) → loopvar capture fixes → pkginit.MakeTask → escape.Funcs → rewriteresults/slice transforms → enqueueFunc→compileFunctions→SSA backend → dumpobj writes the object file.
- The SSA backend pass list is a static ordered table `passes` in ssacompile/compile.go run by ssa.Compile; phases are checked for ordering violations and support per-pass debug flags via -d=ssa/...
- Link flow: Builder.link writes an importcfg (writeLinkImportcfg), invokes cmd/link which loads goobj objects via cmd/internal/goobj, performs deadcode elimination/address layout, and stamps a buildid; external link mode delegates to extld.
- Runtime startup data flow: runtime.main (on g0/m0) → doInit(runtime_inittasks) → gcenable() → doInit over each moduledata's inittasks (linker-computed init graph) → close(mainInitDoneChan) → main_main() i.e. user's main.
- Goroutine lifecycle: newproc/newproc1 creates a g, runqput places it on a P run queue or runnext, wakep may unpark an M; schedule→findRunnable→execute→gogo runs it; timers and netpoll feed the same queues.
- GC cycle data flow: sweep termination STW → concurrent mark with write barrier shading and mutator assists → distributed termination detection (gcMarkDone) → mark termination STW → concurrent sweep; heap goal driven by GOGC.
- go test data flow: runTest → builderTest constructs buildAction/runAction/printAction triples; a generated testmain binary runs and its output is piped through test2json for -json reporting.
- Telemetry data flow: counters are written to a counter file opened at startup (skipped for 'go telemetry off'); MaybeParent spawns the upload sidecar; CountFlags records flag usage patterns.
- API check data flow: cmd/api tests walk each stdlib package's exported API via go/ast and compare against golden lines in api/go1*.txt + api/next, with per-feature proposal issue annotations required since go1.19.