Towards a verified Lustre compiler with modular reset Timothy Bourke - - PowerPoint PPT Presentation

towards a verified lustre compiler with modular reset
SMART_READER_LITE
LIVE PREVIEW

Towards a verified Lustre compiler with modular reset Timothy Bourke - - PowerPoint PPT Presentation

Towards a verified Lustre compiler with modular reset Timothy Bourke 1,2 Llio Brun 1,2 Marc Pouzet 3,2,1 1 Inria Paris 2 DI ENS 3 UPMC SCOPES 2018 May 30, 2018 Screenshot from ANSYS/Esterel Techologies SCADE Suite 1 / 14 Screenshot from


slide-1
SLIDE 1

Towards a verified Lustre compiler with modular reset

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

1Inria Paris 2DI ENS 3UPMC

SCOPES 2018 — May 30, 2018

slide-2
SLIDE 2

Screenshot from ANSYS/Esterel Techologies SCADE Suite

1 / 14

slide-3
SLIDE 3

node controller (joy_v , joy_h , pos_l , pos_r : int) returns (i_l , i_r : int); let

  • mega_l = pos_l - (pos_l

fby pos_l); v_err2 = (2 * v_ref) - (omega_l + omega_r); ... tel

Screenshot from ANSYS/Esterel Techologies SCADE Suite

1 / 14

slide-4
SLIDE 4

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification

2 / 14

slide-5
SLIDE 5

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification
  • Onerous and expensive development process

2 / 14

slide-6
SLIDE 6

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification
  • Onerous and expensive development process
  • No formal proof of correctness

2 / 14

slide-7
SLIDE 7

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification
  • Onerous and expensive development process
  • No formal proof of correctness

Goal

Develop a formally verified code generator

2 / 14

slide-8
SLIDE 8

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification
  • Onerous and expensive development process
  • No formal proof of correctness

Goal

Develop a formally verified code generator

  • formal verification, mechanized proofs, proof assistant (eg. Coq1)

1The Coq Development Team (2016): The Coq proof assistant reference manual 2 / 14

slide-9
SLIDE 9

Context

State of the art: Scade

  • Specification norms (DO-178C), industrial certification
  • Onerous and expensive development process
  • No formal proof of correctness

Goal

Develop a formally verified code generator

  • formal verification, mechanized proofs, proof assistant (eg. Coq)
  • Scade
  • Lighten the qualification to norms
  • Provide a complete semantics

2 / 14

slide-10
SLIDE 10

Lustre:1 example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

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

programming synchronous systems”

3 / 14

slide-11
SLIDE 11

Lustre: example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

y0 y ′ 4 y h 2

3 / 14

slide-12
SLIDE 12

Lustre: example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

y0 5 y ′ 4 2 y 8 h 2 2

3 / 14

slide-13
SLIDE 13

Lustre: example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

y0 5 10 y ′ 4 2 1 y 8 12 h 2 2 2

3 / 14

slide-14
SLIDE 14

Lustre: example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

y0 5 10 – y ′ 4 2 1 – y 8 12 – h 2 2 2 –

3 / 14

slide-15
SLIDE 15

Lustre: example h + z-1

y’ y0 y euler

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel

y0 5 10 – 15 · · · y ′ 4 2 1 – 3 · · · y 8 12 – 14 · · · h 2 2 2 – 2 · · ·

3 / 14

slide-16
SLIDE 16

Lustre: example h + z-1

y’ y0 y euler

euler

x0 x’ x main

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel node main(x0 , x’: int) returns (x: int) let x = euler(x0 , x’); tel

3 / 14

slide-17
SLIDE 17

Scade-like state machines and reset primitive

GPS INS

h + z-1

xGPS x’ x s x x s s NAV

4 / 14

slide-18
SLIDE 18

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

4 / 14

slide-19
SLIDE 19

Scade-like state machines and reset primitive

  • Can be compiled into Lustre
  • Reset:
  • Reset the state of a node,
  • ie. reinitialize the fbys

GPS INS

h + z-1

xGPS x’ x s x x s s NAV

4 / 14

slide-20
SLIDE 20

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)

GPS INS

h + z-1

xGPS x’ x s x x s s NAV

4 / 14

slide-21
SLIDE 21

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

4 / 14

slide-22
SLIDE 22

Non-modular reset

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel node main(x0 , x’: int) returns (x: int) let x = euler(x0 , x’); tel node euler(y0 , y’: int; r: bool) returns (y: int) var h: int; let y = if r then y0 else (y0 fby (y + y’ * h)); h = 2; tel node main(x0 , x’: int) returns (x: int) var r: bool; let x = euler(x0 , x’, r); r = (x’ > 42); tel

5 / 14

slide-23
SLIDE 23

Non-modular reset

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel node main(x0 , x’: int) returns (x: int) let x = euler(x0 , x’); tel node euler(y0 , y’: int; r: bool) returns (y: int) var h: int; let y = if r then y0 else (y0 fby (y + y’ * h)); h = 2; tel node main(x0 , x’: int) returns (x: int) var r: bool; let x = euler(x0 , x’, r); r = (x’ > 42); tel

5 / 14

slide-24
SLIDE 24

Vélus:1 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

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

Compiler for Lustre”

6 / 14

slide-25
SLIDE 25

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

Implemented in Coq and (some) OCaml

6 / 14

slide-26
SLIDE 26

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

  • Validated parsing (menhir –coq) a

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

slide-27
SLIDE 27

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

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

6 / 14

slide-28
SLIDE 28

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

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

aAuger (2013): “Compilation certifiée de SCADE/LUSTRE” 6 / 14

slide-29
SLIDE 29

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

node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let init = true fby false; y1 = 0 fby (y + y’ * h); y = if init then y0 else y1; h = 2; tel

e0 fby e → if (true fby false) then e0 else (0 fby e)

6 / 14

slide-30
SLIDE 30

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

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

6 / 14

slide-31
SLIDE 31

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

node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let init = true fby false; y1 = 0 fby (y + y’ * h); y = if init then y0 else y1; h = 2; tel node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let h = 2; y = if init then y0 else y1; init = true fby false; y1 = 0 fby (y + y’ * h); tel

6 / 14

slide-32
SLIDE 32

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

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

6 / 14

slide-33
SLIDE 33

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

node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let h = 2; y = if init then y0 else y1; init = true fby false; y1 = 0 fby (y + y’ * h); tel class euler { memory init: bool; memory y1: int; step(y0 , y’: int) returns (y: int) var h: int { h := 2; if (state(init)) { y := y0 } else { y := state(y1) }; state(init) := false; state(y1) := y + y’ * h } reset () { state(init) := true; state(y1) := 0 } } 6 / 14

slide-34
SLIDE 34

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

node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let h = 2; y = if init then y0 else y1; init = true fby false; y1 = 0 fby (y + y’ * h); tel class euler { memory init: bool; memory y1: int; step(y0 , y’: int) returns (y: int) var h: int { h := 2; if (state(init)) { y := y0 } else { y := state(y1) }; state(init) := false; state(y1) := y + y’ * h } reset () { state(init) := true; state(y1) := 0 } } 6 / 14

slide-35
SLIDE 35

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

node euler(y0 , y’: int) returns (y: int) var h, y1: int; init: bool; let h = 2; y = if init then y0 else y1; init = true fby false; y1 = 0 fby (y + y’ * h); tel class euler { memory init: bool; memory y1: int; step(y0 , y’: int) returns (y: int) var h: int { h := 2; if (state(init)) { y := y0 } else { y := state(y1) }; state(init) := false; state(y1) := y + y’ * h } reset () { state(init) := true; state(y1) := 0 } } 6 / 14

slide-36
SLIDE 36

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

node main(x0 , s: int) returns (x: int) let x = euler(x0 , s); tel class main { instance x: euler; step(x0 , x’: int) returns (x: int) { x := euler(x).step(x0 , x’) } reset () { euler(x).reset () } } 6 / 14

slide-37
SLIDE 37

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

node main(x0 , s: int) returns (x: int) let x = euler(x0 , s); tel class main { instance x: euler; step(x0 , x’: int) returns (x: int) { x := euler(x).step(x0 , x’) } reset () { euler(x).reset () } } 6 / 14

slide-38
SLIDE 38

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

  • 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

6 / 14

slide-39
SLIDE 39

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

  • 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

6 / 14

slide-40
SLIDE 40

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

  • 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”

6 / 14

slide-41
SLIDE 41

Adding the modular reset

  • Node application: f (⇀

e) call the node f

7 / 14

slide-42
SLIDE 42

Adding the modular reset

  • Node application: f (⇀

e) call the node f

  • Modular reset: f (⇀

e) every r reset the internal state (delays) of f at each tick of r

7 / 14

slide-43
SLIDE 43

Adding the modular reset

  • Node application: f (⇀

e) call the node f

  • Modular reset: f (⇀

e) every r reset the internal state (delays) of f at each tick of r

node euler(y0 , y’: int; r: bool) returns (y: int) var h: int; let y = if r then y0 else (y0 fby (y + y’ * h)); h = 2; tel node main(x0 , x’: int) returns (x: int) var r: bool; let x = euler(x0 , x’, r); r = (x’ > 42); tel node euler(y0 , y’: int) returns (y: int) var h: int; let y = y0 fby (y + y’ * h); h = 2; tel node main(x0 , x’: int) returns (x: int) var r: bool; let x = euler(x0 , x’) every r; r = (x’ > 42); tel

7 / 14

slide-44
SLIDE 44

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

8 / 14

slide-45
SLIDE 45

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

r F i nat(i) nat(i) every r

8 / 14

slide-46
SLIDE 46

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

r F F i 5 nat(i) 1 nat(i) every r 1

8 / 14

slide-47
SLIDE 47

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

r F F T i 5 10 nat(i) 1 2 nat(i) every r 1 10

8 / 14

slide-48
SLIDE 48

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

r F F T F i 5 10 15 nat(i) 1 2 3 nat(i) every r 1 10 11

8 / 14

slide-49
SLIDE 49

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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

8 / 14

slide-50
SLIDE 50

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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

8 / 14

slide-51
SLIDE 51

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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

8 / 14

slide-52
SLIDE 52

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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

8 / 14

slide-53
SLIDE 53

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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

8 / 14

slide-54
SLIDE 54

A simpler example

node nat(i: int) returns (n: int) let n = i fby (n + 1); tel

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 · · ·

8 / 14

slide-55
SLIDE 55

Semantics?

A recursive intuition, not a valid definition in Lustre 1

node true_until (r: bool) returns (c: bool) let c = if r then false else (true fby c); tel node reset_f(x: int , r: bool) returns (y: int) var c: bool; let c = true_until (r); y = merge c (f(x when c)) (reset_f ((x, r) whenot c)); tel

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

Programs”

9 / 14

slide-56
SLIDE 56

Semantics?

A recursive intuition, not a valid definition in Lustre 1

node true_until (r: bool) returns (c: bool) let c = if r then false else (true fby c); tel node reset_f(x: int , r: bool) returns (y: int) var c: bool; let c = true_until (r); y = merge c (f(x when c)) (reset_f ((x, r) whenot c)); tel

Definable in Coq but as an intricate co-inductive predicate: we need another solution

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

Programs”

9 / 14

slide-57
SLIDE 57

Infinitely unrolling the recursion

r F F T F F T F T F · · · i 5 10 15 20 25 30 35 40 · · ·

10 / 14

slide-58
SLIDE 58

Infinitely unrolling the recursion

mask: a cofixpoint written in Coq r F F T F F T F T F · · · 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 · · ·

10 / 14

slide-59
SLIDE 59

Infinitely unrolling the recursion

mask: a cofixpoint written in Coq r F F T F F T F T F · · · 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 · · ·

10 / 14

slide-60
SLIDE 60

Formal semantics

Node application ⊢

eqn ⇀

x = f (⇀ e)

11 / 14

slide-61
SLIDE 61

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

eqn ⇀

x = f (⇀ e)

11 / 14

slide-62
SLIDE 62

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e)

11 / 14

slide-63
SLIDE 63

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e)

11 / 14

slide-64
SLIDE 64

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

11 / 14

slide-65
SLIDE 65

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

11 / 14

slide-66
SLIDE 66

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

11 / 14

slide-67
SLIDE 67

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolmask# rs ⊢

exp ⇀

e ⇓ ⇀ es ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

11 / 14

slide-68
SLIDE 68

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolmask# rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

11 / 14

slide-69
SLIDE 69

Formal semantics

Node application ⊢

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) Modular reset ⊢

var r ⇓ rs

rk = boolmask# 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

11 / 14

slide-70
SLIDE 70

Formal semantics in Coq

Inductive sem_equation : history → clock → equation → Prop := ... | SeqApp: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_node f ess xss → sem_equation H b (EqApp xs ck f es None) | SeqReset: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_var H r rs → sem_reset f (bool_mask rs) ess xss → sem_equation H b (EqApp xs ck f es (Some r)) ... with sem_node : ident → list vstream → list vstream → Prop := ... with sem_reset : ident → clock → list vstream → list vstream → Prop := SReset: (∀ k, sem_node f (map (mask k rk) xss) (map (mask k rk) yss)) → sem_reset f rk xss yss. 12 / 14

slide-71
SLIDE 71

Formal semantics in Coq

Inductive sem_equation : history → clock → equation → Prop := ... | SeqApp: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_node f ess xss → sem_equation H b (EqApp xs ck f es None) | SeqReset: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_var H r rs → sem_reset f (bool_mask rs) ess xss → sem_equation H b (EqApp xs ck f es (Some r)) ... with sem_node : ident → list vstream → list vstream → Prop := ... with sem_reset : ident → clock → list vstream → list vstream → Prop := SReset: (∀ k, sem_node f (map (mask k rk) xss) (map (mask k rk) yss)) → sem_reset f rk xss yss.

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e)

12 / 14

slide-72
SLIDE 72

Formal semantics in Coq

Inductive sem_equation : history → clock → equation → Prop := ... | SeqApp: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_node f ess xss → sem_equation H b (EqApp xs ck f es None) | SeqReset: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_var H r rs → sem_reset f (bool_mask rs) ess xss → sem_equation H b (EqApp xs ck f es (Some r)) ... with sem_node : ident → list vstream → list vstream → Prop := ... with sem_reset : ident → clock → list vstream → list vstream → Prop := SReset: (∀ k, sem_node f (map (mask k rk) xss) (map (mask k rk) yss)) → sem_reset f rk xss yss.

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) ⊢

var r ⇓ rs

rk = boolmask# rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r

12 / 14

slide-73
SLIDE 73

Formal semantics in Coq

Inductive sem_equation : history → clock → equation → Prop := ... | SeqApp: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_node f ess xss → sem_equation H b (EqApp xs ck f es None) | SeqReset: Forall2 (sem_lexp H b) es ess → Forall2 (sem_var H) xs xss → sem_var H r rs → sem_reset f (bool_mask rs) ess xss → sem_equation H b (EqApp xs ck f es (Some r)) ... with sem_node : ident → list vstream → list vstream → Prop := ... with sem_reset : ident → clock → list vstream → list vstream → Prop := SReset: (∀ k, sem_node f (map (mask k rk) xss) (map (mask k rk) yss)) → sem_reset f rk xss yss.

exp ⇀

e ⇓ ⇀ es ⊢

node f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) ⊢

var r ⇓ rs

rk = boolmask# rs ⊢

exp ⇀

e ⇓ ⇀ es rk ⊢

reset f (⇀

es) ⇓ ⇀ xs ⊢

var ⇀

x ⇓ ⇀ xs ⊢

eqn ⇀

x = f (⇀ e) every r ∀k, ⊢

node f (mask k rk ⇀

xs) ⇓ mask k rk ⇀ ys rk ⊢

reset f (⇀

xs) ⇓ ⇀ ys

12 / 14

slide-74
SLIDE 74

Naive compilation

y = f (x) every r:

if (ck_r) { if (r) { f(y).reset () }; }; y := f(y).step(x)

13 / 14

slide-75
SLIDE 75

Naive compilation

y = f (x) every r:

if (ck_r) { if (r) { f(y).reset () }; }; y := f(y).step(x)

Problem with fusion optimization:

node main(x0 , s: int; ck , r: bool) returns (x: int) var v, w: int when ck; let v = filter(s when ck); w = euler ((xo , v) when ck) every r; x = merge ck w 0; tel step(x0 , s: int; ck , r: bool) returns (x: int) var v, w : int { if (ck) { v := filter(v).step(s) }; if (r) { euler(w).reset () }; if (ck) { w := euler(w).step(x0 , v) }; if (ck) { x := w } else { x := 0 } } 13 / 14

slide-76
SLIDE 76

Naive compilation

y = f (x) every r:

if (ck_r) { if (r) { f(y).reset () }; }; y := f(y).step(x)

Problem with fusion optimization:

node main(x0 , s: int; ck , r: bool) returns (x: int) var v, w: int when ck; let v = filter(s when ck); w = euler ((xo , v) when ck) every r; x = merge ck w 0; tel step(x0 , s: int; ck , r: bool) returns (x: int) var v, w : int { if (r) { euler(w).reset () }; if (ck) { v := filter(v).step(s); w := euler(w).step(x0 , v); x := w } else { x := 0 } } 13 / 14

slide-77
SLIDE 77

Conclusion

Summary

  • A verified compiler for Lustre
  • Simple semantics for modular reset

14 / 14

slide-78
SLIDE 78

Conclusion

Summary

  • A verified compiler for Lustre
  • Simple semantics for modular reset

Future Work

  • Compilation and proof of correctness
  • A need for a new intermediate language
  • Automata

14 / 14

slide-79
SLIDE 79

Co-inductive streams based inductive semantics

Expressions

Inductive sem_lexp: history → 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 os → sem_lexp H b (Ewhen e x k) os | Sunop: ∀ H b op e ty es os , sem_lexp H b e es → lift1 op (typeof e) es os → sem_lexp H b (Eunop op e ty) os | Sbinop: ∀ H b op e1 e2 ty es1 es2 os , sem_lexp H b e1 es1 → sem_lexp H b e2 es2 → lift2 op (typeof e1) (typeof e2) es1 es2 os → sem_lexp H b (Ebinop op e1 e2 ty) os. 1 / 6

slide-80
SLIDE 80

Co-inductive streams based inductive semantics

Control expressions

Inductive sem_cexp: history → clock → cexp → vstream → Prop := | Smerge: ∀ H b x t f xs ts fs os , sem_var H x xs → sem_cexp H b t ts → sem_cexp H b f fs → merge xs ts fs os → sem_cexp H b (Emerge x t f) os | Site: ∀ H b e t f es ts fs os , sem_lexp H b e es → sem_cexp H b t ts → sem_cexp H b f fs → ite es ts fs os → sem_cexp H b (Eite e t f) os | Sexp: ∀ H b e es , sem_lexp H b e es → sem_cexp H b (Eexp e) es.

2 / 6

slide-81
SLIDE 81

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-82
SLIDE 82

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-83
SLIDE 83

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-84
SLIDE 84

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-85
SLIDE 85

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-86
SLIDE 86

States correspondence

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

6 / 6

slide-87
SLIDE 87

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-88
SLIDE 88

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-89
SLIDE 89

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-90
SLIDE 90

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-91
SLIDE 91

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-92
SLIDE 92

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