Verifying the Lustre modular reset Timothy Bourke 1,2 Llio Brun 1,2 - - PowerPoint PPT Presentation

verifying the lustre modular reset
SMART_READER_LITE
LIVE PREVIEW

Verifying the Lustre modular reset Timothy Bourke 1,2 Llio Brun 1,2 - - PowerPoint PPT Presentation

Verifying the Lustre modular reset Timothy Bourke 1,2 Llio Brun 1,2 Marc Pouzet 3,2,1 1 Inria Paris 2 DI ENS 3 UPMC SYNCHRON18 November 29, 2018 The problem Adding the modular reset to Vlus 1 / 22 The problem Adding the modular


slide-1
SLIDE 1

Verifying the Lustre modular reset

Timothy Bourke1,2 Lélio Brun1,2 Marc Pouzet 3,2,1

1Inria Paris 2DI ENS 3UPMC

SYNCHRON’18 — November 29, 2018

slide-2
SLIDE 2

The problem

Adding the modular reset to Vélus

1 / 22

slide-3
SLIDE 3

The problem

Adding the modular reset to Vélus

A real challenge

  • Semantics: several alternatives

1 / 22

slide-4
SLIDE 4

The problem

Adding the modular reset to Vélus

A real challenge

  • Semantics: several alternatives
  • Compilation

1 / 22

slide-5
SLIDE 5

The problem

Adding the modular reset to Vélus

A real challenge

  • Semantics: several alternatives
  • Compilation
  • Update the existing proof: fundamental modifications

1 / 22

slide-6
SLIDE 6

The problem

Adding the modular reset to Vélus

A real challenge

  • Semantics: several alternatives
  • Compilation
  • Update the existing proof: fundamental modifications
  • Optimization

1 / 22

slide-7
SLIDE 7

Lustre:1 example h + z-1

y’ y0 y euler

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l

1Caspi, Halbwachs, Pilaud, and Plaice (1987): “LUSTRE: A declarative language for

programming synchronous systems”

2 / 22

slide-8
SLIDE 8

Lustre:1 example h + z-1

y’ y0 y euler

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l

euler

x0 x’ x main

node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) l e t x = e u l e r ( x0 , x ’ ) ; t e l

1Caspi, Halbwachs, Pilaud, and Plaice (1987): “LUSTRE: A declarative language for

programming synchronous systems”

2 / 22

slide-9
SLIDE 9

SCADE-like state machines and reset primitive

GPS INS

h + z-1

xGPS x’ x s x x s s NAV

3 / 22

slide-10
SLIDE 10

SCADE-like state machines and reset primitive

Can be compiled into Lustre GPS INS

h + z-1

xGPS x’ x s x x s s NAV

3 / 22

slide-11
SLIDE 11

SCADE-like state machines and reset primitive

Can be compiled into Lustre

Reset:

  • Reset the state of a node,
  • ie. reinitialize the fbys
  • Useful primitive

(not only for state machines)

  • How?

GPS INS

h + z-1

xGPS x’ x s x x s s NAV

3 / 22

slide-12
SLIDE 12

Without modular reset

Node application: f (e1, . . . , en) call the node f

node e u l e r ( y0 , y ’ : r e a l ; r : bool ) returns ( y : r e a l ) var h : r e a l ; l e t y = i f r then y0 e l s e ( y0 fby ( y + y ’ ∗ h ) ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ , r ) ; r = ( x ’ > 42 ) ; t e l

4 / 22

slide-13
SLIDE 13

Without modular reset

Node application: f (e1, . . . , en) call the node f

node e u l e r ( y0 , y ’ : r e a l ; r : bool ) returns ( y : r e a l ) var h : r e a l ; l e t y = i f r then y0 e l s e ( y0 fby ( y + y ’ ∗ h ) ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ , r ) ; r = ( x ’ > 42 ) ; t e l

4 / 22

slide-14
SLIDE 14

Without modular reset With modular reset

Node application: f (e1, . . . , en) call the node f Modular reset: f (e1, . . . , en) every r reset the internal state (delays) of f at each tick of r

node e u l e r ( y0 , y ’ : r e a l ; r : bool ) returns ( y : r e a l ) var h : r e a l ; l e t y = i f r then y0 e l s e ( y0 fby ( y + y ’ ∗ h ) ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ , r ) ; r = ( x ’ > 42 ) ; t e l node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42 ) ; t e l

4 / 22

slide-15
SLIDE 15

Without modular reset With modular reset

Node application: f (e1, . . . , en) call the node f Modular reset: f (e1, . . . , en) every r reset the internal state (delays) of f at each tick of r

node e u l e r ( y0 , y ’ : r e a l ; r : bool ) returns ( y : r e a l ) var h : r e a l ; l e t y = i f r then y0 e l s e ( y0 fby ( y + y ’ ∗ h ) ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ , r ) ; r = ( x ’ > 42 ) ; t e l node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42 ) ; t e l

4 / 22

slide-16
SLIDE 16

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l

5 / 22

slide-17
SLIDE 17

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F i nat(i) nat(i) every r

5 / 22

slide-18
SLIDE 18

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F i 5 nat(i) 1 nat(i) every r 1

5 / 22

slide-19
SLIDE 19

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T i 5 10 nat(i) 1 2 nat(i) every r 1 10

5 / 22

slide-20
SLIDE 20

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F i 5 10 15 nat(i) 1 2 3 nat(i) every r 1 10 11

5 / 22

slide-21
SLIDE 21

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F i 5 10 15 20 nat(i) 1 2 3 4 nat(i) every r 1 10 11 12

5 / 22

slide-22
SLIDE 22

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F T i 5 10 15 20 25 nat(i) 1 2 3 4 5 nat(i) every r 1 10 11 12 25

5 / 22

slide-23
SLIDE 23

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F T F i 5 10 15 20 25 30 nat(i) 1 2 3 4 5 6 nat(i) every r 1 10 11 12 25 26

5 / 22

slide-24
SLIDE 24

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F T F T i 5 10 15 20 25 30 35 nat(i) 1 2 3 4 5 6 7 nat(i) every r 1 10 11 12 25 26 35

5 / 22

slide-25
SLIDE 25

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F T F T F i 5 10 15 20 25 30 35 40 nat(i) 1 2 3 4 5 6 7 8 nat(i) every r 1 10 11 12 25 26 35 36

5 / 22

slide-26
SLIDE 26

A simpler example

node nat ( i : i n t ) returns (n : i n t ) l e t n = i fby (n + 1 ) ; t e l r F F T F F T F T F · · · i 5 10 15 20 25 30 35 40 · · · nat(i) 1 2 3 4 5 6 7 8 · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

5 / 22

slide-27
SLIDE 27

Semantics?

A recursive intuition, not a valid definition in Lustre:2

node t r u e _ u n t i l ( r : bool ) returns ( c : bool ) l e t c = i f r then f a l s e e l s e ( true fby c ) ; t e l node r e s e t _ f ( x : int , r : bool ) returns ( y : i n t ) var c : bool ; l e t c = t r u e _ u n t i l ( r ) ; y = merge c ( f ( x when c )) ( r e s e t _ f (( x , r ) whenot c ) ) ; t e l

r F F F T F T F · · · c T T T F F F F · · ·

2Hamon and Pouzet (2000): “Modular Resetting of Synchronous Data-flow

Programs”

6 / 22

slide-28
SLIDE 28

Infinitely unrolling the recursion

r F F T F F T F T F · · · i 5 10 15 20 25 30 35 40 · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-29
SLIDE 29

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-30
SLIDE 30

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-31
SLIDE 31

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-32
SLIDE 32

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-33
SLIDE 33

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-34
SLIDE 34

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · mask 2 r i – – – – – 25 30 – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-35
SLIDE 35

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · mask 2 r i – – – – – 25 30 – – · · · nat(mask 2 r i) – – – – – 25 26 – – · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-36
SLIDE 36

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · mask 2 r i – – – – – 25 30 – – · · · nat(mask 2 r i) – – – – – 25 26 – – · · · mask 3 r i – – – – – – – 35 40 · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-37
SLIDE 37

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · mask 2 r i – – – – – 25 30 – – · · · nat(mask 2 r i) – – – – – 25 26 – – · · · mask 3 r i – – – – – – – 35 40 · · · nat(mask 3 r i) – – – – – – – 35 36 · · · nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-38
SLIDE 38

Infinitely unrolling the recursion

r F F T F F T F T F · · · count r 1 1 1 2 2 3 3 · · · i 5 10 15 20 25 30 35 40 · · · mask 0 r i 5 – – – – – – – · · · nat(mask 0 r i) 1 – – – – – – – · · · mask 1 r i – – 10 15 20 – – – – · · · nat(mask 1 r i) – – 10 11 12 – – – – · · · mask 2 r i – – – – – 25 30 – – · · · nat(mask 2 r i) – – – – – 25 26 – – · · · mask 3 r i – – – – – – – 35 40 · · · nat(mask 3 r i) – – – – – – – 35 36 · · · . . . nat(i) every r 1 10 11 12 25 26 35 36 · · ·

7 / 22

slide-39
SLIDE 39

Formal semantics

Node application ⊢

eqn ⇀

x = f (⇀ e)

8 / 22

slide-40
SLIDE 40

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

eqn ⇀

x = f (⇀ e)

8 / 22

slide-41
SLIDE 41

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e)

8 / 22

slide-42
SLIDE 42

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e)

8 / 22

slide-43
SLIDE 43

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

eqn ⇀

x = f (⇀ e) every r

8 / 22

slide-44
SLIDE 44

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

exp ⇀

e ⇓ ⇀ es ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

8 / 22

slide-45
SLIDE 45

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

exp ⇀

e ⇓ ⇀ es ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

8 / 22

slide-46
SLIDE 46

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolof rs ⊢

exp ⇀

e ⇓ ⇀ es ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

8 / 22

slide-47
SLIDE 47

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolof rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

8 / 22

slide-48
SLIDE 48

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolof rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r rk ⊢

reset f (⇀

xs) ⇓ ⇀ ys

8 / 22

slide-49
SLIDE 49

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolof rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r Use of an universally quantified relation as a constraint: ∀k, ⊢

node f (mask k rk ⇀

xs) ⇓ mask k rk ⇀ ys rk ⊢

reset f (⇀

xs) ⇓ ⇀ ys

8 / 22

slide-50
SLIDE 50

Vélus:3 a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

Implemented in Coq and (some) OCaml

3Bourke, Brun, Dagand, Leroy, Pouzet, and Rieg (2017): “A Formally Verified

Compiler for Lustre”

9 / 22

slide-51
SLIDE 51

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq) a

aJourdan, Pottier, and Leroy (2012): “Validating LR(1) parsers” 9 / 22

slide-52
SLIDE 52

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information

9 / 22

slide-53
SLIDE 53

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalizationa

aAuger (2013): “Compilation certifiée de SCADE/LUSTRE” 9 / 22

slide-54
SLIDE 54

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalization
  • Scheduling of dataflow equations

9 / 22

slide-55
SLIDE 55

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalization
  • Scheduling of dataflow equations
  • Translation to intermediate Obc code

9 / 22

slide-56
SLIDE 56

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

node e u l e r ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h , y1 : r e a l ; i n i t : bool ; l e t h = 2; y = i f i n i t then y0 e l s e y1 ; i n i t = t r u e fby f a l s e ; y1 = 0 fby ( y + y ’ ∗ h ) ; t e l c l a s s e u l e r { memory i n i t : bool ; memory y1 : r e a l ; step ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h : r e a l { h := 2; i f ( s t a t e ( i n i t ) ) { y := y0 } e l s e { y := s t a t e ( y1 ) }; s t a t e ( i n i t ) := f a l s e ; s t a t e ( y1 ) := y + y ’ ∗ h } r e s e t ( ) { s t a t e ( i n i t ) := t r u e ; s t a t e ( y1 ) := 0 } }

9 / 22

slide-57
SLIDE 57

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

node e u l e r ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h , y1 : r e a l ; i n i t : bool ; l e t h = 2; y = i f i n i t then y0 e l s e y1 ; i n i t = t r u e fby f a l s e ; y1 = 0 fby ( y + y ’ ∗ h ) ; t e l c l a s s e u l e r { memory i n i t : bool ; memory y1 : r e a l ; step ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h : r e a l { h := 2; i f ( s t a t e ( i n i t ) ) { y := y0 } e l s e { y := s t a t e ( y1 ) }; s t a t e ( i n i t ) := f a l s e ; s t a t e ( y1 ) := y + y ’ ∗ h } r e s e t ( ) { s t a t e ( i n i t ) := t r u e ; s t a t e ( y1 ) := 0 } }

9 / 22

slide-58
SLIDE 58

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

node e u l e r ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h , y1 : r e a l ; i n i t : bool ; l e t h = 2; y = i f i n i t then y0 e l s e y1 ; i n i t = t r u e fby f a l s e ; y1 = 0 fby ( y + y ’ ∗ h ) ; t e l c l a s s e u l e r { memory i n i t : bool ; memory y1 : r e a l ; step ( y0 , y ’ : r e a l ) r e t u r n s ( y : r e a l ) var h : r e a l { h := 2; i f ( s t a t e ( i n i t ) ) { y := y0 } e l s e { y := s t a t e ( y1 ) }; s t a t e ( i n i t ) := f a l s e ; s t a t e ( y1 ) := y + y ’ ∗ h } r e s e t ( ) { s t a t e ( i n i t ) := t r u e ; s t a t e ( y1 ) := 0 } }

9 / 22

slide-59
SLIDE 59

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

node main ( x0 , x ’ : r e a l ) r e t u r n s ( x : r e a l ) l e t x = e u l e r ( x0 , x ’ ) ; t e l c l a s s main { i n s t a n c e i : e u l e r ; step ( x0 , x ’ : r e a l ) r e t u r n s ( x : r e a l ) { x := e u l e r ( i ) . step ( x0 , x ’ ) } r e s e t ( ) { e u l e r ( i ) . r e s e t () } }

9 / 22

slide-60
SLIDE 60

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

node main ( x0 , x ’ : r e a l ) r e t u r n s ( x : r e a l ) l e t x = e u l e r ( x0 , x ’ ) ; t e l c l a s s main { i n s t a n c e i : e u l e r ; step ( x0 , x ’ : r e a l ) r e t u r n s ( x : r e a l ) { x := e u l e r ( i ) . step ( x0 , x ’ ) } r e s e t ( ) { e u l e r ( i ) . r e s e t () } }

9 / 22

slide-61
SLIDE 61

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalization
  • Scheduling of dataflow equations
  • Translation to intermediate Obc code
  • Optimization of intermediate Obc code

9 / 22

slide-62
SLIDE 62

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert node main ( x0 , x ’ : r e a l ; ck : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l when ck ; l e t v = f i l t e r ( x ’ when ck ) ; w = e u l e r ( x0 when ck , v ) ; x = merge ck w ( −1); t e l step ( x0 , x ’ : r e a l ; ck : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l { i f ( ck ) { v := f i l t e r ( i ) . step ( x ’ ) }; i f ( ck ) { w := e u l e r ( j ) . step ( x0 , v ) } ; i f ( ck ) { x := w } e l s e { x := −1 } } 9 / 22

slide-63
SLIDE 63

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert step ( x0 , x ’ : r e a l ; ck : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l { i f ( ck ) { v := f i l t e r ( i ) . step ( x ’ ) }; i f ( ck ) { w := e u l e r ( j ) . step ( x0 , v ) }; i f ( ck ) { x := w } e l s e { x := −1 } } step ( x0 , x ’ : r e a l ; ck : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l { i f ( ck ) { v := f i l t e r ( i ) . step ( x ’ ) ; w := e u l e r ( j ) . step ( x0 , v ) ; x := w } e l s e { x := −1 } } 9 / 22

slide-64
SLIDE 64

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalization
  • Scheduling of dataflow equations
  • Translation to intermediate Obc code
  • Optimization of intermediate Obc code
  • Generation of Clight code

9 / 22

slide-65
SLIDE 65

Vélus: a verified compiler

Unannotated Lustre parsing Lustre elaboration N-Lustre normalization SN-Lustre scheduling Obc translation Clight generation Assembly compilation printing fusion optimization

dataflow imperative

CompCert

  • Validated parsing (menhir –coq)
  • Elaboration to get clock and type information
  • Not yet implemented: normalization
  • Scheduling of dataflow equations
  • Translation to intermediate Obc code
  • Optimization of intermediate Obc code
  • Generation of Clight code
  • Rely on CompCerta for compilation

aBlazy, Dargaye, and Leroy (2006): “Formal verification of a C compiler

front-end”

9 / 22

slide-66
SLIDE 66

First issue: naive compilation

y = f ( x ) every r ; i f ( ck_r ) { i f ( r ) { f ( i ) . r e s e t () }; }; y := f ( i ) . step ( x )

10 / 22

slide-67
SLIDE 67

First issue: naive compilation

y = f ( x ) every r ; i f ( ck_r ) { i f ( r ) { f ( i ) . r e s e t () }; }; y := f ( i ) . step ( x )

Problem with fusion optimization:

node main ( x0 , x ’ : r e a l ; ck , r : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l when ck ; l e t v = f i l t e r ( x ’ when ck ) ; w = e u l e r (( x0 , v ) when ck ) ev er y r ; x = merge ck w 0; t e l

10 / 22

slide-68
SLIDE 68

First issue: naive compilation

y = f ( x ) every r ; i f ( ck_r ) { i f ( r ) { f ( i ) . r e s e t () }; }; y := f ( i ) . step ( x )

Problem with fusion optimization:

node main ( x0 , x ’ : r e a l ; ck , r : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l when ck ; l e t v = f i l t e r ( x ’ when ck ) ; w = e u l e r (( x0 , v ) when ck ) ev er y r ; x = merge ck w 0; t e l step ( x0 , x ’ : r e a l ; ck , r : bool ) r e t u r n s ( x : r e a l ) var v , w : r e a l { i f ( ck ) { v := f i l t e r ( i ) . step ( x ’ ) }; i f ( r ) { e u l e r ( j ) . r e s e t () }; i f ( ck ) { w := e u l e r ( j ) . step ( x0 , v ) }; i f ( ck ) { x := w } e l s e { x := 0 } }

10 / 22

slide-69
SLIDE 69

First issue: naive compilation

y = f ( x ) every r ; i f ( ck_r ) { i f ( r ) { f ( i ) . r e s e t () }; }; y := f ( i ) . step ( x )

Problem with fusion optimization:

node main ( x0 , x ’ : r e a l ; ck , r : bool ) r e t u r n s ( x : r e a l ) var v , w: r e a l when ck ; l e t v = f i l t e r ( x ’ when ck ) ; w = e u l e r (( x0 , v ) when ck ) ev er y r ; x = merge ck w 0; t e l step ( x0 , x ’ : r e a l ; ck , r : bool ) r e t u r n s ( x : r e a l ) var v , w : r e a l { i f ( r ) { e u l e r ( j ) . r e s e t () }; i f ( ck ) { v := f i l t e r ( i ) . step ( x ’ ) ; w := e u l e r ( j ) . step ( x0 , v ) ; x := w } e l s e { x := 0 } }

10 / 22

slide-70
SLIDE 70

Second issue: proof of correctness

N-Lustre

V ω × ⇀ V ω N-Lustre

V ω × M × ⇀ V ω

M i M’ x v0 · · · vω

Obc S × ⇀ V → S × ⇀ V too weak for a direct proof by induction “easy”: ∃M “hard”

11 / 22

slide-71
SLIDE 71

Second issue: proof of correctness

N-Lustre

V ω × ⇀ V ω N-Lustre

V ω × M × ⇀ V ω

M i M’ x v0 · · · vω

Obc S × ⇀ V → S × ⇀ V too weak for a direct proof by induction “easy”: ∃M “hard”

11 / 22

slide-72
SLIDE 72

Second issue: proof of correctness

N-Lustre

V ω × ⇀ V ω N-Lustre

V ω × M × ⇀ V ω

M i M’ x v0 · · · vω

Obc S × ⇀ V → S × ⇀ V too weak for a direct proof by induction “easy”: ∃M “hard”

11 / 22

slide-73
SLIDE 73

Second issue: proof of correctness

N-Lustre

V ω × ⇀ V ω N-Lustre

V ω × M × ⇀ V ω

M i M’ x v0 · · · vω

Obc S × ⇀ V → S × ⇀ V too weak for a direct proof by induction “easy”: ∃M “hard”

11 / 22

slide-74
SLIDE 74

Second issue: proof of correctness

What about the reset?

  • It is possible to give a semantics in the intermediate semantics model

as well

11 / 22

slide-75
SLIDE 75

Second issue: proof of correctness

What about the reset?

  • It is possible to give a semantics in the intermediate semantics model

as well

  • The “easy” proof can be done

11 / 22

slide-76
SLIDE 76

Second issue: proof of correctness

What about the reset?

  • It is possible to give a semantics in the intermediate semantics model

as well

  • The “easy” proof can be done
  • The “hard” one cannot

11 / 22

slide-77
SLIDE 77

Second issue: proof of correctness

The granularity of the intermediate model is not precise enough!

11 / 22

slide-78
SLIDE 78

Second issue: proof of correctness

The granularity of the intermediate model is not precise enough! |

?

|

N-Lustre Obc reset step Indeed, because of the reset, the memory can reach 2 different states within the same synchronous instant

11 / 22

slide-79
SLIDE 79

Second issue: proof of correctness

The granularity of the intermediate model is not precise enough! |

?

|

N-Lustre Obc reset step Indeed, because of the reset, the memory can reach 2 different states within the same synchronous instant → Transient states

11 / 22

slide-80
SLIDE 80

SyBloc

  • Problems with the compilation scheme
  • Problems with the semantics models

12 / 22

slide-81
SLIDE 81

SyBloc

  • Problems with the compilation scheme
  • Problems with the semantics models

Propose a new intermediate language

  • Declarative, like N-Lustre

12 / 22

slide-82
SLIDE 82

SyBloc

  • Problems with the compilation scheme
  • Problems with the semantics models

Propose a new intermediate language

  • Declarative, like N-Lustre
  • Where the reset construct is treated as a separate “equation”

12 / 22

slide-83
SLIDE 83

SyBloc

  • Problems with the compilation scheme
  • Problems with the semantics models

Propose a new intermediate language

  • Declarative, like N-Lustre
  • Where the reset construct is treated as a separate “equation”
  • Mimicking the intermediate memory model of N-Lustre

12 / 22

slide-84
SLIDE 84

SyBloc

  • Problems with the compilation scheme
  • Problems with the semantics models

Propose a new intermediate language

  • Declarative, like N-Lustre
  • Where the reset construct is treated as a separate “equation”
  • Mimicking the intermediate memory model of N-Lustre

N-Lustre SyBloc translation Obc translation fusion optimization scheduling 12 / 22

slide-85
SLIDE 85

N-Lustre SyBloc

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42); t e l

13 / 22

slide-86
SLIDE 86

N-Lustre SyBloc

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42); t e l block e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l block main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; instance i : e u l e r ; l e t () = i . reset_on r ; x = i . e u l e r ( x0 , x ’ ) ; r = ( x ’ > 42); t e l

13 / 22

slide-87
SLIDE 87

N-Lustre SyBloc

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42); t e l block e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l block main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; instance i : e u l e r ; l e t () = i . reset_on r ; x = i . e u l e r ( x0 , x ’ ) ; r = ( x ’ > 42); t e l

13 / 22

slide-88
SLIDE 88

N-Lustre SyBloc

node e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l node main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; l e t x = e u l e r ( x0 , x ’ ) every r ; r = ( x ’ > 42); t e l block e u l e r ( y0 , y ’ : r e a l ) returns ( y : r e a l ) var h : r e a l ; l e t y = y0 fby ( y + y ’ ∗ h ) ; h = 2; t e l block main ( x0 , x ’ : r e a l ) returns ( x : r e a l ) var r : bool ; instance i : e u l e r ; l e t () = i . reset_on r ; x = i . e u l e r ( x0 , x ’ ) ; r = ( x ’ > 42); t e l

13 / 22

slide-89
SLIDE 89

SyBloc formal semantics: memory

A tree with instances as nodes and the values of the fbys together with a boolean reset flag at the leaves : { values: stream val; reset: stream bool } M i M’ x mv =

  • values := v0v1v2 · · ·

reset := r0r1r2 · · ·

  • Notation:

instance M[i] = M′ register M(x) = mv

14 / 22

slide-90
SLIDE 90

SyBloc formal semantics: fby

M ⊢

eqn x = c0 fby e

15 / 22

slide-91
SLIDE 91

SyBloc formal semantics: fby

const c0 ⇓ v0

M ⊢

eqn x = c0 fby e

15 / 22

slide-92
SLIDE 92

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

M ⊢

eqn x = c0 fby e

15 / 22

slide-93
SLIDE 93

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

M ⊢

eqn x = c0 fby e

15 / 22

slide-94
SLIDE 94

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

15 / 22

slide-95
SLIDE 95

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

mfby x v0 vs M xs

15 / 22

slide-96
SLIDE 96

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mfby x v0 vs M xs

15 / 22

slide-97
SLIDE 97

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 mfby x v0 vs M xs

15 / 22

slide-98
SLIDE 98

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 ∀n, fbyspec n v0 (vs n) mv (xs n) mfby x v0 vs M xs

15 / 22

slide-99
SLIDE 99

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 ∀n, fbyspec n v0 (vs n) mv (xs n) mfby x v0 vs M xs fbyspec n v0 v mv (mv.values n)

15 / 22

slide-100
SLIDE 100

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 ∀n, fbyspec n v0 (vs n) mv (xs n) mfby x v0 vs M xs next n mv v0 v fbyspec n v0 v mv (mv.values n) next n mv v0 v := mv.values (n + 1) =

  • v0

if mv.reset (n + 1), v

  • therwise.

15 / 22

slide-101
SLIDE 101

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 ∀n, fbyspec n v0 (vs n) mv (xs n) mfby x v0 vs M xs next n mv v0 v fbyspec n v0 v mv (mv.values n) fbyspec n v0 – mv – next n mv v0 v := mv.values (n + 1) =

  • v0

if mv.reset (n + 1), v

  • therwise.

15 / 22

slide-102
SLIDE 102

SyBloc formal semantics: fby

const c0 ⇓ v0

exp e ⇓ vs

var x ⇓ xs

mfby x v0 vs M xs M ⊢

eqn x = c0 fby e

M(x) = mv mv.values 0 = v0 ∀n, fbyspec n v0 (vs n) mv (xs n) mfby x v0 vs M xs next n mv v0 v fbyspec n v0 v mv (mv.values n) next n mv v0 (mv.values n) fbyspec n v0 – mv – next n mv v0 v := mv.values (n + 1) =

  • v0

if mv.reset (n + 1), v

  • therwise.

15 / 22

slide-103
SLIDE 103

SyBloc formal semantics: reset

M ⊢

eqn() = i.reset_on r

16 / 22

slide-104
SLIDE 104

SyBloc formal semantics: reset

M[i] = M′ M ⊢

eqn() = i.reset_on r

16 / 22

slide-105
SLIDE 105

SyBloc formal semantics: reset

M[i] = M′ ⊢

var r ⇓ rs

M ⊢

eqn() = i.reset_on r

16 / 22

slide-106
SLIDE 106

SyBloc formal semantics: reset

M[i] = M′ ⊢

var r ⇓ rs

reset_memory (boolof rs) M′ M ⊢

eqn() = i.reset_on r

16 / 22

slide-107
SLIDE 107

SyBloc formal semantics: reset

M[i] = M′ ⊢

var r ⇓ rs

reset_memory (boolof rs) M′ M ⊢

eqn() = i.reset_on r

reset_memory rk M

16 / 22

slide-108
SLIDE 108

SyBloc formal semantics: reset

M[i] = M′ ⊢

var r ⇓ rs

reset_memory (boolof rs) M′ M ⊢

eqn() = i.reset_on r

∀x mv, M(x) = mv → ∀n, rk n = true → mv.reset n = true reset_memory rk M

16 / 22

slide-109
SLIDE 109

SyBloc formal semantics: reset

M[i] = M′ ⊢

var r ⇓ rs

reset_memory (boolof rs) M′ M ⊢

eqn() = i.reset_on r

∀i M′, M[i] = M′ → reset_memory rk M′ ∀x mv, M(x) = mv → ∀n, rk n = true → mv.reset n = true reset_memory rk M

16 / 22

slide-110
SLIDE 110

From N-Lustre to SyBloc

  • Overall ideas of the “easy” proof + complications
  • main theorem:

sem_node G f ⇀ xs ⇀ ys → ∃M, sem_block (translate G) f ⇀ xs M ⇀ ys

f

xs

ys →

f

M

xs

ys

17 / 22

slide-111
SLIDE 111

An issue within the mutual induction

Correctness for reset:

   IH :

∀f ⇀ xs ⇀ ys, sem_node G f ⇀ xs ⇀ ys → ∃M, sem_block (translate G) f ⇀ xs M ⇀ ys

    →

sem_reset G f r ⇀ xs ⇀ ys → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M

f

xs

ys r →

f

M reset_memory r M

xs

ys

18 / 22

slide-112
SLIDE 112

An issue within the mutual induction

Inversion on sem_reset:

   IH :

∀f ⇀ xs ⇀ ys, sem_node G f ⇀ xs ⇀ ys → ∃M, sem_block (translate G) f ⇀ xs M ⇀ ys

    →

(∀k, sem_node G f (mask k r ⇀ xs) (mask k r ⇀ ys)) → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M . . . . . .

f

xsk

r

ysk

r

f

xsk+1

r

ysk+1

r

f

M reset_memory r M

xs

ys

18 / 22

slide-113
SLIDE 113

An issue within the mutual induction

Applying the mutual induction hypothesis:

  • ∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀

xs) Mk (mask k r ⇀ ys)

∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M . . . . . .

f

Mk

xsk

r

ysk

r

f

Mk+1

xsk+1

r

ysk+1

r

f

M reset_memory r M

xs

ys

18 / 22

slide-114
SLIDE 114

An issue within the mutual induction

  • ∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀

xs) Mk (mask k r ⇀ ys)

∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M

The idea

Reconstruct a memory from each memories given by each “slice” k

18 / 22

slide-115
SLIDE 115

Axiom of choice?

  • Our hypothesis:

∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀ xs) Mk (mask k r ⇀ ys)

19 / 22

slide-116
SLIDE 116

Axiom of choice?

  • Our hypothesis:

∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀ xs) Mk (mask k r ⇀ ys)

  • The functional axiom of choice in Coq (standard library):

Axiom f u n c t i o n a l _ c h o i c e : ∀ A B (R: A → B → Prop ) , (∀ x , ∃ y , R x y ) → ∃ f , ∀ x , R x ( f x ) .

19 / 22

slide-117
SLIDE 117

Axiom of choice?

  • Our hypothesis:

∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀ xs) Mk (mask k r ⇀ ys)

  • The functional axiom of choice in Coq (standard library):

Axiom f u n c t i o n a l _ c h o i c e : ∀ A B (R: A → B → Prop ) , (∀ x , ∃ y , R x y ) → ∃ f , ∀ x , R x ( f x ) .

  • Result:

∃FM, ∀k, sem_block (translate G) f (mask k r ⇀ xs) (FM k) (mask k r ⇀ ys)

19 / 22

slide-118
SLIDE 118

Axiom of choice?

  • Our hypothesis:

∀k, ∃Mk, sem_block (translate G) f (mask k r ⇀ xs) Mk (mask k r ⇀ ys)

  • The functional axiom of choice in Coq (standard library):

Axiom f u n c t i o n a l _ c h o i c e : ∀ A B (R: A → B → Prop ) , (∀ x , ∃ y , R x y ) → ∃ f , ∀ x , R x ( f x ) .

  • Result:

∃FM, ∀k, sem_block (translate G) f (mask k r ⇀ xs) (FM k) (mask k r ⇀ ys)

19 / 22

slide-119
SLIDE 119

Reconstructing the memory

(∀k, sem_block (translate G) f (mask k r ⇀ xs) (FM k) (mask k r ⇀ ys)) → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M . . . . . . →

f

FM k

xsk

r

ysk

r

f

FM (k + 1)

xsk+1

r

ysk+1

r

f

M reset_memory r M

xs

ys

20 / 22

slide-120
SLIDE 120

Reconstructing the memory

(∀k, sem_block (translate G) f (mask k r ⇀ xs) (FM k) (mask k r ⇀ ys)) → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M . . . . . . →

f

FM k

xsk

r

ysk

r

f

FM (k + 1)

xsk+1

r

ysk+1

r

f

M reset_memory r M

xs

ys We can use FM to build an M that verify the goal: at each instant n the content of M will be the same as FM k where k is the number of reset seen so far at n.

20 / 22

slide-121
SLIDE 121

Reconstructing the memory

FM Mk i M′k x

· · ·vk

a · · · vk b · · ·

· · ·r k

a · · · r k b · · ·

  • Mk+1

i M′k+1 x

· · ·vk+1

b+1 · · · vk+1 c

· · · · · ·r k+1

b+1 · · · r k+1 c

· · ·

  • M

i M′ x

  • · · · va · · · vbvb+1 · · · vc · · ·

· · · ra · · · rbrb+1 · · · rc · · ·

  • r (b + 1) = true

· · · · · · k k + 1

20 / 22

slide-122
SLIDE 122

Reconstructing the memory

FM Mk i M′k x

· · ·vk

a · · · vk b · · ·

· · ·r k

a · · · r k b · · ·

  • Mk+1

i M′k+1 x

· · ·vk+1

b+1 · · · vk+1 c

· · · · · ·r k+1

b+1 · · · r k+1 c

· · ·

  • M

i M′ x

  • · · · va · · · vbvb+1 · · · vc · · ·

· · · ra · · · rbrb+1 · · · rc · · ·

  • r (b + 1) = true

· · · · · · k k + 1

20 / 22

slide-123
SLIDE 123

Reconstructing the memory

FM Mk i M′k x

· · ·vk

a · · · vk b · · ·

· · ·r k

a · · · r k b · · ·

  • Mk+1

i M′k+1 x

· · ·vk+1

b+1 · · · vk+1 c

· · · · · ·r k+1

b+1 · · · r k+1 c

· · ·

  • M

i M′ x

  • · · · va · · · vbvb+1 · · · vc · · ·

· · · ra · · · rbrb+1 · · · rc · · ·

  • r (b + 1) = true

∀n ∈ [a, b], count r n = k rn = r k

n ||r n

· · · · · · k k + 1

20 / 22

slide-124
SLIDE 124

Reconstructing the memory

FM Mk i M′k x

· · ·vk

a · · · vk b · · ·

· · ·r k

a · · · r k b · · ·

  • Mk+1

i M′k+1 x

· · ·vk+1

b+1 · · · vk+1 c

· · · · · ·r k+1

b+1 · · · r k+1 c

· · ·

  • M

i M′ x

  • · · · va · · · vbvb+1 · · · vc · · ·

· · · ra · · · rbrb+1 · · · rc · · ·

  • r (b + 1) = true

∀n ∈ ]b, c], count r n = k + 1 rn = r k+1

n

||r n · · · · · · k k + 1

20 / 22

slide-125
SLIDE 125

Last issue

reset correctness sem_reset G f r ⇀ xs ⇀ ys → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M

21 / 22

slide-126
SLIDE 126

Last issue

reset correctness sem_reset G f r ⇀ xs ⇀ ys → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M reset_memory ∀i M′, M[i] = M′ → reset_memory rk M′ ∀x mv, M(x) = mv → ∀n, rk n = true → mv.reset n = true reset_memory rk M

21 / 22

slide-127
SLIDE 127

Last issue

reset correctness sem_reset G f r ⇀ xs ⇀ ys → ∃M,

  • sem_block (translate G) f ⇀

xs M ⇀ ys reset_memory r M reset_memory ∀i M′, M[i] = M′ → reset_memory rk M′ ∀x mv, M(x) = mv → ∀n, rk n = true → mv.reset n = true reset_memory rk M

Weak specification on reset flags: they could be true without an actual reset asking

21 / 22

slide-128
SLIDE 128

Conclusion

Summary

  • A verified compiler for Lustre
  • Simple semantics for modular reset
  • An intermediate “hybrid” language between dataflow and imperative

worlds

22 / 22

slide-129
SLIDE 129

Conclusion

Summary

  • A verified compiler for Lustre
  • Simple semantics for modular reset
  • An intermediate “hybrid” language between dataflow and imperative

worlds Future Work

  • Solving the issues
  • Is the semantics of SyBloc too weak?
  • Another model, more intricate?
  • Is the axiom of choice really mandatory?
  • Another way of formalizing the reset in N-Lustre?
  • Complete the proof to Obc
  • State machines

22 / 22

slide-130
SLIDE 130

Co-inductive streams based inductive semantics

Expressions Inductive sem_lexp : h i s t o r y → clock → lexp → vstream → Prop := | Sconst : ∀ H b c cs , cs ≡ const c b → sem_lexp H b ( Econst c ) cs | Svar : ∀ H b x ty xs , sem_var H x xs → sem_lexp H b ( Evar x ty ) xs | Swhen : ∀ H b e x k es xs os , sem_lexp H b e es → sem_var H x xs → when k es xs

  • s →

sem_lexp H b (Ewhen e x k )

  • s

| Sunop : H b op e ty es

  • s ,

1 / 6

slide-131
SLIDE 131

Co-inductive streams based inductive semantics

Control expressions

I n d u c t i v e sem_cexp : h i s t o r y → c l o c k → cexp → vstream → Prop := | Smerge : ∀ H b x t f xs t s f s

  • s ,

sem_var H x xs → sem_cexp H b t t s → sem_cexp H b f f s → merge xs t s f s

  • s →

sem_cexp H b ( Emerge x t f )

  • s

| S i t e : ∀ H b e t f es t s f s

  • s ,

sem_lexp H b e es → sem_cexp H b t t s → sem_cexp H b f f s → i t e es t s f s

  • s →

sem_cexp H b ( E i t e e t f )

  • s

| Sexp : ∀ H b e es , sem_lexp H b e es → sem_cexp H b ( Eexp e ) es .

2 / 6

slide-132
SLIDE 132

N-Lustre: abstract syntax

le := expression | k (constant) | x (variable) | le when x (when) | ⋄ e (unary operator) | e ⊕ e (binary operator) ce := control expression | merge x ce ce (merge) | if x then ce else ce (if) | le (expression) eq := equation | x :: c = ce (def) | x :: c = k fby le (fby) |

x :: c = x(⇀ le ) (app) |

x :: c = x(⇀ le ) every x (reset) n := node | node x(⇀ xty::c ) returns (⇀ xty::c ) [var ⇀ xty::c ] let

eq; tel

3 / 6

slide-133
SLIDE 133

Obc: Abstract Syntax

e := expression | x (local variable) | state(x) (state variable) | k (constant) | ⋄ e (unary operator) | e ⊕ e (binary operator) s := statement | x := e (update) | state(x) := e (state update) | if e then s else s (conditional) |

x := k(i).f (⇀ e) (method call) | s; s (composition) | skip (do nothing) cls := declaration | class k { (class) memory ⇀ xty instance ⇀ ik f (⇀ xty ) returns (⇀ xty ) [var ⇀ xty ] { s } }

4 / 6

slide-134
SLIDE 134

Separation logic in CompCert

predicate massert

                

pred : memory → P foot : block → int → P invar : ∀m m′, pred m → unchanged_on foot m m′ → pred m′

                

notation: m P P.pred m

5 / 6

slide-135
SLIDE 135

Separation logic in CompCert

predicate massert

                

pred : memory → P foot : block → int → P invar : ∀m m′, pred m → unchanged_on foot m m′ → pred m′

                

notation: m P P.pred m conjonction P ∗ Q

      

pred = λ m. (m P) ∧ (m Q) ∧ disjoint P.foot Q.foot foot = λ b ofs. P.foot b ofs ∨ Q.foot b ofs

      

5 / 6

slide-136
SLIDE 136

Separation logic in CompCert

predicate massert

                

pred : memory → P foot : block → int → P invar : ∀m m′, pred m → unchanged_on foot m m′ → pred m′

                

notation: m P P.pred m conjonction P ∗ Q

      

pred = λ m. (m P) ∧ (m Q) ∧ disjoint P.foot Q.foot foot = λ b ofs. P.foot b ofs ∨ Q.foot b ofs

      

pure formula m pure (P) ∗ Q ↔ P ∧ m Q

5 / 6

slide-137
SLIDE 137

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states

6 / 6

slide-138
SLIDE 138

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout)

self pointer

  • ut pointer
  • utput structure

6 / 6

slide-139
SLIDE 139

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout) ∗ pure (wt_env ve (all_vars_of f )) ∗ pure (wt_mem me p c)

the Obc state is well-typed wrt. the context

6 / 6

slide-140
SLIDE 140

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout) ∗ pure (wt_env ve (all_vars_of f )) ∗ pure (wt_mem me p c) ∗ staterep p c me bs ofs

memory me ≈ structure pointed by self

6 / 6

slide-141
SLIDE 141

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout) ∗ pure (wt_env ve (all_vars_of f )) ∗ pure (wt_mem me p c) ∗ staterep p c me bs ofs ∗ blockrep ve coout bo

  • utput of f ≈

coout pointed by out

6 / 6

slide-142
SLIDE 142

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout) ∗ pure (wt_env ve (all_vars_of f )) ∗ pure (wt_mem me p c) ∗ staterep p c me bs ofs ∗ blockrep ve coout bo ∗ varsrep f ve le

parameters and local variables ≈ temporaries

6 / 6

slide-143
SLIDE 143

States correspondence

Obc: (me, ve), f ∈ c ∈ p Clight: (e, le, m) match_states pure (le(self) = (bs, ofs)) ∗ pure (le(out) = (bo, 0)) ∗ pure (ge(f_c) = coout) ∗ pure (wt_env ve (all_vars_of f )) ∗ pure (wt_mem me p c) ∗ staterep p c me bs ofs ∗ blockrep ve coout bo ∗ varsrep f ve le ∗ subrep_range e

subcalls output structures allocation

6 / 6