Documentation ¶
Index ¶
- Constants
- Variables
- func AddImplicitDots(n *ir.SelectorExpr) *ir.SelectorExpr
- func AllImportedBodies()
- func AssignConv(n ir.Node, t *types.Type, context string) ir.Node
- func AssignExpr(n ir.Node) ir.Node
- func Assignop(src, dst *types.Type) (ir.Op, string)
- func Assignop1(src, dst *types.Type) (ir.Op, string)
- func AutoLabel(prefix string) *types.Sym
- func BaseTypeIndex(t *types.Type) int64
- func CalcMethods(t *types.Type)
- func Call(pos src.XPos, callee ir.Node, args []ir.Node, dots bool) ir.Node
- func Callee(n ir.Node) ir.Node
- func CheckFuncStack()
- func ClearInstTypeList()
- func ClosureType(clo *ir.ClosureExpr) *types.Type
- func ComputeAddrtaken(top []ir.Node)
- func Conv(n ir.Node, t *types.Type) ir.Node
- func ConvNop(n ir.Node, t *types.Type) ir.Node
- func Convertop(srcConstant bool, src, dst *types.Type) (ir.Op, string)
- func DeclFunc(sym *types.Sym, recv *ir.Field, params, results []*ir.Field) *ir.Func
- func Declare(n *ir.Name, ctxt ir.Class)
- func DeclareUniverse()
- func DefaultLit(n ir.Node, t *types.Type) ir.Node
- func EvalConst(n ir.Node) ir.Node
- func Export(n *ir.Name)
- func Expr(n ir.Node) ir.Node
- func Exprs(exprs []ir.Node)
- func FinishFuncBody()
- func FixMethodCall(call *ir.CallExpr)
- func FixVariadicCall(call *ir.CallExpr)
- func Func(fn *ir.Func)
- func GetInstTypeList() []*types.Type
- func HaveInlineBody(fn *ir.Func) bool
- func ImportBody(fn *ir.Func)
- func ImportedBody(fn *ir.Func)
- func IndexConst(n ir.Node) int64
- func InitRuntime()
- func InitUniverse()
- func InstTypeName(name string, targs []*types.Type) string
- func Instantiate(pos src.XPos, baseType *types.Type, targs []*types.Type) *types.Type
- func Lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field
- func Lookdot1(errnode ir.Node, s *types.Sym, t *types.Type, fs *types.Fields, dostrcmp int) *types.Field
- func Lookup(name string) *types.Sym
- func LookupNum(prefix string, n int) *types.Sym
- func LookupRuntime(name string) *ir.Name
- func LookupRuntimeABI(name string, abi obj.ABI) *obj.LSym
- func LookupRuntimeFunc(name string) *obj.LSym
- func LookupRuntimeVar(name string) *obj.LSym
- func MakeDictSym(gf *types.Sym, targs []*types.Type, hasBrackets bool) *types.Sym
- func MakeDotArgs(pos src.XPos, typ *types.Type, args []ir.Node) ir.Node
- func MakeFuncInstSym(gf *types.Sym, targs []*types.Type, isMethodNode, hasBrackets bool) *types.Sym
- func MethodValueType(n *ir.SelectorExpr) *types.Type
- func NeedInstType(t *types.Type)
- func NewFuncParams(tl *types.Type, mustname bool) []*ir.Field
- func NewIncompleteNamedType(pos src.XPos, sym *types.Sym) *types.Type
- func NewMethodType(sig *types.Type, recv *types.Type) *types.Type
- func NewName(s *types.Sym) *ir.Name
- func NodAddr(n ir.Node) *ir.AddrExpr
- func NodAddrAt(pos src.XPos, n ir.Node) *ir.AddrExpr
- func NodNil() ir.Node
- func OrigBool(n ir.Node, v bool) ir.Node
- func OrigConst(n ir.Node, v constant.Value) ir.Node
- func OrigInt(n ir.Node, v int64) ir.Node
- func RangeExprType(t *types.Type) *types.Type
- func ReadImports(pkg *types.Pkg, data string)
- func Resolve(n ir.Node) (res ir.Node)
- func RewriteMultiValueCall(n ir.InitNode, call ir.Node)
- func RewriteNonNameCall(n *ir.CallExpr)
- func SetBaseTypeIndex(t *types.Type, i, pi int64)
- func Shapify(t *types.Type, index int, tparam *types.Type) *types.Type
- func StartFuncBody(fn *ir.Func)
- func Stmt(n ir.Node) ir.Node
- func Stmts(stmts []ir.Node)
- func SubstArgTypes(old *ir.Name, types_ ...*types.Type) *ir.Name
- func Temp(t *types.Type) *ir.Name
- func TempAt(pos src.XPos, curfn *ir.Func, t *types.Type) *ir.Name
- func TparamExportName(prefix string, name string, index int) string
- func TparamName(exportName string) string
- func TypesOf(x []ir.Ntype) []*types.Type
- func WriteExports(out io.Writer, extensions bool)
- type Tsubster
Constants ¶
const LocalDictName = ".dict"
The name used for dictionary parameters or local variables.
Variables ¶
var DeclContext ir.Class = ir.PEXTERN // PEXTERN/PAUTO
var ( // DeclImporter maps from imported identifiers to an importer // and offset where that identifier's declaration can be read. DeclImporter = map[*types.Sym]iimporterAndOffset{} )
var DirtyAddrtaken = false
If DirtyAddrtaken is true, then there are OADDR whose corresponding arguments have not yet been marked as Addrtaken.
var IncrementalAddrtaken = false
If IncrementalAddrtaken is false, we do not compute Addrtaken for an OADDR Node when it is built. The Addrtaken bits are set in bulk by computeAddrtaken. If IncrementalAddrtaken is true, then when an OADDR Node is built the Addrtaken field of its argument is updated immediately.
var InitTodoFunc = ir.NewFunc(base.Pos)
Function collecting autotmps generated during typechecking, to be included in the package-level init function.
var (
NeedRuntimeType = func(*types.Type) {}
)
var Target *ir.Package
Target is the package being compiled.
var TypecheckAllowed bool
Functions ¶
func AddImplicitDots ¶
func AddImplicitDots(n *ir.SelectorExpr) *ir.SelectorExpr
AddImplicitDots finds missing fields in obj.field that will give the shortest unique addressing and modifies the tree with missing field names.
func AllImportedBodies ¶
func AllImportedBodies()
AllImportedBodies reads in the bodies of all imported functions and typechecks them, if needed.
func Assignop ¶
Is type src assignment compatible to type dst? If so, return op code to use in conversion. If not, return OXXX. In this case, the string return parameter may hold a reason why. In all other cases, it'll be the empty string.
func AutoLabel ¶
AutoLabel generates a new Name node for use with an automatically generated label. prefix is a short mnemonic (e.g. ".s" for switch) to help with debugging. It should begin with "." to avoid conflicts with user labels.
func BaseTypeIndex ¶
func CalcMethods ¶
CalcMethods calculates all the methods (including embedding) of a non-interface type t.
func CheckFuncStack ¶
func CheckFuncStack()
func ClearInstTypeList ¶ added in go1.18
func ClearInstTypeList()
ClearInstTypeList clears the contents of instTypeList.
func ClosureType ¶
func ClosureType(clo *ir.ClosureExpr) *types.Type
ClosureType returns the struct type used to hold all the information needed in the closure for clo (clo must be a OCLOSURE node). The address of a variable of the returned type can be cast to a func.
func ComputeAddrtaken ¶
func ConvNop ¶
ConvNop converts node n to type t using the OCONVNOP op and typechecks the result with ctxExpr.
func Convertop ¶
Can we convert a value of type src to a value of type dst? If so, return op code to use in conversion (maybe OCONVNOP). If not, return OXXX. In this case, the string return parameter may hold a reason why. In all other cases, it'll be the empty string. srcConstant indicates whether the value of type src is a constant.
func Declare ¶
Declare records that Node n declares symbol n.Sym in the specified declaration context.
func DeclareUniverse ¶
func DeclareUniverse()
DeclareUniverse makes the universe block visible within the current package.
func EvalConst ¶
EvalConst returns a constant-evaluated expression equivalent to n. If n is not a constant, EvalConst returns n. Otherwise, EvalConst returns a new OLITERAL with the same value as n, and with .Orig pointing back to n.
func FinishFuncBody ¶
func FinishFuncBody()
finish the body. called in auto-declaration context. returns in extern-declaration context.
func FixMethodCall ¶ added in go1.18
FixMethodCall rewrites a method call t.M(...) into a function call T.M(t, ...).
func FixVariadicCall ¶
FixVariadicCall rewrites calls to variadic functions to use an explicit ... argument if one is not already present.
func GetInstTypeList ¶ added in go1.18
GetInstTypeList returns the current contents of instTypeList.
func HaveInlineBody ¶ added in go1.18
HaveInlineBody reports whether we have fn's inline body available for inlining.
func ImportBody ¶
ImportBody reads in the dcls and body of an imported function (which should not yet have been read in).
func ImportedBody ¶
ImportedBody returns immediately if the inlining information for fn is populated. Otherwise, fn must be an imported function. If so, ImportedBody loads in the dcls and body for fn, and typechecks as needed.
func IndexConst ¶
IndexConst checks if Node n contains a constant expression representable as a non-negative int and returns its value. If n is not a constant expression, not representable as an integer, or negative, it returns -1. If n is too large, it returns -2.
func InitRuntime ¶
func InitRuntime()
InitRuntime loads the definitions for the low-level runtime functions, so that the compiler can generate calls to them, but does not make them visible to user code.
func InstTypeName ¶ added in go1.18
InstTypeName creates a name for an instantiated type, based on the name of the generic type and the type args.
func Instantiate ¶ added in go1.18
Instantiate creates a new named type which is the instantiation of the base named generic type, with the specified type args.
func Lookdot ¶
Lookdot looks up field or method n.Sel in the type t and returns the matching field. It transforms the op of node n to ODOTINTER or ODOTMETH, if appropriate. It also may add a StarExpr node to n.X as needed for access to non-pointer methods. If dostrcmp is 0, it matches the field/method with the exact symbol as n.Sel (appropriate for exported fields). If dostrcmp is 1, it matches by name exactly. If dostrcmp is 2, it matches names with case folding.
func Lookdot1 ¶
func Lookdot1(errnode ir.Node, s *types.Sym, t *types.Type, fs *types.Fields, dostrcmp int) *types.Field
Lookdot1 looks up the specified method s in the list fs of methods, returning the matching field or nil. If dostrcmp is 0, it matches the symbols. If dostrcmp is 1, it matches by name exactly. If dostrcmp is 2, it matches names with case folding.
func LookupRuntime ¶
func LookupRuntimeABI ¶
LookupRuntimeABI looks up a name in package runtime using the given ABI.
func LookupRuntimeFunc ¶
LookupRuntimeFunc looks up Go function name in package runtime. This function must follow the internal calling convention.
func LookupRuntimeVar ¶
LookupRuntimeVar looks up a variable (or assembly function) name in package runtime. If this is a function, it may have a special calling convention.
func MakeDictSym ¶ added in go1.18
func MakeDotArgs ¶
MakeDotArgs package all the arguments that match a ... T parameter into a []T.
func MakeFuncInstSym ¶ added in go1.18
MakeFuncInstSym makes the unique sym for a stenciled generic function or method, based on the name of the function gf and the targs. It replaces any existing bracket type list in the name. MakeInstName asserts that gf has brackets in its name if and only if hasBrackets is true.
Names of declared generic functions have no brackets originally, so hasBrackets should be false. Names of generic methods already have brackets, since the new type parameter is specified in the generic type of the receiver (e.g. func (func (v *value[T]).set(...) { ... } has the original name (*value[T]).set.
The standard naming is something like: 'genFn[int,bool]' for functions and '(*genType[int,bool]).methodName' for methods
isMethodNode specifies if the name of a method node is being generated (as opposed to a name of an instantiation of generic function or name of the shape-based function that helps implement a method of an instantiated type). For method nodes on shape types, we prepend "nofunc.", because method nodes for shape types will have no body, and we want to avoid a name conflict with the shape-based function that helps implement the same method for fully-instantiated types. Function names are also created at the end of (*Tsubster).typ1, so we append "nofunc" there as well, as needed.
func MethodValueType ¶ added in go1.18
func MethodValueType(n *ir.SelectorExpr) *types.Type
MethodValueType returns the struct type used to hold all the information needed in the closure for a OMETHVALUE node. The address of a variable of the returned type can be cast to a func.
func NeedInstType ¶ added in go1.18
NeedInstType adds a new fully-instantiated type to instTypeList.
func NewFuncParams ¶
Given funarg struct list, return list of fn args.
func NewIncompleteNamedType ¶ added in go1.18
NewIncompleteNamedType returns a TFORW type t with name specified by sym, such that t.nod and sym.Def are set correctly. If there are any RParams for the type, they should be set soon after creating the TFORW type, before creating the underlying type. That ensures that the HasTParam and HasShape flags will be set properly, in case this type is part of some mutually recursive type.
func NewMethodType ¶
f is method type, with receiver. return function type, receiver as first argument (or not).
func ReadImports ¶
func Resolve ¶
Resolve resolves an ONONAME node to a definition, if any. If n is not an ONONAME node, Resolve returns n unchanged. If n is an ONONAME node and not in the same package, then n.Sym() is resolved using import data. Otherwise, Resolve returns n.Sym().Def. An ONONAME node can be created using ir.NewIdent(), so an imported symbol can be resolved via Resolve(ir.NewIdent(src.NoXPos, sym)).
func RewriteMultiValueCall ¶ added in go1.18
RewriteMultiValueCall rewrites multi-valued f() to use temporaries, so the backend wouldn't need to worry about tuple-valued expressions.
func RewriteNonNameCall ¶ added in go1.19
RewriteNonNameCall replaces non-Name call expressions with temps, rewriting f()(...) to t0 := f(); t0(...).
func SetBaseTypeIndex ¶ added in go1.18
func Shapify ¶ added in go1.18
Shapify takes a concrete type and a type param index, and returns a GCshape type that can be used in place of the input type and still generate identical code. No methods are added - all methods calls directly on a shape should be done by converting to an interface using the dictionary.
For now, we only consider two types to have the same shape, if they have exactly the same underlying type or they are both pointer types.
tparam is the associated typeparam - it must be TTYPEPARAM type. If there is a structural type for the associated type param (not common), then a pointer type t is mapped to its underlying type, rather than being merged with other pointers.
Shape types are also distinguished by the index of the type in a type param/arg list. We need to do this so we can distinguish and substitute properly for two type params in the same function that have the same shape for a particular instantiation.
func StartFuncBody ¶
declare the function proper and declare the arguments. called in extern-declaration context returns in auto-declaration context.
func SubstArgTypes ¶
SubstArgTypes substitutes the given list of types for successive occurrences of the "any" placeholder in the type syntax expression n.Type. The result of SubstArgTypes MUST be assigned back to old, e.g.
n.Left = SubstArgTypes(n.Left, t1, t2)
func TparamExportName ¶ added in go1.18
TparamExportName creates a unique name for type param in a method or a generic type, using the specified unique prefix and the index of the type param. The index is only used if the type param is blank, in which case the blank is replace by "$<index>". A unique name is needed for later substitution in the compiler and export/import that keeps blank type params associated with the correct constraint.
func TparamName ¶ added in go1.18
TparamName returns the real name of a type parameter, after stripping its qualifying prefix and reverting blank-name encoding. See TparamExportName for details.
func WriteExports ¶
WriteExports writes the indexed export format to out. If extensions is true, then the compiler-only extensions are included.
Types ¶
type Tsubster ¶ added in go1.18
type Tsubster struct { Tparams []*types.Type Targs []*types.Type // If non-nil, the substitution map from name nodes in the generic function to the // name nodes in the new stenciled function. Vars map[*ir.Name]*ir.Name // If non-nil, function to substitute an incomplete (TFORW) type. SubstForwFunc func(*types.Type) *types.Type // Prevent endless recursion on functions. See #51832. Funcs map[*types.Type]bool }
General type substituter, for replacing typeparams with type args.
func (*Tsubster) Typ ¶ added in go1.18
Typ computes the type obtained by substituting any type parameter or shape in t that appears in subst.Tparams with the corresponding type argument in subst.Targs. If t contains no type parameters, the result is t; otherwise the result is a new type. It deals with recursive types by using TFORW types and finding partially or fully created types via sym.Def.