Thanks a lot for your time, Ian. The history info is very helpful. I'm reading the source code of version 1.15.6, but I found the code base structure on master branch is very different, some changes are refactors as you mentioned above(typechecker), and some are for new features(e.g. generics). Contribution guide <https://golang.org/doc/contribute> says Github issue tracker is the place where contributors take task from, but most of the issues are about bugs, so how about the kind of "Features" and "Plans"? Take the typechecker-rewriting task you mentioned above as example, I searched a lot to try to find the "kickoff" place and the original discussion but failed. (Most of issues assigned to Griesemer are specific bug or improvement.)
Is there any place/information I missed? Or reading the source code is the only way to fully catch up the whole process? Thanks again. On Thursday, February 25, 2021 at 10:56:01 PM UTC+8 Ian Lance Taylor wrote: > On Wed, Feb 24, 2021 at 10:24 PM messi...@gmail.com > <messi...@gmail.com> wrote: > > > > I'm trying to read golang compiler source code and now have come to the > middle of syntax analysis: just finished parser.fileOrNil, next step is > noder.node(). > > > > So far everything is fine, both lex and syntax tree parsing is easy to > understand. But after that part, it feels more and more difficult, in order > to make my learning process smoother, I think I need to ask some help/tips > from the community. > > > > Currently I'm doing it this way: > > 1. Figure out the main phases and the role of each one. > > 2. For each phase, figure out related data structures firstly, like > interfaces and structs > > 3. Read the source code of the phase, figure out the main logic > > 3. Guess, and use UT to verify > > 4. Use git log to see the author's original thoughts > > > > Problems I'm facing: > > 1. Can't find enough docs, especially official design docs > > 2. Comment is not enough in code repo, I believe it's enough for > compiler developers, but not for beginners like me > > > > This makes it very difficult to understand the design thoughts, in some > cases you have to read the source code line by line for its purpose, but > still don't know why it's implemented like that in the end. > > > > So my questions are: > > 1. Is there a place I can find the design docs for go compiler design? > > 2. What's the most productive way to learn the source code? Especially > from the perspective of go compiler developers. > > > > Thanks for any helps/suggestions/tips :) > > > Unfortunately there are no design docs. > > The most productive approach is the one you are already doing. Feel > free to ask questions on this mailing list about why things are > written the way they are. > > That said, the history of the compiler is that it was originally > written in C and based on the Inferno C compiler. Ken Thompson > modified that compiler to compile Go code, but the compiler was itself > still written in C. Several years later Russ Cox wrote a tool to > translate the C code into Go code. That Go code was naturally not > very idiomatic. A lot of it has been rewritten, but some still looks > like C code. A couple of years after that Keith Randall rewrote the > entire backend to use an SSA representation. At some point Robert > Griesemer rewrote the entire parser. Matthew Dempsky and Russ Cox > rewrote a lot of the frontend. Right now Robert Griesemer and Rob > Findley are rewriting the type checker. Many other people have > written significant components of the compiler, replacing earlier > components. > > My point in providing this partial history is that many questions > about "why does the compiler work this way" have the answer "because > of the long and complicated history of the code base." It is not the > case that a group of people sat down and designed a clean and elegant > Go compiler. As far as I know nobody has ever written a Go compiler > from scratch. > > Ian > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5e52abe8-bf12-4254-96c3-04861700a0fcn%40googlegroups.com.