base

package standard library
go1.17 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const EnableTrace = false

To enable tracing support (-t flag), set EnableTrace to true.

Variables

View Source
var AutogeneratedPos src.XPos
View Source
var Ctxt *obj.Link
View Source
var DebugSSA func(phase, flag string, val int, valString string) string

DebugSSA is called to set a -d ssa/... option. If nil, those options are reported as invalid options. If DebugSSA returns a non-empty string, that text is reported as a compiler error.

View Source
var NoInstrumentPkgs = []string{
	"runtime/internal/atomic",
	"runtime/internal/sys",
	"runtime/internal/math",
	"runtime",
	"runtime/race",
	"runtime/msan",
	"internal/cpu",
}

Do not instrument the following packages at all, at best instrumentation would cause infinite recursion.

View Source
var NoRacePkgs = []string{"sync", "sync/atomic"}

Don't insert racefuncenter/racefuncexit into the following packages. Memory accesses in the packages are either uninteresting or will cause false positives.

View Source
var Pos src.XPos

Pos is the current source position being processed, printed by Errorf, ErrorfLang, Fatalf, and Warnf.

Functions

func AtExit

func AtExit(f func())

func Compiling

func Compiling(pkgs []string) bool

func ErrorExit

func ErrorExit()

ErrorExit handles an error-status exit. It flushes any pending errors, removes the output file, and exits.

func Errorf

func Errorf(format string, args ...interface{})

Errorf reports a formatted error at the current line.

func ErrorfAt

func ErrorfAt(pos src.XPos, format string, args ...interface{})

ErrorfAt reports a formatted error message at pos.

func ErrorfVers

func ErrorfVers(lang string, format string, args ...interface{})

ErrorfVers reports that a language feature (format, args) requires a later version of Go.

func Errors

func Errors() int

Errors returns the number of errors reported.

func Exit

func Exit(code int)

func ExitIfErrors

func ExitIfErrors()

ExitIfErrors calls ErrorExit if any errors have been reported.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf reports a fatal error - an internal problem - at the current line and exits. If other errors have already been printed, then Fatalf just quietly exits. (The internal problem may have been caused by incomplete information after the already-reported errors, so best to let users fix those and try again without being bothered about a spurious internal error.)

But if no errors have been printed, or if -d panic has been specified, Fatalf prints the error as an "internal compiler error". In a released build, it prints an error asking to file a bug report. In development builds, it prints a stack trace.

If -h has been specified, Fatalf panics to force the usual runtime info dump.

func FatalfAt

func FatalfAt(pos src.XPos, format string, args ...interface{})

FatalfAt reports a fatal error - an internal problem - at pos and exits. If other errors have already been printed, then FatalfAt just quietly exits. (The internal problem may have been caused by incomplete information after the already-reported errors, so best to let users fix those and try again without being bothered about a spurious internal error.)

But if no errors have been printed, or if -d panic has been specified, FatalfAt prints the error as an "internal compiler error". In a released build, it prints an error asking to file a bug report. In development builds, it prints a stack trace.

If -h has been specified, FatalfAt panics to force the usual runtime info dump.

func FlushErrors

func FlushErrors()

FlushErrors sorts errors seen so far by line number, prints them to stdout, and empties the errors array.

func FmtPos

func FmtPos(pos src.XPos) string

FmtPos formats pos as a file:line string.

func Linkname

func Linkname(name string, abi obj.ABI) *obj.LSym

Linkname returns the linker symbol for the given name as it might appear within a //go:linkname directive.

func ParseFlags

func ParseFlags()

ParseFlags parses the command-line flags into Flag.

func PkgLinksym

func PkgLinksym(prefix, name string, abi obj.ABI) *obj.LSym

PkgLinksym returns the linker symbol for name within the given package prefix. For user packages, prefix should be the package path encoded with objabi.PathToPrefix.

func SyntaxErrors

func SyntaxErrors() int

SyntaxErrors returns the number of syntax errors reported

func UpdateErrorDot

func UpdateErrorDot(line string, name, expr string)

UpdateErrorDot is a clumsy hack that rewrites the last error, if it was "LINE: undefined: NAME", to be "LINE: undefined: NAME in EXPR". It is used to give better error messages for dot (selector) expressions.

func Warn

func Warn(format string, args ...interface{})

Warnf reports a formatted warning at the current line. In general the Go compiler does NOT generate warnings, so this should be used only when the user has opted in to additional output by setting a particular flag.

func WarnfAt

func WarnfAt(pos src.XPos, format string, args ...interface{})

WarnfAt reports a formatted warning at pos. In general the Go compiler does NOT generate warnings, so this should be used only when the user has opted in to additional output by setting a particular flag.

Types

type CmdFlags

type CmdFlags struct {
	// Single letters
	B CountFlag    "help:\"disable bounds checking\""
	C CountFlag    "help:\"disable printing of columns in error messages\""
	D string       "help:\"set relative `path` for local imports\""
	E CountFlag    "help:\"debug symbol export\""
	G CountFlag    "help:\"accept generic code\""
	I func(string) "help:\"add `directory` to import search path\""
	K CountFlag    "help:\"debug missing line numbers\""
	L CountFlag    "help:\"show full file names in error messages\""
	N CountFlag    "help:\"disable optimizations\""
	S CountFlag    "help:\"print assembly listing\""
	// V is added by objabi.AddVersionFlag
	W CountFlag "help:\"debug parse tree after type checking\""

	LowerC int          "help:\"concurrency during compilation (1 means no concurrency)\""
	LowerD func(string) "help:\"enable debugging settings; try -d help\""
	LowerE CountFlag    "help:\"no limit on number of errors reported\""
	LowerH CountFlag    "help:\"halt on error\""
	LowerJ CountFlag    "help:\"debug runtime-initialized variables\""
	LowerL CountFlag    "help:\"disable inlining\""
	LowerM CountFlag    "help:\"print optimization decisions\""
	LowerO string       "help:\"write output to `file`\""
	LowerP *string      "help:\"set expected package import `path`\"" // &Ctxt.Pkgpath, set below
	LowerR CountFlag    "help:\"debug generated wrappers\""
	LowerT bool         "help:\"enable tracing for debugging the compiler\""
	LowerW CountFlag    "help:\"debug type checking\""
	LowerV *bool        "help:\"increase debug verbosity\""

	// Special characters
	Percent          int  "flag:\"%\" help:\"debug non-static initializers\""
	CompilingRuntime bool "flag:\"+\" help:\"compiling runtime\""

	// Longer names
	AsmHdr             string       "help:\"write assembly header to `file`\""
	Bench              string       "help:\"append benchmark times to `file`\""
	BlockProfile       string       "help:\"write block profile to `file`\""
	BuildID            string       "help:\"record `id` as the build id in the export metadata\""
	CPUProfile         string       "help:\"write cpu profile to `file`\""
	Complete           bool         "help:\"compiling complete package (no C or assembly)\""
	ClobberDead        bool         "help:\"clobber dead stack slots (for debugging)\""
	ClobberDeadReg     bool         "help:\"clobber dead registers (for debugging)\""
	Dwarf              bool         "help:\"generate DWARF symbols\""
	DwarfBASEntries    *bool        "help:\"use base address selection entries in DWARF\""                        // &Ctxt.UseBASEntries, set below
	DwarfLocationLists *bool        "help:\"add location lists to DWARF in optimized mode\""                      // &Ctxt.Flag_locationlists, set below
	Dynlink            *bool        "help:\"support references to Go symbols defined in other shared libraries\"" // &Ctxt.Flag_dynlink, set below
	EmbedCfg           func(string) "help:\"read go:embed configuration from `file`\""
	GenDwarfInl        int          "help:\"generate DWARF inline info records\"" // 0=disabled, 1=funcs, 2=funcs+formals/locals
	GoVersion          string       "help:\"required version of the runtime\""
	ImportCfg          func(string) "help:\"read import configuration from `file`\""
	ImportMap          func(string) "help:\"add `definition` of the form source=actual to import map\""
	InstallSuffix      string       "help:\"set pkg directory `suffix`\""
	JSON               string       "help:\"version,file for JSON compiler/optimizer detail output\""
	Lang               string       "help:\"Go language version source code expects\""
	LinkObj            string       "help:\"write linker-specific object to `file`\""
	LinkShared         *bool        "help:\"generate code that will be linked against Go shared libraries\"" // &Ctxt.Flag_linkshared, set below
	Live               CountFlag    "help:\"debug liveness analysis\""
	MSan               bool         "help:\"build code compatible with C/C++ memory sanitizer\""
	MemProfile         string       "help:\"write memory profile to `file`\""
	MemProfileRate     int64        "help:\"set runtime.MemProfileRate to `rate`\""
	MutexProfile       string       "help:\"write mutex profile to `file`\""
	NoLocalImports     bool         "help:\"reject local (relative) imports\""
	Pack               bool         "help:\"write to file.a instead of file.o\""
	Race               bool         "help:\"enable race detector\""
	Shared             *bool        "help:\"generate code that can be linked into a shared library\"" // &Ctxt.Flag_shared, set below
	SmallFrames        bool         "help:\"reduce the size limit for stack allocated objects\""      // small stacks, to diagnose GC latency; see golang.org/issue/27732
	Spectre            string       "help:\"enable spectre mitigations in `list` (all, index, ret)\""
	Std                bool         "help:\"compiling standard library\""
	SymABIs            string       "help:\"read symbol ABIs from `file`\""
	TraceProfile       string       "help:\"write an execution trace to `file`\""
	TrimPath           string       "help:\"remove `prefix` from recorded source file paths\""
	WB                 bool         "help:\"enable write barrier\"" // TODO: remove

	// Configuration derived from flags; not a flag itself.
	Cfg struct {
		Embed struct {
			Patterns map[string][]string
			Files    map[string]string
		}
		ImportDirs   []string          // appended to by -I
		ImportMap    map[string]string // set by -importmap OR -importcfg
		PackageFile  map[string]string // set by -importcfg; nil means not in use
		SpectreIndex bool              // set by -spectre=index or -spectre=all
		// Whether we are adding any sort of code instrumentation, such as
		// when the race detector is enabled.
		Instrumenting bool
	}
}

CmdFlags defines the command-line flags (see var Flag). Each struct field is a different flag, by default named for the lower-case of the field name. If the flag name is a single letter, the default flag name is left upper-case. If the flag name is "Lower" followed by a single letter, the default flag name is the lower-case of the last letter.

If this default flag name can't be made right, the `flag` struct tag can be used to replace it, but this should be done only in exceptional circumstances: it helps everyone if the flag name is obvious from the field name when the flag is used elsewhere in the compiler sources. The `flag:"-"` struct tag makes a field invisible to the flag logic and should also be used sparingly.

Each field must have a `help` struct tag giving the flag help message.

The allowed field types are bool, int, string, pointers to those (for values stored elsewhere), CountFlag (for a counting flag), and func(string) (for a flag that uses special code for parsing).

var Flag CmdFlags

Flag holds the parsed command-line flags. See ParseFlag for non-zero defaults.

type CountFlag

type CountFlag int

A CountFlag is a counting integer flag. It accepts -name=value to set the value directly, but it also accepts -name with no =value to increment the count.

type DebugFlags

type DebugFlags struct {
	Append               int    `help:"print information about append compilation"`
	Checkptr             int    `help:"instrument unsafe pointer conversions"`
	Closure              int    `help:"print information about closure compilation"`
	DclStack             int    `help:"run internal dclstack check"`
	Defer                int    `help:"print information about defer compilation"`
	DisableNil           int    `help:"disable nil checks"`
	DumpPtrs             int    `help:"show Node pointers values in dump output"`
	DwarfInl             int    `help:"print information about DWARF inlined function creation"`
	Export               int    `help:"print export data"`
	GCProg               int    `help:"print dump of GC programs"`
	InlFuncsWithClosures int    `help:"allow functions with closures to be inlined"`
	Libfuzzer            int    `help:"enable coverage instrumentation for libfuzzer"`
	LocationLists        int    `help:"print information about DWARF location list creation"`
	Nil                  int    `help:"print information about nil checks"`
	NoOpenDefer          int    `help:"disable open-coded defers"`
	PCTab                string `help:"print named pc-value table"`
	Panic                int    `help:"show all compiler panics"`
	Slice                int    `help:"print information about slice compilation"`
	SoftFloat            int    `help:"force compiler to emit soft-float code"`
	TypeAssert           int    `help:"print information about type assertion inlining"`
	TypecheckInl         int    `help:"eager typechecking of inline function bodies"`
	WB                   int    `help:"print information about write barriers"`
	ABIWrap              int    `help:"print information about ABI wrapper generation"`
	// contains filtered or unexported fields
}

DebugFlags defines the debugging configuration values (see var Debug). Each struct field is a different value, named for the lower-case of the field name. Each field must be an int or string and must have a `help` struct tag.

The -d option takes a comma-separated list of settings. Each setting is name=value; for ints, name is short for name=1.

var Debug DebugFlags

Debug holds the parsed debugging configuration values.

func (*DebugFlags) Any

func (d *DebugFlags) Any() bool

Any reports whether any of the debug flags have been set.

type Timings

type Timings struct {
	// contains filtered or unexported fields
}

Timings collects the execution times of labeled phases which are added trough a sequence of Start/Stop calls. Events may be associated with each phase via AddEvent.

var Timer Timings

func (*Timings) AddEvent

func (t *Timings) AddEvent(size int64, unit string)

AddEvent associates an event, i.e., a count, or an amount of data, with the most recently started or stopped phase; or the very first phase if Start or Stop hasn't been called yet. The unit specifies the unit of measurement (e.g., MB, lines, no. of funcs, etc.).

func (*Timings) Start

func (t *Timings) Start(labels ...string)

Start marks the beginning of a new phase and implicitly stops the previous phase. The phase name is the colon-separated concatenation of the labels.

func (*Timings) Stop

func (t *Timings) Stop(labels ...string)

Stop marks the end of a phase and implicitly starts a new phase. The labels are added to the labels of the ended phase.

func (*Timings) Write

func (t *Timings) Write(w io.Writer, prefix string)

Write prints the phase times to w. The prefix is printed at the start of each line.

Jump to

Keyboard shortcuts

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