what is walk(fn *Node) for?

116 views
Skip to first unread message

xie cui

unread,
Jul 19, 2020, 10:39:17 PM7/19/20
to golang-nuts
the go tool compile will call walk, what 's effect of this call?

Jesper Louis Andersen

unread,
Jul 20, 2020, 5:11:08 AM7/20/20
to xie cui, golang-nuts
From a quick glance that might be wrong:

It looks like the walk function visits an abstract syntax tree (AST) and performs checks for the statics part of the compiler. E.g., it finds unused variables and functions, type-illegal statements and so on. The term "walk" is used as in that it "walks over the tree and visits each node". The purpose is likely to set up the AST in a state where it is well-typed. This simplifies later stages of the compiler as it can assume certain well-formed principles of the AST structure.

On Mon, Jul 20, 2020 at 4:39 AM xie cui <cuiw...@gmail.com> wrote:
the go tool compile will call walk, what 's effect of this call?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6a65acad-3756-4d77-bf16-23be1a1f9055n%40googlegroups.com.


--
J.

Keith Randall

unread,
Jul 20, 2020, 8:23:44 PM7/20/20
to golang-nuts
In addition to what Jesper said, the walk pass does a variety of lowerings and optimizations on the ast. For example, it rewrites the builtin `new` to a runtime call, rewrites switches to a tree of `if` statements, etc.
Reply all
Reply to author
Forward
0 new messages