Transcript
Page 1: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

Firstname LastnameCERN PH-SFT

CH-1211 Geneva 23sftweb.cern.ch

root.cern.ch

Cling – Past, Present and FutureCling – Past, Present and Future

V. Vassilev, P. Canal, A. Naumann, P. RussoV. Vassilev, P. Canal, A. Naumann, P. Russo

CERN, PH-SFT & FermiLabCERN, PH-SFT & FermiLab

Page 2: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Role of C++ Interpreter in ROOT

o Load/Store C++ objectsoRuntime Dynamism

• TFile::Open(“http://...”)• gDirectory->Get(“hist”)• python runReco.py

o Fast Prototyping

2

Limited C++ language support for reflection and type introspection.

ROOT

CINT

Reflection

TPluginManager

IO

...

PyR

OO

T

Type Info

TClass

Page 3: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

LLVM Toolchain As an Alternative

o 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/weekoClang

“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

3

Page 4: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

In The Meanwhile: LLVM

4

LLVM and Clang “The LLVM Project is a collection of modular and reusable compiler and

toolchain technologies...”

Page 5: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Cling's Dual Personality

oAn interpreter – looks like an interpreter and behaves like an interpreterCling follows the read-evaluate-print-loop (repl) concept.

oMore 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.

5

No need to compile Cling/ROOT with Clang/LLVM or having clang installed on the OS

Page 6: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Cling Is Better Than CINT

o Full C++ support incl. C++11o Stable and informative intermediate representations of the

sourceoBeing developed with the vision to be used in multithreaded

environment (an interpreter object per thread)

6

Page 7: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Full C++ Support

o Templates and STL are not an issue

7

Page 8: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Full C++ Support

oNatural path to the new standards C++11/C++*

8

Page 9: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Full C++ Support

oNatural path to the new standards C++11/C++*

9

Page 10: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Full C++ Support

o Boost is not a dream

10

Page 11: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo
Page 12: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Diagnostics

oColumn numbers and caret diagnosticsCaretDiagnostics.C:4:13: warning: '.*' specified field precision is missing a matching 'int' argumentprintf("%.*d"); ~~^~

oRange 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); ~~~~~~~~~~~~ ^ ~~~~~~

12

Page 13: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Diagnostics

13

o Pointer vs Referencesinput_line_410:2:6: error: member reference type 'TNamed' is not a pointernRef->GetName();~~~~^

input_line_413:2:7: error: member reference type 'TNamed *' is a pointer; maybe you meant to use '->’?nPtr1.GetName();~~~~^ ->

o Fix-it hintsFixItHints.C:7:27: warning: use of GNU old-style field designator extensionstruct point origin = { x: 0.0, y: 0.0 }; ^~ .x = FixItHints.C:12:3: error: use of undeclared identifier 'floot'; did you mean 'float’? floot p; ^~~~ float

Page 14: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Diagnostics

o AmbiguitiesAmbiguities.C:20:30: error: return type of virtual function 'Clone' is not covariant with the return type of the function it overrides (ambiguous conversion from derived class 'TeachingAssistant' to base class 'Person': class TeachingAssistant -> class Student -> class Person class TeachingAssistant -> class Teacher -> class Person)virtual TeachingAssistant* Clone() const; ^Ambiguities.C:7:19: note: overridden virtual function is herevirtual Person* Clone() const; ^

o Templatesinput_line_401:2:2:error: use of class template LorentzVector requires template arguments LorentzVector v; ^Math/GenVector/LorentzVectorfwd.h:28:39: note: template is declared here template<class CoordSystem> class LorentzVector; ~~~~~~~~~~~~~~~~~~~~~~~~ ^

14

Personvirtual void

Clone()

Personvirtual void

Clone()

TeachingAssistantvirtual void Clone()TeachingAssistantvirtual void Clone()

StudentStudent TeacherTeacher

Page 15: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Diagnostics

15

o Macro expansionsMacroExpansionInformation.C:14:7: error: invalid operands to binary expression ('int' and 'A’) X = MAX(X, *SomeA); ^~~~~~~~~~~~~~MacroExpansionInformation.C:5:24: note: expanded from macro 'MAX’#define MAX(A, B) ((A) > (B) ? (A) : (B)) ~~~ ^ ~~~

o Template instantiationsinput_line_395:2:18: error: no matching constructor for initialization of 'PtEtaPhiEVector' (aka 'LorentzVector<PtEtaPhiE4D<double> >’)PtEtaPhiEVector v2( "v1.Rho()", v1.Eta(), v1.Phi(), v1.E() ); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~Math/GenVector/LorentzVector.h:77:8: note: candidate constructor not viable: no known conversion from 'const char [9]' to 'const Scalar’ (aka 'const double') for 1st argumentLorentzVector(const Scalar & a,^Math/GenVector/LorentzVector.h:88:17: note: candidate constructor template not viable: requires single argument 'v', but 4 arguments were provided explicit LorentzVector(const LorentzVector<Coords> & v ) : ^

Page 16: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 201316

Page 17: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Data Flow

17

Machine Code (x86, Alpha, ...)

Compilation Engine (clang)

Compilation Engine (clang)

Transformation Engine

Transformation Engine

⑤②③④⑥ClingCling

⑧①, ② –Text③, ④, ⑤, ⑥ – Abstract Syntax Tree⑦ - LLVM Bit Code⑧ -Target Machine Code

LLVM Execution

Engine

LLVM Execution

Engine

Page 18: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Compilation Engine

18

Clang ParserClang Parser

Clang Code Generator

Clang Code Generator

LLVM Execution

Engine

LLVM Execution

Engine

Transformation Engine

Transformation Engine

ClingCling

Page 19: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Transformation Engine

o TransactionCling represents the incremental input as a set of AST nodes.

o Transaction TransformersCling enables each transaction to be further customized by other clients by implementing a transaction transformer.

o Interpreter CallbacksImplements callbacks for the “interesting” events.

19

ClingCling Transformation Engine

Transformation Engine

Transaction

TransactionTransaction

Page 20: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 201320

LLVM EE-s have complete target info Thus calling into compiled libraries is not an issue.

No boundary interpreted/compiled world Possible to derive from compiled classes, proper calculation of offsets and so on.

Machine Code (x86, Alpha, ...)

Compiled libs(.so)

��

LLILLI LLVMJIT

LLVMJIT MCJITMCJIT

Execution Engine

Page 21: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Challenges

o Incompatible concepts like compilation and interpretationMany tasks that are trivial for an interpreter become a nightmare for a compiler.

oMake C++ usable at the promptIncorporate the experience we have with CINT. First step: adopt the successful usability extensions from CINT.

21

Page 22: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Extending C++ Language

22

[root]$ sin(12);void wrapper() { sin(12);}

[root]$ [root]$

int i = 12;sin(i);

void wrapper1() { int i = 12;}

void wrapper2() { sin(i);} ?

Page 23: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Extending C++ Language

23

[root]$ [root]$

void wrapper1() { int i = 12; printf("%d\n",i);}

void wrapper2() { printf("%f\n", sin(i));}

int i = 12;

int i = 12; printf("%d\n",i);printf("%f\n",sin(i));

oWrap the inputo Look for declarationso Extract the declarations one level up, as global declarations

Page 24: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Streaming Execution Results

24

[root]$ [root]$

int i = 12(int) 12sin(i)(double) -5.365729e-01

[root]$

[root]$

std::string s = “Hello”(std::string) @0x7fff65ae783cc_str: “Hello”enum e { e1 = 12, e2 = 13, e3 = 13}; e1(enum e) (e::e1) : (int) 12

[root]$ HelloWorld(void (void)) Function @0x108880030 at /tmp/HelloWorld.h:2:void HelloWorld() { printf("HelloWorld!\n");}

Page 25: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Error Recovery

o Filled input-by-input (aka Transaction)o Incorrect inputs must be discarded as a whole

25

Page 26: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Implicit auto keyword

26

i = 5; f = new TNamed(“a”, ”b”)

Page 27: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Late Binding

27

if (cond) {

TFile* F = 0;

if (is_day_of_month_even())

F = TFile::Open("even.root");

else

F = TFile::Open("odd.root");

hist->Draw();

}

hist->Draw();

Page 28: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Late Binding

28

if (cond) {

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();

Page 29: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Code Unloading

29

[root]$ [root]$ [root]$ [root]$ [root]$ [root]$ [root]$ [root]$

.L Calculator.hCalculator calc;calc.Add(3, 1)(int) 2 //WTF!?*.L Calculator.hCalculator calc;calc.Add(3, 1)(int) 4 //

// Calculator.hclass Calculator { int Add(int a, int b) { return a + b; }...};

// Calculator.hclass Calculator { int Add(int a, int b) { return a - b; }...};

* What's That Function

Page 30: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Future Plans

oMigrate to MCJIT• Object file emitted to memory• Runtime dynamic linker

oWindows 64 Supporto Tools

• Automatic Differentiation

30

Page 31: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

o See Tomas Gahr’s demo later at the workshop

Thank you!

31

Page 32: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Backup slides

32

Page 33: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Pre-Compiled Headers/Modules

Carefully crafted data structures designed to improve translator's performance:oReduce lexical, syntax and semantic analysisoLoaded “lazily” on demand

33

Page 34: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

Pre-Compiled Headers/Modules

Design advantages:oLoading is significantly faster than re-parsingoMinimize the cost of readingoRead times don't depend on sizeoCost of generating isn't large

34

Page 35: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 201335

PCH PCM

Page 36: Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo

sftweb.cern.chroot.cern.ch vvassilev/ROOT Users Workshop 11-14

March 2013

PCH vs PCM

oWhere we should get it from? Who knows more about types than the translator?

36

CINT

Reflection

Type Info

Not very descriptive

GCCXML

Reflex


Top Related