1
0
mirror of https://github.com/golang/go synced 2024-10-01 13:18:33 -06:00
go/ssa/testdata/objlookup.go

161 lines
4.0 KiB
Go
Raw Normal View History

go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
//+build ignore
package main
// This file is the input to TestObjValueLookup in source_test.go,
// which ensures that each occurrence of an ident defining or
// referring to a func, var or const object can be mapped to its
// corresponding SSA Value.
//
// For every reference to a var object, we use annotations in comments
// to denote both the expected SSA Value kind, and whether to expect
// its value (x) or its address (&x).
//
// For const and func objects, the results don't vary by reference and
// are always values not addresses, so no annotations are needed. The
// declaration is enough.
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
import "fmt"
import "os"
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
type J int
func (*J) method() {}
const globalConst = 0
var globalVar int // &globalVar::Global
func globalFunc() {}
type I interface {
interfaceMethod()
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
type S struct {
x int // x::nil
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
func main() {
print(globalVar) // globalVar::UnOp
globalVar = 1 // globalVar::Const
var v0 int = 1 // v0::Const (simple local value spec)
if v0 > 0 { // v0::Const
v0 = 2 // v0::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
print(v0) // v0::Phi
// v1 is captured and thus implicitly address-taken.
var v1 int = 1 // v1::Const
v1 = 2 // v1::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
fmt.Println(v1) // v1::UnOp (load)
f := func(param int) { // f::MakeClosure param::Parameter
if y := 1; y > 0 { // y::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
print(v1, param) // v1::UnOp (load) param::Parameter
}
param = 2 // param::Const
println(param) // param::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
f(0) // f::MakeClosure
var v2 int // v2::Const (implicitly zero-initialized local value spec)
print(v2) // v2::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
m := make(map[string]int) // m::MakeMap
// Local value spec with multi-valued RHS:
var v3, v4 = m[""] // v3::Extract v4::Extract m::MakeMap
print(v3) // v3::Extract
print(v4) // v4::Extract
v3++ // v3::BinOp (assign with op)
v3 += 2 // v3::BinOp (assign with op)
v5, v6 := false, "" // v5::Const v6::Const (defining assignment)
print(v5) // v5::Const
print(v6) // v6::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
var v7 S // &v7::Alloc
v7.x = 1 // &v7::Alloc x::Const
print(v7.x) // v7::UnOp x::Field
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
var v8 [1]int // &v8::Alloc
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
v8[0] = 0 // &v8::Alloc
print(v8[:]) // &v8::Alloc
_ = v8[0] // v8::UnOp (load from Alloc)
_ = v8[:][0] // &v8::Alloc
v8ptr := &v8 // v8ptr::Alloc &v8::Alloc
_ = v8ptr[0] // v8ptr::Alloc
_ = *v8ptr // v8ptr::Alloc
v8a := make([]int, 1) // v8a::MakeSlice
v8a[0] = 0 // v8a::MakeSlice
print(v8a[:]) // v8a::MakeSlice
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
v9 := S{} // &v9::Alloc
v10 := &v9 // v10::Alloc &v9::Alloc
_ = v10 // v10::Alloc
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
var v11 *J = nil // v11::Const
v11.method() // v11::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
var v12 J // &v12::Alloc
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
v12.method() // &v12::Alloc (implicitly address-taken)
// NB, in the following, 'method' resolves to the *types.Func
// of (*J).method, so it doesn't help us locate the specific
// ssa.Values here: a bound-method closure and a promotion
// wrapper.
_ = v11.method // v11::Const
_ = (*struct{ J }).method
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
// These vars are optimised away.
if false {
v13 := 0 // v13::nil
println(v13) // v13::nil
}
switch x := 1; x { // x::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
case v0: // v0::Phi
}
for k, v := range m { // k::Extract v::Extract m::MakeMap
_ = k // k::Extract
v++ // v::BinOp
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
if y := 0; y > 1 { // y::Const y::Const
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
var i interface{} // i::Const (nil interface)
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
i = 1 // i::MakeInterface
switch i := i.(type) { // i::MakeInterface i::MakeInterface
case int:
println(i) // i::Extract
}
ch := make(chan int) // ch::MakeChan
select {
case x := <-ch: // x::UnOp (receive) ch::MakeChan
_ = x // x::UnOp
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}
// .Op is an inter-package FieldVal-selection.
var err os.PathError // &err::Alloc
_ = err.Op // err::UnOp Op::Field
_ = &err.Op // &err::Alloc &Op::FieldAddr
// Exercise corner-cases of lvalues vs rvalues.
// (Guessing IsAddr from the 'pointerness' won't cut it here.)
type N *N
var n N // n::Const
n1 := n // n1::Const n::Const
n2 := &n1 // n2::Alloc &n1::Alloc
n3 := *n2 // n3::UnOp n2::Alloc
n4 := **n3 // n4::UnOp n3::UnOp
_ = n4 // n4::UnOp
go.tools/ssa: add debug information for all ast.Idents. This CL adds three new functions to determine the SSA Value for a given syntactic var, func or const object: Program.{Const,Func,Var}Value. Since constants and functions are immutable, the first two only need a types.Object; but each distinct reference to a var may return a distinct Value, so the third requires an ast.Ident parameter too. Debug information for local vars is encoded in the instruction stream in the form of DebugRef instructions, which are a no-op but relate their operand to a particular ident in the AST. The beauty of this approach is that it naturally stays consistent during optimisation passes (e.g. lifting) without additional bookkeeping. DebugRef instructions are only generated if the DebugMode builder flag is set; I plan to make the policy more fine- grained (per function). DebugRef instructions are inserted for: - expr(Ident) for rvalue idents - address.store() for idents that update an lvalue - address.address() for idents that take address of lvalue (this new method replaces all uses of lval.(address).addr) - expr() for all constant expressions - local ValueSpecs with implicit zero initialization (no RHS) (this case doesn't call store() or address()) To ensure we don't forget to emit debug info for uses of Idents, we must use the lvalue mechanism consistently. (Previously, many simple cases had effectively inlined these functions.) Similarly setCallFunc no longer inlines expr(Ident). Also: - Program.Value() has been inlined & specialized. - Program.Package() has moved nearer the new lookup functions. - refactoring: funcSyntax has lost paramFields, resultFields; gained funcType, which provides access to both. - add package-level constants to Package.values map. - opt: don't call localValueSpec for constants. (The resulting code is always optimised away.) There are a number of comments asking whether Literals should have positions. Will address in a follow-up. Added tests of all interesting cases. R=gri CC=golang-dev https://golang.org/cl/11259044
2013-07-15 11:56:46 -06:00
}