Towards a Coq-verified compiler from Esterel to circuits: 2 years - - PowerPoint PPT Presentation

towards a coq verified compiler from esterel to circuits
SMART_READER_LITE
LIVE PREVIEW

Towards a Coq-verified compiler from Esterel to circuits: 2 years - - PowerPoint PPT Presentation

Towards a Coq-verified compiler from Esterel to circuits: 2 years later Lionel R ieg Yale University Synchron 2016 December 5th, 2016 1/20 Objective: prove the compilation scheme for Esterel Esterel Synchronous dataflow language


slide-1
SLIDE 1

Towards a Coq-verified compiler from Esterel to circuits: 2 years later

Lionel Rieg

Yale University

Synchron 2016

December 5th, 2016

1/20

slide-2
SLIDE 2

Objective: prove the compilation scheme for Esterel

◮ Esterel

◮ Synchronous dataflow language ◮ Control-oriented, imperative-flavored

unlike Lustre

◮ Verified compilation to circuit

◮ Draft book by Gérard Berry

[The Constructive Semantics of Pure Esterel]

◮ Modular compilation ◮ Same spirit as Compcert:

semantics is refined/preserved by compilation

◮ Restrictions

◮ Compilation toward digital circuits only ◮ No data, only Pure Esterel v.5 ◮ No reincarnation, left for future work

2/20

slide-3
SLIDE 3

Syntax of Kernel Esterel (instructions)

p, q := nothing 1 pause s?? await (immediate) s !s emit s s ? p , q if s then p else q end s ⊃ p suspend p when s p ; q p ; q p | q p || q p∗ loop p end k k 2 exit T k k is the level {p} trap T in p end ↑ p p\s signal s in p end

+ macros:

halt := 1∗ await s := {(s ? 2 , 1)∗} abort p when s := {(s ? 2 , 1)∗ | (↑ p ; 2)}

3/20

slide-4
SLIDE 4

Hello world in Esterel: ABRO

Idea:

◮ as soon as both A and B are received, emit O ◮ reinitialize when R is received

halt := loop pause end abort p when s := trap T in loop (if s then exit T else pause end) end || (p ; exit T)

4/20

slide-5
SLIDE 5

Hello world in Esterel: ABRO

Idea:

◮ as soon as both A and B are received, emit O ◮ reinitialize when R is received

(await A || await B) ;

emit O ; halt

halt := loop pause end abort p when s := trap T in loop (if s then exit T else pause end) end || (p ; exit T)

4/20

slide-6
SLIDE 6

Hello world in Esterel: ABRO

Idea:

◮ as soon as both A and B are received, emit O ◮ reinitialize when R is received

abort

(await A || await B) ;

emit O ; halt when R

halt := loop pause end abort p when s := trap T in loop (if s then exit T else pause end) end || (p ; exit T)

4/20

slide-7
SLIDE 7

Hello world in Esterel: ABRO

Idea:

◮ as soon as both A and B are received, emit O ◮ reinitialize when R is received

loop abort

(await A || await B) ;

emit O ; halt when R end

halt := loop pause end abort p when s := trap T in loop (if s then exit T else pause end) end || (p ; exit T)

4/20

slide-8
SLIDE 8

Semantics of an Esterel Program

At each instant, either:

◮ One (macro-)step p E′, k

− − − − →

E

p′ with:

◮ Inputs E ◮ Outputs E′ ◮ A return code k

0 = done, 1 = pending, 2+ = exceptions

◮ Several microsteps

◮ No E′ and k: they can be read from p′ ◮ No Can/Must functions

5/20

slide-9
SLIDE 9

Semantics of an Esterel Program

At each instant, either:

◮ One (macro-)step p E′, k

− − − − →

E

p′ with:

◮ Inputs E ◮ Outputs E′ ◮ A return code k

0 = done, 1 = pending, 2+ = exceptions

◮ Several microsteps

◮ No E′ and k: they can be read from p′ ◮ No Can/Must functions

Some remarks:

◮ E and E′ are maps from declared signals to {−, ⊥, +} ◮ Instantaneous communication: E′ ⊆ E

Not compositional if not done carefully

5/20

slide-10
SLIDE 10

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

6/20

slide-11
SLIDE 11

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

6/20

slide-12
SLIDE 12

Constructive Semantics

◮ Rewrite the program

◮ Erase dead code & only keep active parts ◮ Duplicate loop bodies

loop p end ≡ p ; loop p end

◮ Use Can/Must for local signals

◮ s+ if s must be emitted ◮ s− if s cannot be emitted ◮ Avoid causality problems & non-determinism

forbid “if s then emit s else nothing end”

◮ Usual style of programming language semantics

convenient for high-level reasoning about programs

◮ The if-then rule:

s+ ∈ E p

E′, k

֒− − − − →

E

p′ s ? p , q

E′, k

֒− − − − →

E

p′

7/20

slide-13
SLIDE 13

Execution of ABRO

loop abort

(await A || await B) ;

emit O ; halt when R end

8/20

slide-14
SLIDE 14

Execution of ABRO

loop abort

(await A || await B) ;

emit O ; halt when R end {B}

8/20

slide-15
SLIDE 15

Execution of ABRO

abort

(await A || await B);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B}

8/20

slide-16
SLIDE 16

Execution of ABRO

abort

(await A || nothing);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B}

8/20

slide-17
SLIDE 17

Execution of ABRO

abort

(await A || nothing);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A,

8/20

slide-18
SLIDE 18

Execution of ABRO

abort

(nothing || nothing);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A,

8/20

slide-19
SLIDE 19

Execution of ABRO

abort emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A,

8/20

slide-20
SLIDE 20

Execution of ABRO

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O}

8/20

slide-21
SLIDE 21

Execution of ABRO

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B}

8/20

slide-22
SLIDE 22

Execution of ABRO

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R}

8/20

slide-23
SLIDE 23

Execution of ABRO

loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R}

8/20

slide-24
SLIDE 24

Execution of ABRO

abort

(await A || await B);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R}

8/20

slide-25
SLIDE 25

Execution of ABRO

abort

(await A || await B);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R} =⇒ {A, B,

8/20

slide-26
SLIDE 26

Execution of ABRO

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R} =⇒ {A, B, O}

8/20

slide-27
SLIDE 27

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program

9/20

slide-28
SLIDE 28

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program

9/20

slide-29
SLIDE 29

State Semantics

◮ Evaluation as moving annotations on the source code

◮ The underlying program never changes ◮ Pointers indicate where the execution is

several pointers because of parallelism

◮ Close to circuits:

activated pause = activated register

◮ Two types of programs:

◮ Inert program p ◮ State

p = program under evaluation

◮ Term p = either

p or p

◮ Two sets of rules:

◮ Start: program → term ◮ Resume: state → term

10/20

slide-30
SLIDE 30

Constructive vs. State: the if-then Rule

◮ Constructive Semantics

s+ ∈ E p

E′, k

֒− − − − →

E

p′ s ? p , q

E′, k

֒− − − − →

E

p′

◮ State Semantics

◮ Start rule

s+ ∈ E p

E′, k

֒ − − − − − ։s

E

p′ s ? p , q

E′, k

֒ − − − − − ։s

E

s ? p′ , q

◮ Resume rule

  • p

E′, k

֒ − − − − − − ։r

E

p′ s ? p , q

E′, k

֒ − − − − − − ։r

E

s ? p′ , q

11/20

slide-31
SLIDE 31

ABRO again

Constructive Semantics State Semantics

loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ; halt when R end

12/20

slide-32
SLIDE 32

ABRO again

Constructive Semantics State Semantics

loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ; halt when R end {B}

12/20

slide-33
SLIDE 33

ABRO again

Constructive Semantics State Semantics

abort

(await A || nothing);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(

await A || await B) ; emit O ; halt

  • when R

end {B}

12/20

slide-34
SLIDE 34

ABRO again

Constructive Semantics State Semantics

abort

(await A || nothing);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(

await A || await B) ; emit O ; halt

  • when R

end {B} =⇒ {A, O}

12/20

slide-35
SLIDE 35

ABRO again

Constructive Semantics State Semantics

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ;

  • halt
  • when R

end {B} =⇒ {A, O}

12/20

slide-36
SLIDE 36

ABRO again

Constructive Semantics State Semantics

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ;

  • halt
  • when R

end {B} =⇒ {A, O} =⇒ {B}

12/20

slide-37
SLIDE 37

ABRO again

Constructive Semantics State Semantics

loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ; halt when R end {B} =⇒ {A, O} =⇒ {B} =⇒ {R}

12/20

slide-38
SLIDE 38

ABRO again

Constructive Semantics State Semantics

abort

(await A || await B);

emit O ; halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(

await A ||

  • await B) ;

emit O ; halt

  • when R

end {B} =⇒ {A, O} =⇒ {B} =⇒ {R}

12/20

slide-39
SLIDE 39

ABRO again

Constructive Semantics State Semantics

abort halt when R ; loop abort

(await A || await B) ;

emit O ; halt when R end loop abort

(await A || await B) ;

emit O ;

  • halt
  • when R

end {B} =⇒ {A, O} =⇒ {B} =⇒ {R} =⇒ {A, B, O}

12/20

slide-40
SLIDE 40

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program ⊕ execution as annotations ⊕ correspondance with circuit states ⊖ two sets of rules

13/20

slide-41
SLIDE 41

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program ⊕ execution as annotations ⊕ correspondance with circuit states ⊖ two sets of rules

13/20

slide-42
SLIDE 42

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program ⊕ execution as annotations ⊕ correspondance with circuit states ⊖ two sets of rules

13/20

slide-43
SLIDE 43

Microstep Semantics: Entering the Instant

◮ Key idea:

◮ Atomic steps on source code

that match electric propagation through gates

◮ No more cheating with Must/Can!

◮ Inspiration:

◮ Fixpoint semantics: increase the information ◮ Circuit translation

program

14/20

slide-44
SLIDE 44

Microstep Semantics: Entering the Instant

◮ Key idea:

◮ Atomic steps on source code

that match electric propagation through gates

◮ No more cheating with Must/Can!

◮ Inspiration:

◮ Fixpoint semantics: increase the information ◮ Circuit translation

program

}

Return codes p or p ^

}

Orders to the circuit 14/20

slide-45
SLIDE 45

Microstep Semantics: Entering the Instant

◮ Key idea:

◮ Atomic steps on source code

that match electric propagation through gates

◮ No more cheating with Must/Can!

◮ Inspiration:

◮ Fixpoint semantics: increase the information ◮ Circuit translation

program

}

Return codes p or p ^

}

Orders to the circuit 14/20

slide-46
SLIDE 46

Microstep Semantics: Entering the Instant

◮ Key idea:

◮ Atomic steps on source code

that match electric propagation through gates

◮ No more cheating with Must/Can!

◮ Inspiration:

◮ Fixpoint semantics: increase the information ◮ Circuit translation

program

}

Return codes p or p ^

}

Orders to the circuit

◮ In practice:

◮ Recursively add input/output colors to programs ◮ Microstep rules update them ◮ Until all colors are totally defined

14/20

slide-47
SLIDE 47

Translation of s ? p , q

if s then P else Q end

GO RES SUSP KILL SEL K0 K1 K2 ... E E' P GO RES SUSP KILL SEL K0 K1 K2 ... E E' Q GO s E' SEL K0 K1 K2 RE S SUSP KILL E

15/20

slide-48
SLIDE 48

Microsteps Rules for if-then

= input

  • = output

sb ∈ E

(Go ) < (Go ) ∧ b = [Go ← (Go ) ∧ b] (s ? (p◦) , (q◦))◦

E′, k

− − − − →

E

(s ? (p◦) , (q◦))◦ p◦

E′, k

− − − − →

E

p′◦ (s ? (p◦) , (q◦))◦

E′, k

− − − − →

E

(s ? (p′◦) , (q◦))◦

  • < (◦ ∨ ◦)

(s ? (p◦) , (q◦))◦

E′, k

− − − − →

E

(s ? (p◦) , (q◦))(◦ ∨ ◦)

16/20

slide-49
SLIDE 49

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{0,1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-50
SLIDE 50

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{0,1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-51
SLIDE 51

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{0,1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-52
SLIDE 52

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-53
SLIDE 53

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-54
SLIDE 54

First Instant of ABRO in Microsteps

loop abort

  • (

( await A ◦{1})

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-55
SLIDE 55

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{0,1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-56
SLIDE 56

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-57
SLIDE 57

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-58
SLIDE 58

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦{0}) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-59
SLIDE 59

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-60
SLIDE 60

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦{0}) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-61
SLIDE 61

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦{0}

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-62
SLIDE 62

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • {0,1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-63
SLIDE 63

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • {1}

when R ◦{0,1} end ◦{1}

{ B }

17/20

slide-64
SLIDE 64

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B ◦{0,1}) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • {1}

when R ◦{1} end ◦{1}

{ B }

17/20

slide-65
SLIDE 65

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B •0) )◦{1} ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • {1}

when R ◦{1} end ◦{1}

{ B }

17/20

slide-66
SLIDE 66

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B •0) )•1 ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • {1}

when R ◦{1} end ◦{1}

{ B }

17/20

slide-67
SLIDE 67

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B •0) )•1 ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • 1

when R ◦{1} end ◦{1}

{ B }

17/20

slide-68
SLIDE 68

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B •0) )•1 ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • 1

when R •1 end ◦{1}

{ B }

17/20

slide-69
SLIDE 69

First Instant of ABRO in Microsteps

loop abort

  • (

( await A •1)

||

( await B •0) )•1 ;

( ( emit O ◦∅) ;

( halt ◦∅) ) ◦∅

  • 1

when R •1 end •1

{ B }

17/20

slide-70
SLIDE 70

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program ⊕ execution as annotations ⊕ correspondance with circuit states ⊖ two sets of rules ⊕ low-level local semantics ⊕ very close to circuits ⊕ no Can/Must ⊕ one set of rules ⊖ a lot of rules ⊖ no loop yet

18/20

slide-71
SLIDE 71

Global diagram of semantics

Constructive Semantics State Semantics Microstep Semantics Circuit Semantics

✦ ✦

⊕ closest to PL semantics ⊕ one small set of rules ⊖ modifies the program ⊕ execution as annotations ⊕ correspondance with circuit states ⊖ two sets of rules ⊕ low-level local semantics ⊕ very close to circuits ⊕ no Can/Must ⊕ one set of rules ⊖ a lot of rules ⊖ no loop yet

18/20

slide-72
SLIDE 72

Current state of the proofs

◮ Microsteps are still work in progress

◮ Non deterministic but confluent ◮ Hardest parts by far: ◮ Avoiding Can/Must ◮ Invariants to approximate valid microsteps executions ◮ Having the right design takes time: 1 iteration ≈ 1–2 months

◮ 15 admits left

◮ 5: Link Can/Must with microsteps ◮ 5: Coinduction with up-to techniques ◮ 2: Technical changes (setoid rewriting) ◮ 2: A bug with weak suspend? ◮ 1: Unused property

◮ What about reincarnation?

◮ = Avoid using twice the same wires/gates with different values ◮ Fixpoint semantics already avoid reuse

19/20

slide-73
SLIDE 73

Conclusion

◮ Same as last year

◮ All important elements are in place ◮ No real mistake found yet

weak suspend?

◮ Still work to do

who?

◮ Fixpoint semantics for other synchronous languages

Can we reuse the same proof ideas?

◮ Two years of formal proofs with Coq

◮ What is easy/hard? ◮ Easy part: just formalization to do

constructive → state

◮ Hard part: good design for formal proofs

state → micro

◮ Best representation is not obvious ◮ Sometimes different from the paper one! ◮ Months for each try

20/20

slide-74
SLIDE 74

Conclusion

◮ Same as last year

◮ All important elements are in place ◮ No real mistake found yet

weak suspend?

◮ Still work to do

who?

◮ Fixpoint semantics for other synchronous languages

Can we reuse the same proof ideas?

◮ Two years of formal proofs with Coq

◮ What is easy/hard? ◮ Easy part: just formalization to do

constructive → state

◮ Hard part: good design for formal proofs

state → micro

◮ Best representation is not obvious ◮ Sometimes different from the paper one! ◮ Months for each try

20/20