[cfe-dev] [RFC] A C++ pseudo parser for tooling

Sam McCall via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 9 11:28:24 PST 2021


On Tue, Nov 9, 2021 at 7:30 PM Demi Marie Obenour <demiobenour at gmail.com>
wrote:

> On 11/9/21 1:03 PM, Sam McCall wrote:
> >> Could an index be persisted to disk, reloaded at startup
> >
> > (Clangd does have this too, FWIW)
> >
> >
> >> and incrementally changed as the user edits?
> >
> > User edits mean we need to parse new code.
> > Absent a pseudoparser, the only thing that parses code is clang.
> > Clang needs a full AST, so this step is slow.
>
> What I meant is that clang could reparse only the code the user has
> edited, rather than reparsing the entire source file from scratch.
> I believe rust-analyzer does exactly this for Rust source, and my
> understanding is that it is considered fast enough.

Yes, you could do this, but not with clang as the parser.

Rust-analyzer has a custom parser, it does not reuse rustc for the most
part. (rls does, and is _not_ considered fast enough).
Apart from error-resilience, one big reason for this is to carefully track
its dependencies to allow incremental compilation (using salsa). I don't
believe this is something we could bolt onto clang.

Moreover rust is a smaller language with simpler parsing rules and shorter
dependency chains.
(A _lot_ of normal C++ code can't be parsed according to the spec without
executing template metaprograms.)
So the idea of building a correct parser with incremental parsing is IMO
much harder for C++.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20211109/ea321d1c/attachment.html>


More information about the cfe-dev mailing list