Skip to content

Commit

Permalink
add back multi-function call check
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Sep 19, 2023
1 parent 2ff7c51 commit a9545c3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
12 changes: 7 additions & 5 deletions compiler/coroutine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ func TestCoroutineYield(t *testing.T) {
yields: []int{0, 2, 4, 6, 8, 10, 12, 14, 16, 18},
},

{
name: "range over anonymous function",
coro: func() { RangeTriple(4) },
yields: []int{0, 3, 6, 9},
},
// TODO: desugar function call expressions to enable this test.
//
// {
// name: "range over anonymous function",
// coro: func() { RangeTriple(4) },
// yields: []int{0, 3, 6, 9},
// },

{
name: "range over anonymous function value",
Expand Down
10 changes: 5 additions & 5 deletions compiler/testdata/coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ func Double(n int) {
coroutine.Yield[int, any](2 * n)
}

func RangeTriple(n int) {
Range(n, func(i int) {
coroutine.Yield[int, any](3 * i)
})
}
// func RangeTriple(n int) {
// Range(n, func(i int) {
// coroutine.Yield[int, any](3 * i)
// })
// }

func RangeTripleFuncValue(n int) {
f := func(i int) {
Expand Down
19 changes: 0 additions & 19 deletions compiler/testdata/coroutine_durable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions compiler/testdata/coroutine_functypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions compiler/unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (
func unsupported(decl ast.Node, info *types.Info) (err error) {
ast.Inspect(decl, func(node ast.Node) bool {
switch nn := node.(type) {
case ast.Expr:
switch nn.(type) {
case *ast.FuncLit:
default:
if countFunctionCalls(nn, info) > 1 {
err = fmt.Errorf("not implemented: multiple function calls in an expression")
}
}
case ast.Stmt:
switch n := nn.(type) {
// Not yet supported:
Expand Down Expand Up @@ -74,3 +82,35 @@ func unsupported(decl ast.Node, info *types.Info) (err error) {
})
return
}

func countFunctionCalls(expr ast.Expr, info *types.Info) (count int) {
ast.Inspect(expr, func(node ast.Node) bool {
c, ok := node.(*ast.CallExpr)
if !ok {
return true
}
switch f := c.Fun.(type) {
case *ast.Ident:
if obj := info.ObjectOf(f); types.Universe.Lookup(f.Name) == obj {
return true // skip builtins
} else if _, ok := obj.(*types.TypeName); ok {
return true // skip type casts
}
case *ast.SelectorExpr:
if x, ok := f.X.(*ast.Ident); ok {
if obj := info.ObjectOf(x); obj != nil {
if pkg, ok := obj.(*types.PkgName); ok {
pkgPath := pkg.Imported().Path()
switch {
case pkgPath == "unsafe":
return true // skip unsafe intrinsics
}
}
}
}
}
count++
return true
})
return
}

0 comments on commit a9545c3

Please sign in to comment.