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.
This commit is contained in:
Ayke van Laethem
2021-05-25 23:39:28 +02:00
committed by Ron Evans
parent ec325c0643
commit 3edcdb5f0d
5 changed files with 14 additions and 21 deletions
+2
View File
@@ -994,6 +994,8 @@ func getPos(val posser) token.Pos {
switch val := val.(type) {
case *ssa.MakeInterface:
return getPos(val.X)
case *ssa.MakeClosure:
return val.Fn.(*ssa.Function).Pos()
case *ssa.Return:
syntax := val.Parent().Syntax()
if syntax != nil {