What is the cause of the insane amount of comment deletion bugs? Is it caused by the lexer or parser architecture?
Is it not fuzzed? Or is it impossible to track the amount of comments before and after formatting?
We have fuzzing but it may not be set up to check deleted comments. Feel free to make an issue for that.
Why does it happen often with comments but not with other lexemes?
I opened these:
https://github.com/roc-lang/roc/issues/12145
https://github.com/roc-lang/roc/issues/12146
Comments do not affect the execution of the program so that may be one of the reasons why they are handled differently.
Comments can also be in between a ton of different elements which probably leaves a lot of edge cases.
Aren't comments also special in that we dont tokenize them, we do something different and keep them out of the AST. I'd have to look at it again, but I thought we dont include them to keep compilation leaner.
Does the Roc parser construct a CST? Formatters should work from CST, it's simpler and less error-prone.
I'm not so familiar with a CST specifically or how Roc's AST would differ from that. The choice to do it this way was made for performance reasons, at the cost of a more complicated formatter If I remember correctly. I know we experimented with a lot of different ways of doing things over the years.
I would assume @Anthony Bullard or @Joshua Warner would have more background here for you.
I'm not so familiar with a CST specifically or how Roc's AST would differ from that.
Some parsers construct a Concrete Syntax Tree after tokenization, which is then lowered to an AST. It's sometimes used by tools that provide autoformatting and LSP support. I'm not familiar with the Roc compiler at all, so that's why I asked whether it has CST, or directly parse to an AST.
Last updated: Oct 15 2026 at 17:56 UTC