My mind picture of the runtime is more detailed now. I guess for more I should now read the code itself.
Just one side issue. You said:
"
Memory allocated on the stack in function F can not be used by callees
of F. After F returns, the memory is gone.
"
I don't quite get it.
As I understand it, a caller is earlier in the stack that any of the functions it calls (callees), so those callees will always return before the caller does, their scope is a subset of the caller's.
As such, the fact that the callers locals are gone when it returns does not matter to the callees, which have already been long gone by then.
That is, of course, if those callees are using that callers variables locally only, not passing then elsewhere (other Goroutines, effectively other stacks). That is, there is no variable escape from the stack.
What did I miss here?
On Tue, Jan 24, 2017 at 12:46 PM, josvazg <jos...@gmail.com> wrote:
>
> Golang runtime has been fully translated to Go for a while now. I know I
> could just read the source code directly but...
>
> Is there any known or recommended documentation (talk, slides, article)
> about the runtime Go code?
Not really. It changes pretty quickly so any such docs would be more
or less out of date.
> I am specially interested in anything that describes the Golang runtime
> language subset restrictions:
Mostly the code is written carefully by people who understand the compiler.
> How does it avoid the GC? (while it's implementing it)
By not allocating memory. It is helped by a "secret" compiler option,
-+. When that compiler option is used, the compiler gives an error
for any implicit memory allocation. Note that this is not a change to
the language, it is, as you say, a subset of the language: operations
that implicitly allocate memory are forbidden.
It depends. A call to new can (and will, often) give you a pointer to a stack allocated object. If you pass that pointer to something like fmt.Println() you'll see the object escape to the heap, get flagged by -m, and presumably forbidden by -+.