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