Where in Go's source code can I find their implementation of make
.
Turns out the "code search" functionality is almost useless for such a central feature of the language, and I have no good way to determine if I should be searching for a C function, a Go function, or what.
Also in the future how do I figure out this sort of thing without resorting to asking here? (i.e.: teach me to fish)
EDIT P.S. I already found http://golang.org/pkg/builtin/#make, but that, unlike the rest of the go packages, doesn't include a link to the source, presumably because it's somewhere deep in compiler-land.
There is no make()
as such. Simply put, this is happening:
make(chan int)
OMAKE
OMAKECHAN
runtime·makechan
gc
, which is a go flavoured C parser, parses the make
call according to context (for easier type checking).
This conversion is done in cmd/compile/internal/gc/typecheck.go.
After that, depending on what symbol there is (e.g., OMAKECHAN
for make(chan ...)
), the appropriate runtime call is substituted in cmd/compile/internal/gc/walk.go. In case of OMAKECHAN
this would be makechan64
or makechan
.
Finally, when running the code, said substituted function in pkg/runtime is called.
I tend to find such things mostly by imagining in which stage of the process this particular thing may happen. In case of make
, with the knowledge that there's no definition of make
in pkg/runtime
(the most basic package), it has to be on compiler level and is likely to be substituted to something else.
You then have to search the various compiler stages (gc, *g, *l) and in time you'll find the definitions.