compiler: do not allocate static slot for constants

Their value is known at compile time.
This commit is contained in:
Evgenii Stratonikov 2020-09-06 15:20:15 +03:00
parent 18204ec21a
commit 0b44a43043
2 changed files with 24 additions and 2 deletions

View file

@ -109,8 +109,13 @@ func countGlobals(f ast.Node) (i int) {
return false
// After skipping all funcDecls we are sure that each value spec
// is a global declared variable or constant.
case *ast.ValueSpec:
i += len(n.Names)
case *ast.GenDecl:
if n.Tok == token.VAR {
for _, s := range n.Specs {
i += len(s.(*ast.ValueSpec).Names)
}
}
return false
}
return true
})