6

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"?

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
  • 3
    I don't understand your question. You already seem know what is bootstrapping. Then what you don't know? – Sriram Sakthivel Apr 14 '15 at 11:27
  • Seems like opening https://github.com/dotnet/roslyn/blob/master/src/Roslyn.sln in Visual Studio and pushing the "compile" button would do the trick – xmojmr Apr 14 '15 at 17:00

4 Answers4

9

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.
sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • When new keywords are added to the language, how it will be compiled? because we don't have the compiler(yet) which understands the new tokens ? [Originally asked here](http://stackoverflow.com/questions/27513234/in-which-language-is-the-c-sharp-compiler-written#comment47395673_27513277) – Sriram Sakthivel Apr 14 '15 at 11:40
  • 4
    @SriramSakthivel Just don't use those new features in the compiler (at first). – sepp2k Apr 14 '15 at 11:44
  • Silly me :) It was very easy one :) – Sriram Sakthivel Apr 14 '15 at 11:54
  • 3
    This was somewhat challenging for us -- even though the C# compiler that supported await had shipped, the Roslyn compiler didn't support it yet. We couldn't use it in the IDE codebase because we were trying to get to self-hosting. Now we can use features that we haven't shipped to the entire world yet, but it used to be the reverse! – Jason Malinowski Apr 17 '15 at 20:38
9

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!"

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
2

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.

Georg
  • 5,626
  • 1
  • 23
  • 44
2

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.

Steve Drake
  • 1,968
  • 2
  • 19
  • 41