Question from someone who knows barely anything about the Scheme ecosystem:
It seems that the one of the motivations for starting this effort, besides performance, was to move away from a C code base. Is Chez Scheme primarily written in Scheme?
Yes, Chez Scheme is mostly written in itself, including most primitives and the entire compiler. Additionally, the way Racket CS is architected, significant parts of the C-implemented Racket runtime are instead written in Racket and compiled to Chez Scheme ahead of time, such as the thread system and the IO library.
Yes, Chez Scheme is mostly implemented in Scheme. The garbage collector and some support routines are in C, but the compiler and libraries and most other system stuff is written in Scheme.
Racket is more of a meta language. For another example, see Gerbil Scheme (cons.io). It is a meta language written on top of Gambit Scheme. Gambit was chosen because it can compile to portable, efficient and fast C code. Gerbil on Gambit currently tops the R7RS benchmarks [1].
Actually, Gerbil used to be written on Racket. As you can see, it now benefits from Gambit's strengths without having to re-implement them...
I think the reason is more maintainability, when basing on a solid and faster other Scheme. It's much easier to write in terms of that other Scheme's primitives, than writing a C core, avoiding all kinds of C typical bugs. Furthermore, many improvements in Chez Scheme will carry over to Racket and the 2 communities might join forces in improving Chez and thus Racket in effect.
What that other Scheme is based on is a secondary consideration. Chez Scheme is also said to be implemented very well, however.
About the only notable thing with it (apart from inspiring the target for Idris 2) is that it implements the C FFI, so it will handle Idris programs made to target C.
The result is super fast: if you use if after using Idris1 you'll be blown away by how much quicker it type-checks. I'd never have thought a Scheme could perform noticeably faster than Haskell, but maybe most of the improvements are just due to algorithmic improvements made during the rewrite.
I never played with Idris2, but I recall running some idris1 programs using the chez scheme backend instead of thebc one and got instant 5x speedups. Across the board.
Not that it wouldn't be possible to make the C code fast. It is just that the chez backend was a one man job.
Thank the Chez Scheme developers for an absolutely fantastic compiler, and also Idris for being designed so that it's possible to feed any of the IRs to the particular backend. There's not much of an impedance mismatch between Scheme and Idris lambda output, so the overhead is small. I could have made it a bit better if I had represented Idris lists and bools as the corresponding scheme types, instead of being mapped as all the other types by their structure.
Comments
Question from someone who knows barely anything about the Scheme ecosystem:
It seems that the one of the motivations for starting this effort, besides performance, was to move away from a C code base. Is Chez Scheme primarily written in Scheme?
Yes, Chez Scheme is mostly written in itself, including most primitives and the entire compiler. Additionally, the way Racket CS is architected, significant parts of the C-implemented Racket runtime are instead written in Racket and compiled to Chez Scheme ahead of time, such as the thread system and the IO library.
Yes, Chez Scheme is mostly implemented in Scheme. The garbage collector and some support routines are in C, but the compiler and libraries and most other system stuff is written in Scheme.
Racket is more of a meta language. For another example, see Gerbil Scheme (cons.io). It is a meta language written on top of Gambit Scheme. Gambit was chosen because it can compile to portable, efficient and fast C code. Gerbil on Gambit currently tops the R7RS benchmarks [1].
Actually, Gerbil used to be written on Racket. As you can see, it now benefits from Gambit's strengths without having to re-implement them...
[1]: https://ecraven.github.io/r7rs-benchmarks/
I think the reason is more maintainability, when basing on a solid and faster other Scheme. It's much easier to write in terms of that other Scheme's primitives, than writing a C core, avoiding all kinds of C typical bugs. Furthermore, many improvements in Chez Scheme will carry over to Racket and the 2 communities might join forces in improving Chez and thus Racket in effect.
What that other Scheme is based on is a secondary consideration. Chez Scheme is also said to be implemented very well, however.
Iirc Idris2 went straight to running on chez since Edwin was so impressed by chez scheme and it's runtime.
I made a chez scheme backend for Idris a couple of years ago: https://github.com/melted/idris-chez
About the only notable thing with it (apart from inspiring the target for Idris 2) is that it implements the C FFI, so it will handle Idris programs made to target C.
The result is super fast: if you use if after using Idris1 you'll be blown away by how much quicker it type-checks. I'd never have thought a Scheme could perform noticeably faster than Haskell, but maybe most of the improvements are just due to algorithmic improvements made during the rewrite.
I never played with Idris2, but I recall running some idris1 programs using the chez scheme backend instead of thebc one and got instant 5x speedups. Across the board.
Not that it wouldn't be possible to make the C code fast. It is just that the chez backend was a one man job.
Thank the Chez Scheme developers for an absolutely fantastic compiler, and also Idris for being designed so that it's possible to feed any of the IRs to the particular backend. There's not much of an impedance mismatch between Scheme and Idris lambda output, so the overhead is small. I could have made it a bit better if I had represented Idris lists and bools as the corresponding scheme types, instead of being mapped as all the other types by their structure.