内置源代码位置 [英] Built-In source code location
问题描述
在 Go 的源代码中我可以找到他们对 make
的实现.
Where in Go's source code can I find their implementation of make
.
事实证明,代码搜索"功能对于该语言的这样一个核心功能几乎没有用,而且我没有好的方法来确定我应该搜索 C 函数、Go 函数还是什么.
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)
编辑附言我已经找到了 http://golang.org/pkg/builtin/#make,但这与其他的不同go 包不包含源代码链接,大概是因为它位于编译器领域的深处.
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.
推荐答案
没有 make()
这样的.简单地说,这正在发生:
There is no make()
as such. Simply put, this is happening:
- 代码:
make(chan int)
- 符号替换:
OMAKE
- 符号类型检查:
OMAKECHAN
- 代码生成:
runtime·makechan
gc
是一个 go 风格的 C 解析器,根据上下文解析 make
调用(为了更容易的类型检查).
gc
, which is a go flavoured C parser, parses the make
call according to context (for easier type checking).
这个转换在cmd/compile/internal/gc/typecheck.go.
之后,取决于有什么符号(例如,OMAKECHAN
代表 make(chan ...)
),适当的运行时调用被替换为 cmd/compile/internal/gc/walk.go.在 OMAKECHAN
的情况下,这将是 makechan64
或 makechan
.
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
.
最后,在运行代码时,表示替换函数 在 pkg/runtime 中 被调用.
Finally, when running the code, said substituted function in pkg/runtime is called.
我倾向于通过想象这个过程的哪个阶段来找到这些东西可能会发生特定的事情.在 make
的情况下,知道没有pkg/runtime
(最基本的包)中make
的定义,必须在编译器级别并且很可能会被其他东西取代.
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.
然后你必须搜索不同的编译器阶段(gc、*g、*l),你会及时找到定义.
You then have to search the various compiler stages (gc, *g, *l) and in time you'll find the definitions.
这篇关于内置源代码位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!