怎么会有人做了一个C#编译器增量像Java? [英] how could someone make a c# incremental compiler like Java?

查看:183
本文介绍了怎么会有人做了一个C#编译器增量像Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前,有人问为什么C#没有按'T允许增量编译像Java 。萨尔瓦多斯基特说,这是与Java输出的.class文件而不是组件做。



现在,其2011年和时髦的东西,如单编译器作为一种服务有?被释放,就需要做才能使对C#中的增量编译器是什么



编辑:每个人敲打有关如何,这是没有问题的,这里有一个报价从乔恩斯基特从线程我联系:




你是在暗示你永远不会发现自己等待构建?即便是15
秒?如果构建需要15秒,你想建立在$ B $ 20倍b中的一个小时(这我当然做TDD),这意味着我在浪费5
分钟。以5分钟的休息时间是一件事 - 那就是
等放松的好方法 - 但被关押了15秒20次可以很
沮丧。它不是足够长的时间做有用的东西(超过
等,也许喝杯饮料),但它足够长的刺激。



我怀疑两个因素贡献水平烦恼,我觉得这$​​ b $ b其他人显然并不:
1)TDD真正依靠更快的周转
2)与Java在Eclipse中工作,这样的延迟是非常罕见的。



解决方案

如果它没有这样做那就只有一个原因是:努力做到这一点比可能更高。优点



微软肯定不会做,因为成本太高:.NET代码住在组件和没有人会改变它。是的,集预防类由级增量编译。没有人会停止使用组件。



和这里是我的答案为什么没有人需要它。您可以将多组件之间分配你的类构成单一的项目和一个编译它们。它实际上是渐进式编译但不作为细粒度的类由类增量编译。当你的架构设计正确装配水平增量编译就足够了。



修改:好吧,我下载了单声道C#编译器来看看它能够使其增量。我觉得是不是很辛苦。基本上,它下面的步骤:1)解析文件2)编译3)创建装配。类型编译后,您可以挂钩的地方,然后保存成某种中间文件。然后重新编译才改变的。所以这是可能的,但看起来是不是Mono团队高度优先问题。



编辑2 :我发现的this有趣的线程人们讨论渐进式编译为单声道C#编译器。这是相当旧的,但关键的解释可能是仍然有效:




词法和语法分析通常都很
快,仅在靠
代码的大小被解析。语义
的分析通常是最花时间
耗时步骤,因为加载引用
组件和周围的解析符号和类型
庞大的
元数据筛选是真正的肉编译器,
同样,新的编译的代码是
追加到元数据/ AST什么
增加了随着时间的推移解决
个符号的复杂性。代码发射
在内存中完成第一所以它是快。
保存到磁盘是缓慢的,但依赖于
发出的代码大小。



有关增量编译,缓存
元,就会使一切很
快,因为通常很少会是
从一个编译改成其他的
。但系膜细胞将不得不
无效只有
元/ AST的一部分,是什么它没有内置


< /块引用>

修改3 :在v1.0和V1 C#编译器有 /增量选项。 1,但它删除




在1.0和1.1版的C#编译器的/增量的标志,现在被认为是过时了。




修改4 :米格尔奥德伊卡萨给出了明确的答案(的1 ,的 2 )为什么单编译器将不会是渐进的:




有很多很多地方,
GMCS只是没有设计在$ b $工作b。将编辑后继续运行的情况。



如果有人想使这个他们的
论文题目,那就是没问题,
,但变化量都在太多的领域太
大。我不
甚至想打扰列举他们。



我没有列出的东西的原因是
,因为他们将无处不在
编译器。相信你会只要你尝试出来碰上
它们; - )




因此​​,他认为它是任务更加庞大比一个人的论文。和单有更多优秀的和实际的任务。


Years ago someone asked why c# doesn't allow incremental compilation like Java. El Skeet said it is to do with Java outputting .class files rather than assemblies.

Now that its 2011 and groovy things like the Mono compiler-as-a-service have been released, what would need to be done to make an incremental compiler for c#?

edit: to everyone banging on about how this isn't a problem, here's a quote from Jon Skeet from the thread I linked to :

Are you suggesting you never find yourself waiting for a build? Even 15 seconds? If a build takes 15 seconds and you want to build 20 times in an hour (which I certainly do with TDD) that means I'm wasting 5 minutes. Taking a 5 minute break is one thing - that's a good way of relaxing etc - but being held up for 15 seconds 20 times can be very frustrating. It's not long enough to do anything useful (other than maybe sip a drink) but it's long enough to irritate.

I suspect two factors contribute the level of annoyance I feel which others apparently don't: 1) TDD really relies on a faster turnaround 2) When working with Java in Eclipse, such delays are very rare

解决方案

If it was not done then there is only one reason for it: efforts to do it are higher than possible benefits.

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

And here is my answer why no one needs it. You can distribute your classes that constitute single project among several assemblies and compile them one by one. It is actually incremental compilation but not as fine-grained as class-by-class incremental compilation. And when your architecture is properly designed assembly level incremental compilation is sufficient.

Edit: Okay, I downloaded Mono C# compiler to take a look it is possible to make it incremental. I think it is not very hard. Basically it does following steps: 1) Parse files 2) Compile 3) Create assembly. You could hook somewhere after types are compiled and save then into some sort of intermediate files. Then recompile only changed ones. So it is possible, but looks like it is not high-priority issue for Mono team.

Edit 2: I found this interesting thread where people discuss Incremental compilation for Mono C# compiler. It is rather old but key explanation might be still valid:

Lexing and parsing normally are very fast and depend only on the size of the code being parsed. Semantic analysis is normally the most time consuming step as loading referenced assemblies and sifting around the huge metadata to resolve symbols and types is really the meat of the compiler, also, new "compiled" code is "appended" to this metadata/AST what increases the complexity of resolving symbols over time. Emission of code is done in memory first so it is fast. Saving to disk is slow but depends on emitted code size.

For incremental compiling, caching the metadata, would make everything very fast, as normally very little would be changed from one compilation to the other. But gmcs would have to invalidate only part of the metadata/AST, what it wasn't built for.

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

The /incremental flag found in the 1.0 and 1.1 version of the C# compiler is now considered obsolete.

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

There are many, many more places where GMCS was just not designed to work on an edit-and-continue scenario.

If someone wants to make this their thesis subject, that is fine with me, but the amount of changes are too large in too many areas. I do not even want to bother enumerating them.

The reason I did not list things is because they will be everywhere in the compiler. Am sure you will run into them as soon as you try them out ;-)

So he considers it to be a task huger than for one man's thesis. And Mono has much more outstanding and actual tasks.

这篇关于怎么会有人做了一个C#编译器增量像Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆