Boris D¨ udder
Technical University of Dortmund, Germany
Joint work w. J. Bessai, A. Dudenhefner, M. Martens, and J. Rehof
ISoLA 2014 Evolving Critical Systems
Imperial, Corfu, Greece, October 8th 2014
Outline
Background on Combinatory Logic Synthesis
Combinatory Logic Synthesizer
Current and Future Work
Composition Synthesis
I
Typed function composition (modus ponens) Γ ` F : τ
0→ τ Γ ` G : τ
0Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I
Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I
CLS is inherently component-oriented
Composition Synthesis
I
Typed function composition (modus ponens) Γ ` F : τ
0→ τ Γ ` G : τ
0Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I
Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I
CLS is inherently component-oriented
Composition Synthesis
I
Typed function composition (modus ponens) Γ ` F : τ
0→ τ Γ ` G : τ
0Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I
Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I
CLS is inherently component-oriented
Composition Synthesis
I
Typed function composition (modus ponens) Γ ` F : τ
0→ τ Γ ` G : τ
0Γ ` (F G ) : τ (→E) as logical model of applicative composition of named component interfaces (X : ρ) ∈ Γ from a repository Γ, satisfying goal τ
I
Inhabitation problem as foundation for automatic synthesis:
∃e . Γ ` e : τ ? Notation Γ ` ? : τ
I
Does there exist a program composition e from repository Γ with Γ ` e : τ ? Inhabitation algorithm is used to construct (synthesize) e from Γ and τ
I
CLS is inherently component-oriented
Foundations in Combinatory Logic
Types τ ::= α | τ → τ
0Terms e, e
0::= X | (e e
0) Rules
Γ, (X : τ ) ` X : S(τ ) (var)
Γ ` e : τ
0→ τ Γ ` e
0: τ
0Γ ` (e e
0) : τ (→ E)
Under Curry-Howard isomorphism, Hilbert-style presentation of
minimal propositional logic (schematism + modus ponens)
Relativized Inhabitation
I
We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I
Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I
The CLS view: Already in simple types, relativized
inhabitation defines a Turing-complete logic programming
language for component composition
Relativized Inhabitation
I
We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I
Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I
The CLS view: Already in simple types, relativized
inhabitation defines a Turing-complete logic programming
language for component composition
Relativized Inhabitation
I
We consider the relativized inhabitation problem:
I
Given Γ and τ , does there exist e such that Γ ` e : τ?
I
Relativized inhabitation is much harder
I
Undecidable: Linial-Post theorems, 1948 ff.
I
The CLS view: Already in simple types, relativized
inhabitation defines a Turing-complete logic programming
language for component composition
Example Repository
Γ = {
O : TrObj
Tr : TrObj → D((R, R), R, R) pos : D((R, R), R, R) → ((R, R), R) cdn : ((R, R), R) → (R, R)
fst : (R, R) → R snd : (R, R) → R
tmp : D((R, R), R, R) → R cc2pl : ((R, R), R) → ((R, R), R) cl2fh : R → R
}
JR:Towards Combinatory Logic Synthesis, BEAT’13
Semantic Type Structure
Trackdata
Pos Temp
Coord Time Cel Fh
Cart Polar Gpst Utc
Cx Cy Radius Angle
Semantic Repository
C = {
O : TrObj
Tr : TrObj → D((R, R)∩Cart, R ∩Gpst, R ∩Cel) pos : D((R, R)∩a, R∩a
0, R) → ((R, R)∩a, R∩a
0)∩Pos cdn : ((R, R)∩a, R)∩Pos → (R, R)∩a
fst : ((R, R)∩Coord → R)∩
(Cart → Cx)∩(Polar → Radius) snd : ((R, R)∩Coord → R)∩
(Cart → Cy )∩(Polar → Angle) tmp : D((R, R), R, R∩a) → R∩a
cc2pl : (R, R)∩Cart → (R, R)∩Polar cl2fh : R ∩Cel → R ∩Fh
}
Composition Synthesis via Inhabitation
C={
O : TrObj
Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩Pos cdn : ((R,R)∩a,R)∩Pos→(R,R)∩a
fst : ((R,R)∩Coord→R)∩
(Cart→Cx)∩(Polar→Radius) snd : ((R,R)∩Coord→R)∩
(Cart→Cy)∩(Polar→Angle) tmp : D((R,R),R,R∩a)→R∩a cc2pl : (R,R)∩Cart→(R,R)∩Polar cl2fh : R∩Cel→R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
Composition Synthesis via Inhabitation
C={
O : TrObj
Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩Pos cdn : ((R,R)∩a,R)∩Pos→(R,R)∩a
fst : ((R,R)∩Coord→R)∩
(Cart→Cx)∩(Polar→Radius) snd : ((R,R)∩Coord→R)∩
(Cart→Cy)∩(Polar→Angle) tmp : D((R,R),R,R∩a)→R∩a cc2pl : (R,R)∩Cart→(R,R)∩Polar cl2fh : R∩Cel→R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
Composition Synthesis via Inhabitation
C={
O : TrObj
Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩Pos cdn : ((R,R)∩a,R)∩Pos→(R,R)∩a
fst : ((R,R)∩Coord→R)∩
(Cart→Cx)∩(Polar→Radius) snd : ((R,R)∩Coord→R)∩
(Cart→Cy)∩(Polar→Angle) tmp : D((R,R),R,R∩a)→R∩a cc2pl : (R,R)∩Cart→(R,R)∩Polar cl2fh : R∩Cel→R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
Composition Synthesis via Inhabitation
C={
O : TrObj
Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩Pos cdn : ((R,R)∩a,R)∩Pos→(R,R)∩a
fst : ((R,R)∩Coord→R)∩
(Cart→Cx)∩(Polar→Radius) snd : ((R,R)∩Coord→R)∩
(Cart→Cy)∩(Polar→Angle) tmp : D((R,R),R,R∩a)→R∩a cc2pl : (R,R)∩Cart→(R,R)∩Polar cl2fh : R∩Cel→R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
Composition Synthesis via Inhabitation
C={
O : TrObj
Tr : TrObj→D((R,R)∩Cart,R∩Gpst,R∩Cel) pos : D((R,R)∩a,R∩a0,R)→((R,R)∩a,R∩a0)∩Pos cdn : ((R,R)∩a,R)∩Pos→(R,R)∩a
fst : ((R,R)∩Coord→R)∩
(Cart→Cx)∩(Polar→Radius) snd : ((R,R)∩Coord→R)∩
(Cart→Cy)∩(Polar→Angle) tmp : D((R,R),R,R∩a)→R∩a cc2pl : (R,R)∩Cart→(R,R)∩Polar cl2fh : R∩Cel→R∩Fh
}
C `
C1? : R∩Fh C `
C1cl2fh (tmp (Tr O)) : R∩Fh
C `
C1? : R∩Radius C `
C1fst (cc2pl (cdn (pos (Tr O)))) : R∩Radius
Complexity for Finite and Bounded CL
Theorem (RU TLCA 2011) For finite combinatory logic fcl :
1. Relativized inhabitation in fcl (→) is in Ptime
2. Relativized inhabitation in fcl(→, ∩) is Exptime-complete
Theorem (DMRU CSL 2012) For bounded combinatory logic bcl
k:
1. Relativized inhabitation in bcl
k(→) is Exptime -complete for all k
2. Relativized inhabitation in bcl
k(→, ∩) is
(k + 2)- Exptime -complete
Staged Composition Synthesis (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I
L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I
L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I
Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
Staged Composition Synthesis (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I
L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I
L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I
Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
Staged Composition Synthesis (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I
L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I
L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I
Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
Staged Composition Synthesis (DMR ESOP 2014)
Goal: Introduce metalanguage L2 into composition synthesis
I
L1 may be limited, e.g.:
I
L1 might be very low-level
I
L1 might not have a notion of function application
I
L2 should contain λ-calculus
I
Special-purpose composition operators
I
Meta-level computation over L1-code
I
Higher-order abstraction
I
Challenges
I
How to expose language distinction in types?
I
How to ensure implementation type correctness?
I
How to ensure staged composition?
Main Ideas in Staged Composition Synthesis
Use modal types φ (“code of type φ”) to expose language distinction to composition synthesis.
I
Introduction of modal intersection types
I
Davies and Pfenning’s calculus λ
,→eas L2 implementation language
I
Challenges of staging solved by theory of λ
,→eI
Challenge of implementation type correctness solved by conservative extension theorem
I
Extension of inhabitation (semi-)algorithm for modal intersection types
I
Extension of (CL)S-framework and experiments
Main Ideas in Staged Composition Synthesis
Use modal types φ (“code of type φ”) to expose language distinction to composition synthesis.
I
Introduction of modal intersection types
I
Davies and Pfenning’s calculus λ
,→eas L2 implementation language
I
Challenges of staging solved by theory of λ
,→eI
Challenge of implementation type correctness solved by conservative extension theorem
I
Extension of inhabitation (semi-)algorithm for modal intersection types
I
Extension of (CL)S-framework and experiments
Tool Pipeline
User
Postprocessing Preprocessing
Semantic Types
SCS Combinator Repository
class B { ...
public String msg() { ...
} ...
L1 Target Code class A { ...
public int f() { ...
} ...
}
B L1 Source Code
L1 ASTs
<B msg="...">
<A><f/></A>
</B>
<A>
<f>
<B msg=".."/>
</f>
</A>
L1 Types L2 Types
L2 Implementations
<x>
<y/>
</x>
λx.λy.
λz.λm.
L1 Implementations
<A>
<f/>
</A>
<B msg="...">
...
Combinatory Logic Synthesizer Features
I
Theorem prover (proofs-as-programs correspondence)
I
Combinatory Logic Synthesis for BCL
0(∩, ≤)
I
Version 1.0
I
Proof-of-concept
I
Enumerates inhabitants (even cyclic ones)
I
Variable kinding
I
Atomic subtyping extension for taxonomies
I
Version 2.0
I
Algebraic optimizations
I
Co-variant type constructors
Heuristic Optimizations
Strategies
I
Algorithm engineering
I
Type-theoretic / algebraic optimizations Experimental Runtime Performance for Γ
mnin Z
n(n, m) Initial (CL)S Lookahead-(CL)S Redesigned (CL)S
(2, 3) 210 ms 111 ms 93 ms
(3, 2) 12504 ms 124 ms 98 ms
(3, 3) – 354 ms 110 ms
(4, 4) – 7.5 ∗ 10
6ms 121 ms
(7, 7) – – 1063 ms
(10, 10) – – 54250 ms
(43, 3) – – 8813 ms
Current & Future Work
I
Application to connector synthesis (ArchiType)
I
Application to OO-synthesis (mixins, traits, DI)
I
Combinatory process synthesis
I
Algorithm engineering
I
Constrained types Q (~ α) ⇒ φ
I
Automatic software configuration (OpenNebula Cloud)
I
Stratified logics
I
Component-oriented synthesis in theorem-proving?
I
. . .
Application – Spring DI DAO Synthesis
EmployeeController
:(
Scope∩α)→(EmployeeDAO
∩α)→
(EmployeeController
∩α∩setterTarget)EmployeeController
:λScope. letbox
scope=
Scopein
λDAO.letbox
dao=
DAOin
box "<bean xsi:type=’cls:Constructor’>"
"<name>EmployeeController</name>"
"<typeName>EmployeeController</typeName>"
"<scope>"scope"</scope>"
"<argument>"
"<typeName>EmployeeDAO</typeName>"
"<reference>"dao"</reference>"
"</argument>"
Application – Spring DI DAO Synthesis
Interface to request Spring Dependency Injection candidates (embedded DSL):
p u b l i c i n t e r f a c e
I n h a b i t a t i o n R e q u e s t
{ p u b l i cC l a s s [ ] l i b r a r y C l a s s e s ( ) ;
p u b l i c
C o n f i g u r a b l e A p p l i c a t i o n C o n t e x t l i b r a r y C o n t e x t ( ) ;
p u b l i cS t r i n g c l a s s N a m e E x c l u s i o n R e g e x p ( ) ;
p u b l i c
C l a s s t a r g e t T y p e ( ) ;
p u b l i cS t r i n g t a r g e t S c o p e ( ) ;
}Instead of using goal type:
(EmployeeController∩Session∩setterTarget)
Application – Spring DI DAO Synthesis
Interface to request Spring Dependency Injection candidates (embedded DSL):
p u b l i c i n t e r f a c e
I n h a b i t a t i o n R e q u e s t
{ p u b l i cC l a s s [ ] l i b r a r y C l a s s e s ( ) ;
p u b l i c
C o n f i g u r a b l e A p p l i c a t i o n C o n t e x t l i b r a r y C o n t e x t ( ) ;
p u b l i cS t r i n g c l a s s N a m e E x c l u s i o n R e g e x p ( ) ;
p u b l i c
C l a s s t a r g e t T y p e ( ) ;
p u b l i cS t r i n g t a r g e t S c o p e ( ) ;
}Instead of using goal type:
(EmployeeController
∩Session∩setterTarget)ArchiType
ArchiType
ArchiType Taxonomy
WS-ReliableMessaging ReliableHMessaging
MessageHQueue
is-a instance-of Object
RabbitMQ Pipe
CommunicationHRole ConnectorHType
Linkage HTTP Mail
SOAP Protocol
TCP/IP REST
ArchiType Experiments
e-Commerce ERP Broker SC
Subsystems 37 137 11 3
Classes 1293 691 11 3
LLOC 225 763 38 250 839 37
Generated/LLOC 2171 1731 993 257
Time/s 21.98 18.11 7 8.1
Refactoring/LLOC 5 20 No No
Conclusion
I
A new approach to component-oriented synthesis
I
Types as logic programs that compute compositions
I
Easily applicable to native API’s
I
Very large set of application scenarios
I
Robust foundations in proof theory
I
Applied in several experiments and domains
References
I Staged Composition Synthesis. With J. Rehof and M. Martens. ESOP 2014.
I Intersection Type Matching with Subtyping. With J. Rehof and M. Martens.
TLCA 2013.
I Towards Combinatory Logic Synthesis. BEAT 2013.
I Bounded Combinatory Logic. With J. Rehof, M. Martens and P. Urzyczyn. CSL 2012.
I Using Inhabitation in Bounded Combinatory Logic with Intersection Types for Composition Synthesis. With J. Rehof, O.Garbe, M. Martens and P. Urzyczyn.
EPTCS 2012.
I The Complexity of Inhabitation with Explicit Intersection. J. Rehof and P.
Urzyczyn. R.L. Constable and A. Silva (Eds.): Logic and Program Semantics.
Essays Dedicated to Dexter Kozen 2012.
I Finite Combinatory Logic with Intersection Types. J. Rehof and P. Urzyczyn.
TLCA 2011.
I Automatic Synthesis of Component & Connector-Software Architectures with Bounded Combinatory Logic. B. D¨udder. Dissertation. TU Dortmund 2014.
I See also:Dagstuhl Seminar “Design and Synthesis from Components”, Schloss