How could someone make an incremental C # compiler like Java?

A few years ago, someone asked why C # does not allow incremental compilation, such as Java . El Skeet said this is because Java outputs .class files, not assemblies.

Now that its 2011 and groovy things like Mono compiler as a service have been released, what needs to be done to make an incremental compiler for C #?

edit: for anyone who is worried about how this is not a problem, here is a quote from Jon Skeet from the thread I'm connected to:

Do you suggest that you never wait for assembly? Even 15 seconds? If the assembly takes 15 seconds and you want to build 20 times per hour (which I, of course, do with TDD), which means that I spend 5 minutes. Taking a 5-minute break is one thing - a good way to relax, etc. - but holding for 15 seconds 20 times can be very frustrating. It is not much to do anything useful (except perhaps drink a drink), but it is long enough to annoy.

I suspect that two factors affect the level of annoyance that I feel, others apparently do not: 1) TDD really relies on a faster turnaround 2) When working with Java in Eclipse, such delays are very rare

+29
c # incremental-compiler
Mar 31 2018-11-11T00:
source share
1 answer

If this has not been done, there is only one reason for this: attempts to do this are above the potential benefits.

Microsoft certainly will not do this because the costs are too high: the .net code lives in assemblies and no one will change it. And yes, assemblies prevent phased compilation by class. No one will stop using assemblies.

And here is my answer, why no one needs this. You can distribute your classes that make up a single project between several assemblies and compose them one by one. This is actually an incremental compilation, but not as fine-grained as a phased class compilation. And when your architecture is properly designed, incremental compilation of the assembly level is required.

Edit : Well, I downloaded the Mono C # compiler to see what can be done to make it incremental. I think this is not very difficult. Basically, it performs the following steps: 1) parsing files 2) compilation 3) assembly. You can get caught somewhere after compiling the types and saving as intermediate files. Then recompile only the changed ones. So it's possible, but it seems that for the Mono team this is not a priority.

Change 2 . I found this interesting thread where people discuss incremental compilation for the Mono C # compiler. It is quite old, but a key explanation may remain relevant:

Lexing and parsing is usually very fast and depends only on the size of the analyzed code. semantic analysis is usually the right time step when loading assemblies and sifting around a huge metadata for resolving characters and types it’s actually the meat of the compiler. In addition, the new “compiled” code is “attached” to this metadata / AST, which increases complexity solving characters over time. The radiation code is first made in memory, so it's fast. Saving to disk is slow, but depends on the emitted code.

For incremental compilation, metadata caching will do everything very quickly, since usually very little would be changed from one compilation to others. But gmcs will only have to invalidate the part of the metadata / AST that it was not built for .

Edit 3 : The C # compiler had the /incremental option in versions 1.0 and v1.1, but it was removed :

The / incremental flag found in the C # 1.0 and 1.1 compiler versions is now deprecated.

Edit 4 : Miguel de Icaza gives a clear answer ( 1 , 2 ) why the Mono Compiler will not be incremental:

There are many, many other places where GMCS is simply not designed to run a script to edit and continue.

If someone wants to make this the topic of abstracts, this is fine with me, but the number of changes is also large in too many areas. I don’t even want to list them.

The reason I didn't list things is because they will be everywhere in the compiler. I am sure that you will encounter them as soon as you try them; -)

Therefore, he believes that this task is more difficult than for one person. And Mono has much more outstanding and relevant tasks.

+10
Mar 31 '11 at 15:59
source share



All Articles