Time for another rewrite

Most parts of the compiler have already been rewritten several times and now it’s time again. I tend to put off major rewrites as long as I can, but each time the investment has paid off and allowed me to move faster afterwards.

Doing it incrementally is too slow

This time I’m rewriting the first passes of the frontend, basically the lexer, parser, AST normalizer, that sort of thing. I tried to do it incrementally but there were subtle issues everywhere and it was just going way too slow. I couldn’t leave the code and work on something else for a few days without forgetting crucial details, because it was just a mess of subtle considerations and things that had to be done in just the right order. The issues were in the normalizer, but the planned solution requires the preceding passes to be rewritten as well.

It’s only a partial rewrite but I’m taking this opportunity to reorganize the code in a new repo. Besides moving to a better structure it will also work as a form of tree shaking, because any dead code will simply not be copied over to the new repo.

Stepping back to move forward

In my role as an employee I have always feared ending up in situation where I have to abandon the existing solution to be able to move fast again. Telling another person you are deliberately not going to make tangible progress for a while is uncomfortable. That person is usually not hands-on and doesn’t know if you’re just asking for permission to “play” for a while. As an independent I don’t have to worry about explaining myself to stakeholders, fortunately.

How long will it take?

Hard to say, but I know I need to get out of the cul-de-sac. Probably several months, since I have to prioritize paid work for clients.

Months? Just let an agent do it!

I’d happily let an agent redesign the web site but I won’t let them near the compiler source code. It’s mission critical to keep the complexity and lines of code down in a project like this with substantial inherent complexity.

Having said that, I’m experimenting a bit with AI to see if I can find a middle ground. For instance, I have asked ChatGPT to translate algorithms from academic papers into Python and to outline solutions. Seems to work well for problems such as tokenizers where there are thousands of instances in the training set and I know exactly what I want (and don’t want). Should be great at generating tests as well.

Stefan