Escape analysis is the reason your `x` is on the heap. Because it escaped. Otherwise it'd be on the stack.[1]
Now if by "semantics of the code" you mean "just pretend everything is on the heap, and you won't need to think about escape analysis", then sure.
Now in terms of what actually happens, your code triggers escape analysis, and OP does not.
[1] Well, another way to say this I guess is that without escape analysis, a language would be forced to never use the stack.
func pointless() byte {
var a byte[1024]
a[0] = 1
return a[0]
}
That’s entirely up to the compiler, not something that’s determined by the language semantics. It could vary from platform to platform or compiler version to compiler version. So clearly you don’t need to think about the details of escape analysis to understand what your code does because in many cases you simply won’t know if your value is on the stack or not.