Live data from Hacker News

How Microsoft rewrote its C# compiler in C# and made it open source (2017)

medium.com

41–50 of 136 posts

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#41

Earlier quoted context omitted.

Yeah, if I remember correctly it's indeed a thing in latest versions of .NET Core;

This looks like a pretty cool demonstration of what we're talking about: https://www.strathweb.com/2019/01/collectible-assemblies-in-... See the section titled: Collecting a dynamically emitted assembly

Yeah that's exactly it. Thanks!

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#42
post #39
post #5

Earlier quoted context omitted.

Personally speaking, I'd love to, but I'd then have to figure out how to make them work with an IDE. I'm very tired of waiting for record classes to show up and I could have written a (to be clear: inferior ) set of stuff around regular classes that magics one into "everything is readonly and we autogenerate a `copy` method", much like Kotlin does for its data classes...but my IDE isn't gonna understand it unless I d…

I have a code-gen for records and discriminated unions [1] (as well as other useful features). It will generate a record-type at build-time (which includes the background build process in VS). All that's needed is a [Record] or [Union] attribute: [1] https://github.com/louthy/language-ext/wiki/Code-generation

You just made my day. Not kidding. Thank you.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#43
post #27
post #8

I find amusing how microsoft moved from the closed source referent in the industry into such an open source player. Right now even allows to hook some of their tools and platforms to its competing platforms and tools.

Their intent is still entirely market share. We need to be vigilant on how they get there. History has taught us a lot of lessons we seem to have forgotten because shiny and new layer of marketing. There is still a massive cultural and technical impedance mismatch.

It is interesting to me that I read people criticizing Microsoft for their open sourcing code as doing it for marketing reasons---which seems accurate---but not criticizing Google or Apple or whoever else when they open source code.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#44
Roslyn's parser and syntax tree is pretty amazing. You can recreate the precise source text from the parse tree up to whitespace. This sort of "bijective parsing" is truly incredible and probably one of the cooler innovations I've seen in parsing technology. I can see a bunch of really interesting ideas that you could do with bijective parsing. For instance, imagine Rails style boilerplate generation but done at a semantics aware, within file basis. You could conceivably have a code generator that finds a class, introspects if it has the corresponding method, then generates it if not.

Or imagine syntax reformatting but purely locally. Or semantically aware git diffs that can actually compare the underlying parse trees instead of just raw text. There's so much cool stuff you can do. I wish every language had a parser like this.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#45

Earlier quoted context omitted.

At some point I wrote a barebones scripting system using roslyn for a project of mine. At runtime I got a piece of code compiled to a DLL in memory and then executed this DLL; Worked well; But at that time there was no support for destroying AppDomains or something, don't remember the exact name. Still pretty fun; But yeah, there's no real complete documentation anywhere; And the DLL hell was real. Dozens of DLL's ju…

Maybe Assembly unloading, in which case if you wanted to swap out new dlls in memory you'd have to tear down the process and restart it. Definitely not sexy. That being said: I think Assembly Unloading is a thing now (and AppDomains don't exist in .NET Core last I heard).

In .NET standard (i.e. not .NET Core) you can load and unload assemblies without tearing down whole processes by creating AppDomains within a process. You then load your desired assemblies into these app domain(s), consume and when you need to load say a newer DLL version you just tear down the AppDomain and create a new one for the new DLL's.

It's a feature that's been around since .NET 1.1 and I used to use heavily 10+ years ago.

https://docs.microsoft.com/en-us/dotnet/api/system.appdomain...

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#46

Earlier quoted context omitted.

At some point I wrote a barebones scripting system using roslyn for a project of mine. At runtime I got a piece of code compiled to a DLL in memory and then executed this DLL; Worked well; But at that time there was no support for destroying AppDomains or something, don't remember the exact name. Still pretty fun; But yeah, there's no real complete documentation anywhere; And the DLL hell was real. Dozens of DLL's ju…

Roslyn is very powerful, but it is still pretty cumbersome. At one point I spent quite a while trying to get a game scripting system akin to the way that Lua is commonly used working, and I just couldn't get it working fast enough to be viable. I essentially wanted to have a core C# engine that provided services, and then have it call an initialization function and a gameloop function that were defined in designated…

FWIW, I wrote effectively what you describe pre-Roslyn, using the old CSharpCompiler, and it was plenty fast enough for my own developer tolerances. I ended up going to a compile-on-startup mode instead, though.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#47

Roslyn's parser and syntax tree is pretty amazing. You can recreate the precise source text from the parse tree up to whitespace. This sort of "bijective parsing" is truly incredible and probably one of the cooler innovations I've seen in parsing technology. I can see a bunch of really interesting ideas that you could do with bijective parsing. For instance, imagine Rails style boilerplate generation but done at a se…

Dart's parser can do this too. The formatter (dartfmt) takes advantage of this in order to preserve comments and use the original formatting as a hint to the output in some cases.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#48
post #8

I find amusing how microsoft moved from the closed source referent in the industry into such an open source player. Right now even allows to hook some of their tools and platforms to its competing platforms and tools.

There’s so many flavors of open source. It’s not just about the licenses, but also the way development is done. Do you truly collaborate in open or do you first develop and then push to public repo. Or is the development a joint effort, involving serious contributors from multiple companies or mainly driven by single entity.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#49
If .NET/C# could output native binaries for Windows Desktop apps, I could seriously think about switching to C# over C++. How do people deal with securing their source code otherwise? Quite trivial to get the source from a decompiled C# exe file.

Re: How Microsoft rewrote its C# compiler in C# and made it open source (2017)

#50
While the rewrite enabled faster development of the language as a whole, it also gradually destroyed the IDE's performance. The editor in VS 2019 is simply unworkable.

I blame this directly on the immutable AST. While a nice concept in theory, it causes too many allocations, and is cumbersome to work with.

I predict another rewrite in 2 or 3 years.

Post reply on HN