var localPkgReader … // LookupFunc returns the ir.Func for an arbitrary full symbol name if // that function exists in the set of available export data. // // This allows lookup of arbitrary functions and methods that aren't otherwise // referenced by the local package and thus haven't been read yet. // // TODO(prattmic): Does not handle instantiation of generic types. Currently // profiles don't contain the original type arguments, so we won't be able to // create the runtime dictionaries. // // TODO(prattmic): Hit rate of this function is usually fairly low, and errors // are only used when debug logging is enabled. Consider constructing cheaper // errors by default. func LookupFunc(fullName string) (*ir.Func, error) { … } // PostLookupCleanup performs cleanup operations needed // after a series of calls to LookupFunc, specifically invoking // readBodies to post-process any funcs on the "todoBodies" list // that were added as a result of the lookup operations. func PostLookupCleanup() { … } func lookupFunction(pkg *types.Pkg, symName string) (*ir.Func, error) { … } func lookupMethod(pkg *types.Pkg, symName string) (*ir.Func, error) { … } // unified constructs the local package's Internal Representation (IR) // from its syntax tree (AST). // // The pipeline contains 2 steps: // // 1. Generate the export data "stub". // // 2. Generate the IR from the export data above. // // The package data "stub" at step (1) contains everything from the local package, // but nothing that has been imported. When we're actually writing out export data // to the output files (see writeNewExport), we run the "linker", which: // // - Updates compiler extensions data (e.g. inlining cost, escape analysis results). // // - Handles re-exporting any transitive dependencies. // // - Prunes out any unnecessary details (e.g. non-inlineable functions, because any // downstream importers only care about inlinable functions). // // The source files are typechecked twice: once before writing the export data // using types2, and again after reading the export data using gc/typecheck. // The duplication of work will go away once we only use the types2 type checker, // removing the gc/typecheck step. For now, it is kept because: // // - It reduces the engineering costs in maintaining a fork of typecheck // (e.g. no need to backport fixes like CL 327651). // // - It makes it easier to pass toolstash -cmp. // // - Historically, we would always re-run the typechecker after importing a package, // even though we know the imported data is valid. It's not ideal, but it's // not causing any problems either. // // - gc/typecheck is still in charge of some transformations, such as rewriting // multi-valued function calls or transforming ir.OINDEX to ir.OINDEXMAP. // // Using the syntax tree with types2, which has a complete representation of generics, // the unified IR has the full typed AST needed for introspection during step (1). // In other words, we have all the necessary information to build the generic IR form // (see writer.captureVars for an example). func unified(m posMap, noders []*noder) { … } // readBodies iteratively expands all pending dictionaries and // function bodies. // // If duringInlining is true, then the inline.InlineDecls is called as // necessary on instantiations of imported generic functions, so their // inlining costs can be computed. func readBodies(target *ir.Package, duringInlining bool) { … } // writePkgStub type checks the given parsed source files, // writes an export data package stub representing them, // and returns the result. func writePkgStub(m posMap, noders []*noder) string { … } // freePackage ensures the given package is garbage collected. func freePackage(pkg *types2.Package) { … } // readPackage reads package export data from pr to populate // importpkg. // // localStub indicates whether pr is reading the stub export data for // the local package, as opposed to relocated export data for an // import. func readPackage(pr *pkgReader, importpkg *types.Pkg, localStub bool) { … } // writeUnifiedExport writes to `out` the finalized, self-contained // Unified IR export data file for the current compilation unit. func writeUnifiedExport(out io.Writer) { … }