Advancing Clangd. Bringing persisted indexing to Clang tooling. Marc-André Laperle, Ericsson

Similar documents
Storing Clang Data. For IDEs and static analysis. Marc-André Laperle, Ericsson

Refactoring with Eclipse

Xcode Tricks. ios App Development Fall 2010 Lecture 13

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

DVT Eclipse IDE. My First Verilog/SystemVerilog Project

Scientific Software Development with Eclipse

News in RSA-RTE 10.2 updated for sprint Mattias Mohlin, May 2018

What s new in CDT 4.0 and beyond. Doug Schaefer QNX Software Systems CDT Project Lead

CodeWarrior Development Studio for Power Architecture Processors FAQ Guide

BASICS OF THE RENESAS SYNERGY PLATFORM

CodeCompass an Open Software Comprehension Framework

The Road to CCSv4. Status Update

News in RSA-RTE CP1

SCIRun: Module Development Basics

Final CSE 131B Spring 2004

CodeWarrior Development Studio for Advanced Packet Processing FAQ Guide

Semantic Analysis. Compiler Architecture

Page 1. Agenda. Programming Languages. C Compilation Process

Undefined Behaviour in C

Engineering Tools III: OOP in C++

Scale out Read Only Workload by sharing data files of InnoDB. Zhai weixiang Alibaba Cloud

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

QUIZ. What is wrong with this code that uses default arguments?

Research compiler that will become Scala 3 Type system internals redesigned, inspired by DOT, but externally very similar More info:

Variables, Memory and Pointers

CS 241 Honors Memory

LLVMLinux: x86 Kernel Build

Chapter 10 Introduction to Classes

Using Static Code Analysis to Find Bugs Before They Become Failures

Introduction to Java

CS61C : Machine Structures

Chapter 1 Getting Started

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Express Yourself. What is Eclipse?

Optimizing for Bugs Fixed

Remote Procedure Call (RPC) and Transparency

Module 4: Working with MPI

Starting to Program in C++ (Basics & I/O)

CHAPTER 6 ACTIONS, METHODS, REFACTORING

Advanced CUDA Optimizations. Umar Arshad ArrayFire

The Next Generation of Eclipse: e4. Mike Milinkovich Executive Director Eclipse Foundation

Summer May 11, 2010

Pointers and References

GETTING STARTED WITH ECLIPSE Caitrin Armstrong

CSE 333 Lecture 6 - data structures

OpenACC Course. Office Hour #2 Q&A

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

Operating Systems (ECS 150) Spring 2011

Result: original lp in main is. Goal was.

Distributed Systems. How do regular procedure calls work in programming languages? Problems with sockets RPC. Regular procedure calls

Assertions, pre/postconditions

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Exercise 6.2 A generic container class

public void method() { int a = 1;... int b = a + anotherclass.intvalue(); int c = b + anotherclass.intvalue(); }

At this time we have all the pieces necessary to allocate memory for an array dynamically. Following our example, we allocate N integers as follows:

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

So far, system calls have had easy syntax. Integer, character string, and structure arguments.

Introducing C++ David Chisnall. March 15, 2011

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, November 2017

DDMD AND AUTOMATED CONVERSION FROM C++ TO D

C++- und Ruby- und... Refactoring für Eclipse

AN5171 Application note

The Procedure Abstraction

reinven&ng the compiler

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Today s presentation. Git gdb Project 1

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

News in RSA-RTE 10.2 updated for sprint Mattias Mohlin, January 2018

Language Oriented Modularity: From Theory to Practice

Compiler Construction

Advanced Compiler Design. CSE 231 Instructor: Sorin Lerner

Compiler aided optimization of the pimpl-idiom

Module 3: Working with C/C++

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

Thomas Pelaia II, Ph.D. XAL Workshop 2012 December 13, 2012 Managed by UT-Battelle for the Department of Energy

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

CUDA OPTIMIZATION WITH NVIDIA NSIGHT ECLIPSE EDITION

6.170 Laboratory in Software Engineering Eclipse Reference for 6.170

Advanced Compiler Design. CSE 231 Instructor: Sorin Lerner

Compiler construction 2009

Rational Functional Tester - Tips and Tricks

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

ECE 103 In-Class Exercise L1 Guide

Retaining Comments when Refactoring Code or

Object-Oriented Programming for Scientific Computing

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Scaling Xtext. Lieven Lemiengre

CPS1011. Program Structure {C};

Naming in OOLs and Storage Layout Comp 412

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

CPSC 427: Object-Oriented Programming

New features in AddressSanitizer. LLVM developer meeting Nov 7, 2013 Alexey Samsonov, Kostya Serebryany

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Product Updates TPFUG 2019, Denver

C++ DATA TYPES BASIC CONTROL FLOW

trisycl Open Source C++17 & OpenMP-based OpenCL SYCL prototype Ronan Keryell 05/12/2015 IWOCL 2015 SYCL Tutorial Khronos OpenCL SYCL committee

Lecture 7. Log into Linux New documents posted to course webpage

Transcription:

Advancing Clangd Bringing persisted indexing to Clang tooling Marc-André Laperle, Ericsson

AGENDA 1 Introductions 2 3 The road to persisted indexing 4 Current state 5 What s new in Clangd Future and challenges Ericsson AB 2017 2017-10-19 Page 2

Introductions Marc-André Laperle Software Developer at Ericsson since 2013 Eclipse committer for CDT (C/C++) and several other projects New-ish LLVM/Clang contributor (early 2017) Enthusiastic about C/C++, IDEs and tooling in general (Not a compiler expert! Yet?) Ericsson AB 2017 2017-10-19 Page 3

What is Clangd Tool in Clang Extras Implements the Language Server Protocol (LSP) for C/C++ Protocol in JSON-RPC Code smartness features like code completion, find references, etc. Integrations with Visual Studio Code, Theia and Eclipse (and more?) Ericsson AB 2017 2017-10-19 Page 4

What is Clangd VS Code, Theia, Eclipse... Clangd Original image source: https://github.com/microsoft/language-server-protocol/blob/master/protocol.md Ericsson AB 2017 2017-10-19 Page 5

Current status Ericsson AB 2017 2017-10-19 Page 6 C/C++ Editor feature LSP Clangd Formatting Yes Yes Completion Yes Yes Diagnostics Yes Yes Fix-its Yes Yes Go to Definition Yes Yes* Source hover Yes Soon Signature Help Yes Yes Find References Yes No, index needed Document Highlights Yes Soon Rename Yes No, index needed Code Lens Yes No, index needed * Actually just goes to declarations or definitions visible in the same unit

Current status C/C++ Editor feature LSP Clangd Syntax and Semantic Coloring No No Code folding No No Call hierarchy No No, index needed Type hierarchy No No, index needed Organize Includes No No Quick Assist No No Extract Local Variable No No Extract Function/Method No No Hide Method No No Implement Method No No, index needed Gen. Getters/Setters No No, index needed Ericsson AB 2017 2017-10-19 Page 7

What s new Code Completion Go to Declaration Signature Help Switch between source/header More command-line options (resource-dir, compilation database) Ericsson AB 2017 2017-10-19 Page 8

What s new Performance improvements (multiple thread workers, preamble management, etc) A lot of bug fixes and clean-ups! Growing community! Ericsson AB 2017 2017-10-19 Page 9

Indexing Why? foo.h void foo() foo.cpp #include foo.h void foo() { }?? OK! main.cpp #include foo.h int main() { foo(); } Ericsson AB 2017 2017-10-19 Page 10

First prototypes 1) Outside LLVM/Clang community Before Clangd Separate Github repo Experimentations with code completion and RecursiveASTVisitor libjsoncpp + hand-written JSON-RPC handling Ericsson AB 2017 2017-10-19 Page 11

2) Migration to Clangd Same repo (but in a branch) as other Clang extra tools: more collaboration! LLVM s YAML parser (for JSON), hand-written JSON-RPC handling Open Declaration feature, no index No Clang/Index code reused, only RecursiveASTVisitor Ericsson AB 2017 2017-10-19 Page 12

3) Introducing persistence RecursiveASTVisitor still used to find cursor location Clang/Index s IndexDataConsumer used to feed the index Simple, Very Slow Index file format (linear dump) No definition in headers, only function definitions Ericsson AB 2017 2017-10-19 Page 13

SVSI file format (Simple Very Slow Index) + 4 + 4 + filepath length + 4 + 4 + name length + 4 + 4 Num of files File path length File path Num of symbols Symbol name length Symbol name Symbol loc start Symbol loc end...more symbols...more files Read through the whole file to read a symbol a the end! On source file change => Rebuild the whole file! Ericsson AB 2017 2017-10-19 Page 14

4) Better persistence and code reuse: IndexDataConsumer used for both cursor location and feeding the index ClangdIndexDataStorage, BTree introduced No definition in headers, only function definitions Source file changes handled (but not headers) Dependents of headers stored in index (can now use source file s compilation database when opening header file) Ericsson AB 2017 2017-10-19 Page 15

ClangdIndexDataStorage Malloc-like interface to writing in a file Stores raw bytes, ints, string and pointers (to other locations in the file) Inspired from Eclipse CDT s database Ericsson AB 2017 2017-10-19 Page 16

ClangdIndexDataStorage File layout 0 File version 4 Linked list to free blocks of 8 bytes 8 Linked list to free blocks of 16 bytes... 2048 Linked list to free blocks of 4096B 2052 User data (Blocks) Data block 0 Block size 2..size Free block 0 Free block size 2 Pointer to next free block of same size 6..size Any user data Unused (until it becomes a data block) Ericsson AB 2017 2017-10-19 Page 17

ClangdIndexDataStorage { Data block Free block Free Data Data Free Data 4K pieces Data Free Data { Data Data Data Free Data Data Cache! Data Free Free Data Ericsson AB 2017 2017-10-19 Page 18

BTree Tree with nodes containing multiple children Balanced Logarithmic insertion, search, deletion B D A C E F Ericsson AB 2017 2017-10-19 Page 19

BTree Keys are pointers to data in ClangdIndexDataStorage 4096 5248 ClangdIndexFile Path: B.cpp Occurrences, etc 4928 5240 5224 5200 ClangdIndexFile Path: C.cpp Occurrences, etc Ericsson AB 2017 2017-10-19 Page 20

5) Richer model, file handling Time stamps for all files (source and headers) recorded Dependent source files re-indexed on header change Declarations, Definitions, References all in index Index model closer to Index-While-Building proposal Working Open definition and Find references crashes when indexing Clangd Ericsson AB 2017 2017-10-19 Page 21

Model ClangdIndexFile -Path -First Occurrence (linked list) * * ClangdIndexOccurrence -NextForSymbol (linked list) -NextInFile (linked list) -Location -Roles -Symbol ClangdIndex -BTree of Files -BTree of Symbols * ClangdIndexSymbol -USR -FirstOccurrence (linked list) Ericsson AB 2017 2017-10-19 Page 22

Demo (VS Code, Theia, Eclipse) Ericsson AB 2017 2017-10-19 Page 23

Challenges Lack of header caching Use Precompiled headers? Pretokenized Headers? How to use cached header information when included in a different context? (different order of includes, etc) Heuristics for using cached header even in different context? Split indexing in multiple phases? (Skip bodies at first, etc) Reuse Modules feature in Clang Ericsson AB 2017 2017-10-19 Page 24

Challenges File event handling Server vs client file watching Watching a large number of files (beyond the inotify max) Re-indexing everything when a top level header changes Ericsson AB 2017 2017-10-19 Page 25

Collaborations Indexing Index-While-Building feature in Xcode 9 could be reused. Reuse the index store (instead of ClangdIndexStorage). [1] (Also presented today) Move some indexing logic to Clang/Index instead of Clangd, for others to reuse Make indexing extensible enough so that other tools can add information to the index (Clang Static Analyzer) Use liblmdb, for symbol mapping, similar to Xcode [1] https://docs.google.com/document/d/1ch2stpgsnjzckztjl1ay-rzy4ugpcri-6rrupdato2q/ Ericsson AB 2017 2017-10-19 Page 26

Collaborations Refactoring Specifying LSP well enough to express the refactorings (with options, other languages, etc) Reuse refactoring framework introduced with Xcode 9 [1] (Also presented today) Contribute more refactorings to Clang Add code generations (Generate Getters/Setters, Constructors, etc) Quick assist support, possibly reusing refactoring components [1] http://lists.llvm.org/pipermail/cfe-dev/2017-june/054286.html Ericsson AB 2017 2017-10-19 Page 27

References Clangd: https://clang.llvm.org/extra/clangd.html Language Server Protocol: https://github.com/microsoft/language-server-protocol Clang mailing list: https://lists.llvm.org/mailman/listinfo/cfe-dev Github branch hosting indexing prototype: https://github.com/markz3/clang-tools-extra/tree/indexfunctionsprototype Theia IDE: https://github.com/theia-ide/theia Ericsson AB 2017 2017-10-19 Page 28

Ericsson AB 2017 2017-10-19 Page 29 Q&A