1 / 35

Cling – The New C++ Interpreter for ROOT 6

Cling – The New C++ Interpreter for ROOT 6. V. Vassilev, P. Canal, A. Naumann, P. Russo. CERN, PH-SFT & FermiLab. TPluginManager. CINT. Reflection. Type Info. PyROOT. IO. Role of C++ Interpreter in ROOT. Load/Store C++ objects Runtime Dynamism TFile::Open(“http://...”)

jennyvega
Download Presentation

Cling – The New C++ Interpreter for ROOT 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cling – The New C++ Interpreter for ROOT 6 V. Vassilev, P. Canal, A. Naumann, P. Russo CERN, PH-SFT & FermiLab

  2. vvassilev / CHEP 2012.05.21 TPluginManager CINT Reflection Type Info PyROOT ... IO Role of C++ Interpreter in ROOT • Load/Store C++ objects • Runtime Dynamism • TFile::Open(“http://...”) • gDirectory->Get(“hist”) • python runReco.py • Fast Prototyping ROOT TClass

  3. vvassilev / CHEP 2012.05.21 Role of C++ Interpreter in ROOT • ROOT uses the interpreter much more than one would expect:

  4. vvassilev / CHEP 2012.05.21 Cling Is Better Than CINT • Full C++ support • STL + templates • Path to C++11 • Correctness • Better type information and representations • Always compile in memory • Much less code to maintain

  5. vvassilev / CHEP 2012.05.21 Cling's Dual Personality • An interpreter – looks like an interpreter and behaves like an interpreterCling follows the read-evaluate-print-loop (repl) concept. • More than interpreter – built on top of compiler libraries (Clang and LLVM)Contains interpreter parts and compiler parts. More of an interactive compiler or an interactive compiler interface for clang. No need to compile Cling/ROOT with Clang/LLVM

  6. vvassilev / CHEP 2012.05.21 Cling Uses Clang & LLVM • LLVM and Clang “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies...”

  7. Cling's Codebase * No testsuites included. Credits: generated using David A. Wheeler's 'SLOCCount' Other ROOT – 1400K SLOC* CINT+Reflex – 230K SLOC* Cling – 7K SLOC* vvassilev / CHEP 2012.05.21

  8. Cling's Codebase * No testsuites included. Credits: generated using David A. Wheeler's 'SLOCCount' Other ROOT – 1400K SLOC* CINT+Reflex – 230K SLOC* Cling – 7K SLOC* externals: LLVM + Clang – 800K SLOC* vvassilev / CHEP 2012.05.21

  9. vvassilev / CHEP 2012.05.21 Challenges • Incompatible concepts like compilation and interpretationMany tasks that are trivial for an interpreter become a nightmare for a compiler. • Make C++ usable at the promptIncorporate the experience we have with CINT. First step: adopt the successful usability extensions from CINT.

  10. vvassilev / CHEP 2012.05.21 Cling in a Nutshell

  11. vvassilev / CHEP 2012.05.21 Extending C++ Language void wrapper() { sin(12);} [cling]$ sin(12); We want to be able to run statements void wrapper1() { int i = 12; } ? [cling]$ [cling]$ int i = 12; sin(i); void wrapper2() { sin(i); }

  12. vvassilev / CHEP 2012.05.21 Extending C++ Language • Wrap the input • Look for declarations • Extract the declarations one level up, as global declarations int i = 12; void wrapper1() { int i = 12; printf("%d\n",i); } [cling]$ [cling]$ int i = 12; printf("%d\n",i); printf("%f\n",sin(i)); void wrapper2() { printf("%f\n", sin(i)); }

  13. vvassilev / CHEP 2012.05.21 Streaming Execution Results No semicolon (;) No semicolon (;) [cling]$ [cling]$ int i = 12 (int) 12 sin(i) (double const) -5.365729e-01

  14. vvassilev / CHEP 2012.05.21 Error Recovery • Filled input-by-input • Incorrect inputs must be discarded as a whole

  15. vvassilev / CHEP 2012.05.21 Work in progress: Code Unloading // Calculator.h class Calculator { int Add(int a, int b) { return a - b; } ... }; • * What's That Function [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ [cling]$ .L Calculator.h Calculator calc; calc.Add(3, 1) (int) 2 //WTF!?* .U Calculator.h .L Calculator.h Calculator calc; calc.Add(3, 1) (int) 4 // // Calculator.h class Calculator { int Add(int a, int b) { return a + b; } ... };

  16. vvassilev / CHEP 2012.05.21 Late Binding • { • TFile* F = 0; • if (is_day_of_month_even()) • F = TFile::Open("even.root"); • else • F = TFile::Open("odd.root"); • hist->Draw(); • } • hist->Draw();  Defined in the root file  Opens a dynamic scope. It tells the compiler that cling will take over the resolution of possible unknown identifiers  The root file is gone. Issue an error.

  17. vvassilev / CHEP 2012.05.21 Late Binding • { • TFile* F = 0; • if (is_day_of_month_even()) • F = TFile::Open("even.root"); • else • F = TFile::Open("odd.root"); • gCling->EvaluateT<void>("hist->Draw()", ...); • } • hist->Draw(); Automatically transformed into valid C++ code • Tell the compiler the identifier will be resolved at runtime • Wrap it into valid C++ code • Partially recompile at runtime

  18. vvassilev / CHEP 2012.05.21 Challenges • Error recoveryEven though the user has typed wrong input at the prompt cling must survive, i.e issue an error and continue to work. • Initialization of global variablesCling depends on global variables, which need to be initialized. However, the global variables continue to be added (potentially) with every input line. • Late bindingCling needs to provide a way for symbols unavailable at compile-time a second chance to be provided at runtime. • Value printerThe interactive mode obeys the repl concept and there should be way of easy print value and type of expression in a user-extensible way. • Running statementsCINT-specific C++ extension improving the user interaction with the interpreter from the terminal.

  19. vvassilev / CHEP 2012.05.21 Cling In The World • Announced in July 2011 as working C++ interpreter • Cling and OpenGLhttp://www.youtube.com/watch?v=eoIuqLNvzFs • Cling and QThttp://www.youtube.com/watch?v=BrjV1ZgYbbA • MATLAB to C++ translator • Regular bug reports from outside HEP

  20. vvassilev / CHEP 2012.05.21 Cling In ROOT

  21. vvassilev / CHEP 2012.05.21 TPluginManager TClass CINT Reflection Type Info ... PyROOT IO Dictionaries • Describe compiled codeIncarnation of the type information and reflection in ROOT. The only way of crossing the border between interpretation and compilation. • CINT and Reflex dictionaries: • Double the size of the libraries • Multiple copies of the dictionary data in the memory • Incompatible reflection formats • Do not cover 100% of C++

  22. CINT Dictionary Use Source of ROOT's class description Dictionary.(h|cxx) TClass Member functions injected by the ClassDef macro ClassDef Call Stubs Reflection Info Target-independent, normalized signatures used to call compiled functions. Teaches CINT what a class contains vvassilev / CHEP 2012.05.21

  23. vvassilev / CHEP 2012.05.21 Cling Clang LLVM Just-In-Time Compiler • Compiles lazily just before the function is called • Has full knowledge about the target architecture • Much faster than interpreting the LLVM Bit Code LLVM JIT Compiled libs(.so) Machine Code (x86, Alpha, ...) LLVM Bit Code

  24. vvassilev / CHEP 2012.05.21 Cling + ROOT = ROOT 6 • ROOT 6 in NovemberSee plenary by Fons on Wednesday • Windows support to arrive after 6.00Work in progress in clang • “genreflex”-compatible dictionary generator after 6.00

  25. vvassilev / CHEP 2012.05.21 ROOT 6.x • Reduce size of dictionaries • Mid term: Call Stubs & Reflection Info goes away! • Long term: No dictionaries at all • Compiled TFormula Dictionary.(h|cxx) TClass ClassDef Call Stubs Reflection Info

  26. vvassilev / CHEP 2012.05.21 Additional Features • World class performance and optimizations • OpenCL • C • Objective C[++] • ...

  27. vvassilev / CHEP 2012.05.21 C N G In ActionCome and see at our booth!

  28. vvassilev / CHEP 2012.05.21 • Fons's plenary on Wednesday • Google Tech Talk • LLVM Euro Dev Meeting 2011http://www.llvm.org/devmtg/2011-09-16/EuroLLVM2011-ImplementingDynamicScopesInCling.pdf • LLVM Dev Meeting 2011http://www.llvm.org/devmtg/2010-11/Naumann-Cling.pdfhttp://www.llvm.org/devmtg/2010-11/videos/Naumann_Cling-desktop.mp4 Thank you!

  29. vvassilev / CHEP 2012.05.21 Backup slides

  30. vvassilev / CHEP 2012.05.21 Pre-Compiled Headers/Modules • Carefully crafted data structures designed to improve translator's performance: • Reduce lexical, syntax and semantic analysis • Loaded “lazily” on demand http://clang.llvm.org/docs/PCHInternals.html

  31. vvassilev / CHEP 2012.05.21 Pre-Compiled Headers/Modules • Design advantages: • Loading is significantly faster than re-parsing • Minimize the cost of reading • Read times don't depend on size • Cost of generating isn't large

  32. vvassilev / CHEP 2012.05.21 PCH vs PCM PCM PCH And thus PCM much more flexible

  33. vvassilev / CHEP 2012.05.21 Expressive Diagnostics • Column numbers and caret diagnosticsCaretDiagnostics.C:4:13:warning:'.*' specified field precision is missing a matching 'int' argumentprintf("%.*d");~~^~ • Range highlightingRangeHighlight.C:14:39:error:invalid operands to binary expression ('int' and 'A')return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);~~~~~~~~~~~~ ^ ~~~~~~~ • Fix-it hintsFixItHints.C:7:27:warning:use of GNU old-style field designator extensionstruct point origin = { x: 0.0, y: 0.0 };^~.x =

  34. vvassilev / CHEP 2012.05.21 LLVM Compiler Toolchain • LLVM Core “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies...” • More than 120 active contributorsApple, ARM, Google, Qualcomm, QuIC, NVidia, AMD and more • ~250 commits/week • Clang“The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.“ • More than 100 active contributorsApple, ARM, AMD and more • ~150 commits/week * Stats from last year until 14.10.2011

  35. vvassilev / CHEP 2012.05.21 Correctness • http://root.cern.ch/drupal/content/requested-cling-features

More Related