go/ssa: s/Capture/FreeVar/g
LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/109820044
This commit is contained in:
parent
1edc750a9c
commit
cc02c5be36
|
@ -234,7 +234,7 @@ Functions
|
|||
the parameters and results of the function object, and are
|
||||
collectively known as its "P/R block".
|
||||
|
||||
The treatment of free variables of closures (*ssa.Capture) is like
|
||||
The treatment of free variables of closures (*ssa.FreeVar) is like
|
||||
that of global variables; it is not context-sensitive.
|
||||
*ssa.MakeClosure instructions create copy edges to Captures.
|
||||
|
||||
|
|
|
@ -802,14 +802,14 @@ func (a *analysis) genCall(caller *cgnode, instr ssa.CallInstruction) {
|
|||
// Some SSA instructions always have singletons points-to sets:
|
||||
// Alloc, Function, Global, MakeChan, MakeClosure, MakeInterface, MakeMap, MakeSlice.
|
||||
// Others may be singletons depending on their operands:
|
||||
// Capture, Const, Convert, FieldAddr, IndexAddr, Slice.
|
||||
// FreeVar, Const, Convert, FieldAddr, IndexAddr, Slice.
|
||||
//
|
||||
// Idempotent. Objects are created as needed, possibly via recursion
|
||||
// down the SSA value graph, e.g IndexAddr(FieldAddr(Alloc))).
|
||||
//
|
||||
func (a *analysis) objectNode(cgn *cgnode, v ssa.Value) nodeid {
|
||||
switch v.(type) {
|
||||
case *ssa.Global, *ssa.Function, *ssa.Const, *ssa.Capture:
|
||||
case *ssa.Global, *ssa.Function, *ssa.Const, *ssa.FreeVar:
|
||||
// Global object.
|
||||
obj, ok := a.globalobj[v]
|
||||
if !ok {
|
||||
|
@ -825,7 +825,7 @@ func (a *analysis) objectNode(cgn *cgnode, v ssa.Value) nodeid {
|
|||
case *ssa.Const:
|
||||
// not addressable
|
||||
|
||||
case *ssa.Capture:
|
||||
case *ssa.FreeVar:
|
||||
// not addressable
|
||||
}
|
||||
|
||||
|
@ -1178,9 +1178,9 @@ func (a *analysis) genFunc(cgn *cgnode) {
|
|||
|
||||
// Free variables have global cardinality:
|
||||
// the outer function sets them with MakeClosure;
|
||||
// the inner function accesses them with Capture.
|
||||
// the inner function accesses them with FreeVar.
|
||||
//
|
||||
// TODO(adonovan): treat captures context-sensitively.
|
||||
// TODO(adonovan): treat free vars context-sensitively.
|
||||
|
||||
// Create value nodes for all value instructions
|
||||
// since SSA may contain forward references.
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
// *BinOp ✔ ✔
|
||||
// *Builtin ✔
|
||||
// *Call ✔ ✔
|
||||
// *Capture ✔
|
||||
// *ChangeInterface ✔ ✔
|
||||
// *ChangeType ✔ ✔
|
||||
// *Const ✔
|
||||
|
@ -63,6 +62,7 @@
|
|||
// *Extract ✔ ✔
|
||||
// *Field ✔ ✔
|
||||
// *FieldAddr ✔ ✔
|
||||
// *FreeVar ✔
|
||||
// *Function ✔ ✔ (func)
|
||||
// *Global ✔ ✔ (var)
|
||||
// *Go ✔
|
||||
|
|
|
@ -427,7 +427,7 @@ func (f *Function) lookup(obj types.Object, escaping bool) Value {
|
|||
panic("no Value for type.Object " + obj.Name())
|
||||
}
|
||||
outer := f.parent.lookup(obj, true) // escaping
|
||||
v := &Capture{
|
||||
v := &FreeVar{
|
||||
name: obj.Name(),
|
||||
typ: outer.Type(),
|
||||
pos: outer.Pos(),
|
||||
|
|
|
@ -63,8 +63,8 @@ func (v *Parameter) String() string {
|
|||
return fmt.Sprintf("parameter %s : %s", v.Name(), v.Type())
|
||||
}
|
||||
|
||||
func (v *Capture) String() string {
|
||||
return fmt.Sprintf("capture %s : %s", v.Name(), v.Type())
|
||||
func (v *FreeVar) String() string {
|
||||
return fmt.Sprintf("freevar %s : %s", v.Name(), v.Type())
|
||||
}
|
||||
|
||||
func (v *Builtin) String() string {
|
||||
|
|
|
@ -366,17 +366,17 @@ func makeBound(prog *Program, obj *types.Func) *Function {
|
|||
pos: obj.Pos(),
|
||||
}
|
||||
|
||||
cap := &Capture{name: "recv", typ: recvType(obj), parent: fn}
|
||||
fn.FreeVars = []*Capture{cap}
|
||||
fv := &FreeVar{name: "recv", typ: recvType(obj), parent: fn}
|
||||
fn.FreeVars = []*FreeVar{fv}
|
||||
fn.startBody()
|
||||
createParams(fn, 0)
|
||||
var c Call
|
||||
|
||||
if !isInterface(recvType(obj)) { // concrete
|
||||
c.Call.Value = prog.declaredFunc(obj)
|
||||
c.Call.Args = []Value{cap}
|
||||
c.Call.Args = []Value{fv}
|
||||
} else {
|
||||
c.Call.Value = cap
|
||||
c.Call.Value = fv
|
||||
c.Call.Method = obj
|
||||
}
|
||||
for _, arg := range fn.Params {
|
||||
|
|
|
@ -103,7 +103,7 @@ type Value interface {
|
|||
// Instruction.
|
||||
//
|
||||
// This is the same as the source name for Parameters,
|
||||
// Builtins, Functions, Captures, Globals.
|
||||
// Builtins, Functions, FreeVars, Globals.
|
||||
// For constants, it is a representation of the constant's value
|
||||
// and type. For all other Values this is the name of the
|
||||
// virtual register defined by the instruction.
|
||||
|
@ -135,7 +135,7 @@ type Value interface {
|
|||
// caller may perform mutations to the object's state.
|
||||
//
|
||||
// Referrers is currently only defined if Parent()!=nil,
|
||||
// i.e. for the function-local values Capture, Parameter,
|
||||
// i.e. for the function-local values FreeVar, Parameter,
|
||||
// Functions (iff anonymous) and all value-defining instructions.
|
||||
// It returns nil for named Functions, Builtin, Const and Global.
|
||||
//
|
||||
|
@ -278,7 +278,7 @@ type Node interface {
|
|||
// the loaded values.
|
||||
//
|
||||
// A nested function (Parent()!=nil) that refers to one or more
|
||||
// lexically enclosing local variables ("free variables") has Capture
|
||||
// lexically enclosing local variables ("free variables") has FreeVar
|
||||
// parameters. Such functions cannot be called directly but require a
|
||||
// value created by MakeClosure which, via its Bindings, supplies
|
||||
// values for these parameters.
|
||||
|
@ -306,7 +306,7 @@ type Function struct {
|
|||
Pkg *Package // enclosing package; nil for shared funcs (wrappers and error.Error)
|
||||
Prog *Program // enclosing program
|
||||
Params []*Parameter // function parameters; for methods, includes receiver
|
||||
FreeVars []*Capture // free variables whose values must be supplied by closure
|
||||
FreeVars []*FreeVar // free variables whose values must be supplied by closure
|
||||
Locals []*Alloc
|
||||
Blocks []*BasicBlock // basic blocks of the function; nil => external
|
||||
Recover *BasicBlock // optional; control transfers here after recovered panic
|
||||
|
@ -356,23 +356,23 @@ type BasicBlock struct {
|
|||
|
||||
// Pure values ----------------------------------------
|
||||
|
||||
// A Capture represents a free variable of the function to which it
|
||||
// A FreeVar represents a free variable of the function to which it
|
||||
// belongs.
|
||||
//
|
||||
// Captures are used to implement anonymous functions, whose free
|
||||
// FreeVars are used to implement anonymous functions, whose free
|
||||
// variables are lexically captured in a closure formed by
|
||||
// MakeClosure. The referent of such a capture is an Alloc or another
|
||||
// Capture and is considered a potentially escaping heap address, with
|
||||
// MakeClosure. The value of such a free var is an Alloc or another
|
||||
// FreeVar and is considered a potentially escaping heap address, with
|
||||
// pointer type.
|
||||
//
|
||||
// Captures are also used to implement bound method closures. Such a
|
||||
// capture represents the receiver value and may be of any type that
|
||||
// FreeVars are also used to implement bound method closures. Such a
|
||||
// free var represents the receiver value and may be of any type that
|
||||
// has concrete methods.
|
||||
//
|
||||
// Pos() returns the position of the value that was captured, which
|
||||
// belongs to an enclosing function.
|
||||
//
|
||||
type Capture struct {
|
||||
type FreeVar struct {
|
||||
name string
|
||||
typ types.Type
|
||||
pos token.Pos
|
||||
|
@ -1388,11 +1388,11 @@ func (v *Builtin) Pos() token.Pos { return token.NoPos }
|
|||
func (v *Builtin) Object() types.Object { return v.object }
|
||||
func (v *Builtin) Parent() *Function { return nil }
|
||||
|
||||
func (v *Capture) Type() types.Type { return v.typ }
|
||||
func (v *Capture) Name() string { return v.name }
|
||||
func (v *Capture) Referrers() *[]Instruction { return &v.referrers }
|
||||
func (v *Capture) Pos() token.Pos { return v.pos }
|
||||
func (v *Capture) Parent() *Function { return v.parent }
|
||||
func (v *FreeVar) Type() types.Type { return v.typ }
|
||||
func (v *FreeVar) Name() string { return v.name }
|
||||
func (v *FreeVar) Referrers() *[]Instruction { return &v.referrers }
|
||||
func (v *FreeVar) Pos() token.Pos { return v.pos }
|
||||
func (v *FreeVar) Parent() *Function { return v.parent }
|
||||
|
||||
func (v *Global) Type() types.Type { return v.typ }
|
||||
func (v *Global) Name() string { return v.name }
|
||||
|
@ -1672,7 +1672,7 @@ func (v *UnOp) Operands(rands []*Value) []*Value {
|
|||
|
||||
// Non-Instruction Values:
|
||||
func (v *Builtin) Operands(rands []*Value) []*Value { return rands }
|
||||
func (v *Capture) Operands(rands []*Value) []*Value { return rands }
|
||||
func (v *FreeVar) Operands(rands []*Value) []*Value { return rands }
|
||||
func (v *Const) Operands(rands []*Value) []*Value { return rands }
|
||||
func (v *Function) Operands(rands []*Value) []*Value { return rands }
|
||||
func (v *Global) Operands(rands []*Value) []*Value { return rands }
|
||||
|
|
Loading…
Reference in New Issue