diff options
author | Ayke van Laethem <[email protected]> | 2021-05-25 23:39:28 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2021-05-26 20:21:08 +0200 |
commit | 3edcdb5f0d057363b4270195f99165a3825cde48 (patch) | |
tree | 3bf6f252ed77df6b9bf9a3d0d10eb40d5033c239 /transform | |
parent | ec325c0643ab5e577e086c474252e4fd1405e7f6 (diff) | |
download | tinygo-3edcdb5f0d057363b4270195f99165a3825cde48.tar.gz tinygo-3edcdb5f0d057363b4270195f99165a3825cde48.zip |
compiler: do not emit nil checks for loading closure variables
Closure variables are allocated in a parent function and are thus never
nil. Don't do a nil check before reading or modifying the value.
This commit results in a slight reduction in code size in some test
cases: calls.go, channel.go, goroutines.go, json.go, sort.go -
presumably wherever closures are used.
Diffstat (limited to 'transform')
-rw-r--r-- | transform/testdata/allocs2.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/transform/testdata/allocs2.go b/transform/testdata/allocs2.go index aeddcf6ba..bf39fdefa 100644 --- a/transform/testdata/allocs2.go +++ b/transform/testdata/allocs2.go @@ -33,7 +33,7 @@ func main() { c1 := getComplex128() // OUT: object allocated on the heap: escapes at line 34 useInterface(c1) - n3 := 5 // OUT: object allocated on the heap: escapes at line 39 + n3 := 5 func() int { return n3 }() @@ -42,6 +42,13 @@ func main() { s8 := []int{3, 5, 8} // OUT: object allocated on the heap: escapes at line 44 callVariadic(s8...) + + n4 := 3 // OUT: object allocated on the heap: escapes at line 48 + n5 := 7 // OUT: object allocated on the heap: escapes at line 48 + func() { + n4 = n5 + }() + println(n4, n5) } func derefInt(x *int) int { |