noder

package standard library
go1.27.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

README

Making Unified Intermediate Representation (UIR) Changes

For general information on export data, see here.

UIR is the serial form of the compiler's intermediate representation, used to propagate bodies of generic and/or inlined functions from one compilation unit to another.

The Go compiler has a single, canonical UIR writer implementation in src/cmd/compile/internal/noder/writer.go. When we update the byte stream that the UIR writer writes, all of the UIR readers need to be reviewed and potentially updated; a change might not be backward compatible for them. These instructions outline the steps required to keep all UIR readers up-to-date.

The Writer

The UIR version written by the compiler is controlled by src/cmd/compile/internal/noder/unified.go. Do not change this yet. Instead:

  1. Add a version flag N+1 for MyChange in internal/pkgbits/version.go.
  2. Update the UIR writer in src/cmd/compile/internal/noder/writer.go to guard the writing of any fields added in N+1. Note: readers still on version N must be oblivious to this change to avoid breaking the readers on submission.

The Readers

Besides the compiler itself, there are other readers in go, x/tools, and externally. Those in x/tools and the general public exist because go list -export produces export data files in this format and we support the ability of applications to decode it.

Note that there is an upcoming plan to decouple the compiler's IR from x/tools by changing the format encoded by go list -export; this would make UIR a private detail of the compiler, free to break at any time. For now, these instructions must still be followed.

We assume that external readers will update on their own. The necessary reader updates in go and x/tools are detailed below.

go
  1. Update the compiler's own UIR reader in src/cmd/compile/internal/noder/reader.go to guard the reading of any fields added in N+1.
  2. Repeat this change for the readers in src/go/internal/gcimporter/ureader.go and src/cmd/compile/internal/importer/ureader.go. Note that these readers only read data needed for type checking (in src/go/types and src/cmd/compile/internal/types2 respectively). For instance, they do not read exported function bodies. Thus, it's possible that a change to UIR (such as the encoding of function bodies) would require no change to these readers.
x/tools
  1. Add a version flag for MyChange in internal/pkgbits/version.go. Note: x/tools has its own pkgbits implementation, which is intended to be an exact copy of the one in go. Any change made to one must be reflected in the other.
  2. Update the x/tools UIR reader in internal/gcimporter/ureader.go to guard the reading of any fields added in N+1. Call this commit C.
  3. In go, take the commit hash for C and update src/cmd/go.mod to use x/tools@C per the vendoring instructions.

Finalizing

If this UIR change will be tested, check the following section and consider when it makes to finalize.

Only after reviewing all of the readers, bump the UIR version written by the writer to N+1 in src/cmd/compile/internal/noder/unified.go. Because the readers have already been updated to handle version N+1, this change is compatible.

Testing

If making changes related to some new feature requiring extensive testing, it's best to postpone bumping the UIR version until all of the tests are in. To commit tests incrementally, develop them with a locally-incremented UIR version and commit skipped tests; don't yet bump the remote UIR version.

Once all of the required tests are in, bump the remote UIR version while turning on all of the previously skipped tests. This minimizes churn on the UIR version as testing uncovers any discrepancies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addr

func Addr(pos src.XPos, x ir.Node) *ir.AddrExpr

func CloseHTMLWriters

func CloseHTMLWriters()

CloseHTMLWriters closes the HTML writer for fn, if one exists.

func Deref

func Deref(pos src.XPos, typ *types.Type, x ir.Node) *ir.StarExpr

func DumpNodeHTML

func DumpNodeHTML(pkg *types2.Package, file *syntax.File, info *types2.Info, fn *syntax.FuncDecl, why string, n syntax.Node)

DumpNodeHTML dumps the node n to the HTML writer for fn.

func FixValue

func FixValue(typ *types.Type, val constant.Value) constant.Value

FixValue returns val after converting and truncating it as appropriate for typ.

func LoadPackage

func LoadPackage(filenames []string)

func LookupFunc

func LookupFunc(fullName string) (*ir.Func, error)

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 MakeWrappers

func MakeWrappers(target *ir.Package)

MakeWrappers constructs all wrapper methods needed for the target compilation unit.

func MatchASTDump

func MatchASTDump(fn *syntax.FuncDecl) bool

MatchASTDump returns true if the fn matches the value of the astdump debug flag.

func PostLookupCleanup

func PostLookupCleanup()

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 Renameinit

func Renameinit() *types.Sym

func Shapify

func Shapify(targ *types.Type, basic bool) *types.Type

Shapify returns the shape type for targ.

If basic is true, then the type argument is used to instantiate a type parameter whose constraint is a basic interface.

func WriteExports

func WriteExports(out *bio.Writer)

Types

type HTMLWriter

type HTMLWriter struct {
	ir.HTMLWriterBase

	Decl *syntax.FuncDecl
	// contains filtered or unexported fields
}

An HTMLWriter dumps syntax nodes to multicolumn HTML, similar to what the ssa backend does for GOSSAFUNC.

func NewHTMLWriter

func NewHTMLWriter(pkg *types2.Package, file *syntax.File, info *types2.Info, path string, decl *syntax.FuncDecl, cfgMask string) *HTMLWriter

func (*HTMLWriter) DeclHTML

func (w *HTMLWriter) DeclHTML(phase string) func()

type ImplicitNode

type ImplicitNode interface {
	ir.Node
	SetImplicit(x bool)
}

func Implicit

func Implicit(n ImplicitNode) ImplicitNode

Implicit returns n after marking it as Implicit.

type WasmExport

type WasmExport struct {
	Pos  syntax.Pos
	Name string
}

WasmExport stores metadata associated with the //go:wasmexport pragma

type WasmImport

type WasmImport struct {
	Pos    syntax.Pos
	Module string
	Name   string
}

WasmImport stores metadata associated with the //go:wasmimport pragma

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL