简体   繁体   中英

How's Roslyn C# compiler bootstrapped?

I've started reading about "Roslyn" the new C# compiler and was wondering how was the Roslyn compiler compiled?
I understand that boostrapping is needed in order to have "self hosting compiler" , and I wondered how was the Roslyn compiler "bootstrapped"?

Bootstrapping is only a problem if there isn't already an existing implementation of the language. In this case there was, so it's easy.

  1. Compile the first version of Roslyn using the existing C# compiler
  2. Then re-compile it using the freshly compiled Roslyn build.
  3. Done.

This is how it was actually (not guessing) done by the C# team, according to Eric Lippert :

C# 1.0 through 5.0 compilers were written in C++. For quite a long time -- over a year -- we wrote the Roslyn C# compiler in C# and compiled it with C# 4.0. (C# 5.0 was being developed in parallel by a sister team.) The day that we could compile the Roslyn compiler, and then turn right around and compile it again using the compiler we'd just built, that was a happy day.

Nice piece on the business case for bootstrapping the compiler by Mads Torgersen:

"Here, finally was our value proposition: Make it so that there only needs to be one code base in the world that understands C#, shared by everyone who wants to build tools over code!"

I would guess that the existing C# compiler has been used for this. I mean, a fully bootstrapped compiler is nice but in this case not really necessary.

Have a read of

http://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29

If one needs to obtain a compiler for language X (which is written in language X), there is the issue of how the first compiler can be written. The different methods that are used in practice to solving this chicken or the egg problem include:

Implementing an interpreter or compiler for language X in language Y. Niklaus Wirth reported that he wrote the first Pascal compiler in Fortran.[citation needed] Another interpreter or compiler for X has already been written in another language Y; this is how Scheme is often bootstrapped.

But for the specifics of Roslyn I would guess, built with c# compiler (pre-Roslyn) then built with its self :) (first few runs) once its stable, they probs just build Roslyn with Roslyn :)

I would also guess that its all automated and unit tested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM