Documentation ¶
Index ¶
- Constants
- Variables
- func Assert(b bool)
- func Assertf(b bool, format string, args ...interface{})
- func AssertfAt(b bool, pos src.XPos, format string, args ...interface{})
- func AtExit(f func())
- func Compiling(pkgs []string) bool
- func ErrorExit()
- func Errorf(format string, args ...interface{})
- func ErrorfAt(pos src.XPos, format string, args ...interface{})
- func ErrorfVers(lang string, format string, args ...interface{})
- func Errors() int
- func Exit(code int)
- func ExitIfErrors()
- func Fatalf(format string, args ...interface{})
- func FatalfAt(pos src.XPos, format string, args ...interface{})
- func FlushErrors()
- func FmtPos(pos src.XPos) string
- func Linkname(name string, abi obj.ABI) *obj.LSym
- func MapFile(f *os.File, offset, length int64) (string, error)
- func ParseFlags()
- func PkgLinksym(prefix, name string, abi obj.ABI) *obj.LSym
- func SyntaxErrors() int
- func UpdateErrorDot(line string, name, expr string)
- func Warn(format string, args ...interface{})
- func WarnfAt(pos src.XPos, format string, args ...interface{})
- type CmdFlags
- type CountFlag
- type DebugFlags
- type Timings
Constants ¶
const CompilerBootstrap = false
CompilerBootstrap reports whether the current compiler binary was built with -tags=compiler_bootstrap.
const EnableTrace = false
To enable tracing support (-t flag), set EnableTrace to true.
Variables ¶
var AutogeneratedPos src.XPos
var Ctxt *obj.Link
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.
var NoInstrumentPkgs = []string{
"runtime/internal/atomic",
"runtime/internal/math",
"runtime/internal/sys",
"runtime/internal/syscall",
"runtime",
"runtime/race",
"runtime/msan",
"runtime/asan",
"internal/cpu",
}
Do not instrument the following packages at all, at best instrumentation would cause infinite recursion.
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.
var Pos src.XPos
Pos is the current source position being processed, printed by Errorf, ErrorfLang, Fatalf, and Warnf.
Functions ¶
func Assert ¶ added in go1.18
func Assert(b bool)
Assert reports "assertion failed" with Fatalf, unless b is true.
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 ErrorfVers ¶
ErrorfVers reports that a language feature (format, args) requires a later version of Go.
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 ¶
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 Linkname ¶
Linkname returns the linker symbol for the given name as it might appear within a //go:linkname directive.
func MapFile ¶ added in go1.18
mapFile returns length bytes from the file starting at the specified offset as a string.
func PkgLinksym ¶
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 ¶
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.
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\"" I func(string) "help:\"add `directory` to import search path\"" K CountFlag "help:\"debug missing line numbers\"" L CountFlag "help:\"also show actual source file names in error messages for positions affected by //line directives\"" 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 flag.Value "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`\"" ASan bool "help:\"build code compatible with C/C++ address sanitizer\"" 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`\"" 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`\"" 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 int "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\"" 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 -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 `` /* 187-byte string literal not displayed */ 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"` NoRefName int `help:"do not include referenced symbol names in object file"` PCTab string `help:"print named pc-value table\nOne of: pctospadj, pctofile, pctoline, pctoinline, pctopcdata"` 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"` SyncFrames int `help:"how many writer stack frames to include at sync points in unified export data"` TypeAssert int `help:"print information about type assertion inlining"` TypecheckInl int `help:"eager typechecking of inline function bodies"` Unified int `help:"enable unified IR construction"` WB int `help:"print information about write barriers"` ABIWrap int `help:"print information about ABI wrapper generation"` MayMoreStack string `help:"call named function before all stack growth checks"` Any bool // set when any of the debug flags have been set }
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.
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 ¶
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 ¶
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.