compiler,runtime: check for channel size limits

This patch is a combination of two related changes:

 1. The compiler now allows other types than `int` when specifying the
    size of a channel in a make(chan ..., size) call.
 2. The compiler now checks for maximum allowed channel sizes. Such
    checks are trivially optimized out in the vast majority of cases as
    channel sizes are usually constant.

I discovered this issue when trying out channels on AVR.
This commit is contained in:
Ayke van Laethem
2020-03-10 21:58:34 +01:00
committed by Ron Evans
parent 1a7369af6e
commit 79dae62c78
4 changed files with 94 additions and 0 deletions
+10
View File
@@ -54,6 +54,16 @@ func main() {
n, ok = <-ch
println("recv from closed channel:", n, ok)
// Test various channel size types.
_ = make(chan int, int8(2))
_ = make(chan int, int16(2))
_ = make(chan int, int32(2))
_ = make(chan int, int64(2))
_ = make(chan int, uint8(2))
_ = make(chan int, uint16(2))
_ = make(chan int, uint32(2))
_ = make(chan int, uint64(2))
// Test bigger values
ch2 := make(chan complex128)
wg.add(1)