[clang-repl] Implement autocompletion in clang-repl

Description

The Clang compiler is part of the LLVM compiler infrastructure and supports various languages such as C, C++, ObjC and ObjC++. The design of LLVM and Clang enables them to be used as libraries, and has led to the creation of an entire compiler-assisted ecosystem of tools. The relatively friendly codebase of Clang and advancements in the JIT infrastructure in LLVM further enable research into different methods for processing C++ by blurring the boundary between compile time and runtime. Challenges include incremental compilation and fitting compile/link time optimizations into a more dynamic environment.

Incremental compilation pipelines process code chunk-by-chunk by building an ever-growing translation unit. Code is then lowered into the LLVM IR and subsequently run by the LLVM JIT. Such a pipeline allows creation of efficient interpreters. The interpreter enables interactive exploration and makes the C++ language more user friendly. The incremental compilation mode is used by the interactive C++ interpreter, Cling, initially developed to enable interactive high-energy physics analysis in a C++ environment.

Our group puts efforts to incorporate and possibly redesign parts of Cling in Clang mainline through a new tool, clang-repl. The project aims at the design and implementation of robust autocompletion when users type C++ at the prompt of clang-repl. For example:

[clang-repl] class MyLongClassName {};
[clang-repl] My<tab>
// list of suggestions.

Expected results

There are several foreseen tasks:

  • Research the current approaches for autocompletion in clang such as clang -code-completion-at=file:col1:col2.
  • Implement a version of the autocompletion support using the partial
    translation unit infrastructure in clang’s libInterpreter.
  • Investigate the requirements for semantic autocompletion which takes into
    account the exact grammar position and semantics of the code. Eg:
  [clang-repl] struct S {S* operator+(S&) { return nullptr;}};
  [clang-repl] S a, b;
  [clang-repl] v = a + <tab> // shows b as the only acceptable choice here.
  • Present the work at the relevant meetings and conferences

Desirable skills

Intermediate C++; Understanding of Clang and the Clang API in particular

Project type

Large

Mentors

@vvassilev

Further reading

clang-repl
clang-repl RFC
Cling

Hello @vvassilev, I am interested in working on this project. I just graduated, and now I am working at Oracle. My end-of-studies project (at Oracle Labs) was about compiling a domain-specific language by analyzing and transforming an intermediate representation of programs written in this DSL, it was my first interaction with IRs and compilers and the project was a success.

Hi @mabbay,

Thanks for reaching out and thanks for your interest.

Since GSoC22 is over I was wondering under what form you want to be involved in the project? I am happy to mentor you as a unfunded contributor for example.

My goal is to contribute to LLVM and a project like this one is a great opportunity to get started, right?

Absolutely! I am happy to discuss design or review patches in that area. I’d propose to start by building clang-repl and maybe preparing an draft design document and an implementation plan.

Thanks for accepting to mentor me.
At this point, do you think I need to learn about Clang?

I think that’s a prerequisite.

So, I will take some time to learn about Clang. What concepts do I need to learn?