-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vta: extends VTA graph construction to handle collections
Collections include channels, slices, ranges, maps, and their related SSA statements. Statements involving functions and function calls will be addressed in a future CL. Change-Id: I552cbf3ee9d65e125270db69d1fc3c3f6491b121 Reviewed-on: https://go-review.googlesource.com/c/tools/+/322951 Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Zvonimir Pavlinovic <zpavlinovic@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
- Loading branch information
1 parent
126df1d
commit 234f954
Showing
7 changed files
with
325 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// go:build ignore | ||
|
||
package testdata | ||
|
||
func foo(c chan interface{}, j int) { | ||
c <- j + 1 | ||
} | ||
|
||
func Baz(i int) { | ||
c := make(chan interface{}) | ||
go foo(c, i) | ||
x := <-c | ||
print(x) | ||
} | ||
|
||
// Relevant SSA: | ||
// func foo(c chan interface{}, j int): | ||
// t0 = j + 1:int | ||
// t1 = make interface{} <- int (t0) | ||
// send c <- t1 // t1 -> chan {}interface | ||
// return | ||
// | ||
// func Baz(i int): | ||
// t0 = make chan interface{} 0:int | ||
// go foo(t0, i) | ||
// t1 = <-t0 // chan {}interface -> t1 | ||
// t2 = print(t1) | ||
// return | ||
|
||
// WANT: | ||
// Channel(chan interface{}) -> Local(t1) | ||
// Local(t1) -> Channel(chan interface{}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// go:build ignore | ||
|
||
package testdata | ||
|
||
type I interface { | ||
Foo() string | ||
} | ||
|
||
type J interface { | ||
Foo() string | ||
Bar() | ||
} | ||
|
||
type B struct { | ||
p string | ||
} | ||
|
||
func (b B) Foo() string { return b.p } | ||
func (b B) Bar() {} | ||
|
||
func Baz(m map[I]I, b1, b2 B, n map[string]*J) *J { | ||
m[b1] = b2 | ||
|
||
return n[b1.Foo()] | ||
} | ||
|
||
// Relevant SSA: | ||
// func Baz(m map[I]I, b1 B, b2 B, n map[string]*J) *J: | ||
// t0 = local B (b1) | ||
// *t0 = b1 | ||
// t1 = local B (b2) | ||
// *t1 = b2 | ||
// t2 = *t0 | ||
// t3 = make I <- B (t2) | ||
// t4 = *t1 | ||
// t5 = make I <- B (t4) | ||
// m[t3] = t5 | ||
// t6 = *t0 | ||
// t7 = (B).Foo(t6) | ||
// t8 = n[t7] | ||
// return t8 | ||
|
||
// WANT: | ||
// Local(t4) -> Local(t5) | ||
// Local(t5) -> MapValue(testdata.I) | ||
// Local(t3) -> MapKey(testdata.I) | ||
// Local(t8) -> MapValue(*testdata.J) | ||
// MapValue(*testdata.J) -> Local(t8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// go:build ignore | ||
|
||
package testdata | ||
|
||
type I interface { | ||
Foo() string | ||
} | ||
|
||
type B struct { | ||
p string | ||
} | ||
|
||
func (b B) Foo() string { return b.p } | ||
|
||
func Baz(m map[I]*I) { | ||
for i, v := range m { | ||
*v = B{p: i.Foo()} | ||
} | ||
} | ||
|
||
// Relevant SSA: | ||
// func Baz(m map[I]*I): | ||
// 0: | ||
// t0 = range m | ||
// jump 1 | ||
// 1: | ||
// t1 = next t0 | ||
// t2 = extract t1 #0 | ||
// if t2 goto 2 else 3 | ||
// 2: | ||
// t3 = extract t1 #1 | ||
// t4 = extract t1 #2 | ||
// t5 = local B (complit) | ||
// t6 = &t5.p [#0] | ||
// t7 = invoke t3.Foo() | ||
// *t6 = t7 | ||
// t8 = *t5 | ||
// t9 = make I <- B (t8) | ||
// *t4 = t9 | ||
// jump 1 | ||
// 3: | ||
// return | ||
|
||
// WANT: | ||
// MapKey(testdata.I) -> Local(t1[1]) | ||
// Local(t1[1]) -> Local(t3) | ||
// MapValue(*testdata.I) -> Local(t1[2]) | ||
// Local(t1[2]) -> Local(t4), MapValue(*testdata.I) | ||
// Local(t8) -> Local(t9) | ||
// Local(t9) -> Local(t4) | ||
// Local(t4) -> Local(t1[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// go:build ignore | ||
|
||
package testdata | ||
|
||
type I interface { | ||
Foo() string | ||
} | ||
|
||
type J interface { | ||
I | ||
} | ||
|
||
type B struct { | ||
p string | ||
} | ||
|
||
func (b B) Foo() string { return b.p } | ||
|
||
func Baz(b1, b2 B, c1 chan I, c2 chan J) { | ||
for { | ||
select { | ||
case c1 <- b1: | ||
print("b1") | ||
case c2 <- b2: | ||
print("b2") | ||
case <-c1: | ||
print("c1") | ||
case k := <-c2: | ||
print(k.Foo()) | ||
return | ||
} | ||
} | ||
} | ||
|
||
// Relevant SSA: | ||
// func Baz(b1 B, b2 B, c1 chan I, c2 chan J): | ||
// ... | ||
// t2 = *t0 | ||
// t3 = make I <- B (t2) | ||
// t4 = *t1 | ||
// t5 = make J <- B (t4) | ||
// t6 = select blocking [c1<-t3, c2<-t5, <-c1, <-c2] (index int, ok bool, I, J) | ||
// t7 = extract t6 #0 | ||
// t8 = t7 == 0:int | ||
// if t8 goto 2 else 3 | ||
// ... | ||
// 8: | ||
// t15 = extract t6 #3 | ||
// t16 = invoke t15.Foo() | ||
// t17 = print(t18) | ||
|
||
// WANT: | ||
// Local(t3) -> Channel(chan testdata.I) | ||
// Local(t5) -> Channel(chan testdata.J) | ||
// Channel(chan testdata.I) -> Local(t6[2]) | ||
// Channel(chan testdata.J) -> Local(t6[3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters