What is causing a compiler to be slow?

时间:2018-06-04 16:49:49

标签: compiler-construction

I found that go is incredibly fast to compile as a compiler language compared to other languages like c++ or rust. Almost as fast as running an interpreted language, I think. Haskell is slower than go to compile even though it is like go, compiled with a runtime and garbage collector (am I correct?). I suspect that the complexity of type system is the main cause, since Haskell has more complex type system than go.

If someone want create a new programming language, and his main priority is compile time, what things should he consider in lexical, syntax and semantic analysis phases?

1 个答案:

答案 0 :(得分:0)

解析可能会变得相当昂贵,并且像之前的评论者所说,如果可能的话,你想避免重复它。这就是为什么有些语言使用模块系统而不是C风格的头文件的一个原因。不是在其他源文件中多次包含文件并重新解析整个文件,而是编译模块并通过某种接口导出其功能。

除此之外,优化还会影响编译时间。生产编译器最近试图将优化过程限制为优于二次复杂度,以避免耗尽编译时间,但还有很多工作要做。

您的语言使用案例的性能越关键,您希望编译器进行优化的次数越多。