digibury: edd barrett - a case study in cross-language tracing

58
Language Composition A Case Study in Cross-Language Tracing Edd Barrett Carl Friedrich Bolz Laurence Tratt Naveneetha Krishnan Vasudevan Lukas Diekmann Software Development Team 2013-11-13 1 / 25 http://soft-dev.org/

Upload: lizzie-hodgson

Post on 14-Jan-2015

218 views

Category:

Technology


2 download

DESCRIPTION

A talk exploring the challenges of programming language composition and how the team at King's College London propose to overcome them.

TRANSCRIPT

Page 1: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language CompositionA Case Study in Cross-Language Tracing

Edd Barrett CarlFriedrich

Bolz

LaurenceTratt

NaveneethaKrishnan

Vasudevan

LukasDiekmann

Software Development Team2013-11-13

1 / 25 http://soft-dev.org/

Page 2: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Life is Good

2 / 25 http://soft-dev.org/

Page 3: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Life is Good

3D Engine

2 / 25 http://soft-dev.org/

Page 4: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Life is Good

Mobile App

2 / 25 http://soft-dev.org/

Page 5: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Life is Good

Quick Script

2 / 25 http://soft-dev.org/

Page 6: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

That is, until...

// A load of Android Java code...

// find pairs where i + j < 10Arraylist<int> result = new ArrayList();

for (int i : ints1) {for (int j : ints2) {

if (i + j < 10) {ArrayList<int> n = new ArrayList();n.add(i);n.add(j);result.add(n);

}}

}// More Android Java code...

3 / 25 http://soft-dev.org/

Page 7: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

That is, until...

// A load of Android Java code...

# find pairs where i + j < 10 in *Python*result = [

(i, j) for i in ints1 for j in ints2if i + j < 10

]

// More Android Java code...

3 / 25 http://soft-dev.org/

Page 8: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Or until...

# Some Python code...if first == 1:

if second == 1:return 999

elif second == 2:return 666

else:raise TrollException("naughty")

elif first == 2:if second == 1:

return 1337elif second == 2:

return 42else:

raise TrollException("naughty")else:

raise TrollException("naughty")# More Python code...

4 / 25 http://soft-dev.org/

Page 9: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Or until...

# Some Python code...

(* Much easier to use pattern matching from functionalworld, e.g. Ocaml *)

match (first, second) with| (1, 1) -> 999| (1, 2) -> 666| (2, 1) -> 1337| (2, 2) -> 42| _ -> raise (TrollException "naughty");;

# More Python code...

4 / 25 http://soft-dev.org/

Page 10: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

So what is my point?

THE POINT:

5 / 25 http://soft-dev.org/

Page 11: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

So what is my point?

THE POINT:

PL Wars!

5 / 25 http://soft-dev.org/

Page 12: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

So what is my point?

THE POINT:

PL Wars!

5 / 25 http://soft-dev.org/

Page 13: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

So what is my point?

THE POINT:

It would be sweet to composeprogramming languages.

5 / 25 http://soft-dev.org/

Page 14: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Composition

PL X

PL Y

PL Z

6 / 25 http://soft-dev.org/

Page 15: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Not a New Idea

Existing composition methods:

Poor syntactic integration.Stringly-typed.

Languages not born equal.One language hosts the other.

Poor performanceNo cross-language optimisations.

Too much engineering effort.

7 / 25 http://soft-dev.org/

Page 16: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

What do we want from a languagecomposition?

8 / 25 http://soft-dev.org/

Page 17: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

What do we want from a language composition?

High performance

PL

>>>

9 / 25 http://soft-dev.org/

Page 18: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

What do we want from a language composition?

Good syntactic integration

pl x

pl ypl z

9 / 25 http://soft-dev.org/

Page 19: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

What do we want from a language composition?

Little effort

<

9 / 25 http://soft-dev.org/

Page 20: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Breaking down the problem

10 / 25 http://soft-dev.org/

Page 21: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Breaking Down the Problem

PL X

PL Y

PL Z

11 / 25 http://soft-dev.org/

Page 22: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Breaking Down the Problem

PL X

PL Y

PL Z

syntax

runtime

syntax

runtime

syntax

runtime

11 / 25 http://soft-dev.org/

Page 23: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Syntactic Composition

12 / 25 http://soft-dev.org/

Page 24: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

13 / 25 http://soft-dev.org/

Page 25: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL X<program>

for (j : js) { doStuff();}...

13 / 25 http://soft-dev.org/

Page 26: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL X<program>

for (j : js) { doStuff();}...

Parsing

13 / 25 http://soft-dev.org/

Page 27: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL X<program>

for (j : js) { doStuff();}...

Parsing

Parse Tree

13 / 25 http://soft-dev.org/

Page 28: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

14 / 25 http://soft-dev.org/

Page 29: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL Y<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

14 / 25 http://soft-dev.org/

Page 30: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL Y<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL Z<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

14 / 25 http://soft-dev.org/

Page 31: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL X<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL Y<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

PL Z<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

AMBIGUOUS

14 / 25 http://soft-dev.org/

Page 32: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Parsing

PL Z<program>

for (j : js) { doStuff();}...

Parsing

PL Z<grammar>

expr::= ...term::= ... | ... | ...func ::= ...

AMBIGUOUS ?14 / 25 http://soft-dev.org/

Page 33: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

15 / 25 http://soft-dev.org/

Page 34: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

C/C++

Interpreter Interpreter

16 / 25 http://soft-dev.org/

Page 35: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

C/C++

Interpreter Interpreter

Too slow

16 / 25 http://soft-dev.org/

Page 36: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

C/C++

Interpreter Interpreter

JIT Compiler JIT Compiler

16 / 25 http://soft-dev.org/

Page 37: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

C/C++

Interpreter Interpreter

Too much

engineering

JIT Compiler JIT Compiler

16 / 25 http://soft-dev.org/

Page 38: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

JVM/CLR

Interpreter Interpreter

JIT Compiler

16 / 25 http://soft-dev.org/

Page 39: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Challenges: Runtime Composition

PL X PL Y

JVM/CLR

Interpreter

JIT Compiler

Interpreter

Poor performance

for dynamic languages

16 / 25 http://soft-dev.org/

Page 40: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Our Proposed Solution

17 / 25 http://soft-dev.org/

Page 41: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Proposed solution

Meta-tracing + Language Boxes

18 / 25 http://soft-dev.org/

Page 42: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

Meta-tracing

19 / 25 http://soft-dev.org/

Page 43: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

Meta

-tra

cing

PLInterpreter

Tracing JIT

PLInterpreter

20 / 25 http://soft-dev.org/

Page 44: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

RPyth

on

Interpreter

Tracing JIT

PL YPL X

Interpreters

Glue

PL Z

Meta

-tra

cing

20 / 25 http://soft-dev.org/

Page 45: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

Meta

-tra

cing

Interpreter

Tracing JIT

PL YPL X

Interpreters

Glue

PL ZGood performance

20 / 25 http://soft-dev.org/

Page 46: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

Meta

-tra

cing

Interpreter

Tracing JIT

PL YPL X

Interpreters

Glue

PL ZGood performance

Little effort

20 / 25 http://soft-dev.org/

Page 47: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Meta-tracing

Language Boxes

21 / 25 http://soft-dev.org/

Page 48: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

22 / 25 http://soft-dev.org/

Page 49: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Begin writing Java code

22 / 25 http://soft-dev.org/

Page 50: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Open SQL language box

22 / 25 http://soft-dev.org/

Page 51: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Write SQL code

SELECT * FROM tbl WHERE

22 / 25 http://soft-dev.org/

Page 52: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Java code

SELECT * FROM tbl WHEREname = this.name;) {

22 / 25 http://soft-dev.org/

Page 53: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Java code

SELECT * FROM tbl WHEREname = this.name;) {

Good Syntactic Integration

22 / 25 http://soft-dev.org/

Page 54: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Java code

SELECT * FROM tbl WHEREname = this.name;) {

Good Syntactic Integration

Avoids Ambiguity

22 / 25 http://soft-dev.org/

Page 55: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Language Boxes Editor

Suppose we want to write a Java + SQL program.

for (string s :

Java code

SELECT * FROM tbl WHEREname = this.name;) {

Good Syntactic Integration

Avoids Ambiguity

Needs Custom Editor

22 / 25 http://soft-dev.org/

Page 56: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Our First Composition

23 / 25 http://soft-dev.org/

Page 57: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Unipycation

RPyth

on

Unip

yca

tion

Interpreter

Tracing JIT

PrologPython

Interpreters

Glue

+ our language box editor (eco)

24 / 25 http://soft-dev.org/

Page 58: Digibury: Edd Barrett - A Case Study in Cross-Language Tracing

Thanks

for (string s :

Java code

SELECT * FROM tbl WHEREname = this.name;) {

RPyth

on

Unip

yca

tion

Interpreter

Tracing JIT

PrologPython

Interpreters

Glue

http://soft-dev.org

25 / 25 http://soft-dev.org/