2020-11-28 07:13:54 -05:00
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package ir
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"cmd/compile/internal/base"
|
|
|
|
|
"cmd/compile/internal/types"
|
|
|
|
|
"cmd/internal/obj"
|
|
|
|
|
"cmd/internal/src"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A Func corresponds to a single function in a Go program
|
|
|
|
|
// (and vice versa: each function is denoted by exactly one *Func).
|
|
|
|
|
//
|
|
|
|
|
// There are multiple nodes that represent a Func in the IR.
|
|
|
|
|
//
|
2020-12-01 20:51:18 -08:00
|
|
|
// The ONAME node (Func.Nname) is used for plain references to it.
|
|
|
|
|
// The ODCLFUNC node (the Func itself) is used for its declaration code.
|
|
|
|
|
// The OCLOSURE node (Func.OClosure) is used for a reference to a
|
2020-11-28 07:13:54 -05:00
|
|
|
// function literal.
|
|
|
|
|
//
|
2020-12-01 20:51:18 -08:00
|
|
|
// An imported function will have an ONAME node which points to a Func
|
|
|
|
|
// with an empty body.
|
|
|
|
|
// A declared function or method has an ODCLFUNC (the Func itself) and an ONAME.
|
2020-11-28 07:13:54 -05:00
|
|
|
// A function literal is represented directly by an OCLOSURE, but it also
|
|
|
|
|
// has an ODCLFUNC (and a matching ONAME) representing the compiled
|
|
|
|
|
// underlying form of the closure, which accesses the captured variables
|
|
|
|
|
// using a special data structure passed in a register.
|
|
|
|
|
//
|
|
|
|
|
// A method declaration is represented like functions, except f.Sym
|
|
|
|
|
// will be the qualified method name (e.g., "T.m") and
|
|
|
|
|
// f.Func.Shortname is the bare method name (e.g., "m").
|
|
|
|
|
//
|
|
|
|
|
// A method expression (T.M) is represented as an OMETHEXPR node,
|
|
|
|
|
// in which n.Left and n.Right point to the type and method, respectively.
|
|
|
|
|
// Each distinct mention of a method expression in the source code
|
|
|
|
|
// constructs a fresh node.
|
|
|
|
|
//
|
|
|
|
|
// A method value (t.M) is represented by ODOTMETH/ODOTINTER
|
|
|
|
|
// when it is called directly and by OCALLPART otherwise.
|
|
|
|
|
// These are like method expressions, except that for ODOTMETH/ODOTINTER,
|
|
|
|
|
// the method name is stored in Sym instead of Right.
|
|
|
|
|
// Each OCALLPART ends up being implemented as a new
|
|
|
|
|
// function, a bit like a closure, with its own ODCLFUNC.
|
2020-12-01 20:51:18 -08:00
|
|
|
// The OCALLPART uses n.Func to record the linkage to
|
|
|
|
|
// the generated ODCLFUNC, but there is no
|
2020-11-28 07:13:54 -05:00
|
|
|
// pointer from the Func back to the OCALLPART.
|
|
|
|
|
type Func struct {
|
2020-11-28 07:23:50 -05:00
|
|
|
miniNode
|
2020-12-23 00:02:08 -05:00
|
|
|
Body Nodes
|
|
|
|
|
Iota int64
|
2020-11-28 07:23:50 -05:00
|
|
|
|
2020-11-26 00:47:44 -05:00
|
|
|
Nname *Name // ONAME node
|
|
|
|
|
OClosure *ClosureExpr // OCLOSURE node
|
2020-11-28 07:13:54 -05:00
|
|
|
|
|
|
|
|
Shortname *types.Sym
|
|
|
|
|
|
|
|
|
|
// Extra entry code for the function. For example, allocate and initialize
|
|
|
|
|
// memory for escaping parameters.
|
|
|
|
|
Enter Nodes
|
|
|
|
|
Exit Nodes
|
2021-01-11 15:07:09 -08:00
|
|
|
|
2020-11-28 07:13:54 -05:00
|
|
|
// ONAME nodes for all params/locals for this func/closure, does NOT
|
|
|
|
|
// include closurevars until transformclosure runs.
|
2021-01-11 15:07:09 -08:00
|
|
|
// Names must be listed PPARAMs, PPARAMOUTs, then PAUTOs,
|
|
|
|
|
// with PPARAMs and PPARAMOUTs in order corresponding to the function signature.
|
|
|
|
|
// However, as anonymous or blank PPARAMs are not actually declared,
|
|
|
|
|
// they are omitted from Dcl.
|
|
|
|
|
// Anonymous and blank PPARAMOUTs are declared as ~rNN and ~bNN Names, respectively.
|
2020-11-28 07:31:18 -05:00
|
|
|
Dcl []*Name
|
2020-11-28 07:13:54 -05:00
|
|
|
|
2021-01-01 01:46:55 -08:00
|
|
|
// ClosureVars lists the free variables that are used within a
|
|
|
|
|
// function literal, but formally declared in an enclosing
|
|
|
|
|
// function. The variables in this slice are the closure function's
|
|
|
|
|
// own copy of the variables, which are used within its function
|
|
|
|
|
// body. They will also each have IsClosureVar set, and will have
|
|
|
|
|
// Byval set if they're captured by value.
|
|
|
|
|
ClosureVars []*Name
|
|
|
|
|
|
2021-01-12 12:00:58 -08:00
|
|
|
// Enclosed functions that need to be compiled.
|
|
|
|
|
// Populated during walk.
|
|
|
|
|
Closures []*Func
|
|
|
|
|
|
2020-11-28 07:13:54 -05:00
|
|
|
// Parents records the parent scope of each scope within a
|
|
|
|
|
// function. The root scope (0) has no parent, so the i'th
|
|
|
|
|
// scope's parent is stored at Parents[i-1].
|
|
|
|
|
Parents []ScopeID
|
|
|
|
|
|
|
|
|
|
// Marks records scope boundary changes.
|
|
|
|
|
Marks []Mark
|
|
|
|
|
|
2020-12-28 19:14:39 -08:00
|
|
|
FieldTrack map[*obj.LSym]struct{}
|
2020-11-28 07:13:54 -05:00
|
|
|
DebugInfo interface{}
|
|
|
|
|
LSym *obj.LSym
|
|
|
|
|
|
|
|
|
|
Inl *Inline
|
|
|
|
|
|
2020-11-28 07:31:18 -05:00
|
|
|
// Closgen tracks how many closures have been generated within
|
|
|
|
|
// this function. Used by closurename for creating unique
|
|
|
|
|
// function names.
|
|
|
|
|
Closgen int32
|
|
|
|
|
|
2020-11-28 07:13:54 -05:00
|
|
|
Label int32 // largest auto-generated label in this function
|
|
|
|
|
|
|
|
|
|
Endlineno src.XPos
|
|
|
|
|
WBPos src.XPos // position of first write barrier; see SetWBPos
|
|
|
|
|
|
|
|
|
|
Pragma PragmaFlag // go:xxx function annotations
|
|
|
|
|
|
|
|
|
|
flags bitset16
|
2020-11-28 07:31:18 -05:00
|
|
|
NumDefers int32 // number of defer calls in the function
|
|
|
|
|
NumReturns int32 // number of explicit returns in the function
|
2020-11-28 07:13:54 -05:00
|
|
|
|
|
|
|
|
// nwbrCalls records the LSyms of functions called by this
|
|
|
|
|
// function for go:nowritebarrierrec analysis. Only filled in
|
|
|
|
|
// if nowritebarrierrecCheck != nil.
|
|
|
|
|
NWBRCalls *[]SymAndPos
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-28 07:23:50 -05:00
|
|
|
func NewFunc(pos src.XPos) *Func {
|
|
|
|
|
f := new(Func)
|
|
|
|
|
f.pos = pos
|
|
|
|
|
f.op = ODCLFUNC
|
2020-12-23 00:02:08 -05:00
|
|
|
f.Iota = -1
|
2020-11-28 07:23:50 -05:00
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 11:37:54 -05:00
|
|
|
func (f *Func) isStmt() {}
|
|
|
|
|
|
2020-12-29 19:46:31 -08:00
|
|
|
func (n *Func) copy() Node { panic(n.no("copy")) }
|
|
|
|
|
func (n *Func) doChildren(do func(Node) bool) bool { return doNodes(n.Body, do) }
|
|
|
|
|
func (n *Func) editChildren(edit func(Node) Node) { editNodes(n.Body, edit) }
|
2020-12-29 15:36:48 -08:00
|
|
|
|
2020-12-29 03:08:23 -08:00
|
|
|
func (f *Func) Type() *types.Type { return f.Nname.Type() }
|
2020-12-28 19:14:39 -08:00
|
|
|
func (f *Func) Sym() *types.Sym { return f.Nname.Sym() }
|
|
|
|
|
func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
|
2020-11-28 07:23:50 -05:00
|
|
|
|
2020-11-28 07:13:54 -05:00
|
|
|
// An Inline holds fields used for function bodies that can be inlined.
|
|
|
|
|
type Inline struct {
|
|
|
|
|
Cost int32 // heuristic cost of inlining this function
|
|
|
|
|
|
|
|
|
|
// Copies of Func.Dcl and Nbody for use during inlining.
|
2020-11-28 07:31:18 -05:00
|
|
|
Dcl []*Name
|
2020-11-28 07:13:54 -05:00
|
|
|
Body []Node
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A Mark represents a scope boundary.
|
|
|
|
|
type Mark struct {
|
|
|
|
|
// Pos is the position of the token that marks the scope
|
|
|
|
|
// change.
|
|
|
|
|
Pos src.XPos
|
|
|
|
|
|
|
|
|
|
// Scope identifies the innermost scope to the right of Pos.
|
|
|
|
|
Scope ScopeID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A ScopeID represents a lexical scope within a function.
|
|
|
|
|
type ScopeID int32
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
funcDupok = 1 << iota // duplicate definitions ok
|
|
|
|
|
funcWrapper // is method wrapper
|
|
|
|
|
funcNeedctxt // function uses context register (has closure variables)
|
|
|
|
|
funcReflectMethod // function calls reflect.Type.Method or MethodByName
|
|
|
|
|
// true if closure inside a function; false if a simple function or a
|
|
|
|
|
// closure in a global variable initialization
|
|
|
|
|
funcIsHiddenClosure
|
|
|
|
|
funcHasDefer // contains a defer statement
|
|
|
|
|
funcNilCheckDisabled // disable nil checks when compiling this function
|
|
|
|
|
funcInlinabilityChecked // inliner has already determined whether the function is inlinable
|
|
|
|
|
funcExportInline // include inline body in export data
|
|
|
|
|
funcInstrumentBody // add race/msan instrumentation during SSA construction
|
|
|
|
|
funcOpenCodedDeferDisallowed // can't do open-coded defers
|
2020-11-28 07:31:18 -05:00
|
|
|
funcClosureCalled // closure is only immediately called
|
2020-11-28 07:13:54 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SymAndPos struct {
|
|
|
|
|
Sym *obj.LSym // LSym of callee
|
|
|
|
|
Pos src.XPos // line of call
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (f *Func) Dupok() bool { return f.flags&funcDupok != 0 }
|
|
|
|
|
func (f *Func) Wrapper() bool { return f.flags&funcWrapper != 0 }
|
|
|
|
|
func (f *Func) Needctxt() bool { return f.flags&funcNeedctxt != 0 }
|
|
|
|
|
func (f *Func) ReflectMethod() bool { return f.flags&funcReflectMethod != 0 }
|
|
|
|
|
func (f *Func) IsHiddenClosure() bool { return f.flags&funcIsHiddenClosure != 0 }
|
|
|
|
|
func (f *Func) HasDefer() bool { return f.flags&funcHasDefer != 0 }
|
|
|
|
|
func (f *Func) NilCheckDisabled() bool { return f.flags&funcNilCheckDisabled != 0 }
|
|
|
|
|
func (f *Func) InlinabilityChecked() bool { return f.flags&funcInlinabilityChecked != 0 }
|
|
|
|
|
func (f *Func) ExportInline() bool { return f.flags&funcExportInline != 0 }
|
|
|
|
|
func (f *Func) InstrumentBody() bool { return f.flags&funcInstrumentBody != 0 }
|
|
|
|
|
func (f *Func) OpenCodedDeferDisallowed() bool { return f.flags&funcOpenCodedDeferDisallowed != 0 }
|
2020-11-28 07:31:18 -05:00
|
|
|
func (f *Func) ClosureCalled() bool { return f.flags&funcClosureCalled != 0 }
|
2020-11-28 07:13:54 -05:00
|
|
|
|
|
|
|
|
func (f *Func) SetDupok(b bool) { f.flags.set(funcDupok, b) }
|
|
|
|
|
func (f *Func) SetWrapper(b bool) { f.flags.set(funcWrapper, b) }
|
|
|
|
|
func (f *Func) SetNeedctxt(b bool) { f.flags.set(funcNeedctxt, b) }
|
|
|
|
|
func (f *Func) SetReflectMethod(b bool) { f.flags.set(funcReflectMethod, b) }
|
|
|
|
|
func (f *Func) SetIsHiddenClosure(b bool) { f.flags.set(funcIsHiddenClosure, b) }
|
|
|
|
|
func (f *Func) SetHasDefer(b bool) { f.flags.set(funcHasDefer, b) }
|
|
|
|
|
func (f *Func) SetNilCheckDisabled(b bool) { f.flags.set(funcNilCheckDisabled, b) }
|
|
|
|
|
func (f *Func) SetInlinabilityChecked(b bool) { f.flags.set(funcInlinabilityChecked, b) }
|
|
|
|
|
func (f *Func) SetExportInline(b bool) { f.flags.set(funcExportInline, b) }
|
|
|
|
|
func (f *Func) SetInstrumentBody(b bool) { f.flags.set(funcInstrumentBody, b) }
|
|
|
|
|
func (f *Func) SetOpenCodedDeferDisallowed(b bool) { f.flags.set(funcOpenCodedDeferDisallowed, b) }
|
2020-11-28 07:31:18 -05:00
|
|
|
func (f *Func) SetClosureCalled(b bool) { f.flags.set(funcClosureCalled, b) }
|
2020-11-28 07:13:54 -05:00
|
|
|
|
|
|
|
|
func (f *Func) SetWBPos(pos src.XPos) {
|
|
|
|
|
if base.Debug.WB != 0 {
|
|
|
|
|
base.WarnfAt(pos, "write barrier")
|
|
|
|
|
}
|
|
|
|
|
if !f.WBPos.IsKnown() {
|
|
|
|
|
f.WBPos = pos
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// funcname returns the name (without the package) of the function n.
|
2020-12-26 21:43:30 -08:00
|
|
|
func FuncName(f *Func) string {
|
2020-12-21 15:10:26 -05:00
|
|
|
if f == nil || f.Nname == nil {
|
2020-11-28 07:13:54 -05:00
|
|
|
return "<nil>"
|
|
|
|
|
}
|
2020-12-26 21:43:30 -08:00
|
|
|
return f.Sym().Name
|
2020-11-28 07:13:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pkgFuncName returns the name of the function referenced by n, with package prepended.
|
|
|
|
|
// This differs from the compiler's internal convention where local functions lack a package
|
|
|
|
|
// because the ultimate consumer of this is a human looking at an IDE; package is only empty
|
|
|
|
|
// if the compilation package is actually the empty string.
|
2020-12-26 21:43:30 -08:00
|
|
|
func PkgFuncName(f *Func) string {
|
|
|
|
|
if f == nil || f.Nname == nil {
|
2020-11-28 07:13:54 -05:00
|
|
|
return "<nil>"
|
|
|
|
|
}
|
2020-12-26 21:43:30 -08:00
|
|
|
s := f.Sym()
|
2020-11-28 07:13:54 -05:00
|
|
|
pkg := s.Pkg
|
|
|
|
|
|
|
|
|
|
p := base.Ctxt.Pkgpath
|
|
|
|
|
if pkg != nil && pkg.Path != "" {
|
|
|
|
|
p = pkg.Path
|
|
|
|
|
}
|
|
|
|
|
if p == "" {
|
|
|
|
|
return s.Name
|
|
|
|
|
}
|
|
|
|
|
return p + "." + s.Name
|
|
|
|
|
}
|
[dev.regabi] cmd/compile: move helpers into package ir [generated]
[git-generate]
cd src/cmd/compile/internal/gc
sed -i '' 's/TestBuiltin.*/& t.Skip("mkbuiltin needs fixing")/' builtin_test.go
gofmt -w builtin_test.go
rf '
# Inline a few little-used constructors to avoid bringing them.
ex {
import "cmd/compile/internal/base"
import "cmd/compile/internal/ir"
import "cmd/compile/internal/types"
import "cmd/internal/src"
var typ *types.Type
var sym *types.Sym
var str string
symfield(sym, typ) -> ir.NewField(base.Pos, sym, nil, typ)
anonfield(typ) -> ir.NewField(base.Pos, nil, nil, typ)
namedfield(str, typ) -> ir.NewField(base.Pos, lookup(str), nil, typ)
var cp *ir.CallPartExpr
callpartMethod(cp) -> cp.Method
var n ir.Node
callpartMethod(n) -> n.(*ir.CallPartExpr).Method
var ns []ir.Node
liststmt(ns) -> ir.NewBlockStmt(src.NoXPos, ns)
}
rm symfield anonfield namedfield liststmt callpartMethod
mv maxStackVarSize MaxStackVarSize
mv maxImplicitStackVarSize MaxImplicitStackVarSize
mv smallArrayBytes MaxSmallArraySize
mv MaxStackVarSize cfg.go
mv nodbool NewBool
mv nodintconst NewInt
mv nodstr NewString
mv NewBool NewInt NewString const.go
mv Mpprec ConstPrec
mv bigFloatVal BigFloat
mv doesoverflow ConstOverflow
mv isGoConst IsConstNode
mv smallintconst IsSmallIntConst
mv isZero IsZero
mv islvalue IsAssignable
mv staticValue StaticValue
mv samesafeexpr SameSafeExpr
mv checkPtr ShouldCheckPtr
mv isReflectHeaderDataField IsReflectHeaderDataField
mv paramNnames ParamNames
mv methodSym MethodSym
mv methodSymSuffix MethodSymSuffix
mv methodExprFunc MethodExprFunc
mv methodExprName MethodExprName
mv IsZero IsAssignable StaticValue staticValue1 reassigned \
IsIntrinsicCall \
SameSafeExpr ShouldCheckPtr IsReflectHeaderDataField \
ParamNames MethodSym MethodSymSuffix \
MethodExprName MethodExprFunc \
expr.go
mv Curfn CurFunc
mv funcsymname FuncSymName
mv newFuncNameAt NewFuncNameAt
mv setNodeNameFunc MarkFunc
mv CurFunc FuncSymName NewFuncNameAt MarkFunc func.go
mv isParamStackCopy IsParamStackCopy
mv isParamHeapCopy IsParamHeapCopy
mv nodfp RegFP
mv IsParamStackCopy IsParamHeapCopy RegFP name.go
mv hasUniquePos HasUniquePos
mv setlineno SetPos
mv initExpr InitExpr
mv hasNamedResults HasNamedResults
mv outervalue OuterValue
mv HasNamedResults HasUniquePos SetPos InitExpr OuterValue EscNever node.go
mv visitBottomUp VisitFuncsBottomUp # scc.go
mv cfg.go \
NewBool NewInt NewString \ # parts of const.go
ConstPrec BigFloat ConstOverflow IsConstNode IsSmallIntConst \
expr.go func.go name.go node.go scc.go \
cmd/compile/internal/ir
'
Change-Id: I13402c5a2cedbf78d993a1eae2940718f23ac166
Reviewed-on: https://go-review.googlesource.com/c/go/+/279421
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-23 00:38:15 -05:00
|
|
|
|
|
|
|
|
var CurFunc *Func
|
|
|
|
|
|
|
|
|
|
func FuncSymName(s *types.Sym) string {
|
|
|
|
|
return s.Name + "·f"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MarkFunc marks a node as a function.
|
|
|
|
|
func MarkFunc(n *Name) {
|
2021-01-03 20:14:00 -08:00
|
|
|
if n.Op() != ONAME || n.Class != Pxxx {
|
[dev.regabi] cmd/compile: move helpers into package ir [generated]
[git-generate]
cd src/cmd/compile/internal/gc
sed -i '' 's/TestBuiltin.*/& t.Skip("mkbuiltin needs fixing")/' builtin_test.go
gofmt -w builtin_test.go
rf '
# Inline a few little-used constructors to avoid bringing them.
ex {
import "cmd/compile/internal/base"
import "cmd/compile/internal/ir"
import "cmd/compile/internal/types"
import "cmd/internal/src"
var typ *types.Type
var sym *types.Sym
var str string
symfield(sym, typ) -> ir.NewField(base.Pos, sym, nil, typ)
anonfield(typ) -> ir.NewField(base.Pos, nil, nil, typ)
namedfield(str, typ) -> ir.NewField(base.Pos, lookup(str), nil, typ)
var cp *ir.CallPartExpr
callpartMethod(cp) -> cp.Method
var n ir.Node
callpartMethod(n) -> n.(*ir.CallPartExpr).Method
var ns []ir.Node
liststmt(ns) -> ir.NewBlockStmt(src.NoXPos, ns)
}
rm symfield anonfield namedfield liststmt callpartMethod
mv maxStackVarSize MaxStackVarSize
mv maxImplicitStackVarSize MaxImplicitStackVarSize
mv smallArrayBytes MaxSmallArraySize
mv MaxStackVarSize cfg.go
mv nodbool NewBool
mv nodintconst NewInt
mv nodstr NewString
mv NewBool NewInt NewString const.go
mv Mpprec ConstPrec
mv bigFloatVal BigFloat
mv doesoverflow ConstOverflow
mv isGoConst IsConstNode
mv smallintconst IsSmallIntConst
mv isZero IsZero
mv islvalue IsAssignable
mv staticValue StaticValue
mv samesafeexpr SameSafeExpr
mv checkPtr ShouldCheckPtr
mv isReflectHeaderDataField IsReflectHeaderDataField
mv paramNnames ParamNames
mv methodSym MethodSym
mv methodSymSuffix MethodSymSuffix
mv methodExprFunc MethodExprFunc
mv methodExprName MethodExprName
mv IsZero IsAssignable StaticValue staticValue1 reassigned \
IsIntrinsicCall \
SameSafeExpr ShouldCheckPtr IsReflectHeaderDataField \
ParamNames MethodSym MethodSymSuffix \
MethodExprName MethodExprFunc \
expr.go
mv Curfn CurFunc
mv funcsymname FuncSymName
mv newFuncNameAt NewFuncNameAt
mv setNodeNameFunc MarkFunc
mv CurFunc FuncSymName NewFuncNameAt MarkFunc func.go
mv isParamStackCopy IsParamStackCopy
mv isParamHeapCopy IsParamHeapCopy
mv nodfp RegFP
mv IsParamStackCopy IsParamHeapCopy RegFP name.go
mv hasUniquePos HasUniquePos
mv setlineno SetPos
mv initExpr InitExpr
mv hasNamedResults HasNamedResults
mv outervalue OuterValue
mv HasNamedResults HasUniquePos SetPos InitExpr OuterValue EscNever node.go
mv visitBottomUp VisitFuncsBottomUp # scc.go
mv cfg.go \
NewBool NewInt NewString \ # parts of const.go
ConstPrec BigFloat ConstOverflow IsConstNode IsSmallIntConst \
expr.go func.go name.go node.go scc.go \
cmd/compile/internal/ir
'
Change-Id: I13402c5a2cedbf78d993a1eae2940718f23ac166
Reviewed-on: https://go-review.googlesource.com/c/go/+/279421
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-23 00:38:15 -05:00
|
|
|
base.Fatalf("expected ONAME/Pxxx node, got %v", n)
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 20:14:00 -08:00
|
|
|
n.Class = PFUNC
|
[dev.regabi] cmd/compile: move helpers into package ir [generated]
[git-generate]
cd src/cmd/compile/internal/gc
sed -i '' 's/TestBuiltin.*/& t.Skip("mkbuiltin needs fixing")/' builtin_test.go
gofmt -w builtin_test.go
rf '
# Inline a few little-used constructors to avoid bringing them.
ex {
import "cmd/compile/internal/base"
import "cmd/compile/internal/ir"
import "cmd/compile/internal/types"
import "cmd/internal/src"
var typ *types.Type
var sym *types.Sym
var str string
symfield(sym, typ) -> ir.NewField(base.Pos, sym, nil, typ)
anonfield(typ) -> ir.NewField(base.Pos, nil, nil, typ)
namedfield(str, typ) -> ir.NewField(base.Pos, lookup(str), nil, typ)
var cp *ir.CallPartExpr
callpartMethod(cp) -> cp.Method
var n ir.Node
callpartMethod(n) -> n.(*ir.CallPartExpr).Method
var ns []ir.Node
liststmt(ns) -> ir.NewBlockStmt(src.NoXPos, ns)
}
rm symfield anonfield namedfield liststmt callpartMethod
mv maxStackVarSize MaxStackVarSize
mv maxImplicitStackVarSize MaxImplicitStackVarSize
mv smallArrayBytes MaxSmallArraySize
mv MaxStackVarSize cfg.go
mv nodbool NewBool
mv nodintconst NewInt
mv nodstr NewString
mv NewBool NewInt NewString const.go
mv Mpprec ConstPrec
mv bigFloatVal BigFloat
mv doesoverflow ConstOverflow
mv isGoConst IsConstNode
mv smallintconst IsSmallIntConst
mv isZero IsZero
mv islvalue IsAssignable
mv staticValue StaticValue
mv samesafeexpr SameSafeExpr
mv checkPtr ShouldCheckPtr
mv isReflectHeaderDataField IsReflectHeaderDataField
mv paramNnames ParamNames
mv methodSym MethodSym
mv methodSymSuffix MethodSymSuffix
mv methodExprFunc MethodExprFunc
mv methodExprName MethodExprName
mv IsZero IsAssignable StaticValue staticValue1 reassigned \
IsIntrinsicCall \
SameSafeExpr ShouldCheckPtr IsReflectHeaderDataField \
ParamNames MethodSym MethodSymSuffix \
MethodExprName MethodExprFunc \
expr.go
mv Curfn CurFunc
mv funcsymname FuncSymName
mv newFuncNameAt NewFuncNameAt
mv setNodeNameFunc MarkFunc
mv CurFunc FuncSymName NewFuncNameAt MarkFunc func.go
mv isParamStackCopy IsParamStackCopy
mv isParamHeapCopy IsParamHeapCopy
mv nodfp RegFP
mv IsParamStackCopy IsParamHeapCopy RegFP name.go
mv hasUniquePos HasUniquePos
mv setlineno SetPos
mv initExpr InitExpr
mv hasNamedResults HasNamedResults
mv outervalue OuterValue
mv HasNamedResults HasUniquePos SetPos InitExpr OuterValue EscNever node.go
mv visitBottomUp VisitFuncsBottomUp # scc.go
mv cfg.go \
NewBool NewInt NewString \ # parts of const.go
ConstPrec BigFloat ConstOverflow IsConstNode IsSmallIntConst \
expr.go func.go name.go node.go scc.go \
cmd/compile/internal/ir
'
Change-Id: I13402c5a2cedbf78d993a1eae2940718f23ac166
Reviewed-on: https://go-review.googlesource.com/c/go/+/279421
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-23 00:38:15 -05:00
|
|
|
n.Sym().SetFunc(true)
|
|
|
|
|
}
|
2020-12-23 01:05:16 -05:00
|
|
|
|
|
|
|
|
// ClosureDebugRuntimeCheck applies boilerplate checks for debug flags
|
|
|
|
|
// and compiling runtime
|
|
|
|
|
func ClosureDebugRuntimeCheck(clo *ClosureExpr) {
|
|
|
|
|
if base.Debug.Closure > 0 {
|
|
|
|
|
if clo.Esc() == EscHeap {
|
|
|
|
|
base.WarnfAt(clo.Pos(), "heap closure, captured vars = %v", clo.Func.ClosureVars)
|
|
|
|
|
} else {
|
|
|
|
|
base.WarnfAt(clo.Pos(), "stack closure, captured vars = %v", clo.Func.ClosureVars)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if base.Flag.CompilingRuntime && clo.Esc() == EscHeap {
|
|
|
|
|
base.ErrorfAt(clo.Pos(), "heap-allocated closure, not allowed in runtime")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsTrivialClosure reports whether closure clo has an
|
|
|
|
|
// empty list of captured vars.
|
|
|
|
|
func IsTrivialClosure(clo *ClosureExpr) bool {
|
|
|
|
|
return len(clo.Func.ClosureVars) == 0
|
|
|
|
|
}
|