A Constraint-Solving Approach to Faust Program Type Checking - - PowerPoint PPT Presentation

a constraint solving approach to faust program type
SMART_READER_LITE
LIVE PREVIEW

A Constraint-Solving Approach to Faust Program Type Checking - - PowerPoint PPT Presentation

A Constraint-Solving Approach to Faust Program Type Checking Constraint Programming Meets Verification 2014 Workhsop Imr Frotier de la Messelire 1 , Pierre Jouvelot 1 , Jean-Pierre Talpin 2 1 MINES ParisTech, PSL Research University 2 INRIA


slide-1
SLIDE 1

A Constraint-Solving Approach to Faust Program Type Checking

Constraint Programming Meets Verification 2014 Workhsop

Imré Frotier de la Messelière1, Pierre Jouvelot1, Jean-Pierre Talpin2

1MINES ParisTech, PSL Research University 2INRIA

September 8, 2014

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 1 / 26

slide-2
SLIDE 2

Contents

1

Faust program type checking

2

Constraint-solving approach

3

Handling the multirate version of Faust

4

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 2 / 26

slide-3
SLIDE 3

1

Faust program type checking

2

Constraint-solving approach

3

Handling the multirate version of Faust

4

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 3 / 26

slide-4
SLIDE 4

Faust program type checking

Motivation

Specification and implementation of a new type inference algorithm for Faust Inspiration from:

◮ Hindley-Milner’s algorithm W [3] ◮ the algebraic reconstruction approach of Jouvelot and Gifford [1]

Formally proven static typing system = ⇒ Better reliability and efficiency

Constraint-programming approach

Use of constraints as the foundation of the whole typing process Contrary to more standard approaches adopting techniques based on substitutions and principal types Creation of large and multi-sorted constraint systems that will need to be processed efficiently

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 4 / 26

slide-5
SLIDE 5

Faust program type checking

Type syntax for a Faust monorate expression

expression_type ::= (beam_type,beam_type) beam_type ::= signal_type list signal_type ::= base_type [x,x] base_type ::= int | float x ∈ Z

Type examples

1 = ⇒ ( ( ) , (int [-2,2]) ) 2 = ⇒ ( ( ) , (int [0,3]) ) + = ⇒ ( (int [-20,20], int [-20,20]), (int [-40,40]) ) 1 , 2 : + = ⇒ ( ( ) , (int [-40,40]) )

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 5 / 26

slide-6
SLIDE 6

Faust program type checking

Typing rules : = ⇒ Type specification for programmers

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 6 / 26

slide-7
SLIDE 7

Faust program type checking

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 7 / 26

slide-8
SLIDE 8

Faust program type checking

Type checking overview

Algorithm in two parts: a classic type inference algorithm, coupled with the generation of typing constraints a solver (1) to determine if the resulting constraints system is decidable and (2) to provide a mapping yielding the type of Faust expressions

Implementation

First prototype in OCaml Rewriting in C++ = ⇒ Inclusion within the current Faust compiler Based on the type checking algorithm:

◮ Input: Faust expression ◮ Output: type of the Faust expression or “fail”

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 8 / 26

slide-9
SLIDE 9

1

Faust program type checking

2

Constraint-solving approach

3

Handling the multirate version of Faust

4

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 9 / 26

slide-10
SLIDE 10

Constraint-solving approach

Origin of constraints

Environment T: mapping of Faust identifiers to their types Identifiers’ types plugged into the typing rules

Constraints implementation

Type templates with type variables in the environment + : ( (int [a1,b1], int [a2,b2]), (int [a1+a2,b1+b2]) ) Templates implemented by replacing type variables by actual values or unification variables (buffer values) 1 , 1 : + = ⇒ + : ( (int [-1,1], int [-1,1]), (int [-2,2]) ) Unification variables = variables for constraints Different possible instances, based on subtyping: 1 , 10 : + = ⇒ + : ( (int [-1,1], int [-10,10]), (int [-11,11]) )

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 10 / 26

slide-11
SLIDE 11

Constraint-solving approach

Predicates syntax

p ∈ P ::= true | e b e e ∈ E ::= i | o1 e | e o2 e b ∈ B ::= = | < | ≤ | > | ≥

  • 1 ∈ O1 ::= sin | cos | ...
  • 2 ∈ O2 ::= + | − | ...

i ∈ I

Constraints syntax

c ∈ C ::= ( p list , i list ) | c ∪ c where, for c = (ps,is) and c′ = (ps′,is′) ∈ C, c ∪ c′ = (ps @ ps′ , is @ is′)

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 11 / 26

slide-12
SLIDE 12

Constraint-solving approach

Constrained types

constrained_type ::= ( expression_type , c ) Result of the constraint generation part of the type checking algorithm Solver input = c Solver output = Mapping m from unification variables to values Application of m to expression_type = ⇒ Type (Global result of the algorithm)

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 12 / 26

slide-13
SLIDE 13

Constraint-solving approach

Solver

Solving handled by existing solvers, using SMT-LIB as a common representation framework for constraints Currently using Z3 Possibility to design a lighter solver, only using theories involved in the algorithm? Output = mapping of unification variables to values

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 13 / 26

slide-14
SLIDE 14

1

Faust program type checking

2

Constraint-solving approach

3

Handling the multirate version of Faust

4

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 14 / 26

slide-15
SLIDE 15

Handling the multirate version of Faust

vectorize: Input signal at rate f = ⇒ Output signal at rate f/n serialize: Input signal at rate f = ⇒ Output signal at rate n × f [ ]: element access #: concatenation

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 15 / 26

slide-16
SLIDE 16

Handling the multirate version of Faust

Type syntax for a Faust multirate expression

expression_type ::= (beam_type,beam_type) beam_type ::= signal_type list signal_type ::= faust_typerate faust_type ::= base_type [x,x] | vectorn(faust_type) base_type ::= int | float rate ∈ Q+ x ∈ Z n ∈ N

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 16 / 26

slide-17
SLIDE 17

Handling the multirate version of Faust

Input sample rate = 44000 Hz:

1 , 2 : vectorize = ⇒ ( ( ) , ( vector2(int [-1,1])22000 ) ) 1 , 2 : vectorize : serialize = ⇒ ( ( ) , ( int [-1,1]44000 ) ) 1 , 2 : vectorize , 1 : [ ] = ⇒ ( ( ) , ( int [-1,1]22000 ) ) ( 1,2 : vectorize) , ( 6,3 : vectorize) : # = ⇒ ( ( ) , ( vector5(int [-10,10])22000 ) ) 1 , 2 : vectorize , 3 : vectorize = ⇒ ( ( ) , ( vector3( vector2(int [-1,1]) )22000 ) )

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 17 / 26

slide-18
SLIDE 18

Handling the multirate version of Faust

Additional environment entries in T: T(vectorize) = (τ f ,int[n,n]f ′) − → (vectorn(τ)f/n) T(serialize) = (vectorn(τ)f ) − → (τ f×n) T([ ]) = (vectorn(τ)f ,int[0,n − 1]f ) − → (τ f ) T(#) = (vectorm(τ)f ,vectorn(τ)f ) − → (vectorm+n(τ)f )

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 18 / 26

slide-19
SLIDE 19

1

Faust program type checking

2

Constraint-solving approach

3

Handling the multirate version of Faust

4

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 19 / 26

slide-20
SLIDE 20

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 20 / 26

slide-21
SLIDE 21

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 21 / 26

slide-22
SLIDE 22

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 22 / 26

slide-23
SLIDE 23

Type checking examples and results

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 23 / 26

slide-24
SLIDE 24

Conclusion

Faustine + Faust Type checker = interpreter + type checker for the multirate version of Faust Link between the classic typing approach, based on substitutions, and the constraint programming approach Future work:

◮ Performance statistics on type checking benchmarks ◮ Constraint solving =

⇒ Constraint programming

◮ Study of different combinations between the typing and constraint

programming approaches

◮ Possible case of study: Optimization of the loop case in the Faust syntax ◮ Integration into the C++ compiler of Faust

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 24 / 26

slide-25
SLIDE 25

Selective bibliography

[1] Jouvelot, P ., and Gifford, D. K. Algebraic Reconstruction of Types and Effects. In Proceedings of the 1991 ACM Conference on Principles of Programming Languages. ACM, New-York, 1991. [2] Jouvelot, P ., and Orlarey, Y. Dependent vector types for data structuring in multirate Faust. In Computer Languages, Systems & Structures Journal. Elsevier, 2011. [3] Milner, R. A Theory for type polymorphism in programming. In Journal of Computer and Systems Sciences, Vol. 17, pages 348-375. 1978.

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 25 / 26

slide-26
SLIDE 26

A Constraint-Solving Approach to Faust Program Type Checking

Constraint Programming Meets Verification 2014 Workhsop

Imré Frotier de la Messelière1, Pierre Jouvelot1, Jean-Pierre Talpin2

1MINES ParisTech, PSL Research University 2INRIA

September 8, 2014

  • I. Frotier de la Messelière, P

. Jouvelot, J.-P . Talpin () Constraint-Solving Approach to Faust Type Checking September 8, 2014 26 / 26