From cc02c5be3657f1c949e316dcfbb5d418dbba15a9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 11 Jun 2014 14:04:45 -0400 Subject: [PATCH] go/ssa: s/Capture/FreeVar/g LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/109820044 --- go/pointer/doc.go | 2 +- go/pointer/gen.go | 10 +++++----- go/ssa/doc.go | 2 +- go/ssa/func.go | 2 +- go/ssa/print.go | 4 ++-- go/ssa/promote.go | 8 ++++---- go/ssa/ssa.go | 34 +++++++++++++++++----------------- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/go/pointer/doc.go b/go/pointer/doc.go index 013cc107..13441e11 100644 --- a/go/pointer/doc.go +++ b/go/pointer/doc.go @@ -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. diff --git a/go/pointer/gen.go b/go/pointer/gen.go index ee680f6b..850591fa 100644 --- a/go/pointer/gen.go +++ b/go/pointer/gen.go @@ -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. diff --git a/go/ssa/doc.go b/go/ssa/doc.go index 9cb00e38..0b5c33df 100644 --- a/go/ssa/doc.go +++ b/go/ssa/doc.go @@ -53,7 +53,6 @@ // *BinOp ✔ ✔ // *Builtin ✔ // *Call ✔ ✔ -// *Capture ✔ // *ChangeInterface ✔ ✔ // *ChangeType ✔ ✔ // *Const ✔ @@ -63,6 +62,7 @@ // *Extract ✔ ✔ // *Field ✔ ✔ // *FieldAddr ✔ ✔ +// *FreeVar ✔ // *Function ✔ ✔ (func) // *Global ✔ ✔ (var) // *Go ✔ diff --git a/go/ssa/func.go b/go/ssa/func.go index 5de5b61f..5e364da1 100644 --- a/go/ssa/func.go +++ b/go/ssa/func.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(), diff --git a/go/ssa/print.go b/go/ssa/print.go index 8797b140..19d58830 100644 --- a/go/ssa/print.go +++ b/go/ssa/print.go @@ -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 { diff --git a/go/ssa/promote.go b/go/ssa/promote.go index bf545007..fa8c755b 100644 --- a/go/ssa/promote.go +++ b/go/ssa/promote.go @@ -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 { diff --git a/go/ssa/ssa.go b/go/ssa/ssa.go index b940255b..e68650ea 100644 --- a/go/ssa/ssa.go +++ b/go/ssa/ssa.go @@ -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 }