compiler: add support for running a builtin in a goroutine

Not sure why you would ever do this, but it appears to be allowed by the
Go specification and previously TinyGo would crash with an unhelpful
error message when you would do this. I don't see any practical use of
it.

The implementation simply runs the builtin directly.
This commit is contained in:
Ayke van Laethem
2021-05-25 13:43:54 +02:00
committed by Ron Evans
parent 87c2ccb0b9
commit ec325c0643
5 changed files with 130 additions and 0 deletions
+27
View File
@@ -73,6 +73,8 @@ func main() {
time.Sleep(2 * time.Millisecond)
testGoOnBuiltins()
testCond()
}
@@ -131,6 +133,31 @@ type simpleFunc func()
func emptyFunc() {
}
func testGoOnBuiltins() {
// Test copy builtin (there is no non-racy practical use of this).
go copy(make([]int, 8), []int{2, 5, 8, 4})
// Test recover builtin (no-op).
go recover()
// Test close builtin.
ch := make(chan int)
go close(ch)
n, ok := <-ch
if n != 0 || ok != false {
println("error: expected closed channel to return 0, false")
}
// Test delete builtin.
m := map[string]int{"foo": 3}
go delete(m, "foo")
time.Sleep(time.Millisecond)
v, ok := m["foo"]
if v != 0 || ok != false {
println("error: expected deleted map entry to be 0, false")
}
}
func testCond() {
var cond runtime.Cond
go func() {