Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CoALP-Ty 2016

CoALP-Ty 2016

Structural resolution for Abstract Compilation of
Object-Oriented Languages

Luca Franceschini

November 29, 2016
Tweet

More Decks by Luca Franceschini

Other Decks in Research

Transcript

  1. Structural resolution for Abstract Compilation of Object-Oriented Languages Luca Franceschini

    1 Davide Ancona 1 Ekaterina Komendantskaya 2 1Department of Informatics, Bioengineering, Robotics and Systems Engineering University of Genoa 2Department of Computer Science Heriot-Watt University of Edinburgh Workshop on Coalgebra, Horn Clause Logic Programming and Types, 29th November 2016, Edinburgh, UK
  2. Abstract compilation Abstract compilation: encoding of source code in a

    logic program P and then write type-checking/inference queries to be solved w.r.t. to P (Ancona and Lagorio, 2009).
  3. Abstract compilation Abstract compilation: encoding of source code in a

    logic program P and then write type-checking/inference queries to be solved w.r.t. to P (Ancona and Lagorio, 2009). types are terms
  4. Abstract compilation Abstract compilation: encoding of source code in a

    logic program P and then write type-checking/inference queries to be solved w.r.t. to P (Ancona and Lagorio, 2009). types are terms inductive semantics is not enough
  5. Abstract compilation Abstract compilation: encoding of source code in a

    logic program P and then write type-checking/inference queries to be solved w.r.t. to P (Ancona and Lagorio, 2009). types are terms inductive semantics is not enough the system is parametric w.r.t. the resolution method
  6. Contents Corecursion in abstract compilation Co-LP and abstract compilation S-resolution

    & abstract compilation Productivity of logic programs Conclusions
  7. Induction and coinduction Finite derivations SLD resolution Infinite derivations Co-LP

    (Simon et al., 2006): terms and derivations can be cyclic (a.k.a. regular or rational) S-resolution (Komendantskaya and Johann, 2015): coinduction is not limited to cyclic terms and proofs but logic programs must be productive
  8. Induction and coinduction Finite derivations SLD resolution Infinite derivations Co-LP

    (Simon et al., 2006): terms and derivations can be cyclic (a.k.a. regular or rational) S-resolution (Komendantskaya and Johann, 2015): coinduction is not limited to cyclic terms and proofs but logic programs must be productive Two different (sound but not complete) implementations for the greatest complete fixed-point semantics. Which one to choose?
  9. Co-LP & abstract compilation class F a c t o

    r i a l extends Object { F a c t o r i a l () { super ( ) ; } compute ( int n) { // no r e t u r n type annotation i f (n ≤ 0) 1 else n × t h i s . compute (n−1) } }
  10. Co-LP & abstract compilation class F a c t o

    r i a l extends Object { F a c t o r i a l () { super ( ) ; } compute ( int n) { // no r e t u r n type annotation i f (n ≤ 0) 1 else n × t h i s . compute (n−1) } } new F a c t o r i a l ( ) . compute (4)
  11. Co-LP & abstract compilation class F a c t o

    r i a l extends Object { F a c t o r i a l () { super ( ) ; } compute ( int n) { // no r e t u r n type annotation i f (n ≤ 0) 1 else n × t h i s . compute (n−1) } } new F a c t o r i a l ( ) . compute (4) new(factorial, [], F) ∧ invoke(F, compute, [int], T)
  12. Co-LP & abstract compilation new(factorial, [], F) ∧ invoke(F, compute,

    [int], T) . . . invoke(F, compute, [int], T) . . . invoke(F, compute, [int], int) . . . invoke(F, compute, [int], int)
  13. Co-LP & abstract compilation new(factorial, [], F) ∧ invoke(F, compute,

    [int], T) . . . invoke(F, compute, [int], T) . . . invoke(F, compute, [int], int) . . . invoke(F, compute, [int], int) Successful derivation in Co-LP!
  14. S-resolution & abstract compilation Not all infinite derivations are cyclic

    though. . . class L i s t extends Object { . . . b u i l d L i s t (n , l ) { i f (n ≤ 0) l else t h i s . b u i l d L i s t (n−1, new NEList (n , l )) } }
  15. S-resolution & abstract compilation Not all infinite derivations are cyclic

    though. . . class L i s t extends Object { . . . b u i l d L i s t (n , l ) { i f (n ≤ 0) l else t h i s . b u i l d L i s t (n−1, new NEList (n , l )) } } new L i s t ( ) . b u i l d L i s t (n , new EList ( ) )
  16. S-resolution & abstract compilation Not all infinite derivations are cyclic

    though. . . class L i s t extends Object { . . . b u i l d L i s t (n , l ) { i f (n ≤ 0) l else t h i s . b u i l d L i s t (n−1, new NEList (n , l )) } } new L i s t ( ) . b u i l d L i s t (n , new EList ( ) ) invoke(L, buildList, [int, E], R)
  17. S-resolution & abstract compilation new L i s t (

    ) . b u i l d L i s t (n , new EList ( ) ) invoke(L, buildList, [int, E], R) . . . invoke(L, buildList, [int, E ], R ) . . . invoke(L, buildList, [int, E ], R ) . . .
  18. S-resolution & abstract compilation new L i s t (

    ) . b u i l d L i s t (n , new EList ( ) ) invoke(L, buildList, [int, E ], R ) . . . invoke(L, buildList, [int, E ], R ) . . . invoke(L, buildList, [int, E ], R ) . . . Co-LP: infinite derivation... S-resolution: success! R = E ∨ obj(nelist, [head : int, tail : R ])
  19. Contents Corecursion in abstract compilation Co-LP and abstract compilation S-resolution

    & abstract compilation Productivity of logic programs Conclusions
  20. Productivity S-resolution does not come for free: logic programs have

    to be productive. p(f (X)) ← p(X) p(X) ← p(X)
  21. Productivity S-resolution does not come for free: logic programs have

    to be productive. p(f (X)) ← p(X) p(X) ← p(X) S-resolution is strictly more powerful than Co-LP only for productive logic programs.
  22. Productivity Can we make arbitrary logic programs productive? p(X) ←

    p(X) p(X, f (Y )) ← p(X, Y ) More generally. . . p(tn) ← p1(t1 n1 ) ∧ · · · ∧ pm(tm nm ) p(tn, f (X1, . . . , Xm)) ← p1(t1 n1 , X1) ∧ · · · ∧ pm(tm nm , Xm)
  23. A simple transformation A logic program P is a set

    {C1, . . . , Cn} of n Horn clauses. The transformation − is inductively defined on the structure of logic programs (Fu and Komendantskaya, 2017).
  24. A simple transformation A logic program P is a set

    {C1, . . . , Cn} of n Horn clauses. The transformation − is inductively defined on the structure of logic programs (Fu and Komendantskaya, 2017). P = {C1, . . . , Cn} = { C1 κ1 , . . . , Cn κn } C κ = A ← A1 ∧ · · · ∧ An κ = A κ(X1,...,Xn) ← A1 X1 ∧· · ·∧ An Xn A τ = p(t1, . . . , tn) τ = p(t1, . . . , tn, τ)
  25. A simple transformation A logic program P is a set

    {C1, . . . , Cn} of n Horn clauses. The transformation − is inductively defined on the structure of logic programs (Fu and Komendantskaya, 2017). P = {C1, . . . , Cn} = { C1 κ1 , . . . , Cn κn } C κ = A ← A1 ∧ · · · ∧ An κ = A κ(X1,...,Xn) ← A1 X1 ∧· · ·∧ An Xn A τ = p(t1, . . . , tn) τ = p(t1, . . . , tn, τ) G = ← A1 ∧ · · · ∧ An =← A1 X1 ∧ · · · ∧ An Xn
  26. Example of transformation subclass(A, A) ← class(A) subclass(A, object) ←

    class(A) subclass(A, C) ← extends(A, B) ∧ subclass(B, C)
  27. Example of transformation subclass(A, A) ← class(A) subclass(A, object) ←

    class(A) subclass(A, C) ← extends(A, B) ∧ subclass(B, C) = subclass(A, A) ← class(A) κ1 subclass(A, object) ← class(A) κ2 subclass(A, C) ← extends(A, B) ∧ subclass(B, C) κ3
  28. Example of transformation subclass(A, A) ← class(A) subclass(A, object) ←

    class(A) subclass(A, C) ← extends(A, B) ∧ subclass(B, C) = subclass(A, A) ← class(A) κ1 subclass(A, object) ← class(A) κ2 subclass(A, C) ← extends(A, B) ∧ subclass(B, C) κ3 = subclass(A, A) κ1(X) ← class(A) X subclass(A, object) κ2(X) ← class(A) X subclass(A, C) κ3(X,Y ) ← extends(A, B) X ∧ subclass(B, C) Y
  29. Example of transformation subclass(A, A) ← class(A) subclass(A, object) ←

    class(A) subclass(A, C) ← extends(A, B) ∧ subclass(B, C) = subclass(A, A) ← class(A) κ1 subclass(A, object) ← class(A) κ2 subclass(A, C) ← extends(A, B) ∧ subclass(B, C) κ3 = subclass(A, A) κ1(X) ← class(A) X subclass(A, object) κ2(X) ← class(A) X subclass(A, C) κ3(X,Y ) ← extends(A, B) X ∧ subclass(B, C) Y = subclass(A, A, κ1(X)) ← class(A, X) subclass(A, object, κ2(X)) ← class(A, X) subclass(A, C, κ3(X, Y )) ← extends(A, B, X) ∧ subclass(B, C, Y )
  30. Properties of − Logic programs can be made productive by

    construction (productivity checking is hard!)
  31. Properties of − Logic programs can be made productive by

    construction (productivity checking is hard!) Simple, easy to implement, inductive and compositional
  32. Properties of − Logic programs can be made productive by

    construction (productivity checking is hard!) Simple, easy to implement, inductive and compositional Sound and complete both inductively and coinductively!
  33. Properties of − Logic programs can be made productive by

    construction (productivity checking is hard!) Simple, easy to implement, inductive and compositional Sound and complete both inductively and coinductively! Given a logic program P and an atom A, for some term τ: A ∈ MP ⇐⇒ A τ ∈ M P A ∈ Mco P ⇐⇒ A τ ∈ Mco P (MP and Mco P are the inductive and coinductive model of P, respectively)
  34. Contents Corecursion in abstract compilation Co-LP and abstract compilation S-resolution

    & abstract compilation Productivity of logic programs Conclusions
  35. Conclusions The system we propose is divided into three phases:

    1. abstract compilation (object-oriented source logic program) 2. transformation ensuring productivity 3. S-resolution for type-checking/inference queries
  36. Conclusions The system we propose is divided into three phases:

    1. abstract compilation (object-oriented source logic program) 2. transformation ensuring productivity 3. S-resolution for type-checking/inference queries Pros: very precise static type analysis for object-oriented languages support for parametric and data polymorphism modularity: the system is parametric w.r.t. the resolution method inference and type annotation work together seamlessly
  37. Conclusions The system we propose is divided into three phases:

    1. abstract compilation (object-oriented source logic program) 2. transformation ensuring productivity 3. S-resolution for type-checking/inference queries Pros: very precise static type analysis for object-oriented languages support for parametric and data polymorphism modularity: the system is parametric w.r.t. the resolution method inference and type annotation work together seamlessly Cons: sometimes inferred types may not have a finite regular representation (probably) undecidable: union and record types together are very expressive
  38. Related work D. Ancona and G. Lagorio. Coinductive type systems

    for object-oriented languages. ECOOP, 2009. L. Simon, A. Mallya, A. Bansal and G. Gupta. Coinductive logic programming. ICLP, 2006. E. Komendantskaya and P. Johann. Structural Resolution: a Framework for Coinductive Proof Search and Proof Construction in Horn Clause Logic. Submitted to ACM Transactions in Computational Logic, 2015. P. Fu and E. Komendantskaya. Operational semantics of resolution and productivity in Horn clause logic. Formal Aspects of Computing, 2017.