KDevelop/ClangRoadmap

From KDE Community Wiki
Revision as of 10:37, 18 July 2013 by Milianw (talk | contribs)

This document is supposed to lay out the roadmap towards proper Clang integration into KDevelop. This is about Clang as a backend for our C++ language support, not related to using Clang as a compiler for your project (you can already do that).

Why Clang

Maintenance

Our existing C++ language plugin might work reasonably well for C++03 code. But for more complicated features from C++11 (e.g. variadic templates, constexpr, ...) are not yet supported. Due to lack of time and manpower, it is an open question when, if ever, we come around to implementing this. Furthermore one can note that the C++ standards committee picked up speed. With C++14 concepts e.g. will become a technical preview which again will be lots of work to implement properly.

Using Clang as a backend will give us kickass support of C++ "for free".

Static Analysis

Using an IDE like KDevelop for writing C++ should reduce the amount of time you need to compile your code, just to see what errors you made. Clang comes with excellent error reporting tools. These we will then be able to show directly inside the editor.

Refactoring

KDevelop so far comes with only very rudimentary support for refactoring. The clang community is very actively writing new tools though which we can then integrate.

Why Not Clang

File-based Workflow

So far, KDevelop uses a file-based workflow which is different from what compilers do: They work on translation units and a given file is not necessarily compiling standalone. We will need to figure out how to support this, such that one can still open a file in KDevelop without first loading a project and still getting _some_ language support. Also, working on headers or new files in a project should "work" just like it does now.

Performance

It is left to be seen how clang works in terms of performance. So far it looks "OK", especially since one should be able to write code that leverages multiple CPU cores much better. We will probably have to look into precompiled headers though. Potentially we will also have to spearhead the effort behind the clangd idea, where one could share information acquired for the IDE with the compiler and other external tools.

API/ABI

The C++ API of clang is still not stable. Probably the AST part will never become stable. It is left to be seen how this will be problematic. As long as source compatibility is given, or at least source changes are minimal, I think this will work out OK. It might mean requiring new versions of Clang and it will definitely mean that we need to get in contact with the Clang community. We need to be aware of changes they make and make them aware of what we are using it for.

Problems with integrating Clang into the existing DUChain code

Olijg investigated and spearheaded a clang based C++ langugae plugin for KDevelop, see http://quickgit.kde.org/?p=scratch%2Folivierjg%2Fkdev-clang.git

It became apparent that it won't work properly with what we have right now in our language abstraction API in kdevplatformlanguage. On one hand there is the file-based workflow mentioned above, we will find a way to solve or workaround that though. Other problems are:

Tight Coupling between Abstraction and Storage

The classes in the DUChain are so far our abstraction of a language. Things like common types, contexts, declarations, definitions and uses. The big trouble there is that all these classes are tightly coupled to the storage. For Clang e.g. the concept of ranges for a declarations is different (TODO: olijg: please elaborate once more what we want to do in the new clang plugin).

Thus we should refactor our API and decouple the language abstraction from the storage and make it possible for a given language to implement a custom storage layer. This would also be good in future if we have clangd or similar and do not want to duplicate the caching inside KDevelop.

Roadmap

  • refactor KDevplatform code, decouple language abstraction from storage
    • instead of asking the storage for contexts, declarations, etc. pp. in a given file/project/... ask the language plugin of that file
    • don't put lookup code and similar that is only required to implement a _language plugin_ into the new api
    • add API for tasks such as:
      • create outline of a given document
      • quickopen of classes, functions
      • classbrowser functionality, basically project outline
      • context browsing functionality
  • keep existing DUChain API as common implementation of new language abstraction for reuse in existing language plugins (php, ruby, python, ...)

Positive Side Effects

  • decoupling of storage will allow it to more easily exchange the storage with a different implementation. This should then allow us to test e.g. NoSQL or SQL databases for storage.
  • once we get clang working, we can remove a ton of C++ specific code from the existing DUChain API, thus simplifying it.
  • with the storage decoupled, it should be the next goal to further simplify the existing DUChain API. The goals should be:
    • simple to use, no magic knowledge required
    • rethink (i.e. get rid of) the locking concept, improve performance scaling with multiple cores
    • simple to extend for different languages