mirror of
https://github.com/golang/go
synced 2024-11-19 05:54:44 -07:00
c28bf6e069
CanonicalPos was inadequate since many pairs of instruction share the same pos (e.g. Allocs and Phis). Instead, we generalize the DebugRef instruction to associate not just Idents but Exprs with ssa.Values. We no longer store any DebugRefs for constant expressions, to save space. (The type and value of such expressions can be obtained by other means, at a cost in complexity.) Function.ValueForExpr queries the DebugRef info to return the ssa.Value of a given Expr. Added tests. Also: - the DebugInfo flag is now per package, not global. It must be set between Create and Build phases if desired. - {Value,Instruction}.Pos() documentation updated: we still maintain this information in the instruction stream even in non-debug mode, but we make fewer claims about its invariants. - Go and Defer instructions can now use their respective go/defer token positions (not the call's lparen), so they do. - SelectState: Posn token.Pos indicates the <- position DebugNode ast.Expr is the send stmt or receive expr. - In building SelectStmt, we introduce extra temporaries in debug mode to hold the result of the receive in 'case <-ch' even though this value isn't ordinarily needed. - Use *SelectState (indirectly) since the struct is getting bigger. - Document some missing instructions in doc.go. R=gri CC=golang-dev https://golang.org/cl/12147043
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
//+build ignore
|
|
|
|
package main
|
|
|
|
// This file is the input to TestCanonicalPos in source_test.go, which
|
|
// ensures that each expression e immediately following a /*@kind*/(x)
|
|
// annotation, when passed to Function.ValueForExpr(e), returns a
|
|
// non-nil Value of the same type as e and of kind 'kind'.
|
|
|
|
func f(param int) {
|
|
_ = /*@<nil>*/ (1 + 2) // (constant)
|
|
i := 0
|
|
/*@Call*/ (print( /*@BinOp*/ (i + 1)))
|
|
ch := /*@MakeChan*/ (make(chan int))
|
|
/*@UnOp*/ (<-ch)
|
|
x := /*@UnOp*/ (<-ch)
|
|
select {
|
|
case /*@Extract*/ (<-ch):
|
|
case x := /*@Extract*/ (<-ch):
|
|
}
|
|
defer /*@Function*/ (func() {
|
|
})()
|
|
go /*@Function*/ (func() {
|
|
})()
|
|
y := 0
|
|
if true && /*@BinOp*/ (bool(y > 0)) {
|
|
y = 1
|
|
}
|
|
_ = /*@Phi*/ (y)
|
|
map1 := /*@MakeMap*/ (make(map[string]string))
|
|
_ = /*@MakeMap*/ (map[string]string{"": ""})
|
|
_ = /*@MakeSlice*/ (make([]int, 0))
|
|
_ = /*@MakeClosure*/ (func() { print(param) })
|
|
sl := /*@Slice*/ ([]int{})
|
|
_ = /*@Alloc*/ (&struct{}{})
|
|
_ = /*@Slice*/ (sl[:0])
|
|
_ = /*@Alloc*/ (new(int))
|
|
var iface interface{}
|
|
_ = /*@TypeAssert*/ (iface.(int))
|
|
_ = /*@UnOp*/ (sl[0])
|
|
_ = /*@IndexAddr*/ (&sl[0])
|
|
_ = /*@Index*/ ([2]int{}[0])
|
|
var p *int
|
|
_ = /*@UnOp*/ (*p)
|
|
}
|