Built-In source code location
Solution 1:
There is no make()
as such. Simply put, this is happening:
- go code:
make(chan int)
- symbol substitution:
OMAKE
- symbol typechecking:
OMAKECHAN
- code generation:
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.
How do you find this
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.
Solution 2:
As a matter of fact make
is a combination of different functions, implemented in Go, in the runtime.
makeslice for e.g.
make([]int, 10)
makemap for e.g.
make(map[string]int)
makechan for e.g.
make(chan int)
The same applies for the other built-ins like append
and copy
.