[cfe-dev] How can I use incremental compiler?

Douglas Gregor dgregor at apple.com
Thu Feb 18 16:36:34 PST 2010

On Feb 18, 2010, at 3:10 AM, Tomohiro Matsuyama wrote:

> Hi all,
> I'm working on C++ code completion in Emacs by using -code-completion-at option.
> I know C++ is not fully supported yet, but It seems work well (I'm
> looking forward it).
> However, I have also found that incremental compiler is not seen, which is the
> most important part for code-completion.
> So, where can I find incremental compiler? And how can I use it to
> make code-completion
> faster?

Clang does not support incremental compilation, although that's certainly a long-term goal.

First, obvious question: are you using a Release build of Clang, rather than a Debug build? There's more than an order of magnitude of difference between the two, and I've found a Release build to be reasonably responsive.

> If you don't implement it yet, how can I start to implement it?

Here are three ideas:

  - First, start with precompiled headers. You can build a precompiled header for the file you're code-completing in (which consists of, say, all of the #includes at the top). Then, Clang doesn't have to parse that code each time you run code-completion. Precompiled headers aren't yet implemented for C++, so that would be the right place to start.

  - Second, teach Clang how to skip parsing function bodies when performing code completion, caching or throwing away the tokens if the code-completion token isn't within that function definition. Here, you'd hook into Clang's Parse module where it parses a function definition. That should eliminate a lot of work that won't affect how code-completion behaves.

  - Finally, consider real incremental parsing. It's going to be tricky, because you  would need to teach both Parse and Sema how to pretend that they're in a particular compilation context to re-parse the code you're in (e.g., if you're inside a function definition). I recommend trying this only if the other two, combined, don't make code-completion fast enough for you.

> Actually, all what I need is just incremental parser, not incremental compiler.

Parsing and semantic analysis will need to be incremental for code completion to work. You won't need incremental code generation.

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100218/e56e8c2b/attachment.html>

More information about the cfe-dev mailing list