diff options
| author | Dan Scales <danscales@google.com> | 2021-06-01 10:49:14 -0700 |
|---|---|---|
| committer | Dan Scales <danscales@google.com> | 2021-06-04 17:48:10 +0000 |
| commit | de614651561c6d5bfe1e68bddaf0dedab9a0ecb0 (patch) | |
| tree | a39ef75b81e36091467f1e09765ed4022475c1d0 /test/typeparam | |
| parent | 4cf7f5f6947c1e3200d669ae7b8016f7431d718c (diff) | |
| download | go-de614651561c6d5bfe1e68bddaf0dedab9a0ecb0.tar.xz | |
[dev.typeparams] cmd/compile: allow inlining in instantiated functions
Change markType to scan generic types and methods, so that inlineable
functions inside generic functions/methods will be properly marked for
export, which means inlining inside instantiated functions will work
correctly.
Also, fix handling of closures for instantiated functions. Some code
needs to be adjusted, since instantiated functions/methods are compiled
as if in the package of the source generic function/type, rather than in
the local package. When we create the closure struct, we want to make
sure that the .F field has the same package as the other fields for the
closure variables. Also, we need to disable a check in tcCompLit() when
being done for an instantiated function, since fields of the closure
struct will be from the source package, not the local package.
Re-enabled part of the orderedmapsimp test that was disabled because of
these issues.
Change-Id: Ic4dba8917da0a36b17c0bdb69d6d6edfdf14104a
Reviewed-on: https://go-review.googlesource.com/c/go/+/324331
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/typeparam')
| -rw-r--r-- | test/typeparam/orderedmapsimp.dir/a.go | 38 | ||||
| -rw-r--r-- | test/typeparam/orderedmapsimp.dir/main.go | 33 |
2 files changed, 34 insertions, 37 deletions
diff --git a/test/typeparam/orderedmapsimp.dir/a.go b/test/typeparam/orderedmapsimp.dir/a.go index 1b5827b4bb..37fc3e79b9 100644 --- a/test/typeparam/orderedmapsimp.dir/a.go +++ b/test/typeparam/orderedmapsimp.dir/a.go @@ -100,25 +100,25 @@ type keyValue[K, V any] struct { } // iterate returns an iterator that traverses the map. -// func (m *Map[K, V]) Iterate() *Iterator[K, V] { -// sender, receiver := Ranger[keyValue[K, V]]() -// var f func(*node[K, V]) bool -// f = func(n *node[K, V]) bool { -// if n == nil { -// return true -// } -// // Stop the traversal if Send fails, which means that -// // nothing is listening to the receiver. -// return f(n.left) && -// sender.Send(context.Background(), keyValue[K, V]{n.key, n.val}) && -// f(n.right) -// } -// go func() { -// f(m.root) -// sender.Close() -// }() -// return &Iterator[K, V]{receiver} -// } +func (m *Map[K, V]) Iterate() *Iterator[K, V] { + sender, receiver := Ranger[keyValue[K, V]]() + var f func(*node[K, V]) bool + f = func(n *node[K, V]) bool { + if n == nil { + return true + } + // Stop the traversal if Send fails, which means that + // nothing is listening to the receiver. + return f(n.left) && + sender.Send(context.Background(), keyValue[K, V]{n.key, n.val}) && + f(n.right) + } + go func() { + f(m.root) + sender.Close() + }() + return &Iterator[K, V]{receiver} +} // Iterator is used to iterate over the map. type Iterator[K, V any] struct { diff --git a/test/typeparam/orderedmapsimp.dir/main.go b/test/typeparam/orderedmapsimp.dir/main.go index 77869ad9fc..ac4cee6a78 100644 --- a/test/typeparam/orderedmapsimp.dir/main.go +++ b/test/typeparam/orderedmapsimp.dir/main.go @@ -41,24 +41,21 @@ func TestMap() { panic(fmt.Sprintf("unexpectedly found %q", []byte("d"))) } - // TODO(danscales): Iterate() has some things to be fixed with inlining in - // stenciled functions and using closures across packages. - - // gather := func(it *a.Iterator[[]byte, int]) []int { - // var r []int - // for { - // _, v, ok := it.Next() - // if !ok { - // return r - // } - // r = append(r, v) - // } - // } - // got := gather(m.Iterate()) - // want := []int{'a', 'b', 'x'} - // if !a.SliceEqual(got, want) { - // panic(fmt.Sprintf("Iterate returned %v, want %v", got, want)) - // } + gather := func(it *a.Iterator[[]byte, int]) []int { + var r []int + for { + _, v, ok := it.Next() + if !ok { + return r + } + r = append(r, v) + } + } + got := gather(m.Iterate()) + want := []int{'a', 'b', 'x'} + if !a.SliceEqual(got, want) { + panic(fmt.Sprintf("Iterate returned %v, want %v", got, want)) + } } |
