0

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?

Mas Bagol
  • 4,377
  • 10
  • 44
  • 72
  • Quality code generation and optimization is relatively costly. Using -O0 is often quite a lot faster. To really limit compilation time, the first thing to do is never do any of them twice. IOW avoid reparsing tens of thousands of lines in headers for every compilation unit. – Marco van de Voort Jun 06 '18 at 12:31
  • Notice that the fastest compiler is assembler. (Assembler translates processor instructions written as text into numbers.) Hence adapting a programming language to that criterion makes little sense. Rather they need to reduce compile time by other means like switching off optimizations (mentioned above). – beroal Jun 06 '18 at 17:36
  • Complementary question: https://stackoverflow.com/questions/2976630/how-does-go-compile-so-quickly – PaulR Jun 08 '18 at 16:50

1 Answers1

0

Parsing can get pretty expensive and, like a previous commenter said, you want to avoid repeating it if possible. That is one reason why some languages use a module system rather than C-style header files. Instead of including a file multiple times inside other source files and re-parsing the whole thing you would compile the module and export its functionality via some kind of interface.

Beyond that optimisation will affect compile time. Production compilers try to limit their optimisation passes to better-than-quadratic complexity these days to avoid blowing up compile time but there's still a lot of work to do.

The more performance-critical the use case for your language is, the more you'd want the compiler to optimise.

Kyrill
  • 2,963
  • 1
  • 8
  • 12