logopt

Imports

Imports #

"cmd/internal/obj"
"cmd/internal/src"
"encoding/json"
"fmt"
"internal/buildcfg"
"io"
"log"
"net/url"
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
"unicode"

Constants & Variables

Format var #

var Format = None

Json0 const #

const Json0

None const #

const None logFormat = iota

SeverityInformation const #

SeverityInformation defined: * Reports an information.

const SeverityInformation DiagnosticSeverity = 3

dest var #

var dest string

loggedOpts var #

var loggedOpts []*LoggedOpt

mu var #

var mu = sync.Mutex{...}

Type Aliases

DiagnosticSeverity type #

DiagnosticSeverity defines constants

type DiagnosticSeverity uint

DiagnosticTag type #

DiagnosticTag defines constants

type DiagnosticTag uint

DocumentURI type #

type DocumentURI string

logFormat type #

type logFormat uint8

Structs

Diagnostic struct #

Diagnostic defined: * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects * are only valid in the scope of a resource.

type Diagnostic struct {
Range Range `json:"range"`
Severity DiagnosticSeverity `json:"severity,omitempty"`
Code string `json:"code,omitempty"`
Source string `json:"source,omitempty"`
Message string `json:"message"`
Tags []DiagnosticTag `json:"tags,omitempty"`
RelatedInformation []DiagnosticRelatedInformation `json:"relatedInformation,omitempty"`
}

DiagnosticRelatedInformation struct #

DiagnosticRelatedInformation defined: * Represents a related message and source code location for a diagnostic. This should be * used to point to code locations that cause or related to a diagnostics, e.g when duplicating * a symbol in a scope.

type DiagnosticRelatedInformation struct {
Location Location `json:"location"`
Message string `json:"message"`
}

Location struct #

A Location represents a location inside a resource, such as a line inside a text file.

type Location struct {
URI DocumentURI `json:"uri"`
Range Range `json:"range"`
}

LoggedOpt struct #

A LoggedOpt is what the compiler produces and accumulates, to be converted to JSON for human or IDE consumption.

type LoggedOpt struct {
pos src.XPos
lastPos src.XPos
compilerPass string
functionName string
what string
target []interface{}
}

Position struct #

type Position struct {
Line uint `json:"line"`
Character uint `json:"character"`
}

Range struct #

A Range in a text document expressed as (zero-based) start and end positions. A range is comparable to a selection in an editor. Therefore the end position is exclusive. If you want to specify a range that contains a line including the line ending character(s) then use an end position denoting the start of the next line.

type Range struct {
Start Position `json:"start"`
End Position `json:"end"`
}

VersionHeader struct #

type VersionHeader struct {
Version int `json:"version"`
Package string `json:"package"`
Goos string `json:"goos"`
Goarch string `json:"goarch"`
GcVersion string `json:"gc_version"`
File string `json:"file,omitempty"`
}

byPos struct #

byPos sorts diagnostics by source position.

type byPos struct {
ctxt *obj.Link
a []*LoggedOpt
}

Functions

Enabled function #

Enabled returns whether optimization logging is enabled.

func Enabled() bool

FlushLoggedOpts function #

FlushLoggedOpts flushes all the accumulated optimization log entries.

func FlushLoggedOpts(ctxt *obj.Link, slashPkgPath string)

Len method #

func (x byPos) Len() int

Less method #

func (x byPos) Less(i int, j int) bool

LogJsonOption function #

LogJsonOption parses and validates the version,directory value attached to the -json compiler flag.

func LogJsonOption(flagValue string)

LogOpt function #

LogOpt logs information about a (usually missed) optimization performed by the compiler. Pos is the source position (including inlining), what is the message, pass is which pass created the message, funcName is the name of the function.

func LogOpt(pos src.XPos, what string, pass string, funcName string, args ...interface{})

LogOptRange function #

LogOptRange is the same as LogOpt, but includes the ability to express a range of positions, not just a point.

func LogOptRange(pos src.XPos, lastPos src.XPos, what string, pass string, funcName string, args ...interface{})

NewLoggedOpt function #

NewLoggedOpt allocates a new LoggedOpt, to later be passed to either NewLoggedOpt or LogOpt as "args". Pos is the source position (including inlining), what is the message, pass is which pass created the message, funcName is the name of the function A typical use for this to accumulate an explanation for a missed optimization, for example, why did something escape?

func NewLoggedOpt(pos src.XPos, lastPos src.XPos, what string, pass string, funcName string, args ...interface{}) *LoggedOpt

Swap method #

func (x byPos) Swap(i int, j int)

appendInlinedPos function #

appendInlinedPos extracts inlining information from posTmp and append it to diagnostic.

func appendInlinedPos(posTmp []src.Pos, lastTmp []src.Pos, diagnostic *Diagnostic)

checkLogPath function #

checkLogPath does superficial early checking of the string specifying the directory to which optimizer logging is directed, and if it passes the test, stores the string in LO_dir.

func checkLogPath(destination string) string

fixSlash function #

func fixSlash(f string) string

isWindowsDriveURIPath function #

isWindowsDriveURIPath returns true if the file URI is of the format used by Windows URIs. The url.Parse package does not specially handle Windows paths (see golang/go#6027), so we check if the URI path has a drive prefix (e.g. "/C:"). (copied from tools/internal/span/uri.go) this is less comprehensive that the processing in filepath.IsAbs on Windows.

func isWindowsDriveURIPath(uri string) bool

newLocation function #

newLocation returns the Location for the compiler source location p.

func newLocation(p src.Pos, last src.Pos) Location

newRange function #

newRange returns a single-position Range for the compiler source location p.

func newRange(p src.Pos, last src.Pos) Range

parseLogFlag function #

parseLogFlag checks the flag passed to -json for version,destination format and returns the two parts.

func parseLogFlag(flag string, value string) (version int, directory string)

parseLogPath function #

func parseLogPath(destination string) (string, string)

parsePos function #

parsePos expands a src.XPos into a slice of src.Pos, with the outermost first. It returns the slice, and the outermost.

func parsePos(ctxt *obj.Link, pos src.XPos, posTmp []src.Pos) ([]src.Pos, src.Pos)

uprootedPath function #

Return filename, replacing a first occurrence of $GOROOT with the actual value of the GOROOT (because LSP does not speak "$GOROOT").

func uprootedPath(filename string) string

uriIfy function #

func uriIfy(f string) DocumentURI

writerForLSP function #

func writerForLSP(subdirpath string, file string) io.WriteCloser

Generated with Arrow